diff options
author | Ted Trask <ttrask01@yahoo.com> | 2008-09-23 15:36:59 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2008-09-23 15:36:59 +0000 |
commit | 6cb727c05b7562dd7eb428da8494f09210e3dac0 (patch) | |
tree | d67ff29ab2e9c7867a98db41472950646de094e9 | |
parent | 7fc71cd1135d13ce1cb5192f7909c52f427725df (diff) | |
download | acf-ipsec-tools-6cb727c05b7562dd7eb428da8494f09210e3dac0.tar.bz2 acf-ipsec-tools-6cb727c05b7562dd7eb428da8494f09210e3dac0.tar.xz |
Modified ipsectools to use new libraries and lsp files.
git-svn-id: svn://svn.alpinelinux.org/acf/ipsec-tools/trunk@1483 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r-- | ipsectools-controller.lua | 111 | ||||
-rw-r--r-- | ipsectools-details-html.lsp | 41 | ||||
l--------- | ipsectools-editipsec-html.lsp | 1 | ||||
l--------- | ipsectools-editracoon-html.lsp | 1 | ||||
-rw-r--r-- | ipsectools-expert-html.lsp | 70 | ||||
-rw-r--r-- | ipsectools-logfile-html.lsp | 32 | ||||
-rw-r--r-- | ipsectools-model.lua | 195 | ||||
l--------- | ipsectools-startstop-html.lsp | 1 | ||||
l---------[-rw-r--r--] | ipsectools-status-html.lsp | 45 | ||||
-rw-r--r-- | ipsectools.menu | 2 | ||||
-rw-r--r-- | ipsectools.roles | 4 |
11 files changed, 104 insertions, 399 deletions
diff --git a/ipsectools-controller.lua b/ipsectools-controller.lua index c7b6d1a..3ce1896 100644 --- a/ipsectools-controller.lua +++ b/ipsectools-controller.lua @@ -1,119 +1,32 @@ module(..., package.seeall) -- Load libraries -require("format") +require("controllerfunctions") -- ################################################################################ -- LOCAL FUNCTIONS -local function displaycmdmanagement(pidofstatus) - -- Add a management buttons - local management = {} - management.start = cfe({ name="cmdmanagement", - label="Program control-panel", - value="Start", - type="submit", - }) - management.stop = cfe({ name="cmdmanagement", - label="Program control-panel", - value="Stop", - type="submit", - }) - management.restart = cfe({ name="cmdmanagement", - label="Program control-panel", - value="Restart", - type="submit", - }) - -- next CFE can be used to present the result of the previous action - management.actionresult = cfe({ name="actionresult", - label="Previous action result", - }) - - -- Disable management buttons based on if the process is running or not - if (pidofstatus) then - management.start.disabled = "yes" - else - management.stop.disabled = "yes" - management.restart.disabled = "yes" - end - - return management -end - -- ################################################################################ -- PUBLIC FUNCTIONS default_action = "status" function status(self) - return { status=self.model.getstatus() } + return self.model.getstatus() end -function expert (self) - local modifications = self.clientdata.filecontent or "" - local modifications2 = self.clientdata.filecontent2 or "" - if ( self.clientdata.cmdsave ) then - modifications = self.model:update_filecontent(modifications) - modifications2 = self.model:update_filecontent2(modifications2) - end - - local url = self.conf.script .. self.conf.prefix .. self.conf.controller - - -- Start/Stop/Restart process - local cmdmanagement, actionresult - if ( self.clientdata.cmdmanagement) then - cmdmanagement = cfe({ - name="cmdmanagement", - label="Previous action result", - action=cfe({ - name="cmdmanagement", - value=string.lower(self.clientdata.cmdmanagement), -- This row contains start/stop/restart (one of these commands) - }), - }) - actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action ) - end - - local status=self.model.getstatus() - local file = self.model:get_filedetails() - local file2 = self.model:get_filedetails("2") - - -- Add buttons - file.cmdsave = cfe ({ - name="cmdsave", - label="Apply settings", - value="Apply", - type="submit", - }) - if (self.clientdata.cmdsave) then - file.cmdsave.descr="* Changes has been saved!" - end - - -- Management buttons (Hide/show buttons - local pidofstatus - if (string.lower(status.status.value) == "enabled" ) then pidofstatus = true end - management = displaycmdmanagement(pidofstatus) - if (actionresult) then - management.actionresult.descr=cmdmanagement.descr - management.actionresult.errtxt=cmdmanagement.errtxt - end - - return ( { - status = status, - file = file, - file2 = file2, - modifications = modifications, - management = management, - url = url, } ) +function startstop(self) + return controllerfunctions.handle_startstop(self, self.model.startstop_service, self.model.getstatus, self.clientdata) end -function logfile (self) +function details(self) + return self.model.getstatusdetails() +end - local status=self.model.getstatus() - local logfile = self.model:get_logfile() +function editracoon (self) + return controllerfunctions.handle_form(self, self.model.get_racoonfiledetails, self.model.update_racoonfiledetails, self.clientdata, "Save", "Edit Racoon Config", "Configuration Set") +end - return ({ - status = status, - logfile = logfile, - url = url, - }) +function editipsec (self) + return controllerfunctions.handle_form(self, self.model.get_ipsecfiledetails, self.model.update_ipsecfiledetails, self.clientdata, "Save", "Edit IPSec Config", "Configuration Set") end diff --git a/ipsectools-details-html.lsp b/ipsectools-details-html.lsp new file mode 100644 index 0000000..b16da64 --- /dev/null +++ b/ipsectools-details-html.lsp @@ -0,0 +1,41 @@ +<% local data, viewlibrary = ... +require("viewfunctions") +--[[ DEBUG INFORMATION +io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") +io.write(html.cfe_unpack(data)) +io.write("</span>") +--]] +%> + +<% viewlibrary.dispatch_component("status") %> + +<H2><%= data.label %></H2> +<DL> +<% +if not data.value.show_isakmp or #data.value.show_isakmp.value == 0 then + io.write("No status details available") +else + for i,entry in pairs(data.value.show_isakmp.value) do + if (type(entry) == "table") and (entry.Destination) and (entry.Destination.value) and (#entry.Destination.value > 0) then + io.write("<H3><IMG SRC='/skins/static/tango/16x16/status/network-") + if (tonumber(entry.St.value) < 9) then + io.write("error") + else + io.write("idle") + end + io.write(".png' width='16' height='16'> ".. entry.Destination.value .. "</H3>") + io.write("<TABLE>\n") + local tags = {"Created","Source","Destination", "St", "Phase2details"} + for j,tag in pairs(tags) do + io.write("<TR><TD STYLE='font-weight:bold;width:120px;border:none;'>" .. + (entry[tag].label or "") .. "</TD><TD STYLE='border:none;'>"..(entry[tag].value or "")) + if (entry[tag].descr) and (#entry[tag].descr > 0) then io.write(" (".. entry[tag].descr .. ")") end + io.write("</TD></TR>") + end + io.write("</TABLE>") + end + end +end +--displayitem(data.value.ip_xfrm_policy) +%> +</DL> diff --git a/ipsectools-editipsec-html.lsp b/ipsectools-editipsec-html.lsp new file mode 120000 index 0000000..15b1930 --- /dev/null +++ b/ipsectools-editipsec-html.lsp @@ -0,0 +1 @@ +../filedetails-html.lsp
\ No newline at end of file diff --git a/ipsectools-editracoon-html.lsp b/ipsectools-editracoon-html.lsp new file mode 120000 index 0000000..15b1930 --- /dev/null +++ b/ipsectools-editracoon-html.lsp @@ -0,0 +1 @@ +../filedetails-html.lsp
\ No newline at end of file diff --git a/ipsectools-expert-html.lsp b/ipsectools-expert-html.lsp index effaba1..e699690 100644 --- a/ipsectools-expert-html.lsp +++ b/ipsectools-expert-html.lsp @@ -1,68 +1,8 @@ -<% local form = ... %> -<% -require("viewfunctions") -%> - -<H1>SYSTEM INFO</H1> -<DL> -<% -local myform = form.status -local tags = { "status", "version", "autostart", } -displayinfo(myform,tags,"viewonly") -%> -</DL> - -<form name="myform" action="" method="POST"> -<h1>CONFIGURATION</h1> -<H2>Expert config - Config</H2> -<h3>File details</h3> -<DL> -<% -local myform = form.file -local tags = { "filename", "filesize", "mtime", "sumerrors", } -displayinfo(myform,tags,"viewonly") -%> -</DL> - -<H3>FILE CONTENT</H3> -<% -local myform = form.file -io.write(html.form[myform.filecontent.type](myform.filecontent)) -%> +<% local data, viewlibrary = ... %> -<H2>Expert config - Policy</H2> -<h3>File details</h3> -<DL> <% -local myform = form.file2 -local tags = { "filename2", "filesize2", "mtime2", "sumerrors2", } -displayinfo(myform,tags,"viewonly") +viewlibrary.dispatch_component("status") +viewlibrary.dispatch_component("editracoon") +viewlibrary.dispatch_component("editipsec") +viewlibrary.dispatch_component("startstop") %> -</DL> - -<H3>FILE CONTENT</H3> -<% -io.write(html.form[myform.filecontent2.type](myform.filecontent2)) -%> - -<H2>SAVE AND APPLY ABOVE SETTINGS</H2> -<DL> -<% -local myform = form.file -local tags = { "cmdsave", } -displayinfo(myform,tags) -%> -</DL> - -<% --- Management buttons -local myform = form.management -local tags = { "start", "stop", "restart" } -if (myform) then - io.write("<H1>MANAGEMENT</H1>\n<DL>") - displaymanagement(myform,tags) - io.write("</DL>") -end -%> -</form> - diff --git a/ipsectools-logfile-html.lsp b/ipsectools-logfile-html.lsp index a23c3d6..5543322 100644 --- a/ipsectools-logfile-html.lsp +++ b/ipsectools-logfile-html.lsp @@ -1,31 +1,7 @@ -<% local form = ... %> -<% +<% local data, viewlibrary = ... require("viewfunctions") %> -<H1>SYSTEM INFO</H1> -<DL> -<% -local myform = form.status -local tags = { "status", "version", "autostart", } -displayinfo(myform,tags,"viewonly") -%> -</DL> - -<% local myform = form.logfile %> -<form name="myform" action="" method="POST"> -<h1>LOGFILE</h1> -<h2>Details</h2> -<DL> -<% -local tags = { "filename", "filesize", "mtime", "sumerrors", } -displayinfo(myform,tags,"viewonly") -%> -</DL> - -<H3>FILE CONTENT</H3> -<% -io.write(html.form[myform.filecontent.type](myform.filecontent)) -%> - -</form> +<% if viewlibrary and viewlibrary.dispatch_component then + viewlibrary.dispatch_component("alpine-baselayout/logfiles/view", {name="/var/log/messages", grep="racoon"}) +end %> 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 diff --git a/ipsectools-startstop-html.lsp b/ipsectools-startstop-html.lsp new file mode 120000 index 0000000..0ea2627 --- /dev/null +++ b/ipsectools-startstop-html.lsp @@ -0,0 +1 @@ +../startstop-html.lsp
\ No newline at end of file diff --git a/ipsectools-status-html.lsp b/ipsectools-status-html.lsp index 447f007..b2f8480 100644..120000 --- a/ipsectools-status-html.lsp +++ b/ipsectools-status-html.lsp @@ -1,44 +1 @@ -<% local form = ... -require("viewfunctions") ---[[ DEBUG INFORMATION -io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>") -io.write(html.cfe_unpack(form)) -io.write("</span>") ---]] -%> - -<H1>SYSTEM INFO</H1> -<DL> -<% -local myform = form.status -local tags = { "status", "version", "autostart", } -displayinfo(myform,tags,"viewonly") -%> -</DL> - -<H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2> -<DL> -<% -local myform = form.status.show_isakmp.option -for k,v in pairs(myform) do - if (type(v) == "table") and (v.Destination) and (v.Destination.value) and (#v.Destination.value > 0) then - io.write("<H3><IMG SRC='/skins/static/tango/16x16/status/network-") - if (tonumber(v['St']['value']) < 9) then - io.write("error") - else - io.write("idle") - end - io.write(".png' width='16' height='16'> ".. v['Destination']['value'] .. "</H3>") - io.write("<TABLE>\n") - local tags = {"Created","Source","Destination", "St", "Phase2details"} - for k1,v1 in pairs(tags) do - io.write("<TR><TD STYLE='font-weight:bold;width:120px;border:none;'>" .. - (v[v1]['label'] or "") .. "</TD><TD STYLE='border:none;'>"..(v[v1]['value'] or "")) - if (v[v1]['descr']) and (#v[v1]['descr'] > 0) then io.write(" (".. v[v1]['descr'] .. ")") end - io.write("</TD></TR>") - end - io.write("</TABLE>") - end -end -%> -</DL> +../status-html.lsp
\ No newline at end of file diff --git a/ipsectools.menu b/ipsectools.menu index b194bec..a1df99e 100644 --- a/ipsectools.menu +++ b/ipsectools.menu @@ -1,5 +1,5 @@ #CAT GROUP/DESC TAB ACTION -Networking 45IPsec Status status +Networking 45IPsec Status details Networking 45IPsec Expert expert Networking 45IPsec Logfile logfile diff --git a/ipsectools.roles b/ipsectools.roles index f0b9319..95a11e2 100644 --- a/ipsectools.roles +++ b/ipsectools.roles @@ -1,2 +1,2 @@ -READ=ipsectools:status,ipsectools:logfile -UPDATE=ipsectools:expert +READ=ipsectools:status,ipsectools:logfile,ipsectools:details +UPDATE=ipsectools:startstop,ipsectools:editracoon,ipsectools:editipsec,ipsectools:expert |