summaryrefslogtreecommitdiffstats
path: root/openldap-model.lua
diff options
context:
space:
mode:
authorAlan Messias Cordeiro <alancordeiro@gmail.com>2013-12-30 18:14:53 +0000
committerAlan Messias Cordeiro <alancordeiro@gmail.com>2013-12-30 18:14:53 +0000
commit2d12c7f0a21f1310017fb208698e893127c41d35 (patch)
tree41f54edd36fa688422b4747e2570b6c767437bb6 /openldap-model.lua
parente6640f57ec18dbd9ac586de790a00350844e09a8 (diff)
downloadacf-openldap-2d12c7f0a21f1310017fb208698e893127c41d35.tar.bz2
acf-openldap-2d12c7f0a21f1310017fb208698e893127c41d35.tar.xz
testing/acf-openldap added Search tab
Diffstat (limited to 'openldap-model.lua')
-rw-r--r--openldap-model.lua56
1 files changed, 16 insertions, 40 deletions
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