1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
local mymodule = {}
modelfunctions = require("modelfunctions")
local processname = "slapd"
local packagename = "openldap"
local configfile = "/etc/openldap/slapd.conf"
function mymodule.getstatus()
return modelfunctions.getstatus(processname, packagename, "OpenLDAP Status")
end
function mymodule.get_startstop(self, clientdata)
return modelfunctions.get_startstop(processname)
end
function mymodule.startstop_service(self, startstop, action)
return modelfunctions.startstop_service(startstop, action)
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 = mymodule.parse_config(configfile)
local result = {}
local cmd ="ldapsearch -x -L -b ".. cnf.suffix
local handle = io.popen(cmd)
local file = handle:read("*a")
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, "^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 mymodule.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
|