summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-04-01 15:40:14 +0000
committerMika Havela <mika.havela@gmail.com>2008-04-01 15:40:14 +0000
commitf8b1afd4fed3f3df068fae35692bfff675b50cdc (patch)
treeee513568cd20ea20b9161b3ac0e513b5a0ab41e8
parentfdaecbf0715a1f68252d400585811d06998b56fc (diff)
downloadacf-ipsec-tools-f8b1afd4fed3f3df068fae35692bfff675b50cdc.tar.bz2
acf-ipsec-tools-f8b1afd4fed3f3df068fae35692bfff675b50cdc.tar.xz
Saving work for today.
Adding Expert tab to edit config (still missing edit /etc/ipsec.conf) git-svn-id: svn://svn.alpinelinux.org/acf/ipsec-tools/trunk@872 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--Makefile1
-rw-r--r--ipsectools-controller.lua82
-rw-r--r--ipsectools-model.lua203
-rw-r--r--ipsectools-status-html.lsp61
-rw-r--r--ipsectools.menu1
5 files changed, 241 insertions, 107 deletions
diff --git a/Makefile b/Makefile
index d658971..db4969e 100644
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,7 @@ APP_DIST=\
ipsectools-controller.lua \
ipsectools-model.lua \
ipsectools-status-html.lsp \
+ ipsectools-expert-html.lsp \
ipsectools.menu \
diff --git a/ipsectools-controller.lua b/ipsectools-controller.lua
index 2a31dd6..11d597d 100644
--- a/ipsectools-controller.lua
+++ b/ipsectools-controller.lua
@@ -17,9 +17,91 @@ mvc.on_load = function(self, parent)
end
end
+local function displaycmdmanagement(disablestart,disablestop,disablerestart)
+ -- 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",
+ })
+
+ -- Disable management buttons based on if the process is running or not
+ if (disablestart) then management.start.disabled = "yes" end
+ if (disablestop) then management.stop.disabled = "yes" end
+ if (disablerestart) then management.restart.disabled = "yes" end
+
+ return management
+end
+
-- ################################################################################
-- PUBLIC FUNCTIONS
function status(self)
return { status=self.model.getstatus() }
end
+expert = function (self)
+ local modifications = self.clientdata.filecontent or ""
+ if ( self.clientdata.cmdsave ) then
+ modifications = self.model:update_filecontent(modifications)
+ end
+ local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller
+
+ -- Start/Stop/Restart process
+ local cmdmanagement
+ 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)
+ }),
+ })
+ local actionresult, cmdmanagement = self.model:startstop_service( cmdmanagement.action )
+ end
+
+ local status=self.model.getstatus()
+ local file = self.model:get_filedetails()
+
+ -- 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
+ local disablestart,disablestop,disablerestart
+ -- Disable management buttons based on if the process is running or not
+ if (string.lower(status.status.value) == "enabled" ) then
+ disablestart = "yes"
+ else
+ disablestop = "yes"
+ end
+ -- Display management buttons
+ management = displaycmdmanagement(disablestart,disablestop,disablerestart)
+
+ return ( {
+ status = status,
+ file = file,
+ modifications = modifications,
+ management = management,
+ cmdmanagement = cmdmanagement,
+ url = url, } )
+end
diff --git a/ipsectools-model.lua b/ipsectools-model.lua
index 26d9ffc..3582900 100644
--- a/ipsectools-model.lua
+++ b/ipsectools-model.lua
@@ -12,6 +12,21 @@ local processname = "racoon"
local pkgname = "ipsec-tools"
local baseurl = "/etc/racoon/"
+local descr = {
+ state={
+ ['9']="Established",
+ },
+ side={
+ ['R']="We are 'Responder'.",
+ ['I']="We 'Initiated' this phase1",
+ },
+ exchange={
+ ['M']="Main mode",
+ ['A']="Agressive mode",
+ ['B']="Basic mode",
+ },
+
+}
local function get_version()
local cmd_output_result, cmd_output_error
local cmd = "/sbin/apk_version -vs " .. pkgname .." 2>/dev/null"
@@ -41,85 +56,91 @@ local function autostarts()
end
-local function racoonctl()
- local cmd_output_result, cmd_output_error
- local cmd = "/usr/sbin/racoonctl -lll show-sa isakmp 2>/dev/null"
+local function ip_xfrm(mode)
+ local cmd_output_result
+ local cmd = "/bin/ip xfrm " .. mode .. " 2>/dev/null"
local f = io.popen( cmd )
local cmd_output_result = f:read("*a")
f:close()
- return cmd_output_result,cmd_output_error
+ return cmd_output_result
end
-local function racoonctl_table()
- local value = racoonctl()
+local function phase2details(dst)
local output = {}
- for k,v in pairs(format.string_to_table(value,"\n")) do
- if not (string.find(v,"^Source")) then
- output[k]={}
- local variable=format.string_to_table(v,"%s+")
- output[k]['Source']=cfe({
- name="Source",
- label="Source",
- value=variable[1],
- })
- output[k]['Destination']=cfe({
- name="Destination",
- label="Destination",
- value=variable[2],
- })
- output[k]['Cookies']=cfe({
- name="Cookies",
- label="Cookies",
- value=variable[3],
- })
- output[k]['St']=cfe({
- name="St",
- label="Variable St",
- value=variable[4],
- })
- output[k]['S']=cfe({
- name="S",
- label="Variable S",
- value=variable[5],
- })
- output[k]['V']=cfe({
- name="V",
- label="Variable V",
- value=variable[6],
- })
- output[k]['E']=cfe({
- name="E",
- label="Variable E",
- value=variable[7],
- })
- output[k]['Created']=cfe({
- name="Created",
- label="Created",
- value=(variable[8] or "") .. " " .. (variable[9] or ""),
- })
-
- output[k]['Phase2']=cfe({
- name="Phase2",
- label="Phase2",
- value=variable[10],
- })
- end
- end
+ dst = string.match(dst,"^(.*)%.") -- Removes the portnumber
+ table.insert(output, {label="Outgoing", value=ip_xfrm("state list src ".. dst)})
+ table.insert(output, {label="Incoming", value=ip_xfrm("state list dst ".. dst)})
return output
end
-local function ip_xfrm(mode)
- local cmd_output_result
- local cmd = "/bin/ip xfrm " .. mode .. " 2>/dev/null"
+local function racoonctl_table()
+ local output = {}
+ local cmd = "/usr/sbin/racoonctl -lll show-sa isakmp 2>/dev/null"
local f = io.popen( cmd )
- local cmd_output_result = f:read("*a")
+ local value = f:read("*a")
f:close()
- return cmd_output_result
+ 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",
+ label="Source",
+ value=variable[1],
+ })
+ output[k]['Destination']=cfe({
+ name="Destination",
+ label="Destination",
+ value=variable[2],
+ })
+ output[k]['Cookies']=cfe({
+ name="Cookies",
+ label="Cookies",
+ value=variable[3],
+ })
+ output[k]['St']=cfe({
+ name="St",
+ label="State",
+ value=variable[4],
+ descr=descr.state[variable[4]],
+ })
+ output[k]['S']=cfe({
+ name="S",
+ label="Side",
+ value=variable[5],
+ descr=descr.side[variable[5]],
+ })
+ output[k]['V']=cfe({
+ name="V",
+ label="Version",
+ value=variable[6],
+ })
+ output[k]['E']=cfe({
+ name="E",
+ label="Exchange",
+ value=variable[7],
+ descr=descr.exchange[variable[7]],
+ })
+ output[k]['Created']=cfe({
+ name="Created",
+ label="Created",
+ value=(variable[8] or "") .. " " .. (variable[9] or ""),
+ })
+
+ output[k]['Phase2']=cfe({
+ name="Phase2",
+ label="Phase2",
+ value=variable[10],
+ option=phase2details(variable[2]),
+ })
+ end
+ end
+ return output
end
function process_status_text(procname)
local t = procps.pidof(procname)
- if #t > 0 then
+ if (t) and (#t > 0) then
return "Enabled"
else
return "Disabled"
@@ -129,6 +150,14 @@ 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
+ -- Reporting back (true|false, the original acition)
+ return cmdresult,action
+end
function getstatus()
local status = {}
@@ -147,19 +176,9 @@ function getstatus()
errtxt=autostart_errtxt,
})
- status.show_isakmp2 = cfe({ name="show_isakmp2",
- label="Tunnels",
- value=racoonctl_table(),
- })
-
status.show_isakmp = cfe({ name="show_isakmp",
- label="racoonctl -lll show-sa isakmp",
- value=racoonctl(),
- })
-
- status.ip_xfrm_state = cfe({ name="show_esp",
- label="ip xfrm state",
- value=ip_xfrm("state"),
+ label="Tunnels",
+ option=racoonctl_table(),
})
status.ip_xfrm_policy = cfe({ name="ip_xfrm_policy",
@@ -170,4 +189,36 @@ function getstatus()
return status
end
+function get_filedetails()
+ local path = configfile
+ local filedetails = fs.stat(path)
+ local file = {}
+ file["filename"] = cfe({
+ name="filename",
+ label="File name",
+ value=path,
+ })
+ file["filesize"] = cfe({
+ name="filesize",
+ label="File size",
+ value=filedetails.size or 0,
+ })
+ file["mtime"] = cfe({
+ name="mtime",
+ label="File date",
+ value=filedetails.mtime or "---",
+ })
+ file["filecontent"] = cfe({
+ type="longtext",
+ name="filecontent",
+ label="File content",
+ value=fs.read_file(path),
+ })
+ return file
+end
+function update_filecontent (self, modifications)
+ local path = configfile
+ local file_result,err = fs.write_file(path, format.dostounix(modifications))
+ return file_result
+end
diff --git a/ipsectools-status-html.lsp b/ipsectools-status-html.lsp
index b76acfe..463474c 100644
--- a/ipsectools-status-html.lsp
+++ b/ipsectools-status-html.lsp
@@ -35,50 +35,49 @@ informationform(myform,tags)
</DL>
<H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2>
-
-<H3>Phase1</H3>
+<H3>Phase1 and Phase2 information</H3>
<DL>
-
-<TABLE>
-<TR><TD CLASS='header'>Source</TD><TD CLASS='header'>Destination</TD><TD CLASS='header'>Cookies</TD><TD CLASS='header'>St</TD><TD CLASS='header'>S</TD><TD CLASS='header'>V</TD><TD CLASS='header'>E</TD><TD CLASS='header'>Created</TD><TD CLASS='header'>Phase2</TD></TR>
<?
-local myform = form.status.show_isakmp2.value
+local myform = form.status.show_isakmp.option
for k,v in pairs(myform) do
- io.write("\t<TR>\n")
- io.write("\t \t<TD>" .. (v['Source']['value'] or "") .. "</TD>\n")
- io.write("\t \t<TD>" .. (v['Destination']['value'] or "") .. "</TD>\n")
- io.write("\t \t<TD>" .. (v['Cookies']['value'] or "") .. "</TD>\n")
- io.write("\t \t<TD>" .. (v['St']['value'] or "") .. "</TD>\n")
- io.write("\t \t<TD>" .. (v['S']['value'] or "") .. "</TD>\n")
- io.write("\t \t<TD>" .. (v['V']['value'] or "") .. "</TD>\n")
- io.write("\t \t<TD>" .. (v['E']['value'] or "") .. "</TD>\n")
- io.write("\t \t<TD>" .. (v['Created']['value'] or "") .. "</TD>\n")
- io.write("\t \t<TD>" .. (v['Phase2']['value'] or "") .. "</TD>\n")
- io.write("\t</TR>\n")
+ if (type(v) == "table") and (v.Destination) and (v.Destination.value) and (#v.Destination.value > 0) then
+ io.write("<DT><IMG SRC='/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'] .. "</DT>")
+ io.write("<DD><TABLE>\n")
+ io.write("<TR><TD COLSPAN=2 CLASS='header'>Phase1 details</TD></TR>")
+ local tags = {"Created","Source", "St", "S", "E",}
+ for k1,v1 in pairs(tags) do
+ io.write("<TR><TD STYLE='font-weight:bold;width:120px;'>" ..
+ (v[v1]['label'] or "") .. "</TD><TD>"..(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("<TR><TD COLSPAN=2 CLASS='header' STYLE='padding-left:15px;'>Phase2 details</TD></TR>")
+ for k1,v1 in pairs(v['Phase2']['option']) do
+ io.write("<TR><TD STYLE='padding-left:15px;' COLSPAN=2><PRE>" .. (v1['value'] or "") .. "</PRE>")
+ io.write("</TD></TR>")
+ end
+ io.write("</TABLE></DD>")
+ end
end
?>
-</TABLE>
</DL>
-
-<H3>Phase2</H3>
+<H3>Policy information</H3>
<DL>
<?
-
-local myform = form.status.ip_xfrm_state
-io.write("\t\t<PRE>" .. myform.value .. "</PRE></P>\n")
-?>
-</DL>
-
-<H3>Policy</H3>
-<DL>
-<?
local myform = form.status.ip_xfrm_policy
-io.write("\t\t<PRE>" .. myform.value .. "</PRE></P>\n")
+io.write("<DT>"..myform.label .."</DT>\n")
+io.write("<DD><PRE>"..myform.value .."</PRE></DT>\n")
?>
-
</DL>
+
<?
--[[ DEBUG INFORMATION
io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
diff --git a/ipsectools.menu b/ipsectools.menu
index 17e5df1..b46dfdd 100644
--- a/ipsectools.menu
+++ b/ipsectools.menu
@@ -1,3 +1,4 @@
#CAT GROUP/DESC TAB ACTION
Networking 45IPsec Status status
+Networking 45IPsec Expert expert