From d092540f0864ce1851af4ccebe697fecee169002 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 22 Jun 2025 13:11:25 +0900 Subject: [PATCH] merged xterm.html and xterm-pts.html made relevant code changes oin the server side as well --- Makefile | 3 +- client-pts.go | 35 ++++-- client.go | 14 +-- cmd/config.go | 2 +- cmd/main.go | 16 +-- hodu.go | 8 +- server-pxy.go | 8 +- xterm-pts.html | 286 ------------------------------------------------- xterm.html | 74 ++++++++++--- 9 files changed, 107 insertions(+), 339 deletions(-) delete mode 100644 xterm-pts.html diff --git a/Makefile b/Makefile index 93d3186..e299718 100644 --- a/Makefile +++ b/Makefile @@ -33,8 +33,7 @@ DATA = \ xterm.css \ xterm.js \ xterm-addon-fit.js \ - xterm.html \ - xterm-pts.html + xterm.html CMD_DATA=\ cmd/rsa.key \ diff --git a/client-pts.go b/client-pts.go index 22dd87d..ca3186d 100644 --- a/client-pts.go +++ b/client-pts.go @@ -11,6 +11,7 @@ import "os/user" import "strconv" import "sync" import "syscall" +import "text/template" import "github.com/creack/pty" import "golang.org/x/net/websocket" @@ -276,7 +277,7 @@ done: func (pts *client_pts_xterm_file) ServeHTTP(w http.ResponseWriter, req *http.Request) (int, error) { var c *Client var status_code int -// var err error + var err error c = pts.c @@ -290,13 +291,27 @@ func (pts *client_pts_xterm_file) ServeHTTP(w http.ResponseWriter, req *http.Req case "xterm.css": status_code = WriteCssRespHeader(w, http.StatusOK) w.Write(xterm_css) - case "xterm-pts.html": - status_code = WriteHtmlRespHeader(w, http.StatusOK) - if c.xterm_pts_html != "" { - w.Write([]byte(c.xterm_pts_html)) - } else { - w.Write(xterm_pts_html) - } + case "xterm.html": + var tmpl *template.Template + + tmpl = template.New("") + if c.xterm_html != "" { + _, err = tmpl.Parse(c.xterm_html) + } else { + _, err = tmpl.Parse(xterm_html) + } + if err != nil { + status_code = WriteEmptyRespHeader(w, http.StatusInternalServerError) + goto oops + } else { + status_code = WriteHtmlRespHeader(w, http.StatusOK) + tmpl.Execute(w, + &xterm_session_info{ + Mode: "pts", + ConnId: "-1", + RouteId: "-1", + }) + } case "_forbidden": status_code = WriteEmptyRespHeader(w, http.StatusForbidden) @@ -311,6 +326,6 @@ func (pts *client_pts_xterm_file) ServeHTTP(w http.ResponseWriter, req *http.Req //done: return status_code, nil -//oops: -// return status_code, err +oops: + return status_code, err } diff --git a/client.go b/client.go index a061ec5..9518eec 100644 --- a/client.go +++ b/client.go @@ -151,7 +151,7 @@ type Client struct { pts_user string pts_shell string - xterm_pts_html string + xterm_html string } type ClientConnState = int32 @@ -1660,8 +1660,8 @@ func NewClient(ctx context.Context, name string, logger Logger, cfg *ClientConfi c.WrapHttpHandler(&client_pts_xterm_file{client_ctl: client_ctl{c: &c, id: HS_ID_CTL}, file: "_notfound"})) c.ctl_mux.Handle("/_pts/xterm.css", c.WrapHttpHandler(&client_pts_xterm_file{client_ctl: client_ctl{c: &c, id: HS_ID_CTL}, file: "xterm.css"})) - c.ctl_mux.Handle("/_pts/xterm-pts.html", - c.WrapHttpHandler(&client_pts_xterm_file{client_ctl: client_ctl{c: &c, id: HS_ID_CTL}, file: "xterm-pts.html"})) + c.ctl_mux.Handle("/_pts/xterm.html", + c.WrapHttpHandler(&client_pts_xterm_file{client_ctl: client_ctl{c: &c, id: HS_ID_CTL}, file: "xterm.html"})) c.ctl_mux.Handle("/_pts/", c.WrapHttpHandler(&client_pts_xterm_file{client_ctl: client_ctl{c: &c, id: HS_ID_CTL}, file: "_forbidden"})) c.ctl_mux.Handle("/_pts/favicon.ico", @@ -1977,12 +1977,12 @@ func (c *Client) ReqStop() { } } -func (c *Client) SetXtermPtsHtml(html string) { - c.xterm_pts_html = html +func (c *Client) SetXtermHtml(html string) { + c.xterm_html = html } -func (c *Client) GetXtermPtsHtml() string { - return c.xterm_pts_html +func (c *Client) GetXtermHtml() string { + return c.xterm_html } func (c *Client) SetPtsUser(user string) { diff --git a/cmd/config.go b/cmd/config.go index 988f7e9..94019b0 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -107,7 +107,7 @@ type ClientAppConfig struct { PeerConnTmout time.Duration `yaml:"peer-conn-timeout"` PtsUser string `yaml:"pts-user"` PtsShell string `yaml:"pts-shell"` - XtermPtsHtmlFile string `yaml:"xterm-pts-html-file"` + XtermHtmlFile string `yaml:"xterm-html-file"` } type ServerConfig struct { diff --git a/cmd/main.go b/cmd/main.go index 0e02934..cbe7730 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -254,8 +254,8 @@ func client_main(ctl_addrs []string, rpc_addrs []string, route_configs []string, var logfile_rotate int var pts_user string var pts_shell string - var xterm_pts_html_file string - var xterm_pts_html string + var xterm_html_file string + var xterm_html string var i int var err error @@ -287,7 +287,7 @@ func client_main(ctl_addrs []string, rpc_addrs []string, route_configs []string, logfile_rotate = cfg.APP.LogRotate pts_user = cfg.APP.PtsUser pts_shell = cfg.APP.PtsShell - xterm_pts_html_file = cfg.APP.XtermPtsHtmlFile + xterm_html_file = cfg.APP.XtermHtmlFile config.RpcConnMax = cfg.APP.MaxRpcConns config.PeerConnMax = cfg.APP.MaxPeers config.PeerConnTmout = cfg.APP.PeerConnTmout @@ -313,20 +313,20 @@ func client_main(ctl_addrs []string, rpc_addrs []string, route_configs []string, } } - if xterm_pts_html_file != "" { + if xterm_html_file != "" { var tmp []byte - tmp, err = os.ReadFile(xterm_pts_html_file) + tmp, err = os.ReadFile(xterm_html_file) if err != nil { - return fmt.Errorf("failed to read %s - %s", xterm_pts_html_file, err.Error()) + return fmt.Errorf("failed to read %s - %s", xterm_html_file, err.Error()) } - xterm_pts_html = string(tmp) + xterm_html = string(tmp) } c = hodu.NewClient(context.Background(), HODU_NAME, logger, config) if pts_user != "" { c.SetPtsUser(pts_user) } if pts_shell != "" { c.SetPtsShell(pts_shell) } - if xterm_pts_html != "" { c.SetXtermPtsHtml(xterm_pts_html) } + if xterm_html != "" { c.SetXtermHtml(xterm_html) } c.StartService(&cc) c.StartCtlService() // control channel diff --git a/hodu.go b/hodu.go index 8a03480..eec3c60 100644 --- a/hodu.go +++ b/hodu.go @@ -128,8 +128,12 @@ var xterm_addon_fit_js []byte var xterm_css []byte //go:embed xterm.html var xterm_html string -//go:embed xterm-pts.html -var xterm_pts_html []byte + +type xterm_session_info struct { + Mode string + ConnId string + RouteId string +} // --------------------------------------------------------- diff --git a/server-pxy.go b/server-pxy.go index 0ea853e..ac2c2c8 100644 --- a/server-pxy.go +++ b/server-pxy.go @@ -458,11 +458,6 @@ func (pxy *server_pxy_http_wpx) ServeHTTP(w http.ResponseWriter, req *http.Reque } // ------------------------------------ -type server_pxy_xterm_session_info struct { - ConnId string - RouteId string -} - func (pxy *server_pxy_xterm_file) ServeHTTP(w http.ResponseWriter, req *http.Request) (int, error) { var s *Server var status_code int @@ -516,7 +511,8 @@ func (pxy *server_pxy_xterm_file) ServeHTTP(w http.ResponseWriter, req *http.Req } else { status_code = WriteHtmlRespHeader(w, http.StatusOK) tmpl.Execute(w, - &server_pxy_xterm_session_info{ + &xterm_session_info{ + Mode: "ssh", ConnId: conn_id, RouteId: route_id, }) diff --git a/xterm-pts.html b/xterm-pts.html deleted file mode 100644 index 2bf15c7..0000000 --- a/xterm-pts.html +++ /dev/null @@ -1,286 +0,0 @@ - - - - - - -Terminal - - - - - - - - - - -
-
-
-
- - Click Connect below to start a new terminal session -

- -
-
-
- -
-
-
-
-
-
- -
-
-
-
- - diff --git a/xterm.html b/xterm.html index 46b0cb8..494a798 100644 --- a/xterm.html +++ b/xterm.html @@ -90,6 +90,7 @@