luci-mod-status: add ACL entry for storage index
authorChristian Marangi <ansuelsmth@gmail.com>
Thu, 15 Jun 2023 16:52:55 +0000 (18:52 +0200)
committerPaul Donald <newtwen@gmail.com>
Wed, 6 Dec 2023 23:15:33 +0000 (00:15 +0100)
Add missing ACL entry for storage index page.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
luci-mod-status: expand storage index page with mount points

Expand storage index page with mount points. For custom mounts point we
use the device name and we reference the mount point between ().

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
luci-mod-status: ensure each storage getMountPoints result is unique

Signed-off-by: Paul Donald <newtwen@gmail.com>
Closes #2767

modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/25_storage.js
modules/luci-mod-status/root/usr/share/rpcd/acl.d/luci-mod-status-index.json

index f6a3cef0365cb8e5aec88e0727c6388eb1db5e56..60661f63e51ddb6b8e098d242df016538f35276e 100644 (file)
@@ -7,6 +7,20 @@ var callSystemInfo = rpc.declare({
        method: 'info'
 });
 
+var callMountPoints = rpc.declare({
+       object: 'luci',
+       method: 'getMountPoints',
+       expect: { result: [] }
+});
+
+var MountSkipList = [
+       "/rom",
+       "/tmp",
+       "/dev",
+       "/overlay",
+       "/",
+]
+
 function progressbar(value, max, byte) {
        var vn = parseInt(value) || 0,
            mn = parseInt(max) || 100,
@@ -24,27 +38,49 @@ return baseclass.extend({
        title: _('Storage'),
 
        load: function() {
-               return L.resolveDefault(callSystemInfo(), {});
+               return Promise.all([
+                       L.resolveDefault(callSystemInfo(), {}),
+                       L.resolveDefault(callMountPoints(), {}),
+               ]);
        },
 
-       render: function(systeminfo) {
-               var root = L.isObject(systeminfo.root) ? systeminfo.root : {},
+       render: function(data) {
+               var systeminfo = data[0],
+                   mounts = data[1],
+                   root = L.isObject(systeminfo.root) ? systeminfo.root : {},
                    tmp = L.isObject(systeminfo.tmp) ? systeminfo.tmp : {};
 
-               var fields = [];
-               fields.push(_('Disk space'), root.used*1024, root.total*1024);
-               fields.push(_('Temp space'), tmp.used*1024, tmp.total*1024);
+               const existenceChk = function(fields, name, values) {
+                       if (!fields.hasOwnProperty(name))
+                               fields[name] = values;
+               };
+
+               var fields = {};
+               existenceChk(fields, _('Disk space'), { used: root.used * 1024, size: root.total * 1024 });
+               existenceChk(fields, _('Temp space'), { used: tmp.used * 1024, size: tmp.total * 1024 });
+
+               for (var i = 0; i < mounts.length; i++) {
+                       var entry = mounts[i];
+
+                       if (MountSkipList.includes(entry.mount))
+                               continue;
+
+                       var name = entry.device + ' (' + entry.mount +')',
+                           used = entry.size - entry.free;
+
+                       existenceChk(fields, name, { used: used, size: entry.size });
+               }
 
                var table = E('table', { 'class': 'table' });
 
-               for (var i = 0; i < fields.length; i += 3) {
+               Object.keys(fields).forEach(function(key) {
                        table.appendChild(E('tr', { 'class': 'tr' }, [
-                               E('td', { 'class': 'td left', 'width': '33%' }, [ fields[i] ]),
+                               E('td', { 'class': 'td left', 'width': '33%' }, [ key ]),
                                E('td', { 'class': 'td left' }, [
-                                       (fields[i + 1] != null) ? progressbar(fields[i + 1], fields[i + 2], true) : '?'
+                                       (fields[key].used != null) ? progressbar(fields[key].used, fields[key].size, true) : '?'
                                ])
                        ]));
-               }
+               });
 
                return table;
        }
index 20cd23bb6c9f5d92d8f6b14206355d05c5a36d62..99b4d02b1d44ea5660b2fad8fa5251c1173b540f 100644 (file)
                }
        },
 
+       "luci-mod-status-index-storage": {
+               "description": "Grant access to Storage and Mount status display",
+               "read": {
+                       "ubus": {
+                               "luci": [ "getMountPoints" ],
+                               "system": [ "info" ]
+                       }
+               }
+       },
+
        "luci-mod-status-index-dhcp": {
                "description": "Grant access to DHCP status display",
                "read": {