luci-proto-modemmanager: use nmcli to detemrine modem choices
Fixes: #3586 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
50720d36a3
commit
58c091ac9b
2 changed files with 48 additions and 16 deletions
|
@ -1,21 +1,40 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
'require rpc';
|
'require fs';
|
||||||
'require form';
|
'require form';
|
||||||
'require network';
|
'require network';
|
||||||
|
|
||||||
var callFileList = rpc.declare({
|
function getModemList() {
|
||||||
object: 'file',
|
return fs.exec_direct('/usr/bin/mmcli', [ '-L' ]).then(function(res) {
|
||||||
method: 'list',
|
var lines = (res || '').split(/\n/),
|
||||||
params: [ 'path' ],
|
tasks = [];
|
||||||
expect: { entries: [] },
|
|
||||||
filter: function(list, params) {
|
for (var i = 0; i < lines.length; i++) {
|
||||||
var rv = [];
|
var m = lines[i].match(/\/Modem\/(\d+)/);
|
||||||
for (var i = 0; i < list.length; i++)
|
if (m)
|
||||||
if (list[i].name.match(/^cdc-wdm/))
|
tasks.push(fs.exec_direct('/usr/bin/mmcli', [ '-m', m[1] ]));
|
||||||
rv.push(params.path + list[i].name);
|
}
|
||||||
return rv.sort();
|
|
||||||
}
|
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;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
network.registerPatternVirtual(/^mobiledata-.+$/);
|
network.registerPatternVirtual(/^mobiledata-.+$/);
|
||||||
network.registerErrorCode('CALL_FAILED', _('Call failed'));
|
network.registerErrorCode('CALL_FAILED', _('Call failed'));
|
||||||
|
@ -57,9 +76,10 @@ return network.registerProtocol('modemmanager', {
|
||||||
o = s.taboption('general', form.ListValue, 'device', _('Modem device'));
|
o = s.taboption('general', form.ListValue, 'device', _('Modem device'));
|
||||||
o.rmempty = false;
|
o.rmempty = false;
|
||||||
o.load = function(section_id) {
|
o.load = function(section_id) {
|
||||||
return callFileList('/dev/').then(L.bind(function(devices) {
|
return getModemList().then(L.bind(function(devices) {
|
||||||
for (var i = 0; i < devices.length; i++)
|
for (var i = 0; i < devices.length; i++)
|
||||||
this.value(devices[i]);
|
this.value(devices[i].device,
|
||||||
|
'%s - %s'.format(devices[i].manufacturer, devices[i].model));
|
||||||
return form.Value.prototype.load.apply(this, [section_id]);
|
return form.Value.prototype.load.apply(this, [section_id]);
|
||||||
}, this));
|
}, this));
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"luci-proto-modemmanager": {
|
||||||
|
"description": "Grant access to mmcli",
|
||||||
|
"read": {
|
||||||
|
"cgi-io": [ "exec" ],
|
||||||
|
"file": {
|
||||||
|
"/usr/bin/mmcli -L": [ "exec" ],
|
||||||
|
"/usr/bin/mmcli -m [0-9]": [ "exec" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue