From e6640f57ec18dbd9ac586de790a00350844e09a8 Mon Sep 17 00:00:00 2001 From: Alan Messias Cordeiro Date: Tue, 17 Dec 2013 16:08:18 +0000 Subject: Parse configuration fil --- openldap-model.lua | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) (limited to 'openldap-model.lua') 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 -- cgit v1.2.3