luci-base: replace luci/getHostname with generic file/read rpc operation
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
9cae3b9e67
commit
5dc61be746
3 changed files with 11 additions and 19 deletions
|
@ -3,10 +3,12 @@
|
||||||
'require form';
|
'require form';
|
||||||
'require network';
|
'require network';
|
||||||
|
|
||||||
var callHostname = rpc.declare({
|
var callFileRead = rpc.declare({
|
||||||
object: 'luci',
|
object: 'file',
|
||||||
method: 'getHostname',
|
method: 'read',
|
||||||
expect: { result: '' }
|
params: [ 'path' ],
|
||||||
|
expect: { data: '' },
|
||||||
|
filter: function(value) { return value.trim() }
|
||||||
});
|
});
|
||||||
|
|
||||||
return network.registerProtocol('dhcp', {
|
return network.registerProtocol('dhcp', {
|
||||||
|
@ -20,7 +22,7 @@ return network.registerProtocol('dhcp', {
|
||||||
o = s.taboption('general', form.Value, 'hostname', _('Hostname to send when requesting DHCP'));
|
o = s.taboption('general', form.Value, 'hostname', _('Hostname to send when requesting DHCP'));
|
||||||
o.datatype = 'hostname';
|
o.datatype = 'hostname';
|
||||||
o.load = function(section_id) {
|
o.load = function(section_id) {
|
||||||
return callHostname().then(L.bind(function(hostname) {
|
return callFileRead('/proc/sys/kernel/hostname').then(L.bind(function(hostname) {
|
||||||
this.placeholder = hostname;
|
this.placeholder = hostname;
|
||||||
return form.Value.prototype.load.apply(this, [section_id]);
|
return form.Value.prototype.load.apply(this, [section_id]);
|
||||||
}, this));
|
}, this));
|
||||||
|
|
|
@ -468,17 +468,6 @@ local methods = {
|
||||||
|
|
||||||
return rv
|
return rv
|
||||||
end
|
end
|
||||||
},
|
|
||||||
|
|
||||||
getHostname = {
|
|
||||||
call = function()
|
|
||||||
local fs = require "nixio.fs"
|
|
||||||
local hostname, code, err = fs.readfile("/proc/sys/kernel/hostname")
|
|
||||||
if err then
|
|
||||||
return { error = err }, 1
|
|
||||||
end
|
|
||||||
return { result = hostname:gsub("\n$", "") }
|
|
||||||
end
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,12 +22,13 @@
|
||||||
"read": {
|
"read": {
|
||||||
"file": {
|
"file": {
|
||||||
"/": [ "list" ],
|
"/": [ "list" ],
|
||||||
"/*": [ "list" ]
|
"/*": [ "list" ],
|
||||||
|
"/proc/sys/kernel/hostname": [ "read" ]
|
||||||
},
|
},
|
||||||
"ubus": {
|
"ubus": {
|
||||||
"file": [ "list", "stat" ],
|
"file": [ "list", "read", "stat" ],
|
||||||
"iwinfo": [ "assoclist", "freqlist", "txpowerlist", "countrylist" ],
|
"iwinfo": [ "assoclist", "freqlist", "txpowerlist", "countrylist" ],
|
||||||
"luci": [ "getBoardJSON", "getDUIDHints", "getHostHints", "getIfaddrs", "getInitList", "getLocaltime", "getTimezones", "getDHCPLeases", "getLEDs", "getNetworkDevices", "getUSBDevices", "getHostname", "getWirelessDevices" ],
|
"luci": [ "getBoardJSON", "getDUIDHints", "getHostHints", "getIfaddrs", "getInitList", "getLocaltime", "getTimezones", "getDHCPLeases", "getLEDs", "getNetworkDevices", "getUSBDevices", "getWirelessDevices" ],
|
||||||
"network.device": [ "status" ],
|
"network.device": [ "status" ],
|
||||||
"network.interface": [ "dump" ],
|
"network.interface": [ "dump" ],
|
||||||
"network": [ "get_proto_handlers" ],
|
"network": [ "get_proto_handlers" ],
|
||||||
|
|
Loading…
Reference in a new issue