From 7be64d543de046b80ae7987fa0276e6caa302351 Mon Sep 17 00:00:00 2001 From: Richard Yu Date: Tue, 26 Mar 2024 01:08:06 +0800 Subject: [PATCH] luci-app-ttyd: add option for UNIX socket and URL override Signed-off-by: Richard Yu (cherry picked from commit 9f3ae08703e23d7395ef9daa05ab1000dde09152) --- .../luci-static/resources/view/ttyd/config.js | 18 ++++++++++++++++-- .../luci-static/resources/view/ttyd/term.js | 5 +++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/applications/luci-app-ttyd/htdocs/luci-static/resources/view/ttyd/config.js b/applications/luci-app-ttyd/htdocs/luci-static/resources/view/ttyd/config.js index d4c0a57b75..e302e651eb 100644 --- a/applications/luci-app-ttyd/htdocs/luci-static/resources/view/ttyd/config.js +++ b/applications/luci-app-ttyd/htdocs/luci-static/resources/view/ttyd/config.js @@ -17,14 +17,23 @@ return view.extend({ o = s.option(form.Flag, 'enable', _('Enable')); o.default = true; + s.option(form.Flag, 'unix_sock', _('UNIX socket'), _('Bind to UNIX domain socket instead of IP port')); + o = s.option(form.Value, 'port', _('Port'), _('Port to listen (default: 7681, use `0` for random port)')); + o.depends('unix_sock', '0'); o.datatype = 'port'; o.placeholder = 7681; - o = s.option(widgets.DeviceSelect, 'interface', _('Interface'), _('Network interface to bind (eg: eth0), or UNIX domain socket path (eg: /var/run/ttyd.sock)')); + o = s.option(widgets.DeviceSelect, 'interface', _('Interface'), _('Network interface to bind (eg: eth0)')); + o.depends('unix_sock', '0'); o.nocreate = true; o.unspecified = true; + o = s.option(form.Value, '_unix_sock_path', _('UNIX socket path'), _('UNIX domain socket path (eg: /var/run/ttyd.sock)')); + o.depends('unix_sock', '1'); + o.ucioption = 'interface'; + o.retain = true; + o = s.option(form.Value, 'credential', _('Credential'), _('Credential for Basic Authentication')); o.placeholder = 'username:password'; @@ -55,7 +64,7 @@ return view.extend({ s.option(form.Flag, 'once', _('Once'), _('Accept only one client and exit on disconnection')); - o = s.option(form.Value, 'index', _('Index'), _('Custom index.html path')); + s.option(form.Value, 'index', _('Index'), _('Custom index.html path')); s.option(form.Flag, 'ipv6', _('IPv6'), _('Enable IPv6 support')); @@ -79,6 +88,11 @@ return view.extend({ s.option(form.Value, 'command', _('Command')); + s.option(form.Value, 'url_override', _('URL override'), + _('Override URL in Terminal tab. For use with reverse proxy.') + '
' + + _('Note that reverse proxied pages is NOT protected by password like LuCI.') + '
' + + _('Make sure to set up another authorization method.')); + return m.render(); } }); diff --git a/applications/luci-app-ttyd/htdocs/luci-static/resources/view/ttyd/term.js b/applications/luci-app-ttyd/htdocs/luci-static/resources/view/ttyd/term.js index 6ee712a0b7..fac6da51a2 100644 --- a/applications/luci-app-ttyd/htdocs/luci-static/resources/view/ttyd/term.js +++ b/applications/luci-app-ttyd/htdocs/luci-static/resources/view/ttyd/term.js @@ -8,12 +8,13 @@ return view.extend({ }, render: function() { var port = uci.get_first('ttyd', 'ttyd', 'port') || '7681', - ssl = uci.get_first('ttyd', 'ttyd', 'ssl') || '0'; + ssl = uci.get_first('ttyd', 'ttyd', 'ssl') || '0', + url = uci.get_first('ttyd', 'ttyd', 'url_override'); if (port === '0') return E('div', { class: 'alert-message warning' }, _('Random ttyd port (port=0) is not supported.
Change to a fixed port and try again.')); return E('iframe', { - src: (ssl === '1' ? 'https' : 'http') + '://' + window.location.hostname + ':' + port, + src: url || ((ssl === '1' ? 'https' : 'http') + '://' + window.location.hostname + ':' + port), style: 'width: 100%; min-height: 500px; border: none; border-radius: 3px; resize: vertical;' }); }, -- 2.30.2