summaryrefslogtreecommitdiffstats
path: root/openldap-model.lua
diff options
context:
space:
mode:
authorAlan Messias Cordeiro <alancordeiro@gmail.com>2013-12-17 16:08:18 +0000
committerAlan Messias Cordeiro <alancordeiro@gmail.com>2013-12-17 16:08:18 +0000
commite6640f57ec18dbd9ac586de790a00350844e09a8 (patch)
tree63ee4a92afaf913f9e0365c2dc7acc86be9e6e5e /openldap-model.lua
parentcc910aa04ee1dc635b2672eac5ad9008b537755d (diff)
downloadacf-openldap-e6640f57ec18dbd9ac586de790a00350844e09a8.tar.bz2
acf-openldap-e6640f57ec18dbd9ac586de790a00350844e09a8.tar.xz
Parse configuration fil
Diffstat (limited to 'openldap-model.lua')
-rw-r--r--openldap-model.lua52
1 files changed, 50 insertions, 2 deletions
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