enhanced wpx to handle ssh stuffs

This commit is contained in:
hyung-hwan 2025-01-09 20:30:14 +09:00
parent 26c40ea70e
commit 7f8d5e270a
3 changed files with 28 additions and 2 deletions

View File

@ -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
```

View File

@ -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

View File

@ -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("/",