diff options
-rw-r--r-- | openldap-controller.lua | 7 | ||||
-rw-r--r-- | openldap-model.lua | 56 | ||||
-rw-r--r-- | openldap.menu | 2 | ||||
-rw-r--r-- | openldap.roles | 6 |
4 files changed, 22 insertions, 49 deletions
diff --git a/openldap-controller.lua b/openldap-controller.lua index a1d7a9d..3e63f70 100644 --- a/openldap-controller.lua +++ b/openldap-controller.lua @@ -1,9 +1,6 @@ local mymodule = {} mymodule.mvc = {} -mymodule.mvc.on_load = function(self, parent) - self.model.set_processname("slapd") -end mymodule.default_action = "status" @@ -19,8 +16,8 @@ mymodule.expert = function(self) return self.handle_form(self, self.model.get_filecontent, self.model.update_filecontent, self.clientdata, "Save", "Edit Config File", "Config File Saved") end -mymodule.manage = function(self) - return self.handle_form(self, self.model.get_ldapsearch, self.model.get_ldapsearch, "Search", "Search") +mymodule.search = function(self) + return self.handle_form(self, self.model.get_ldapsearch, self.model.get_ldapsearch, "Search", "Search Again") end return mymodule diff --git a/openldap-model.lua b/openldap-model.lua index 8839171..5c525a4 100644 --- a/openldap-model.lua +++ b/openldap-model.lua @@ -1,26 +1,11 @@ local mymodule = {} modelfunctions = require("modelfunctions") -posix = require("posix") -format = require("acf.format") -fs = require("acf.fs") -processinfo = require("acf.processinfo") -validator = require("acf.validator") -date = require("acf.date") local processname = "slapd" local packagename = "openldap" local configfile = "/etc/openldap/slapd.conf" -function mymodule.set_processname(p) - processname = p - configfile = "/etc/openldap/"..processname..".conf" -end - -local function log_content( f ) - return fs.read_file(f) or "" -end - function mymodule.getstatus() return modelfunctions.getstatus(processname, packagename, "OpenLDAP Status") end @@ -33,11 +18,6 @@ function mymodule.startstop_service(self, startstop, action) return modelfunctions.startstop_service(startstop, action) end -function mymodule.get_logfile(f) - local config = log_content(configfile) - return cfe({ value=config.log or "", label="Log file" }) -end - function mymodule.get_filecontent() return modelfunctions.getfiledetails(configfile) end @@ -47,32 +27,29 @@ function mymodule.update_filecontent(self, filedetails) end function mymodule.get_ldapsearch(self, ldapdata) - local cnf = {} - cnf = parse_config(configfile) + local cnf = mymodule.parse_config(configfile) + local result = {} - local cmd = {"ldapsearch", "-x", "-L", "ldap://127.0.0.1", "-b", "dc=teste,dc=local"} - local file = modelfunctions.run_executable(cmd) + local cmd ="ldapsearch -x -L -b ".. cnf.suffix + local handle = io.popen(cmd) + local file = handle:read("*a") - result.file = cfe({type="select", option={"/etc/openldap/slapd.conf", "/etc/openldap/ldap.conf"}, label="File"}) - result.version= cfe({label="Version", description="LDIF file format version"}) - result.basedn = cfe({label="Root DN"}) + result.dn = cfe({type="longtext", label="DNs"}) + result.suffix = cfe({label="Suffix"}) + result.suffix.value = cnf.suffix or "" + result.suffix.readonly = true - for line in string.gmatch(file, "([^\n]+)") do - if string.match(line, "version") then - --local cn = string.match(line, "version: (%d)") - --local entry = string.match(line, "^result(%w+)") or "Entrada" - --result.value = cfe({value=cn}) - result.version.value = string.match(line, "version: (%d)") - result.version.readonly = true - result.basedn.value = cnf.suffix or "" - end + for line in string.gmatch(file, "[^\n]+") do + if string.match(line, "^dn") then + result.dn.value = result.dn.value .."\n"..string.match(line, "dn: (.*)") + end end return cfe({type="group", value=result, label="Ldap Search Result"}) end -function parse_config(configfile) +function mymodule.parse_config(configfile) local file = io.open (configfile) local confs = {} @@ -83,15 +60,14 @@ function parse_config(configfile) if string.match(line,"^%a") then for key, value in string.gmatch(line,"(%w*)%s(.*)") do if key then - confs[key] = string.gsub(value,"%s*","") + confs[key] = string.gsub(value,"^%s*","") end end end end end - + file:close() - return confs end diff --git a/openldap.menu b/openldap.menu index 566e1d6..ce378e7 100644 --- a/openldap.menu +++ b/openldap.menu @@ -2,4 +2,4 @@ Networking 65OpenLDAP Status status Networking 65OpenLDAP Expert expert Networking 65OpenLDAP Log_File logfile -Networking 65OpenLDAP Manage manage +Networking 65OpenLDAP Search search diff --git a/openldap.roles b/openldap.roles index 7346a42..814c56b 100644 --- a/openldap.roles +++ b/openldap.roles @@ -1,3 +1,3 @@ -USER=openldap:status,openldap:logfile,openldap:viewconfig,openldap:startstop -EXPERT=openldap:status,openldap:logfile,openldap:viewconfig,openldap:startstop,openldap:expert -ADMIN=openldap:status,openldap:logfile,openldap:viewconfig,openldap:startstop,openldap:expert,openldap:manage +USER=openldap:status,openldap:startstop +EXPERT=openldap:status,openldap:startstop,openldap:expert,openldap:logfile +ADMIN=openldap:status,openldap:startstop,openldap:expert,openldap:logfile,openldap:search |