protocols: replace luci/getTTYDevices calls with generic file/list ones
authorJo-Philipp Wich <jo@mein.io>
Sun, 8 Sep 2019 14:12:25 +0000 (16:12 +0200)
committerJo-Philipp Wich <jo@mein.io>
Tue, 10 Sep 2019 13:29:04 +0000 (15:29 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/root/usr/libexec/rpcd/luci
modules/luci-base/root/usr/share/rpcd/acl.d/luci-base.json
protocols/luci-proto-3g/htdocs/luci-static/resources/protocol/3g.js
protocols/luci-proto-ncm/htdocs/luci-static/resources/protocol/ncm.js
protocols/luci-proto-ppp/htdocs/luci-static/resources/protocol/ppp.js
protocols/luci-proto-qmi/htdocs/luci-static/resources/protocol/qmi.js

index ab6a7ecfeebaacd491bea4050644ca29d04cff53..b8243b8272719402df4f3de4a8a35b5ee85a9092 100755 (executable)
@@ -479,40 +479,6 @@ local methods = {
                        end
                        return { result = hostname:gsub("\n$", "") }
                end
-       },
-
-       getTTYDevices = {
-               args = { with_cdc = false, with_tts = true },
-               call = function(args)
-                       local fs = require "nixio.fs"
-                       local iter = fs.glob("/dev/tty[A-Z]*")
-                       local rv = {}
-                       if iter then
-                               local node
-                               for node in iter do
-                                       rv[#rv+1] = node
-                               end
-                       end
-                       if args.with_tts then
-                               iter = fs.glob("/dev/tts/*")
-                               if iter then
-                                       local node
-                                       for node in iter do
-                                               rv[#rv+1] = node
-                                       end
-                               end
-                       end
-                       if args.with_cdc then
-                               iter = fs.glob("/dev/cdc-wdm*")
-                               if iter then
-                                       local node
-                                       for node in iter do
-                                               rv[#rv+1] = node
-                                       end
-                               end
-                       end
-                       return { result = rv }
-               end
        }
 }
 
index d05ba841e48ec7ab8e2c9d85cc225fc0cf12c7fc..417296a394e6c4f5be62bd4da5deb9e091183c93 100644 (file)
@@ -27,7 +27,7 @@
                        "ubus": {
                                "file": [ "list", "stat" ],
                                "iwinfo": [ "assoclist", "freqlist", "txpowerlist", "countrylist" ],
-                               "luci": [ "getBoardJSON", "getDUIDHints", "getHostHints", "getIfaddrs", "getInitList", "getLocaltime", "getTimezones", "getDHCPLeases", "getLEDs", "getNetworkDevices", "getUSBDevices", "getHostname", "getTTYDevices", "getWirelessDevices" ],
+                               "luci": [ "getBoardJSON", "getDUIDHints", "getHostHints", "getIfaddrs", "getInitList", "getLocaltime", "getTimezones", "getDHCPLeases", "getLEDs", "getNetworkDevices", "getUSBDevices", "getHostname", "getWirelessDevices" ],
                                "network.device": [ "status" ],
                                "network.interface": [ "dump" ],
                                "network": [ "get_proto_handlers" ],
index d1273ce563fd68ff7745955b8be4814d7ff3dcac..07bed36c23aedec1fedad9d0d08ee8c40620b72c 100644 (file)
@@ -4,11 +4,18 @@
 'require form';
 'require network';
 
-var callTTYDevices = rpc.declare({
-       object: 'luci',
-       method: 'getTTYDevices',
-       params: [ 'with_cdc', 'with_tts' ],
-       expect: { result: [] }
+var callFileList = rpc.declare({
+       object: 'file',
+       method: 'list',
+       params: [ 'path' ],
+       expect: { entries: [] },
+       filter: function(list, params) {
+               var rv = [];
+               for (var i = 0; i < list.length; i++)
+                       if (list[i].name.match(/^tty[A-Z]/) || list[i].name.match(/^cdc-wdm/) || list[i].name.match(/^[0-9]+$/))
+                               rv.push(params.path + list[i].name);
+               return rv.sort();
+       }
 });
 
 network.registerPatternVirtual(/^3g-.+$/);
@@ -66,11 +73,13 @@ return network.registerProtocol('3g', {
                o = s.taboption('general', form.Value, 'device', _('Modem device'));
                o.rmempty = false;
                o.load = function(section_id) {
-                       return callTTYDevices(false, true).then(L.bind(function(devices) {
-                               if (Array.isArray(devices))
-                                       for (var i = 0; i < devices.length; i++)
-                                               this.value(devices[i]);
-
+                       return callFileList('/dev/').then(L.bind(function(devices) {
+                               for (var i = 0; i < devices.length; i++)
+                                       this.value(devices[i]);
+                               return callFileList('/dev/tts/');
+                       }, this)).then(L.bind(function(devices) {
+                               for (var i = 0; i < devices.length; i++)
+                                       this.value(devices[i]);
                                return form.Value.prototype.load.apply(this, [section_id]);
                        }, this));
                };
index ba673b4a0bf031c9379b96bd6141359818c01cce..3ab6c01d61e631e96b4bce87f816373c665791fa 100644 (file)
@@ -3,11 +3,18 @@
 'require form';
 'require network';
 
-var callTTYDevices = rpc.declare({
-       object: 'luci',
-       method: 'getTTYDevices',
-       params: [ 'with_cdc', 'with_tts' ],
-       expect: { result: [] }
+var callFileList = rpc.declare({
+       object: 'file',
+       method: 'list',
+       params: [ 'path' ],
+       expect: { entries: [] },
+       filter: function(list, params) {
+               var rv = [];
+               for (var i = 0; i < list.length; i++)
+                       if (list[i].name.match(/^ttyUSB/) || list[i].name.match(/^cdc-wdm/))
+                               rv.push(params.path + list[i].name);
+               return rv.sort();
+       }
 });
 
 network.registerPatternVirtual(/^ncm-.+$/);
@@ -54,12 +61,9 @@ return network.registerProtocol('ncm', {
                o = s.taboption('general', form.Value, 'device', _('Modem device'));
                o.rmempty = false;
                o.load = function(section_id) {
-                       return callTTYDevices(true, false).then(L.bind(function(devices) {
-                               if (Array.isArray(devices))
-                                       for (var i = 0; i < devices.length; i++)
-                                               if (/(ttyUSB|cdc-wdm)/.test(devices[i]))
-                                                       this.value(devices[i]);
-
+                       return callFileList('/dev/').then(L.bind(function(devices) {
+                               for (var i = 0; i < devices.length; i++)
+                                       this.value(devices[i]);
                                return form.Value.prototype.load.apply(this, [section_id]);
                        }, this));
                };
index 133b472d1a979965b103495f4705ed34a7c0eb77..57a7b6a0e115a0043cb45b3e2f50044db01ce817 100644 (file)
@@ -4,11 +4,18 @@
 'require form';
 'require network';
 
-var callTTYDevices = rpc.declare({
-       object: 'luci',
-       method: 'getTTYDevices',
-       params: [ 'with_cdc', 'with_tts' ],
-       expect: { result: [] }
+var callFileList = rpc.declare({
+       object: 'file',
+       method: 'list',
+       params: [ 'path' ],
+       expect: { entries: [] },
+       filter: function(list, params) {
+               var rv = [];
+               for (var i = 0; i < list.length; i++)
+                       if (list[i].name.match(/^tty[A-Z]/) || list[i].name.match(/^cdc-wdm/) || list[i].name.match(/^[0-9]+$/))
+                               rv.push(params.path + list[i].name);
+               return rv.sort();
+       }
 });
 
 network.registerPatternVirtual(/^ppp-.+$/);
@@ -66,11 +73,13 @@ return network.registerProtocol('ppp', {
                o = s.taboption('general', form.Value, 'device', _('Modem device'));
                o.rmempty = false;
                o.load = function(section_id) {
-                       return callTTYDevices(true, true).then(L.bind(function(devices) {
-                               if (Array.isArray(devices))
-                                       for (var i = 0; i < devices.length; i++)
-                                               this.value(devices[i]);
-
+                       return callFileList('/dev/').then(L.bind(function(devices) {
+                               for (var i = 0; i < devices.length; i++)
+                                       this.value(devices[i]);
+                               return callFileList('/dev/tts/');
+                       }, this)).then(L.bind(function(devices) {
+                               for (var i = 0; i < devices.length; i++)
+                                       this.value(devices[i]);
                                return form.Value.prototype.load.apply(this, [section_id]);
                        }, this));
                };
index 79b1fd3b22938ccbfa9cae3af47490e364b59816..eeda91f6e61d7c6b2aea147affba84359d8fb53e 100644 (file)
@@ -3,11 +3,18 @@
 'require form';
 'require network';
 
-var callTTYDevices = rpc.declare({
-       object: 'luci',
-       method: 'getTTYDevices',
-       params: [ 'with_cdc', 'with_tts' ],
-       expect: { result: [] }
+var callFileList = rpc.declare({
+       object: 'file',
+       method: 'list',
+       params: [ 'path' ],
+       expect: { entries: [] },
+       filter: function(list, params) {
+               var rv = [];
+               for (var i = 0; i < list.length; i++)
+                       if (list[i].name.match(/^cdc-wdm/))
+                               rv.push(params.path + list[i].name);
+               return rv.sort();
+       }
 });
 
 network.registerPatternVirtual(/^qmi-.+$/);
@@ -50,12 +57,9 @@ return network.registerProtocol('qmi', {
                o = s.taboption('general', form.Value, 'device', _('Modem device'));
                o.rmempty = false;
                o.load = function(section_id) {
-                       return callTTYDevices(true, false).then(L.bind(function(devices) {
-                               if (Array.isArray(devices))
-                                       for (var i = 0; i < devices.length; i++)
-                                               if (/cdc-wdm/.test(devices[i]))
-                                                       this.value(devices[i]);
-
+                       return callFileList('/dev/').then(L.bind(function(devices) {
+                               for (var i = 0; i < devices.length; i++)
+                                       this.value(devices[i]);
                                return form.Value.prototype.load.apply(this, [section_id]);
                        }, this));
                };