|
@@ -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))
|
|
|
+
|
|
|
+}
|