1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package main
- import (
- "encoding/json"
- "fmt"
- "net/http"
- "strconv"
- "strings"
- "imuslab.com/zoraxy/mod/sshprox"
- "imuslab.com/zoraxy/mod/utils"
- )
- func HandleCreateProxySession(w http.ResponseWriter, r *http.Request) {
-
- ipaddr, err := utils.PostPara(r, "ipaddr")
- if err != nil {
- http.Error(w, "Invalid Usage", http.StatusInternalServerError)
- return
- }
- portString, err := utils.PostPara(r, "port")
- if err != nil {
- portString = "22"
- }
- username, err := utils.PostPara(r, "username")
- if err != nil {
- username = ""
- }
- port, err := strconv.Atoi(portString)
- if err != nil {
- utils.SendErrorResponse(w, "invalid port number given")
- return
- }
-
- if !sshprox.IsSSHConnectable(ipaddr, port) {
- utils.SendErrorResponse(w, ipaddr+":"+strconv.Itoa(port)+" is not a valid SSH server")
- return
- }
-
- instance, err := webSshManager.NewSSHProxy("./system/gotty")
- if err != nil {
- utils.SendErrorResponse(w, strings.ReplaceAll(err.Error(), "\\", "/"))
- return
- }
-
- err = instance.CreateNewConnection(webSshManager.GetNextPort(), username, ipaddr, port)
- if err != nil {
- utils.SendErrorResponse(w, err.Error())
- return
- }
-
- js, _ := json.Marshal(instance.UUID)
- utils.SendJSONResponse(w, string(js))
- }
- func HandleTest(w http.ResponseWriter, r *http.Request) {
- fmt.Println(sshprox.IsSSHConnectable("192.168.1.120", 22))
- }
|