Преглед изворни кода

auto update script executed

Toby Chui пре 1 година
родитељ
комит
274d875731
2 измењених фајлова са 21 додато и 0 уклоњено
  1. 11 0
      mod/sshprox/utils.go
  2. 10 0
      router.go

+ 11 - 0
mod/sshprox/utils.go

@@ -3,9 +3,20 @@ package sshprox
 import (
 	"fmt"
 	"net"
+	"net/url"
 	"time"
 )
 
+//Rewrite url based on proxy root
+func RewriteURL(rooturl string, requestURL string) (*url.URL, error) {
+	rewrittenURL := requestURL
+	if len(requestURL) > len(rooturl) {
+		rewrittenURL = requestURL[len(rooturl):]
+	}
+
+	return url.Parse(rewrittenURL)
+}
+
 //Check if a given domain and port is a valid ssh server
 func IsSSHConnectable(ipOrDomain string, port int) bool {
 	timeout := time.Second * 3

+ 10 - 0
router.go

@@ -4,6 +4,8 @@ import (
 	"fmt"
 	"net/http"
 	"strings"
+
+	"imuslab.com/zoraxy/mod/sshprox"
 )
 
 /*
@@ -32,8 +34,16 @@ func AuthFsHandler(handler http.Handler) http.Handler {
 		if strings.HasPrefix(r.URL.Path, "/web.ssh/") {
 			parts := strings.Split(r.URL.Path, "/")
 			if len(parts) > 2 {
+				//Extract the instance ID from the request path
 				instanceUUID := parts[2]
 				fmt.Println(instanceUUID)
+
+				//Rewrite the url so the proxy knows how to serve stuffs
+				r.URL, _ = sshprox.RewriteURL("/web.ssh/"+instanceUUID, r.RequestURI)
+				webSshManager.HandleHttpByInstanceId(instanceUUID, w, r)
+			} else {
+				http.Error(w, "Invalid Usage", http.StatusInternalServerError)
+				return
 			}
 		}