123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- package main
- import (
- "encoding/json"
- "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 !*allowSshLoopback {
-
- if strings.EqualFold(strings.TrimSpace(ipaddr), "localhost") || strings.TrimSpace(ipaddr) == "127.0.0.1" {
-
- utils.SendErrorResponse(w, "loopback web ssh connection is not enabled on this host")
- return
- }
- }
-
- if !sshprox.IsSSHConnectable(ipaddr, port) {
- utils.SendErrorResponse(w, ipaddr+":"+strconv.Itoa(port)+" is not a valid SSH server")
- return
- }
-
- instance, err := webSshManager.NewSSHProxy("./tmp/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 HandleWebSshSupportCheck(w http.ResponseWriter, r *http.Request) {
- domain, err := utils.PostPara(r, "domain")
- if err != nil {
-
- isSupport := sshprox.IsWebSSHSupported()
- js, _ := json.Marshal(isSupport)
- utils.SendJSONResponse(w, string(js))
- } else {
-
- portString, err := utils.PostPara(r, "port")
- if err != nil {
- portString = "22"
- }
- port, err := strconv.Atoi(portString)
- if err != nil {
- utils.SendErrorResponse(w, "invalid port number given")
- return
- }
- if port < 1 || port > 65534 {
- utils.SendErrorResponse(w, "invalid port number given")
- return
- }
- looksLikeSSHServer := sshprox.IsSSHConnectable(domain, port)
- js, _ := json.Marshal(looksLikeSSHServer)
- utils.SendJSONResponse(w, string(js))
- }
- }
|