luci-base: widgets.js: add user and group select 3172/head
authorRichard Yu <yurichard3839@gmail.com>
Thu, 10 Oct 2019 17:05:08 +0000 (01:05 +0800)
committerRichard Yu <yurichard3839@gmail.com>
Thu, 10 Oct 2019 17:05:08 +0000 (01:05 +0800)
Signed-off-by: Richard Yu <yurichard3839@gmail.com>
modules/luci-base/htdocs/luci-static/resources/tools/widgets.js
modules/luci-base/root/usr/share/rpcd/acl.d/luci-base.json

index 1667fa670726d5f95719c385840320f6e85ef4e3..9cc3e26ed2816daccad2f74b8aa0ca35f88374f0 100644 (file)
@@ -3,6 +3,19 @@
 'require form';
 'require network';
 'require firewall';
+'require fs';
+
+function getUsers() {
+    return fs.lines('/etc/passwd').then(function(lines) {
+        return lines.map(function(line) { return line.split(/:/)[0] });
+    });
+}
+
+function getGroups() {
+    return fs.lines('/etc/group').then(function(lines) {
+        return lines.map(function(line) { return line.split(/:/)[0] });
+    });
+}
 
 var CBIZoneSelect = form.ListValue.extend({
        __name__: 'CBI.ZoneSelect',
@@ -559,10 +572,48 @@ var CBIDeviceSelect = form.ListValue.extend({
        },
 });
 
+var CBIUserSelect = form.ListValue.extend({
+       __name__: 'CBI.UserSelect',
+
+       load: function(section_id) {
+               return getUsers().then(L.bind(function(users) {
+                       for (var i = 0; i < users.length; i++) {
+                               this.value(users[i]);
+                       }
+
+                       return this.super('load', section_id);
+               }, this));
+       },
+
+       filter: function(section_id, value) {
+               return true;
+       },
+});
+
+var CBIGroupSelect = form.ListValue.extend({
+       __name__: 'CBI.GroupSelect',
+
+       load: function(section_id) {
+               return getGroups().then(L.bind(function(groups) {
+                       for (var i = 0; i < groups.length; i++) {
+                               this.value(groups[i]);
+                       }
+
+                       return this.super('load', section_id);
+               }, this));
+       },
+
+       filter: function(section_id, value) {
+               return true;
+       },
+});
+
 
 return L.Class.extend({
        ZoneSelect: CBIZoneSelect,
        ZoneForwards: CBIZoneForwards,
        NetworkSelect: CBINetworkSelect,
        DeviceSelect: CBIDeviceSelect,
+       UserSelect: CBIUserSelect,
+       GroupSelect: CBIGroupSelect,
 });
index 001e6deec8c61cf783c4c12252cca89757686cc5..f811fb99ea1e8d00a30e78bb7dd0a048d88d0c1f 100644 (file)
@@ -30,6 +30,8 @@
                                "/etc/filesystems": [ "read" ],
                                "/etc/rc.local": [ "read" ],
                                "/etc/sysupgrade.conf": [ "read" ],
+                               "/etc/passwd": [ "read" ],
+                               "/etc/group": [ "read" ],
                                "/proc/filesystems": [ "read" ],
                                "/proc/mtd": [ "read" ],
                                "/proc/partitions": [ "read" ],