diff options
author | Mika Havela <mika.havela@gmail.com> | 2008-04-01 15:43:00 +0000 |
---|---|---|
committer | Mika Havela <mika.havela@gmail.com> | 2008-04-01 15:43:00 +0000 |
commit | 50898e8dfaca505529a20dde4faa40e4806f32bc (patch) | |
tree | 6162979965f44f1a01badbee150d16eb9a788109 | |
parent | 52868a753cfd1b7e770880d5299c2b7301413a95 (diff) | |
download | acf-opennhrp-50898e8dfaca505529a20dde4faa40e4806f32bc.tar.bz2 acf-opennhrp-50898e8dfaca505529a20dde4faa40e4806f32bc.tar.xz |
Saving work for today.
Added expert tab and start/stop/restart process.
git-svn-id: svn://svn.alpinelinux.org/acf/opennhrp/trunk@873 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r-- | opennhrp-controller.lua | 90 | ||||
-rw-r--r-- | opennhrp-model.lua | 92 | ||||
-rw-r--r-- | opennhrp-status-html.lsp | 22 | ||||
-rw-r--r-- | opennhrp.menu | 1 |
4 files changed, 166 insertions, 39 deletions
diff --git a/opennhrp-controller.lua b/opennhrp-controller.lua index e592bbc..f59ac0a 100644 --- a/opennhrp-controller.lua +++ b/opennhrp-controller.lua @@ -19,19 +19,91 @@ mvc.on_load = function(self, parent) end end -local function getstatus(self) - local status = self.model.getstatus() - if (#status.status.value > 0) then - status.status.value = "Enabled" - else - status.status.value = "Disabled" - 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", + }) - return status + -- 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=getstatus(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/opennhrp-model.lua b/opennhrp-model.lua index f809283..ae5531e 100644 --- a/opennhrp-model.lua +++ b/opennhrp-model.lua @@ -11,7 +11,8 @@ local configfile = "/etc/opennhrp/opennhrp.conf" local processname = "opennhrp" local baseurl = "/etc/opennhrp/" -local type_status = { +local descr = { + Type = { ['incomplete']="The protocol address is being resolved", ['negative']="This protocol address is not available", ['cached']="Protocol address was resolved successfully", @@ -19,7 +20,12 @@ local type_status = { ['dynamic']="This entry is from a node that connected to us", ['local']="Local interface address", ['static']="Static mapping from configuration file (e.g. address of core)", - } + }, + Flags= { +-- ['up']="Connection is fully usable", + ['lower-up']="ipsec connections is up, but registration is not yet done", + }, +} local function get_version() local cmd_output_result, cmd_output_error @@ -71,27 +77,46 @@ local function opennhrpctl_show() end if ( cnt > 0 ) and (v ~= "") then local k = string.match(v,"^(.-):%s?.*") - cmd_output_result_table[cnt][k]=string.match(v,"^.-:%s?(.*)") - if (string.lower(k) == "type") then - local tooltip = string.match(v,"^.-:%s?(.*)") - cmd_output_result_table[cnt]["Tooltip"] = type_status[tooltip] - local typestatus = string.lower(string.match(v,"^.-:%s?(.*)")) - cmd_output_result_table[cnt]['type_descr']=(type_status[typestatus] or "") + cmd_output_result_table[cnt][k]=cfe({value=string.match(v,"^.-:%s?(.*)")}) + local statusdescription = string.lower(string.match(v,"^.-:%s?(.*)")) + if (type(descr[k]) == "table") then + cmd_output_result_table[cnt][k]['descr']=descr[k][statusdescription] end end end - return cmd_output_result_table,opennhrpstatus,cmd_output_error -end - + local peers_list = {} + for k,v in pairs(cmd_output_result_table) do + if (v.Interface.value) and not (peers_list[v.Interface.value]) then + peers_list[v.Interface.value] = {} + end + table.insert(peers_list[v.Interface.value], v) + end - + return peers_list,opennhrpstatus,cmd_output_error +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 + -- Reporting back (true|false, the original acition) + return cmdresult,action +end function getstatus() local status = {} @@ -104,7 +129,7 @@ function getstatus() status.status = cfe({ name="status", label="Program status", - value=procps.pidof(processname), + value=process_status_text(processname), }) local autostart_sequense, autostart_errtxt = autostarts() status.autostart = cfe({ name="autostart", @@ -119,19 +144,44 @@ function getstatus() value=opennhrpctl_status, }) - local peers_list = {} - for k,v in pairs(opennhrpctl_show) do - if (v.Interface) and not (peers_list[v.Interface]) then - peers_list[v.Interface] = {} - end - table.insert(peers_list[v.Interface], v) - end status.show = cfe({ name="show", label="Peers", - option=peers_list, + option=opennhrpctl_show, }) 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/opennhrp-status-html.lsp b/opennhrp-status-html.lsp index 0d84bc1..765de12 100644 --- a/opennhrp-status-html.lsp +++ b/opennhrp-status-html.lsp @@ -49,28 +49,32 @@ for k,v in pairs(myform.option or {}) do for k1,v1 in pairs(v) do io.write("\n\t\t\t<TR STYLE='padding-bottom:10px;'><TD WIDTH='150px' STYLE='font-weight:bold;padding-left:20px;'><IMG SRC='/static/tango/16x16/status/") - if (v1) and (string.lower(v1['Type']) == "incomplete") then + if (v1) and (string.lower(v1['Type']['value']) == "incomplete") then io.write("network-error") - elseif (v1) and (string.lower(v1['Type']) == "negative") then + elseif (v1) and (string.lower(v1['Type']['value']) == "negative") then io.write("network-offline") - elseif (v1) and (string.lower(v1['Flags']) == "up") then + elseif (v1) and (string.lower(v1['Flags']['value']) == "up") then io.write("network-idle") - elseif (v1) and (string.lower(v1['Flags']) == "used up") then + elseif (v1) and (string.lower(v1['Flags']['value']) == "used up") then io.write("network-transmit-receive") + elseif (v1) and (string.lower(v1['Flags']['value']) == "used up") then + io.write("network-offline") else io.write("network-error") end - io.write(".png' width='16' height='16' title='" .. v1["Tooltip"] .. "'> " .. v1["Protocol-Address"] .. "</TD><TD STYLE='font-weight:bold;'></TD></TR>\n") + io.write(".png' width='16' height='16' title='" .. (v1['Type']['descr'] or "") .. "'> " .. v1["Protocol-Address"]['value'] .. "</TD><TD STYLE='font-weight:bold;'></TD></TR>\n") for k2,v2 in pairs(v1) do + +---[[ if (k2) and not ((string.lower(k2) == "protocol-address") or - (string.lower(k2) == "tooltip") or (string.lower(k2) == "interface")) then - io.write("<TR><TD STYLE='font-weight:bold;padding-left:40px;'>"..k2.."</TD><TD>"..v2) - if (string.lower(k2) == "type") then - io.write(" <I>(" .. (v1['type_descr'] or "") .. ")</I>") + io.write("<TR><TD STYLE='font-weight:bold;padding-left:40px;'>"..k2.."</TD><TD>"..v2['value']) + if (v2['descr']) and (#v2['descr'] > 0) then + io.write(" <I>(" .. (v2['descr'] or "") .. ")</I>") end io.write("</TD></TR>\n") end +--]] end end diff --git a/opennhrp.menu b/opennhrp.menu index cb5d25d..c836a24 100644 --- a/opennhrp.menu +++ b/opennhrp.menu @@ -1,3 +1,4 @@ #CAT GROUP/DESC TAB ACTION Networking 45NHRP Status status +Networking 45NHRP Expert expert |