luci-app-ttyd: add option for UNIX socket and URL override
authorRichard Yu <yurichard3839@gmail.com>
Mon, 25 Mar 2024 17:08:06 +0000 (01:08 +0800)
committerPaul Donald <itsascambutmailmeanyway+github@gmail.com>
Wed, 27 Mar 2024 01:01:20 +0000 (02:01 +0100)
Signed-off-by: Richard Yu <yurichard3839@gmail.com>
applications/luci-app-ttyd/htdocs/luci-static/resources/view/ttyd/config.js
applications/luci-app-ttyd/htdocs/luci-static/resources/view/ttyd/term.js

index 3ab453a0ab2c3a46627d4c8308a5aa0068217bfa..240b5140ebe7a728f301c623db19f9cba2455a74 100644 (file)
@@ -17,13 +17,22 @@ 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 = 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';
 
@@ -54,7 +63,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'));
 
@@ -78,6 +87,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.') + '<br />' +
+                       _('Note that reverse proxied pages is NOT protected by password like LuCI.') + '<br />' +
+                       _('Make sure to set up another authorization method.'));
+
                return m.render();
        }
 });
index 6ee712a0b748f690601f9b488eabbaa36e4eaa56..fac6da51a2373c3523f9db7ea72727b4311fe481 100644 (file)
@@ -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.<br />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;'
                });
        },