|
@@ -6,6 +6,7 @@ import (
|
|
"net"
|
|
"net"
|
|
"sync"
|
|
"sync"
|
|
"sync/atomic"
|
|
"sync/atomic"
|
|
|
|
+ "time"
|
|
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/google/uuid"
|
|
"imuslab.com/zoraxy/mod/database"
|
|
"imuslab.com/zoraxy/mod/database"
|
|
@@ -88,6 +89,11 @@ func NewStreamProxy(options *Options) *Manager {
|
|
//Inject manager into the rules
|
|
//Inject manager into the rules
|
|
for _, rule := range previousRules {
|
|
for _, rule := range previousRules {
|
|
rule.parent = &thisManager
|
|
rule.parent = &thisManager
|
|
|
|
+ if rule.Running {
|
|
|
|
+ //This was previously running. Start it again
|
|
|
|
+ log.Println("[Stream Proxy] Resuming stream proxy rule " + rule.Name)
|
|
|
|
+ rule.Start()
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
thisManager.Configs = previousRules
|
|
thisManager.Configs = previousRules
|
|
@@ -164,6 +170,11 @@ func (m *Manager) EditConfig(configUUID string, newName string, newListeningAddr
|
|
|
|
|
|
m.SaveConfigToDatabase()
|
|
m.SaveConfigToDatabase()
|
|
|
|
|
|
|
|
+ //Check if config is running. If yes, restart it
|
|
|
|
+ if foundConfig.IsRunning() {
|
|
|
|
+ foundConfig.Restart()
|
|
|
|
+ }
|
|
|
|
+
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
@@ -196,13 +207,11 @@ func (c *ProxyRelayConfig) Start() error {
|
|
|
|
|
|
// Create a stopChan to control the loop
|
|
// Create a stopChan to control the loop
|
|
tcpStopChan := make(chan bool)
|
|
tcpStopChan := make(chan bool)
|
|
- c.tcpStopChan = tcpStopChan
|
|
|
|
-
|
|
|
|
udpStopChan := make(chan bool)
|
|
udpStopChan := make(chan bool)
|
|
- c.udpStopChan = udpStopChan
|
|
|
|
|
|
|
|
//Start the proxy service
|
|
//Start the proxy service
|
|
if c.UseUDP {
|
|
if c.UseUDP {
|
|
|
|
+ c.udpStopChan = udpStopChan
|
|
go func() {
|
|
go func() {
|
|
if !c.UseTCP {
|
|
if !c.UseTCP {
|
|
//By default running state shows TCP proxy. If TCP is not in use, UDP is shown instead
|
|
//By default running state shows TCP proxy. If TCP is not in use, UDP is shown instead
|
|
@@ -219,6 +228,7 @@ func (c *ProxyRelayConfig) Start() error {
|
|
}
|
|
}
|
|
|
|
|
|
if c.UseTCP {
|
|
if c.UseTCP {
|
|
|
|
+ c.tcpStopChan = tcpStopChan
|
|
go func() {
|
|
go func() {
|
|
//Default to transport mode
|
|
//Default to transport mode
|
|
c.Running = true
|
|
c.Running = true
|
|
@@ -235,25 +245,36 @@ func (c *ProxyRelayConfig) Start() error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-// Stop a running proxy if running
|
|
|
|
|
|
+// Return if a proxy config is running
|
|
func (c *ProxyRelayConfig) IsRunning() bool {
|
|
func (c *ProxyRelayConfig) IsRunning() bool {
|
|
return c.tcpStopChan != nil || c.udpStopChan != nil
|
|
return c.tcpStopChan != nil || c.udpStopChan != nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// Restart a proxy config
|
|
|
|
+func (c *ProxyRelayConfig) Restart() {
|
|
|
|
+ if c.IsRunning() {
|
|
|
|
+ c.Stop()
|
|
|
|
+ }
|
|
|
|
+ time.Sleep(300 * time.Millisecond)
|
|
|
|
+ c.Start()
|
|
|
|
+}
|
|
|
|
+
|
|
// Stop a running proxy if running
|
|
// Stop a running proxy if running
|
|
func (c *ProxyRelayConfig) Stop() {
|
|
func (c *ProxyRelayConfig) Stop() {
|
|
- log.Println("[PROXY] Stopping Stream Proxy " + c.Name)
|
|
|
|
|
|
+ log.Println("[STREAM PROXY] Stopping Stream Proxy " + c.Name)
|
|
|
|
|
|
if c.udpStopChan != nil {
|
|
if c.udpStopChan != nil {
|
|
|
|
+ log.Println("[STREAM PROXY] Stopping UDP for " + c.Name)
|
|
c.udpStopChan <- true
|
|
c.udpStopChan <- true
|
|
c.udpStopChan = nil
|
|
c.udpStopChan = nil
|
|
}
|
|
}
|
|
|
|
|
|
if c.tcpStopChan != nil {
|
|
if c.tcpStopChan != nil {
|
|
|
|
+ log.Println("[STREAM PROXY] Stopping TCP for " + c.Name)
|
|
c.tcpStopChan <- true
|
|
c.tcpStopChan <- true
|
|
c.tcpStopChan = nil
|
|
c.tcpStopChan = nil
|
|
}
|
|
}
|
|
|
|
|
|
- log.Println("[PROXY] Stopped Stream Proxy " + c.Name)
|
|
|
|
|
|
+ log.Println("[STREAM PROXY] Stopped Stream Proxy " + c.Name)
|
|
c.Running = false
|
|
c.Running = false
|
|
}
|
|
}
|