luci-base: replace luci/getHostname with generic file/read rpc operation
authorJo-Philipp Wich <jo@mein.io>
Mon, 9 Sep 2019 09:09:18 +0000 (11:09 +0200)
committerJo-Philipp Wich <jo@mein.io>
Tue, 10 Sep 2019 13:29:15 +0000 (15:29 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/protocol/dhcp.js
modules/luci-base/root/usr/libexec/rpcd/luci
modules/luci-base/root/usr/share/rpcd/acl.d/luci-base.json

index b0b65974a8914e4745eb5dc6aa5b3ca1ad5efa33..f0a3ec579c2e8d98cdcab91b0df8111ddb8504d3 100644 (file)
@@ -3,10 +3,12 @@
 'require form';
 'require network';
 
-var callHostname = rpc.declare({
-       object: 'luci',
-       method: 'getHostname',
-       expect: { result: '' }
+var callFileRead = rpc.declare({
+       object: 'file',
+       method: 'read',
+       params: [ 'path' ],
+       expect: { data: '' },
+       filter: function(value) { return value.trim() }
 });
 
 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.datatype    = 'hostname';
                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;
                                return form.Value.prototype.load.apply(this, [section_id]);
                        }, this));
index b8243b8272719402df4f3de4a8a35b5ee85a9092..850b159acfa8bfa6d57606c3d38874c2da93f6da 100755 (executable)
@@ -468,17 +468,6 @@ local methods = {
 
                        return rv
                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
        }
 }
 
index 417296a394e6c4f5be62bd4da5deb9e091183c93..1952a7c3ae014f08a351f7a192610fa7afdc7adc 100644 (file)
                "read": {
                        "file": {
                                "/": [ "list" ],
-                               "/*": [ "list" ]
+                               "/*": [ "list" ],
+                               "/proc/sys/kernel/hostname": [ "read" ]
                        },
                        "ubus": {
-                               "file": [ "list", "stat" ],
+                               "file": [ "list", "read", "stat" ],
                                "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.interface": [ "dump" ],
                                "network": [ "get_proto_handlers" ],