luci-proto-modemmanager: use helper in protocol 6451/head
authorLukas Voegl <lvoegl@tdt.de>
Fri, 30 Jun 2023 13:51:54 +0000 (15:51 +0200)
committerLukas Voegl <lvoegl@tdt.de>
Fri, 30 Jun 2023 13:52:28 +0000 (15:52 +0200)
Signed-off-by: Lukas Voegl <lvoegl@tdt.de>
protocols/luci-proto-modemmanager/htdocs/luci-static/resources/protocol/modemmanager.js
protocols/luci-proto-modemmanager/root/usr/share/rpcd/acl.d/luci-proto-modemmanager.json

index 501f759646afb44553cd33436aacf6f2dbf76a4a..34b71addd67f85033d7f2927e017acfcd21041fc 100644 (file)
@@ -2,39 +2,7 @@
 'require fs';
 'require form';
 'require network';
-
-function getModemList() {
-       return fs.exec_direct('/usr/bin/mmcli', [ '-L' ]).then(function(res) {
-               var lines = (res || '').split(/\n/),
-                   tasks = [];
-
-               for (var i = 0; i < lines.length; i++) {
-                       var m = lines[i].match(/\/Modem\/(\d+)/);
-                       if (m)
-                               tasks.push(fs.exec_direct('/usr/bin/mmcli', [ '-m', m[1] ]));
-               }
-
-               return Promise.all(tasks).then(function(res) {
-                       var modems = [];
-
-                       for (var i = 0; i < res.length; i++) {
-                               var man = res[i].match(/manufacturer: ([^\n]+)/),
-                                   mod = res[i].match(/model: ([^\n]+)/),
-                                   dev = res[i].match(/device: ([^\n]+)/);
-
-                               if (dev) {
-                                       modems.push({
-                                               device:       dev[1].trim(),
-                                               manufacturer: (man ? man[1].trim() : '') || '?',
-                                               model:        (mod ? mod[1].trim() : '') || dev[1].trim()
-                                       });
-                               }
-                       }
-
-                       return modems;
-               });
-       });
-}
+'require modemmanager_helper as helper';
 
 network.registerPatternVirtual(/^mobiledata-.+$/);
 network.registerErrorCode('MM_CONNECT_FAILED', _('Connection attempt failed.'));
@@ -83,10 +51,12 @@ return network.registerProtocol('modemmanager', {
                o.ucioption = 'device';
                o.rmempty = false;
                o.load = function(section_id) {
-                       return getModemList().then(L.bind(function(devices) {
-                               for (var i = 0; i < devices.length; i++)
-                                       this.value(devices[i].device,
-                                               '%s - %s'.format(devices[i].manufacturer, devices[i].model));
+                       return helper.getModems().then(L.bind(function(devices) {
+                               for (var i = 0; i < devices.length; i++) {
+                                       var generic = devices[i].modem.generic;
+                                       this.value(generic.device,
+                                               '%s - %s'.format(generic.manufacturer, generic.model));
+                               }
                                return form.Value.prototype.load.apply(this, [section_id]);
                        }, this));
                };
index dd4da115eb1bedc8ff292cd93ae33f30edf407b6..cde3e9cbb013389f95bb26a23560017ea0be31b7 100644 (file)
@@ -4,10 +4,6 @@
                "read": {
                        "cgi-io": [ "exec" ],
                        "file": {
-                               "/usr/bin/mmcli -L": [ "exec" ],
-                               "/usr/bin/mmcli -m [0-9]": [ "exec" ],
-                               "/usr/bin/mmcli -m [0-9][0-9]": [ "exec" ],
-                               "/usr/bin/mmcli -m [0-9][0-9][0-9]": [ "exec" ],
                                "/usr/bin/mmcli -L -J": [ "exec" ],
                                "/usr/bin/mmcli -m [0-9]* -J": [ "exec" ],
                                "/usr/bin/mmcli -i [0-9]* -J": [ "exec" ],