luci-base, luci-mod-system: replace luci/setReboot with fs.exec
authorJo-Philipp Wich <jo@mein.io>
Thu, 31 Oct 2019 14:54:21 +0000 (15:54 +0100)
committerJo-Philipp Wich <jo@mein.io>
Fri, 1 Nov 2019 11:03:33 +0000 (12:03 +0100)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/root/usr/libexec/rpcd/luci
modules/luci-base/root/usr/share/rpcd/acl.d/luci-base.json
modules/luci-mod-system/htdocs/luci-static/resources/view/system/reboot.js

index 4eb62d215229fcd4cc71e6b215e0cd18737f2c5d..f200ee5f4ff6ca0077645eb57797a065a80b8a97 100755 (executable)
@@ -524,12 +524,6 @@ local methods = {
                        local util = require "luci.util"
                        return { result = (os.execute(string.format("/bin/umount %s", util.shellquote(args.path))) == 0) }
                end
-       },
-
-       setReboot = {
-               call = function()
-                       return { result = (os.execute("/sbin/reboot >/dev/null 2>&1") == 0) }
-               end
        }
 }
 
index d801f0168f8c8caa231bfdfbce39607f412373b6..51a7860deadcb7afdb556e65791c743539f1fe87 100644 (file)
@@ -69,7 +69,7 @@
                        "ubus": {
                                "file": [ "write", "remove", "exec" ],
                                "iwinfo": [ "scan" ],
-                               "luci": [ "setInitAction", "setLocaltime", "setPassword", "setBlockDetect", "setUmount", "setReboot" ],
+                               "luci": [ "setInitAction", "setLocaltime", "setPassword", "setBlockDetect", "setUmount" ],
                                "uci": [ "add", "apply", "confirm", "delete", "order", "set", "rename" ]
                        },
                        "uci": [ "*" ]
index 0a144655590a6235fe39b797f0efd6870e3c4163..3ed87f413fba700a9985078ba9e1050d01e16272 100644 (file)
@@ -2,13 +2,6 @@
 'require fs';
 'require ui';
 'require uci';
-'require rpc';
-
-var callReboot = rpc.declare({
-       object: 'luci',
-       method: 'setReboot',
-       expect: { result: false }
-});
 
 return L.view.extend({
        load: function() {
@@ -37,7 +30,12 @@ return L.view.extend({
        },
 
        handleReboot: function(ev) {
-               return callReboot().then(function() {
+               return fs.exec('/sbin/reboot').then(function(res) {
+                       if (res.code != 0) {
+                               L.ui.addNotification(null, E('p', _('The reboot command failed with code %d').format(res.code)));
+                               L.raise('Error', 'Reboot failed');
+                       }
+
                        L.ui.showModal(_('Rebooting…'), [
                                E('p', { 'class': 'spinning' }, _('Waiting for device...'))
                        ]);
@@ -50,7 +48,8 @@ return L.view.extend({
                        }, 150000);
 
                        L.ui.awaitReconnect();
-               });
+               })
+               .catch(function(e) { L.ui.addNotification(null, E('p', e.message)) });
        },
 
        handleSaveApply: null,