Przeglądaj źródła

auto update script executed

Toby Chui 1 rok temu
rodzic
commit
2736552124
4 zmienionych plików z 117 dodań i 0 usunięć
  1. 3 0
      api.go
  2. 5 0
      mod/tcpprox/conn.go
  3. 60 0
      mod/tcpprox/handler.go
  4. 49 0
      web/components/tcpprox.html

+ 3 - 0
api.go

@@ -107,6 +107,9 @@ func initAPIs() {
 	authRouter.HandleFunc("/api/tcpprox/config/add", tcpProxyManager.HandleAddProxyConfig)
 	authRouter.HandleFunc("/api/tcpprox/config/edit", tcpProxyManager.HandleEditProxyConfigs)
 	authRouter.HandleFunc("/api/tcpprox/config/list", tcpProxyManager.HandleListConfigs)
+	authRouter.HandleFunc("/api/tcpprox/config/start", tcpProxyManager.HandleStartProxy)
+	authRouter.HandleFunc("/api/tcpprox/config/stop", tcpProxyManager.HandleStopProxy)
+	authRouter.HandleFunc("/api/tcpprox/config/delete", tcpProxyManager.HandleRemoveProxy)
 	authRouter.HandleFunc("/api/tcpprox/config/status", tcpProxyManager.HandleGetProxyStatus)
 	authRouter.HandleFunc("/api/tcpprox/config/validate", tcpProxyManager.HandleConfigValidate)
 

+ 5 - 0
mod/tcpprox/conn.go

@@ -157,6 +157,11 @@ func (c *ProxyRelayConfig) Start() error {
 	return nil
 }
 
+// Stop a running proxy if running
+func (c *ProxyRelayConfig) IsRunning() bool {
+	return c.Running || c.stopChan != nil
+}
+
 // Stop a running proxy if running
 func (c *ProxyRelayConfig) Stop() {
 	if c.Running || c.stopChan != nil {

+ 60 - 0
mod/tcpprox/handler.go

@@ -122,6 +122,66 @@ func (m *Manager) HandleListConfigs(w http.ResponseWriter, r *http.Request) {
 	utils.SendJSONResponse(w, string(js))
 }
 
+func (m *Manager) HandleStartProxy(w http.ResponseWriter, r *http.Request) {
+	uuid, err := utils.PostPara(r, "uuid")
+	if err != nil {
+		utils.SendErrorResponse(w, "invalid uuid given")
+		return
+	}
+
+	targetProxyConfig, err := m.GetConfigByUUID(uuid)
+	if err != nil {
+		utils.SendErrorResponse(w, err.Error())
+		return
+	}
+
+	err = targetProxyConfig.Start()
+	if err != nil {
+		utils.SendErrorResponse(w, err.Error())
+		return
+	}
+
+	utils.SendOK(w)
+}
+
+func (m *Manager) HandleStopProxy(w http.ResponseWriter, r *http.Request) {
+	uuid, err := utils.PostPara(r, "uuid")
+	if err != nil {
+		utils.SendErrorResponse(w, "invalid uuid given")
+		return
+	}
+
+	targetProxyConfig, err := m.GetConfigByUUID(uuid)
+	if err != nil {
+		utils.SendErrorResponse(w, err.Error())
+		return
+	}
+
+	if !targetProxyConfig.IsRunning() {
+		utils.SendErrorResponse(w, "target proxy service is not running")
+		return
+	}
+
+	targetProxyConfig.Stop()
+	utils.SendOK(w)
+}
+
+func (m *Manager) HandleRemoveProxy(w http.ResponseWriter, r *http.Request) {
+	uuid, err := utils.PostPara(r, "uuid")
+	if err != nil {
+		utils.SendErrorResponse(w, "invalid uuid given")
+		return
+	}
+
+	targetProxyConfig, err := m.GetConfigByUUID(uuid)
+	if err != nil {
+		utils.SendErrorResponse(w, err.Error())
+		return
+	}
+
+	m.RemoveConfig(targetProxyConfig.UUID)
+}
+
 func (m *Manager) HandleGetProxyStatus(w http.ResponseWriter, r *http.Request) {
 	uuid, err := utils.GetPara(r, "uuid")
 	if err != nil {

+ 49 - 0
web/components/tcpprox.html

@@ -177,6 +177,7 @@
             
         function clearTCPProxyAddEditForm(){
             $('#tcpProxyForm input, #tcpProxyForm select').val('');
+            $('#tcpProxyForm select').dropdown('clear');
         }
 
         function validateTCPProxyConfig(form){
@@ -342,7 +343,55 @@
         }
 
         function deleteTCPProxyConfig(configUUID){
+            $.ajax({
+                url: "/api/tcpprox/config/delete",
+                method: "POST",
+                data: {uuid: configUUID},
+                success: function(data){
+                    if (data.error != undefined){
+                        msgbox(data.error, false, 6000);
+                    }else{
+                        msgbox("Proxy Config Removed");
+                        initProxyConfigList();
+                    }
+                }
+            })
+        }
 
+        //Start a TCP proxy by their config UUID
+        function startTcpProx(configUUID){
+            $.ajax({
+                url: "/api/tcpprox/config/start",
+                method: "POST",
+                data: {uuid: configUUID},
+                success: function(data){
+                    if (data.error != undefined){
+                        msgbox(data.error, false, 6000);
+                    }else{
+                        msgbox("Service Started");
+                        initProxyConfigList();
+                    }
+                }
+
+            });
+        }
+
+        //Stop a TCP proxy by their config UUID
+        function stopTcpProx(configUUID){
+            $.ajax({
+                url: "/api/tcpprox/config/stop",
+                method: "POST",
+                data: {uuid: configUUID},
+                success: function(data){
+                    if (data.error != undefined){
+                        msgbox(data.error, false, 6000);
+                    }else{
+                        msgbox("Service Stopped");
+                        initProxyConfigList();
+                    }
+                }
+
+            });
         }
 
         function initProxyConfigList(){