luci-base, luci-mod-system: replace luci/setUmount with fs.exec calls
authorJo-Philipp Wich <jo@mein.io>
Thu, 31 Oct 2019 15:25:49 +0000 (16:25 +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/mounts.js

index f200ee5f4ff6ca0077645eb57797a065a80b8a97..2601512da6b9617acf45ea5fd58353551a34ab32 100755 (executable)
@@ -516,14 +516,6 @@ local methods = {
                                return { error = err }
                        end
                end
-       },
-
-       setUmount = {
-               args = { path = "/mnt" },
-               call = function(args)
-                       local util = require "luci.util"
-                       return { result = (os.execute(string.format("/bin/umount %s", util.shellquote(args.path))) == 0) }
-               end
        }
 }
 
index 51a7860deadcb7afdb556e65791c743539f1fe87..e757beab6cb0d6c6ae20e8687357db2ef4c4a674 100644 (file)
                                "/sbin/reboot": [ "exec" ],
                                "/sbin/sysupgrade": [ "exec" ],
                                "/bin/tar": [ "exec" ],
+                               "/bin/umount": [ "exec" ],
                                "/tmp/backup.tar.gz": [ "write" ],
                                "/tmp/firmware.bin": [ "write" ]
                        },
                        "ubus": {
                                "file": [ "write", "remove", "exec" ],
                                "iwinfo": [ "scan" ],
-                               "luci": [ "setInitAction", "setLocaltime", "setPassword", "setBlockDetect", "setUmount" ],
+                               "luci": [ "setInitAction", "setLocaltime", "setPassword", "setBlockDetect" ],
                                "uci": [ "add", "apply", "confirm", "delete", "order", "set", "rename" ]
                        },
                        "uci": [ "*" ]
index 301ebab33159638b4348b209679ee61250cdf2f9..b4f5cf71a53de9857fd5e6ccf93b33fc1ecf3054 100644 (file)
@@ -1,10 +1,10 @@
 'use strict';
+'require fs';
 'require uci';
 'require rpc';
 'require form';
 
-var callBlockDevices, callMountPoints, callBlockDetect, callUmount,
-    callFileRead, callFileStat, callFileExec;
+var callBlockDevices, callMountPoints, callBlockDetect;
 
 callBlockDevices = rpc.declare({
        object: 'luci',
@@ -24,44 +24,6 @@ callBlockDetect = rpc.declare({
        expect: { result: false }
 });
 
-callUmount = rpc.declare({
-       object: 'luci',
-       method: 'setUmount',
-       params: [ 'path' ],
-       expect: { result: false }
-});
-
-callFileRead = rpc.declare({
-       object: 'file',
-       method: 'read',
-       params: [ 'path' ],
-       expect: { data: '' },
-       filter: function(s) {
-               return (s || '').split(/\n/).filter(function(ln) {
-                       return ln.match(/\S/) && !ln.match(/^nodev\t/);
-               }).map(function(ln) {
-                       return ln.trim();
-               });
-       }
-});
-
-callFileStat = rpc.declare({
-       object: 'file',
-       method: 'stat',
-       params: [ 'path' ],
-       expect: { '': {} },
-       filter: function(st) {
-               return (L.isObject(st) && st.path != null);
-       }
-});
-
-callFileExec = rpc.declare({
-       object: 'file',
-       method: 'exec',
-       params: [ 'command', 'params' ],
-       expect: { code: 255 }
-});
-
 function device_textvalue(devices, section_id) {
        var v = (uci.get('fstab', section_id, 'uuid') || '').toLowerCase(),
            e = Object.keys(devices).filter(function(dev) { return (devices[dev].uuid || '-').toLowerCase() == v })[0];
@@ -114,30 +76,32 @@ return L.view.extend({
        },
 
        handleMountAll: function(m, ev) {
-               return callFileExec('/sbin/block', ['mount'])
-                       .then(function(rc) {
-                               if (rc != 0)
-                                       L.ui.addNotification(null, E('p', _('The <em>block mount</em> command failed with code %d').format(rc)));
+               return fs.exec('/sbin/block', ['mount'])
+                       .then(function(res) {
+                               if (res.code != 0)
+                                       L.ui.addNotification(null, E('p', _('The <em>block mount</em> command failed with code %d').format(res.code)));
                        })
                        .then(L.bind(uci.unload, uci, 'fstab'))
                        .then(L.bind(m.render, m));
        },
 
        handleUmount: function(m, path, ev) {
-               return callUmount(path)
+               return fs.exec('/bin/umount', [path])
                        .then(L.bind(uci.unload, uci, 'fstab'))
-                       .then(L.bind(m.render, m));
+                       .then(L.bind(m.render, m))
+                       .catch(function(e) { L.ui.addNotification(null, E('p', e.message)) });
        },
 
        load: function() {
                return Promise.all([
                        callBlockDevices(),
-                       callFileRead('/proc/filesystems'),
-                       callFileRead('/etc/filesystems'),
-                       callFileStat('/usr/sbin/e2fsck'),
-                       callFileStat('/usr/sbin/fsck.f2fs'),
-                       callFileStat('/usr/sbin/dosfsck'),
-                       callFileStat('/usr/bin/btrfsck'),
+                       fs.lines('/proc/filesystems'),
+                       fs.lines('/etc/filesystems'),
+                       L.resolveDefault(fs.stat('/usr/sbin/e2fsck'), null),
+                       L.resolveDefault(fs.stat('/usr/sbin/fsck.f2fs'), null),
+                       L.resolveDefault(fs.stat('/usr/sbin/fsck.fat'), null),
+                       L.resolveDefault(fs.stat('/usr/bin/btrfsck'), null),
+                       L.resolveDefault(fs.stat('/usr/bin/ntfsfix'), null),
                        uci.load('fstab')
                ]);
        },
@@ -149,19 +113,29 @@ return L.view.extend({
                    triggers = {},
                    trigger, m, s, o;
 
-               var filesystems = procfs.concat(etcfs.filter(function(fs) {
-                       return procfs.indexOf(fs) < 0;
-               })).sort();
-
                var fsck = {
                        ext2: results[3],
                        ext3: results[3],
                        ext4: results[3],
                        f2fs: results[4],
                        vfat: results[5],
-                       btrfs: results[6]
+                       btrfs: results[6],
+                       ntfs: results[7]
                };
 
+               var filesystems = {};
+
+               for (var i = 0; i < procfs.length; i++)
+                       if (procfs[i].match(/\S/) && !procfs[i].match(/^nodev\t/))
+                               filesystems[procfs[i].trim()] = true;
+
+               for (var i = 0; i < etcfs.length; i++)
+                       if (etcfs[i].match(/\S/))
+                               filesystems[etcfs[i].trim()] = true;
+
+               filesystems = Object.keys(filesystems).sort();
+
+
                if (!uci.sections('fstab', 'global').length)
                        uci.add('fstab', 'global');