diff options
Diffstat (limited to 'ipsectools-model.lua')
-rw-r--r-- | ipsectools-model.lua | 195 |
1 files changed, 35 insertions, 160 deletions
diff --git a/ipsectools-model.lua b/ipsectools-model.lua index c30fbb7..1df9a54 100644 --- a/ipsectools-model.lua +++ b/ipsectools-model.lua @@ -1,6 +1,7 @@ module(..., package.seeall) -- Load libraries +require("modelfunctions") require("fs") require("procps") require("format") @@ -57,222 +58,96 @@ local function racoonctl_table() local f = io.popen( cmd ) local value = f:read("*a") f:close() - for k,v in pairs(format.string_to_table(value,"\n")) do - if not ((string.find(v,"^Source")) or (#v == 0)) then - output[k]={} - local variable=format.string_to_table(v,"%s+") - output[k]['Source']=cfe({ - name="Source", + for i,line in pairs(format.string_to_table(value,"\n")) do + if not ((string.find(line,"^Source")) or (#line == 0)) then + entry={} + local variable=format.string_to_table(line,"%s+") + entry['Source']=cfe({ label="Source", value=variable[1], }) - output[k]['Destination']=cfe({ - name="Destination", + entry['Destination']=cfe({ label="Destination", value=variable[2], }) - output[k]['Cookies']=cfe({ - name="Cookies", + entry['Cookies']=cfe({ label="Cookies", value=variable[3], }) - output[k]['St']=cfe({ - name="St", + entry['St']=cfe({ label="State", value=variable[4], descr=descr.state[variable[4]], }) - output[k]['S']=cfe({ - name="S", + entry['S']=cfe({ label="Side", value=variable[5], descr=descr.side[variable[5]], }) - output[k]['V']=cfe({ - name="V", + entry['V']=cfe({ label="Version", value=variable[6], }) - output[k]['E']=cfe({ - name="E", + entry['E']=cfe({ label="Exchange", value=variable[7], descr=descr.exchange[variable[7]], }) - output[k]['Created']=cfe({ - name="Created", + entry['Created']=cfe({ label="Created", value=(variable[8] or "") .. " " .. (variable[9] or ""), }) local phase2s = phase2details(variable[2]) - output[k]['Phase2']=cfe({ - name="Phase2", + entry['Phase2']=cfe({ label="Phase2", value=variable[10], option=phase2s, }) - output[k]['Phase2details']=cfe({ - name="Phase2details", + entry['Phase2details']=cfe({ label="Phase2details", value=tostring(string.gsub(phase2s[1]['value'],"\n","<BR>")) .. tostring(string.gsub(phase2s[2]['value'],"\n","<BR>")) }) + output[#output + 1] = entry end end return output end -function process_status_text(procname) - local t = procps.pidof(procname) - if (t) and (#t > 0) then - return "Enabled" - else - return "Disabled" - end -end - -- ################################################################################ -- PUBLIC FUNCTIONS -function startstop_service ( self, action ) - local cmd = action.value - local cmdresult,cmdmessage,cmderror,cmdaction = daemoncontrol.daemoncontrol(processname, cmd) - action.descr=cmdmessage - action.errtxt=cmderror - return cmdresult,action +function startstop_service(action) + return modelfunctions.startstop_service(processname, action) end function getstatus() - local status = {} - - local value, errtxt = processinfo.package_version(packagename) - status.version = cfe({ name = "version", - label="Program version", - value=value, - errtxt=errtxt, - }) - - status.status = cfe({ name="status", - label="Program status", - value=process_status_text(processname), - }) - - local autostart_sequense, autostart_errtxt = processinfo.process_botsequence(processname) - status.autostart = cfe({ name="autostart", - label="Autostart sequence", - value=autostart_sequense, - errtxt=autostart_errtxt, - }) - - status.show_isakmp = cfe({ name="show_isakmp", - label="Tunnels", - option=racoonctl_table(), - }) + return modelfunctions.getstatus(processname, packagename, "Racoon Status") +end - status.ip_xfrm_policy = cfe({ name="ip_xfrm_policy", - label="ip xfrm policy", - value=ip_xfrm("policy"), - }) +function getstatusdetails() + local status = {} + status.show_isakmp = cfe({ type="list", value=racoonctl_table(), label="Tunnels" }) + status.ip_xfrm_policy = cfe({ type="longtext", value=ip_xfrm("policy"), label="ip xfrm policy" }) - return status + return cfe({ type="group", value=status, label="Racoon Status Details" }) end -function getconfig() - local config = {} - return config +function get_racoonfiledetails() + return modelfunctions.getfiledetails(configfile) end -function get_filedetails(self,num) - local path - if (num == "2") then - path = configfile2 - else - path = configfile - end - local file = {} - local filedetails = {} - local config = {} - local filenameerrtxt - if (path) and (fs.is_file(path)) then - filedetails = fs.stat(path) - config = getconfig(path) - else - config = {} - config.filename = {} - config["filename"]["errtxt"]="Config file '".. path .. "' is missing!" - end - - file["filename" .. (num or "")] = cfe({ - name="filename" .. (num or ""), - label="File name", - value=path, - errtxt=filenameerrtxt - }) - file["filesize" .. (num or "")] = cfe({ - name="filesize" .. (num or ""), - label="File size", - value=filedetails.size or 0, - }) - file["mtime" .. (num or "")] = cfe({ - name="mtime" .. (num or ""), - label="File date", - value=filedetails.mtime or "---", - }) - file["filecontent" .. (num or "")] = cfe({ - type="longtext", - name="filecontent" .. (num or ""), - label="File content", - value=fs.read_file(path), - }) - - -- Sum all errors into one cfe - local sumerrors = "" - for k,v in pairs(config) do - if (config[k]) and (config[k]["errtxt"]) and (config[k]["errtxt"] ~= "") then - sumerrors = sumerrors .. config[k]["errtxt"] .. "\n" - end - end - if (sumerrors ~= "") then - file["sumerrors" .. (num or "")] = cfe ({ - name="sumerrors" .. (num or ""), - label = "Configuration errors", - errtxt = string.match(sumerrors, "(.-)\n$"), - }) - end - - return file +function update_racoonfiledetails(filedetails) + filedetails.value.filename.value = configfile + return modelfunctions.setfiledetails(filedetails) end -function update_filecontent (self, modifications) - local path = configfile - local file_result,err = fs.write_file(path, format.dostounix(modifications)) - return file_result -end -function update_filecontent2 (self, modifications) - local path = configfile2 - local file_result,err = fs.write_file(path, format.dostounix(modifications)) - return file_result +function get_ipsecfiledetails() + return modelfunctions.getfiledetails(configfile2) end -function get_logfile () - local file = {} - local cmdtxt = "grep " .. processname .. " /var/log/messages" - local cmd, error = io.popen(cmdtxt ,r) - local cmdoutput = cmd:read("*a") - cmd:close() - - file["filename"] = cfe({ - name="filename", - label="File name", - value=cmdtxt, - }) - - file["filecontent"] = cfe({ - type="longtext", - name="filecontent", - label="File content", - value=cmdoutput, - }) - return file +function update_ipsecfiledetails(filedetails) + filedetails.value.filename.value = configfile2 + return modelfunctions.setfiledetails(filedetails) end |