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