mirror of
https://github.com/tobychui/zoraxy.git
synced 2025-06-03 06:07:20 +02:00
parent
bfd64a885e
commit
eeb438eb18
@ -157,3 +157,13 @@ func resolveIpFromDomain(targetIpOrDomain string) string {
|
|||||||
|
|
||||||
return targetIpAddrString
|
return targetIpAddrString
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the given port is already used by another process
|
||||||
|
func CheckIfPortOccupied(portNumber int) bool {
|
||||||
|
listener, err := net.Listen("tcp", ":"+strconv.Itoa(portNumber))
|
||||||
|
if err != nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
listener.Close()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"imuslab.com/zoraxy/mod/dynamicproxy/loadbalance"
|
"imuslab.com/zoraxy/mod/dynamicproxy/loadbalance"
|
||||||
"imuslab.com/zoraxy/mod/dynamicproxy/permissionpolicy"
|
"imuslab.com/zoraxy/mod/dynamicproxy/permissionpolicy"
|
||||||
"imuslab.com/zoraxy/mod/dynamicproxy/rewrite"
|
"imuslab.com/zoraxy/mod/dynamicproxy/rewrite"
|
||||||
|
"imuslab.com/zoraxy/mod/netutils"
|
||||||
"imuslab.com/zoraxy/mod/uptime"
|
"imuslab.com/zoraxy/mod/uptime"
|
||||||
"imuslab.com/zoraxy/mod/utils"
|
"imuslab.com/zoraxy/mod/utils"
|
||||||
)
|
)
|
||||||
@ -28,10 +29,22 @@ func ReverseProxtInit() {
|
|||||||
Load Reverse Proxy Global Settings
|
Load Reverse Proxy Global Settings
|
||||||
*/
|
*/
|
||||||
inboundPort := 443
|
inboundPort := 443
|
||||||
|
autoStartReverseProxy := true
|
||||||
if sysdb.KeyExists("settings", "inbound") {
|
if sysdb.KeyExists("settings", "inbound") {
|
||||||
|
//Read settings from database
|
||||||
sysdb.Read("settings", "inbound", &inboundPort)
|
sysdb.Read("settings", "inbound", &inboundPort)
|
||||||
SystemWideLogger.Println("Serving inbound port ", inboundPort)
|
if netutils.CheckIfPortOccupied(inboundPort) {
|
||||||
|
autoStartReverseProxy = false
|
||||||
|
SystemWideLogger.Println("Inbound port ", inboundPort, " is occupied. Change the listening port in the webmin panel and press \"Start Service\" to start reverse proxy service")
|
||||||
|
} else {
|
||||||
|
SystemWideLogger.Println("Serving inbound port ", inboundPort)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
//Default port
|
||||||
|
if netutils.CheckIfPortOccupied(inboundPort) {
|
||||||
|
inboundPort = 8743
|
||||||
|
SystemWideLogger.Println("Port 443 is occupied. Switching to backup port 8743 instead")
|
||||||
|
}
|
||||||
SystemWideLogger.Println("Inbound port not set. Using default (443)")
|
SystemWideLogger.Println("Inbound port not set. Using default (443)")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,6 +73,9 @@ func ReverseProxtInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
listenOnPort80 := true
|
listenOnPort80 := true
|
||||||
|
if netutils.CheckIfPortOccupied(80) {
|
||||||
|
listenOnPort80 = false
|
||||||
|
}
|
||||||
sysdb.Read("settings", "listenP80", &listenOnPort80)
|
sysdb.Read("settings", "listenP80", &listenOnPort80)
|
||||||
if listenOnPort80 {
|
if listenOnPort80 {
|
||||||
SystemWideLogger.Println("Port 80 listener enabled")
|
SystemWideLogger.Println("Port 80 listener enabled")
|
||||||
@ -136,9 +152,11 @@ func ReverseProxtInit() {
|
|||||||
//Start Service
|
//Start Service
|
||||||
//Not sure why but delay must be added if you have another
|
//Not sure why but delay must be added if you have another
|
||||||
//reverse proxy server in front of this service
|
//reverse proxy server in front of this service
|
||||||
time.Sleep(300 * time.Millisecond)
|
if autoStartReverseProxy {
|
||||||
dynamicProxyRouter.StartProxyService()
|
time.Sleep(300 * time.Millisecond)
|
||||||
SystemWideLogger.Println("Dynamic Reverse Proxy service started")
|
dynamicProxyRouter.StartProxyService()
|
||||||
|
SystemWideLogger.Println("Dynamic Reverse Proxy service started")
|
||||||
|
}
|
||||||
|
|
||||||
//Add all proxy services to uptime monitor
|
//Add all proxy services to uptime monitor
|
||||||
//Create a uptime monitor service
|
//Create a uptime monitor service
|
||||||
|
Loading…
x
Reference in New Issue
Block a user