diff options
author | Ted Trask <ttrask01@yahoo.com> | 2008-09-18 19:32:39 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2008-09-18 19:32:39 +0000 |
commit | 4d42ae72cb319eaff33374f61fec515ee374bdbb (patch) | |
tree | c34451e4a6e16de74b1fafdee27bc8777f9fdd5b | |
parent | 6c92185343afd2a6af20868de2f61337c7288554 (diff) | |
download | acf-opennhrp-4d42ae72cb319eaff33374f61fec515ee374bdbb.tar.bz2 acf-opennhrp-4d42ae72cb319eaff33374f61fec515ee374bdbb.tar.xz |
Modified opennhrp to parse show result and display nicely.
git-svn-id: svn://svn.alpinelinux.org/acf/opennhrp/trunk@1476 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r-- | opennhrp-model.lua | 62 | ||||
-rw-r--r-- | opennhrp-show-html.lsp | 44 |
2 files changed, 64 insertions, 42 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) diff --git a/opennhrp-show-html.lsp b/opennhrp-show-html.lsp index fce8a79..4074cf8 100644 --- a/opennhrp-show-html.lsp +++ b/opennhrp-show-html.lsp @@ -8,5 +8,47 @@ end %> <H1><%= data.label %></H1> <DL> -<% displayitem(data) %> +<% +displayitem(data.value.status) +if #data.value.peers_list then +%> +<DT><%= data.value.peers_list.label %></DT> +<DD> +<% for intf,addresses in pairs(data.value.peers_list.value) do %> + <TABLE STYLE='margin-bottom:10px;'> + <TR><TD STYLE='font-weight:bold;border:none;'><IMG SRC='/skins/static/tango/16x16/places/network-server.png' width='16' height='16' alt> <%= intf %></TD><TD STYLE='border:none;'></TD></TR> +<% for i,entries in ipairs(addresses) do + io.write("<TR STYLE='padding-bottom:10px;'><TD WIDTH='150px' STYLE='font-weight:bold;padding-left:20px;border:none;'><IMG SRC='/skins/static/tango/16x16/status/") + + if entries.Type and (entries.Type.value == "incomplete") then + io.write("network-error") + elseif entries.Type and (entries.Type.value == "negative") then + io.write("network-offline") + elseif entries.Flags and (entries.Flags.value == "up") then + io.write("network-idle") + elseif entries.Flags and (entries.Flags.value == "used up") then + io.write("network-transmit-receive") + elseif entries.Flags and (entries.Flags.value == "used up") then + io.write("network-offline") + else + io.write("network-error") + end + io.write(".png' width='16' height='16' title='" .. (entries.Type.descr or "") .. "'> " .. entries["Protocol-Address"].value .. "</TD><TD STYLE='font-weight:bold;border:none;'></TD></TR>\n") + + for j,entry in pairs(entries) do + if j ~= "Protocol-Address" then + io.write("<TR><TD STYLE='font-weight:bold;padding-left:40px;border:none;'>"..entry.label.."</TD><TD STYLE='border:none;'>"..entry.value) + if entry.descr then + io.write(" <I>(" .. entry.descr .. ")</I>") + end + io.write("</TD></TR>\n") + end + end + end + io.write("\t\t\t</TABLE>") + end +%> +</DD> +<% end %> </DL> + |