protocols: replace luci/getTTYDevices calls with generic file/list ones
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
5697ebbef5
commit
9cae3b9e67
6 changed files with 69 additions and 77 deletions
|
@ -479,40 +479,6 @@ local methods = {
|
||||||
end
|
end
|
||||||
return { result = hostname:gsub("\n$", "") }
|
return { result = hostname:gsub("\n$", "") }
|
||||||
end
|
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
"ubus": {
|
"ubus": {
|
||||||
"file": [ "list", "stat" ],
|
"file": [ "list", "stat" ],
|
||||||
"iwinfo": [ "assoclist", "freqlist", "txpowerlist", "countrylist" ],
|
"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.device": [ "status" ],
|
||||||
"network.interface": [ "dump" ],
|
"network.interface": [ "dump" ],
|
||||||
"network": [ "get_proto_handlers" ],
|
"network": [ "get_proto_handlers" ],
|
||||||
|
|
|
@ -4,11 +4,18 @@
|
||||||
'require form';
|
'require form';
|
||||||
'require network';
|
'require network';
|
||||||
|
|
||||||
var callTTYDevices = rpc.declare({
|
var callFileList = rpc.declare({
|
||||||
object: 'luci',
|
object: 'file',
|
||||||
method: 'getTTYDevices',
|
method: 'list',
|
||||||
params: [ 'with_cdc', 'with_tts' ],
|
params: [ 'path' ],
|
||||||
expect: { result: [] }
|
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-.+$/);
|
network.registerPatternVirtual(/^3g-.+$/);
|
||||||
|
@ -66,11 +73,13 @@ return network.registerProtocol('3g', {
|
||||||
o = s.taboption('general', form.Value, 'device', _('Modem device'));
|
o = s.taboption('general', form.Value, 'device', _('Modem device'));
|
||||||
o.rmempty = false;
|
o.rmempty = false;
|
||||||
o.load = function(section_id) {
|
o.load = function(section_id) {
|
||||||
return callTTYDevices(false, true).then(L.bind(function(devices) {
|
return callFileList('/dev/').then(L.bind(function(devices) {
|
||||||
if (Array.isArray(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++)
|
for (var i = 0; i < devices.length; i++)
|
||||||
this.value(devices[i]);
|
this.value(devices[i]);
|
||||||
|
|
||||||
return form.Value.prototype.load.apply(this, [section_id]);
|
return form.Value.prototype.load.apply(this, [section_id]);
|
||||||
}, this));
|
}, this));
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,11 +3,18 @@
|
||||||
'require form';
|
'require form';
|
||||||
'require network';
|
'require network';
|
||||||
|
|
||||||
var callTTYDevices = rpc.declare({
|
var callFileList = rpc.declare({
|
||||||
object: 'luci',
|
object: 'file',
|
||||||
method: 'getTTYDevices',
|
method: 'list',
|
||||||
params: [ 'with_cdc', 'with_tts' ],
|
params: [ 'path' ],
|
||||||
expect: { result: [] }
|
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-.+$/);
|
network.registerPatternVirtual(/^ncm-.+$/);
|
||||||
|
@ -54,12 +61,9 @@ return network.registerProtocol('ncm', {
|
||||||
o = s.taboption('general', form.Value, 'device', _('Modem device'));
|
o = s.taboption('general', form.Value, 'device', _('Modem device'));
|
||||||
o.rmempty = false;
|
o.rmempty = false;
|
||||||
o.load = function(section_id) {
|
o.load = function(section_id) {
|
||||||
return callTTYDevices(true, false).then(L.bind(function(devices) {
|
return callFileList('/dev/').then(L.bind(function(devices) {
|
||||||
if (Array.isArray(devices))
|
|
||||||
for (var i = 0; i < devices.length; i++)
|
for (var i = 0; i < devices.length; i++)
|
||||||
if (/(ttyUSB|cdc-wdm)/.test(devices[i]))
|
|
||||||
this.value(devices[i]);
|
this.value(devices[i]);
|
||||||
|
|
||||||
return form.Value.prototype.load.apply(this, [section_id]);
|
return form.Value.prototype.load.apply(this, [section_id]);
|
||||||
}, this));
|
}, this));
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,11 +4,18 @@
|
||||||
'require form';
|
'require form';
|
||||||
'require network';
|
'require network';
|
||||||
|
|
||||||
var callTTYDevices = rpc.declare({
|
var callFileList = rpc.declare({
|
||||||
object: 'luci',
|
object: 'file',
|
||||||
method: 'getTTYDevices',
|
method: 'list',
|
||||||
params: [ 'with_cdc', 'with_tts' ],
|
params: [ 'path' ],
|
||||||
expect: { result: [] }
|
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-.+$/);
|
network.registerPatternVirtual(/^ppp-.+$/);
|
||||||
|
@ -66,11 +73,13 @@ return network.registerProtocol('ppp', {
|
||||||
o = s.taboption('general', form.Value, 'device', _('Modem device'));
|
o = s.taboption('general', form.Value, 'device', _('Modem device'));
|
||||||
o.rmempty = false;
|
o.rmempty = false;
|
||||||
o.load = function(section_id) {
|
o.load = function(section_id) {
|
||||||
return callTTYDevices(true, true).then(L.bind(function(devices) {
|
return callFileList('/dev/').then(L.bind(function(devices) {
|
||||||
if (Array.isArray(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++)
|
for (var i = 0; i < devices.length; i++)
|
||||||
this.value(devices[i]);
|
this.value(devices[i]);
|
||||||
|
|
||||||
return form.Value.prototype.load.apply(this, [section_id]);
|
return form.Value.prototype.load.apply(this, [section_id]);
|
||||||
}, this));
|
}, this));
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,11 +3,18 @@
|
||||||
'require form';
|
'require form';
|
||||||
'require network';
|
'require network';
|
||||||
|
|
||||||
var callTTYDevices = rpc.declare({
|
var callFileList = rpc.declare({
|
||||||
object: 'luci',
|
object: 'file',
|
||||||
method: 'getTTYDevices',
|
method: 'list',
|
||||||
params: [ 'with_cdc', 'with_tts' ],
|
params: [ 'path' ],
|
||||||
expect: { result: [] }
|
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-.+$/);
|
network.registerPatternVirtual(/^qmi-.+$/);
|
||||||
|
@ -50,12 +57,9 @@ return network.registerProtocol('qmi', {
|
||||||
o = s.taboption('general', form.Value, 'device', _('Modem device'));
|
o = s.taboption('general', form.Value, 'device', _('Modem device'));
|
||||||
o.rmempty = false;
|
o.rmempty = false;
|
||||||
o.load = function(section_id) {
|
o.load = function(section_id) {
|
||||||
return callTTYDevices(true, false).then(L.bind(function(devices) {
|
return callFileList('/dev/').then(L.bind(function(devices) {
|
||||||
if (Array.isArray(devices))
|
|
||||||
for (var i = 0; i < devices.length; i++)
|
for (var i = 0; i < devices.length; i++)
|
||||||
if (/cdc-wdm/.test(devices[i]))
|
|
||||||
this.value(devices[i]);
|
this.value(devices[i]);
|
||||||
|
|
||||||
return form.Value.prototype.load.apply(this, [section_id]);
|
return form.Value.prototype.load.apply(this, [section_id]);
|
||||||
}, this));
|
}, this));
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue