mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-03 15:00:26 +08:00
优化代码
This commit is contained in:
@@ -469,11 +469,17 @@ func (this *HTTPRequest) configureWeb(web *serverconfigs.HTTPWebConfig, isTop bo
|
||||
if this.web.RequestScripts == nil {
|
||||
this.web.RequestScripts = web.RequestScripts
|
||||
} else {
|
||||
if web.RequestScripts.OnInitScript != nil && (web.RequestScripts.OnInitScript.IsPrior || isTop) {
|
||||
this.web.RequestScripts.OnInitScript = web.RequestScripts.OnInitScript
|
||||
if web.RequestScripts.InitGroup != nil && (web.RequestScripts.InitGroup.IsPrior || isTop) {
|
||||
if this.web.RequestScripts == nil {
|
||||
this.web.RequestScripts = &serverconfigs.HTTPRequestScriptsConfig{}
|
||||
}
|
||||
this.web.RequestScripts.InitGroup = web.RequestScripts.InitGroup
|
||||
}
|
||||
if web.RequestScripts.OnRequestScript != nil && (web.RequestScripts.OnRequestScript.IsPrior || isTop) {
|
||||
this.web.RequestScripts.OnRequestScript = web.RequestScripts.OnRequestScript
|
||||
if web.RequestScripts.RequestGroup != nil && (web.RequestScripts.RequestGroup.IsPrior || isTop) {
|
||||
if this.web.RequestScripts == nil {
|
||||
this.web.RequestScripts = &serverconfigs.HTTPRequestScriptsConfig{}
|
||||
}
|
||||
this.web.RequestScripts.RequestGroup = web.RequestScripts.RequestGroup
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -29,6 +30,8 @@ type ListenerManager struct {
|
||||
|
||||
retryListenerMap map[string]*Listener // 需要重试的监听器 addr => Listener
|
||||
ticker *time.Ticker
|
||||
|
||||
lastPortStrings string
|
||||
}
|
||||
|
||||
// NewListenerManager 获取新对象
|
||||
@@ -223,8 +226,7 @@ func (this *ListenerManager) addToFirewalld(groupAddrs []string) {
|
||||
return
|
||||
}
|
||||
|
||||
remotelogs.Println("FIREWALLD", "open ports automatically")
|
||||
|
||||
// 组合端口号
|
||||
var ports = []string{}
|
||||
for _, addr := range groupAddrs {
|
||||
var protocol = "tcp"
|
||||
@@ -242,11 +244,20 @@ func (this *ListenerManager) addToFirewalld(groupAddrs []string) {
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否有变化
|
||||
sort.Strings(ports)
|
||||
var newPortStrings = strings.Join(ports, ",")
|
||||
if newPortStrings == this.lastPortStrings {
|
||||
return
|
||||
}
|
||||
this.lastPortStrings = newPortStrings
|
||||
|
||||
firewallCmd, err := exec.LookPath("firewall-cmd")
|
||||
if err != nil || len(firewallCmd) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
remotelogs.Println("FIREWALLD", "open ports automatically")
|
||||
for _, port := range ports {
|
||||
{
|
||||
// TODO 需要支持sudo
|
||||
|
||||
Reference in New Issue
Block a user