Преглед на файлове

auto update script executed

Toby Chui преди 2 години
родител
ревизия
c3232874f1
променени са 11 файла, в които са добавени 80 реда и са изтрити 22 реда
  1. 4 3
      config.go
  2. 5 2
      main.go
  3. 4 2
      mod/dynamicproxy/dynamicproxy.go
  4. 42 10
      reverseproxy.go
  5. BIN
      sys.db
  6. BIN
      web/img/00233.png
  7. BIN
      web/img/desktop_icon.png
  8. BIN
      web/img/desktop_icon.psd
  9. BIN
      web/img/small_icon.png
  10. BIN
      web/img/small_icon.psd
  11. 25 5
      web/index.html

+ 4 - 3
config.go

@@ -35,9 +35,10 @@ func SaveReverseProxyConfig(ptype string, rootname string, proxyTarget string, u
 
 func RemoveReverseProxyConfig(rootname string) error {
 	filename := getFilenameFromRootName(rootname)
-	log.Println("Config Removed: ", filepath.Join("conf", filename))
-	if fileExists(filepath.Join("conf", filename)) {
-		err := os.Remove(filepath.Join("conf", filename))
+	removePendingFile := strings.ReplaceAll(filepath.Join("conf", filename), "\\", "/")
+	log.Println("Config Removed: ", removePendingFile)
+	if fileExists(removePendingFile) {
+		err := os.Remove(removePendingFile)
 		if err != nil {
 			log.Println(err.Error())
 			return err

+ 5 - 2
main.go

@@ -36,7 +36,7 @@ func main() {
 		Desc:        "Basic reverse proxy listener",
 		Group:       "Network",
 		IconPath:    "reverseproxy/img/small_icon.png",
-		Version:     "0.1",
+		Version:     "0.3",
 		StartDir:    "reverseproxy/index.html",
 		SupportFW:   true,
 		LaunchFWDir: "reverseproxy/index.html",
@@ -59,13 +59,16 @@ func main() {
 
 	sysdb = db
 
+	//Create tables for the database
+	sysdb.NewTable("settings")
+
 	//Start the reverse proxy server in go routine
 	go func() {
 		ReverseProxtInit()
 	}()
 
 	//Any log println will be shown in the core system via STDOUT redirection. But not STDIN.
-	log.Println("ReverseProxy started. Listening on " + handler.Port)
+	log.Println("ReverseProxy started. Control Panel hosted on " + handler.Port)
 	err = http.ListenAndServe(handler.Port, nil)
 	if err != nil {
 		log.Fatal(err)

+ 4 - 2
mod/dynamicproxy/dynamicproxy.go

@@ -3,6 +3,7 @@ package dynamicproxy
 import (
 	"context"
 	"errors"
+	"fmt"
 	"log"
 	"net/http"
 	"net/url"
@@ -85,8 +86,8 @@ func (router *Router) StartProxyService() error {
 	router.server = &http.Server{Addr: ":" + strconv.Itoa(router.ListenPort), Handler: router.mux}
 	router.Running = true
 	go func() {
-		err := router.server.ListenAndServe()
-		log.Println("[DynamicProxy] " + err.Error())
+		router.server.ListenAndServe()
+		//log.Println("[DynamicProxy] " + err.Error())
 	}()
 
 	return nil
@@ -153,6 +154,7 @@ func (router *Router) AddVirtualDirectoryProxyService(rootname string, domain st
 
 */
 func (router *Router) RemoveProxy(ptype string, key string) error {
+	fmt.Println(ptype, key)
 	if ptype == "vdir" {
 		router.ProxyEndpoints.Delete(key)
 		return nil

+ 42 - 10
reverseproxy.go

@@ -5,6 +5,7 @@ import (
 	"log"
 	"net/http"
 	"path/filepath"
+	"strconv"
 
 	"imuslab.com/arozos/ReverseProxy/mod/dynamicproxy"
 )
@@ -15,7 +16,14 @@ var (
 
 //Add user customizable reverse proxy
 func ReverseProxtInit() {
-	dprouter, err := dynamicproxy.NewDynamicProxy(80)
+	inboundPort := 80
+	if sysdb.KeyExists("settings", "inbound") {
+		sysdb.Read("settings", "inbound", &inboundPort)
+		log.Println("Serving inbound port ", inboundPort)
+	} else {
+		log.Println("Inbound port not set. Using default (80)")
+	}
+	dprouter, err := dynamicproxy.NewDynamicProxy(inboundPort)
 	if err != nil {
 		log.Println(err.Error())
 		return
@@ -29,6 +37,8 @@ func ReverseProxtInit() {
 	http.HandleFunc("/list", ReverseProxyList)
 	http.HandleFunc("/del", DeleteProxyEndpoint)
 
+	http.HandleFunc("/setIncoming", HandleIncomingPortSet)
+
 	//Load all conf from files
 	confs, _ := filepath.Glob("./conf/*.config")
 	for _, conf := range confs {
@@ -59,15 +69,7 @@ func ReverseProxtInit() {
 
 	//Start Service
 	dynamicProxyRouter.StartProxyService()
-
-	/*
-		go func() {
-			time.Sleep(10 * time.Second)
-			dynamicProxyRouter.StopProxyService()
-			fmt.Println("Proxy stopped")
-		}()
-	*/
-	log.Println("Dynamic Proxy service started")
+	log.Println("Dynamic Reverse Proxy service started")
 
 }
 
@@ -199,3 +201,33 @@ func ReverseProxyList(w http.ResponseWriter, r *http.Request) {
 		sendErrorResponse(w, "Invalid type given")
 	}
 }
+
+//Handle incoming port set. Change the current proxy incoming port
+func HandleIncomingPortSet(w http.ResponseWriter, r *http.Request) {
+	newIncomingPort, err := mv(r, "incoming", true)
+	if err != nil {
+		sendErrorResponse(w, "invalid incoming port given")
+		return
+	}
+
+	newIncomingPortInt, err := strconv.Atoi(newIncomingPort)
+	if err != nil {
+		sendErrorResponse(w, "invalid incoming port given")
+		return
+	}
+
+	//Stop and change the setting of the reverse proxy service
+	if dynamicProxyRouter.Running {
+		dynamicProxyRouter.StopProxyService()
+		dynamicProxyRouter.ListenPort = newIncomingPortInt
+		dynamicProxyRouter.StartProxyService()
+	} else {
+		//Only change setting but not starting the proxy service
+		dynamicProxyRouter.ListenPort = newIncomingPortInt
+	}
+
+	sysdb.Write("settings", "inbound", newIncomingPortInt)
+
+	sendOK((w))
+
+}

BIN
sys.db


BIN
web/img/00233.png


BIN
web/img/desktop_icon.png


BIN
web/img/desktop_icon.psd


BIN
web/img/small_icon.png


BIN
web/img/small_icon.psd


+ 25 - 5
web/index.html

@@ -24,7 +24,7 @@
     <body>
         <br>
         <div class="ui container">
-            <h3><img class="ui middle aligned mini image" src="img/desktop_icon.png" style="margin-right: 4px;"> Reverse Proxy Settings</h3>
+            <h3><img class="ui middle aligned mini image" src="img/small_icon.png" style="margin-right:1em;"> Reverse Proxy Settings</h3>
             <div class="ui divider"></div>
             <div id="errmsg" class="ui red message" style="display: none;"></div>
             <div class="ui stackable grid">
@@ -48,13 +48,11 @@
                     </div>
                 </div>
                 <div class="twelve wide column">
-                   
-                    
                     <!-- Status Tab -->
                     <div id="status" class="functiontab">
                         <div id="serverstatus" class="ui message">
                             <h3 class="ui header">
-                                <i class="power off icon"></i>
+                                <i class="exchange icon"></i>
                                 <div class="content">
                                   <span id="statusTitle">Offline</span>
                                   <div class="sub header" id="statusText">Reverse proxy server is offline</div>
@@ -62,6 +60,12 @@
                             </h3>
                         </div>
                         <div class="ui divider"></div>
+                        <p>Inbound Port (Port to be proxied)</p>
+                        <div class="ui action fluid input">
+                            <input type="text" id="incomingPort" placeholder="Incoming Port" value="80">
+                            <button class="ui button" onclick="handlePortChange();">Apply</button>
+                        </div>
+                        <Br>
                         <button id="startbtn" class="ui teal button" onclick="startService();">Start Service</button>
                         <button id="stopbtn" class="ui red disabled button" onclick="stopService();">Stop Service</button>
                     </div>
@@ -214,6 +218,7 @@
                         $("#statusText").text("Reverse proxy server is offline");
                         $("#serverstatus").removeClass("green");
                     }
+                    $("#incomingPort").val(data.ListenPort);
                 });
             }
 
@@ -249,6 +254,21 @@
                 });
             }
 
+            function handlePortChange(){
+                var newPortValue = $("#incomingPort").val();
+                if (isNaN(newPortValue - 1)){
+                    alert("Invalid incoming port value");
+                    return;
+                }
+
+                $.post("setIncoming", {incoming: newPortValue}, function(data){
+                    if (data.error != undefined){
+                        errmsg(data.error);
+                    }
+                    initRPStaste();
+                });
+            }
+
             //Virtual directories functions
             listVdirs();
             function listVdirs(){
@@ -271,7 +291,7 @@
                             $("#vdirList").append(`<tr>
                                 <td data-label="">${vdir.Root}</td>
                                 <td data-label="">${vdir.Domain} ${tlsIcon}</td>
-                                <td data-label=""><button class="ui circular mini red basic button"  onclick='deleteEndpoint("subd","${subd.Root}")'><i class="remove icon"></i> Remove Vdir</button></td>
+                                <td data-label=""><button class="ui circular mini red basic button"  onclick='deleteEndpoint("vdir","${vdir.Root}")'><i class="remove icon"></i> Remove Vdir</button></td>
                             </tr>`);
                         });
                     }