summaryrefslogtreecommitdiffstats
path: root/opennhrp-model.lua
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-04-01 15:43:00 +0000
committerMika Havela <mika.havela@gmail.com>2008-04-01 15:43:00 +0000
commit50898e8dfaca505529a20dde4faa40e4806f32bc (patch)
tree6162979965f44f1a01badbee150d16eb9a788109 /opennhrp-model.lua
parent52868a753cfd1b7e770880d5299c2b7301413a95 (diff)
downloadacf-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
Diffstat (limited to 'opennhrp-model.lua')
-rw-r--r--opennhrp-model.lua92
1 files changed, 71 insertions, 21 deletions
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