diff options
author | Jo-Philipp Wich <jo@mein.io> | 2019-10-10 19:12:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-10 19:12:01 +0200 |
commit | dd6818e188b2d07337479c079749f2f538926d79 (patch) | |
tree | b466e189a8e2a136eed17b1ff3ccf11735cf1596 | |
parent | d18ef580f2f6e5cdfe0839ae6c7ba7c4b52ffb78 (diff) | |
parent | 02a0291d141e3ac8e345a08ab010e05198c895f9 (diff) |
Merge pull request #3172 from ysc3839/userselect
luci-base: widgets.js: add user and group select
-rw-r--r-- | modules/luci-base/htdocs/luci-static/resources/tools/widgets.js | 51 | ||||
-rw-r--r-- | modules/luci-base/root/usr/share/rpcd/acl.d/luci-base.json | 2 |
2 files changed, 53 insertions, 0 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/tools/widgets.js b/modules/luci-base/htdocs/luci-static/resources/tools/widgets.js index 1667fa670..9cc3e26ed 100644 --- a/modules/luci-base/htdocs/luci-static/resources/tools/widgets.js +++ b/modules/luci-base/htdocs/luci-static/resources/tools/widgets.js @@ -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, }); diff --git a/modules/luci-base/root/usr/share/rpcd/acl.d/luci-base.json b/modules/luci-base/root/usr/share/rpcd/acl.d/luci-base.json index 001e6deec..f811fb99e 100644 --- a/modules/luci-base/root/usr/share/rpcd/acl.d/luci-base.json +++ b/modules/luci-base/root/usr/share/rpcd/acl.d/luci-base.json @@ -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" ], |