luci-app-ksmbd: add UI for multiple interfaces 6631/head
authorRani Hod <rani.hod@gmail.com>
Tue, 10 Oct 2023 11:48:22 +0000 (14:48 +0300)
committerRani Hod <rani.hod@gmail.com>
Tue, 10 Oct 2023 11:53:54 +0000 (14:53 +0300)
/etc/config/ksmbd supports multiple interfaces (in config globals->
option interface) but the current UI only supports selecting a single
one. This patch adds support for selecting multiple interfaces, based on
how luci-app-samba4 does it.

Closes: #6620
Suggested-by: @AndroKev
Signed-off-by: Rani Hod <rani.hod@gmail.com>
applications/luci-app-ksmbd/htdocs/luci-static/resources/view/ksmbd.js

index 3c94b15eb3a482d1a7315e8a2b50859c631a7efa..7408c33c44a1e4aea40e7c1a29db220f761e0dcf 100644 (file)
@@ -2,6 +2,7 @@
 'require view';
 'require fs';
 'require form';
+'require uci';
 'require tools.widgets as widgets';
 
 return view.extend({
@@ -32,8 +33,20 @@ return view.extend({
                s.tab('general',  _('General Settings'));
                s.tab('template', _('Edit Template'), _('Edit the template that is used for generating the ksmbd configuration.'));
 
-               s.taboption('general', widgets.NetworkSelect, 'interface', _('Interface'),
+               o = s.taboption('general', widgets.NetworkSelect, 'interface', _('Interface'),
                        _('Listen only on the given interface or, if unspecified, on lan'));
+               o.multiple = true;
+               o.cfgvalue = (section_id => L.toArray(uci.get('ksmbd', section_id, 'interface')));
+               o.write = function(section_id, formvalue) {
+                       var cfgvalue = this.cfgvalue(section_id),
+                           oldNetworks = L.toArray(cfgvalue),
+                           newNetworks = L.toArray(formvalue);
+                       oldNetworks.sort();
+                       newNetworks.sort();
+                       if (oldNetworks.join(' ') == newNetworks.join(' '))
+                               return;
+                       return uci.set('ksmbd', section_id, 'interface', newNetworks.join(' '));
+               };
 
                o = s.taboption('general', form.Value, 'workgroup', _('Workgroup'));
                o.placeholder = 'WORKGROUP';