Browse Source

auto update script executed

Toby Chui 1 year ago
parent
commit
823169c210
2 changed files with 12 additions and 3 deletions
  1. 6 2
      mod/sshprox/sshprox.go
  2. 6 1
      webssh.go

+ 6 - 2
mod/sshprox/sshprox.go

@@ -133,9 +133,13 @@ func (m *Manager) NewSSHProxy(binaryRoot string) (*Instance, error) {
 }
 
 //Create a new Connection to target address
-func (i *Instance) CreateNewConnection(listenPort int, remoteIpAddr string, remotePort int) error {
+func (i *Instance) CreateNewConnection(listenPort int, username string, remoteIpAddr string, remotePort int) error {
 	//Create a gotty instance
-	cmd := exec.Command(i.ExecPath, "-w", "-p", strconv.Itoa(listenPort), "--once", "ssh", remoteIpAddr, "-p", strconv.Itoa(remotePort))
+	connAddr := remoteIpAddr
+	if username != "" {
+		connAddr = username + "@" + remoteIpAddr
+	}
+	cmd := exec.Command(i.ExecPath, "-w", "-p", strconv.Itoa(listenPort), "--once", "ssh", connAddr, "-p", strconv.Itoa(remotePort))
 	cmd.Stdout = os.Stdout
 	cmd.Stderr = os.Stderr
 	go func() {

+ 6 - 1
webssh.go

@@ -29,6 +29,11 @@ func HandleCreateProxySession(w http.ResponseWriter, r *http.Request) {
 		portString = "22"
 	}
 
+	username, err := utils.GetPara(r, "username")
+	if err != nil {
+		username = ""
+	}
+
 	port, err := strconv.Atoi(portString)
 	if err != nil {
 		http.Error(w, "Invalid port number given", http.StatusInternalServerError)
@@ -49,7 +54,7 @@ func HandleCreateProxySession(w http.ResponseWriter, r *http.Request) {
 	}
 
 	//Create an ssh process to the target address
-	err = instance.CreateNewConnection(webSshManager.GetNextPort(), ipaddr, port)
+	err = instance.CreateNewConnection(webSshManager.GetNextPort(), username, ipaddr, port)
 	if err != nil {
 		http.Error(w, err.Error(), http.StatusInternalServerError)
 		return