From 7f8d5e270a1a940ce2f73fe4c77f9328b48f929e Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 9 Jan 2025 20:30:14 +0900 Subject: [PATCH] enhanced wpx to handle ssh stuffs --- README.md | 2 +- server-proxy.go | 8 +++++++- server.go | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 01b659a..5385581 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ## normal operation - ./hodu server --rpc-on=0.0.0.0:9999 --ctl-on=0.0.0.0:8888 --pxy-on=0.0.0.0:9998 --wpx-on=0.0.0.0:9997 -- ./hodu client --rpc-to=127.0.0.1:9999 --ctl-on=127.0.0.1:7777 192.168.1.130:8000 +- ./hodu client --rpc-to=127.0.0.1:9999 --ctl-on=127.0.0.1:7777 "127.0.0.2:22,0.0.0.0:12345,ssh,Access SSH Server" ## server.json ``` diff --git a/server-proxy.go b/server-proxy.go index baf8738..fdbeed0 100644 --- a/server-proxy.go +++ b/server-proxy.go @@ -467,7 +467,13 @@ func (pxy *server_proxy_xterm_file) ServeHTTP(w http.ResponseWriter, req *http.R conn_id = req.PathValue("conn_id") route_id = req.PathValue("route_id") - _, err = s.FindServerRouteByIdStr(conn_id, route_id) + if conn_id == "" && route_id == "" { + conn_id = req.PathValue("port_id") + route_id = PORT_ID_MARKER + _, err = s.FindServerRouteByIdStr(conn_id, PORT_ID_MARKER) + } else { + _, err = s.FindServerRouteByIdStr(conn_id, route_id) + } if err != nil { status_code = http.StatusNotFound; w.WriteHeader(status_code) goto oops diff --git a/server.go b/server.go index a46893f..ab3eb04 100644 --- a/server.go +++ b/server.go @@ -57,6 +57,7 @@ type Server struct { pxy []*http.Server // proxy server wpx_addr []string + wpx_ws *server_proxy_ssh_ws wpx_mux *http.ServeMux wpx []*http.Server // proxy server than handles http/https only @@ -1088,6 +1089,25 @@ func NewServer(ctx context.Context, logger Logger, ctl_addrs []string, rpc_addrs // --------------------------------------------------------- s.wpx_mux = http.NewServeMux() + + s.wpx_ws = &server_proxy_ssh_ws{s: &s, id: "wpx-ssh"} + s.wpx_mux = http.NewServeMux() // TODO: make /_init,_ssh,_ssh_ws,_http configurable... + s.wpx_mux.Handle("/_ssh-ws/{conn_id}/{route_id}", + websocket.Handler(func(ws *websocket.Conn) { s.wpx_ws.ServeWebsocket(ws) })) + + s.wpx_mux.Handle("/_ssh/server-conns/{conn_id}/routes/{route_id}", + s.wrap_http_handler(&server_ctl_server_conns_id_routes_id{server_ctl{s: &s, id: "wpx"}})) + s.wpx_mux.Handle("/_ssh/xterm.js", + s.wrap_http_handler(&server_proxy_xterm_file{server_proxy: server_proxy{s: &s, id: "wpx"}, file: "xterm.js"})) + s.wpx_mux.Handle("/_ssh/xterm-addon-fit.js", + s.wrap_http_handler(&server_proxy_xterm_file{server_proxy: server_proxy{s: &s, id: "wpx"}, file: "xterm-addon-fit.js"})) + s.wpx_mux.Handle("/_ssh/xterm.css", + s.wrap_http_handler(&server_proxy_xterm_file{server_proxy: server_proxy{s: &s, id: "wpx"}, file: "xterm.css"})) + s.wpx_mux.Handle("/_ssh/{port_id}", + s.wrap_http_handler(&server_proxy_xterm_file{server_proxy: server_proxy{s: &s, id: "wpx"}, file: "xterm.html"})) + s.pxy_mux.Handle("/_ssh/", + s.wrap_http_handler(&server_proxy_xterm_file{server_proxy: server_proxy{s: &s, id: "wpx"}, file: "_forbidden"})) + s.wpx_mux.Handle("/{port_id}/{trailer...}", s.wrap_http_handler(&server_proxy_http_main{server_proxy: server_proxy{s: &s, id: "wpx"}, prefix: PORT_ID_MARKER})) s.wpx_mux.Handle("/",