diff options
author | Alan Messias Cordeiro <alancordeiro@gmail.com> | 2013-12-17 16:08:18 +0000 |
---|---|---|
committer | Alan Messias Cordeiro <alancordeiro@gmail.com> | 2013-12-17 16:08:18 +0000 |
commit | e6640f57ec18dbd9ac586de790a00350844e09a8 (patch) | |
tree | 63ee4a92afaf913f9e0365c2dc7acc86be9e6e5e | |
parent | cc910aa04ee1dc635b2672eac5ad9008b537755d (diff) | |
download | acf-openldap-e6640f57ec18dbd9ac586de790a00350844e09a8.tar.bz2 acf-openldap-e6640f57ec18dbd9ac586de790a00350844e09a8.tar.xz |
Parse configuration fil
-rw-r--r-- | openldap-controller.lua | 4 | ||||
-rw-r--r-- | openldap-model.lua | 52 | ||||
-rw-r--r-- | openldap.menu | 2 |
3 files changed, 55 insertions, 3 deletions
diff --git a/openldap-controller.lua b/openldap-controller.lua index 36b8564..a1d7a9d 100644 --- a/openldap-controller.lua +++ b/openldap-controller.lua @@ -19,4 +19,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") +end + return mymodule diff --git a/openldap-model.lua b/openldap-model.lua index 112dedb..8839171 100644 --- a/openldap-model.lua +++ b/openldap-model.lua @@ -39,13 +39,61 @@ function mymodule.get_logfile(f) end function mymodule.get_filecontent() - return modelfunctions.getfiledetails(configfile) end function mymodule.update_filecontent(self, filedetails) - return modelfunctions.setfiledetails(self, filedetails, {configfile}) end +function mymodule.get_ldapsearch(self, ldapdata) + local cnf = {} + cnf = 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) + + 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"}) + + 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 + end + + return cfe({type="group", value=result, label="Ldap Search Result"}) +end + + +function parse_config(configfile) + local file = io.open (configfile) + local confs = {} + + if (file) then + local alllines = file:read("*all") + for line in string.gmatch(alllines, "([^\n]+)") do + -- Ignoring lines starting by # + 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*","") + end + end + end + end + end + + file:close() + + return confs +end + + return mymodule diff --git a/openldap.menu b/openldap.menu index 55bf6db..566e1d6 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 Manage manage |