summaryrefslogtreecommitdiffstats
path: root/opennhrp-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'opennhrp-model.lua')
-rw-r--r--opennhrp-model.lua62
1 files changed, 21 insertions, 41 deletions
diff --git a/opennhrp-model.lua b/opennhrp-model.lua
index 7c31bbc..42497c9 100644
--- a/opennhrp-model.lua
+++ b/opennhrp-model.lua
@@ -9,7 +9,6 @@ local configfile = "/etc/opennhrp/opennhrp.conf"
local processname = "opennhrp"
local packagename = "opennhrp"
---[[
local descr = {
Type = {
['incomplete']="The protocol address is being resolved",
@@ -30,46 +29,34 @@ local descr = {
-- LOCAL FUNCTIONS
local function opennhrpctl_show()
- local cmd_output_result={}
- local cmd_output_result_table={}
- local cmd_output_error, opennhrpstatus
+ local peers_list = cfe({ type="structure", value={}, label="Peers" })
+ local opennhrpstatus = cfe({ value="Show report not available", label="Status" })
local cmd = "/usr/sbin/opennhrpctl show 2>/dev/null"
local f = io.popen( cmd )
- for line in f:lines() do
- if string.find(line, "^Status:") then
- opennhrpstatus=line
- else
- table.insert(cmd_output_result, line)
- end
- end
+ local content = f:read("*a")
f:close()
- local cnt = 0
- for k,v in pairs(cmd_output_result) do
- if string.find(v,"^Interface") then
- cnt = cnt + 1
- cmd_output_result_table[cnt] = {}
- end
- if ( cnt > 0 ) and (v ~= "") then
- local k = string.match(v,"^(.-):%s?.*")
- 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]
+ local current
+ for line in string.gmatch(content, "([^\n]*)\n?") do
+ if string.find(line, "^Status:") then
+ opennhrpstatus.value = string.match(line, ":%s*(%w+)")
+ elseif string.find(line,"^Interface:") then
+ local intf = string.match(line, ":%s*(%w+)")
+ current = {}
+ peers_list.value[intf] = peers_list.value[intf] or {}
+ table.insert(peers_list.value[intf], current)
+ elseif ( current ) and (line ~= "") then
+ local name,val = string.match(line,"^(.-):%s?(.*)")
+ if name and val then
+ current[name] = cfe({value=val, label=name})
+ if (type(descr[name]) == "table") then
+ current[name].descr = descr[name][val]
+ end
end
end
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
+ return cfe({ type="group", value={peers_list=peers_list, status=opennhrpstatus}, label="OpenNHRP Show Report" })
end
---]]
local function parseconfigfile(self, configfile)
if fs.is_file(configfile) then
@@ -193,14 +180,7 @@ function getstatus()
end
function getshowreport()
- local show = cfe({ type="longtext", label="OpenNHRP show report" })
- local cmd = "/usr/sbin/opennhrpctl show 2>/dev/null"
- local f = io.popen( cmd )
- show.value = f:read("*a")
- if not show.value or show.value == "" then
- show.value = "No report available"
- end
- return show
+ return opennhrpctl_show()
end
function getconfig(self)