From 34db03ce3b6a455a17da33bf10a8eb0165b90c2c Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Wed, 26 Mar 2008 14:41:22 +0000 Subject: First commit on opennhrp. Only shows standard process information and shows connected peers (or what to call them). git-svn-id: svn://svn.alpinelinux.org/acf/opennhrp/trunk@841 ab2d0c66-481e-0410-8bed-d214d4d58bed --- opennhrp-controller.lua | 37 +++++++++++++++++++++ opennhrp-model.lua | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ opennhrp-status-html.lsp | 74 ++++++++++++++++++++++++++++++++++++++++++ opennhrp.menu | 3 ++ 4 files changed, 198 insertions(+) create mode 100644 opennhrp-controller.lua create mode 100644 opennhrp-model.lua create mode 100644 opennhrp-status-html.lsp create mode 100644 opennhrp.menu diff --git a/opennhrp-controller.lua b/opennhrp-controller.lua new file mode 100644 index 0000000..e592bbc --- /dev/null +++ b/opennhrp-controller.lua @@ -0,0 +1,37 @@ +module(..., package.seeall) + +-- This is the object/text used when we want to add a new record + +require("format") + +local newrecordtxt = "[New]" + +local list_redir = function (self) + self.conf.action = "status" + self.conf.type = "redir" + error (self.conf) +end + +mvc = {} +mvc.on_load = function(self, parent) + if (self.worker[self.conf.action] == nil ) or ( self.conf.action == "init" ) then + self.worker[self.conf.action] = list_redir(self) + 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 + + return status +end +-- ################################################################################ +-- PUBLIC FUNCTIONS +function status(self) + return { status=getstatus(self) } +end + diff --git a/opennhrp-model.lua b/opennhrp-model.lua new file mode 100644 index 0000000..ebff6a8 --- /dev/null +++ b/opennhrp-model.lua @@ -0,0 +1,84 @@ +module(..., package.seeall) + +require("fs") +require("procps") +require("getopts") +require("format") +require("daemoncontrol") +require("validator") + +local configfile = "/etc/opennhrp/opennhrp.conf" +local processname = "opennhrp" +local baseurl = "/etc/opennhrp/" + +local function get_version() + local cmd_output_result, cmd_output_error + local cmd = "/sbin/apk_version -vs " .. processname .." 2>/dev/null" + local f = io.popen( cmd ) + local cmdresult = f:read("*l") + if (cmdresult) and (#cmdresult > 0) then + cmd_output_result = string.match(cmdresult,"^%S*") or "Unknown" + else + cmd_output_error = "Program not installed" + end + f:close() + return cmd_output_result,cmd_output_error +end + +local function opennhrpctl_show() + local cmd_output_result={} + local cmd_output_result_table={} + local cmd_output_error, opennhrpstatus + 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 + 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]=string.match(v,"^.-:%s?(.*)") + end + end + + return cmd_output_result_table,opennhrpstatus,cmd_output_error +end + +-- ################################################################################ +-- PUBLIC FUNCTIONS + + +function getstatus() + local status = {} + status.version = cfe({ name = "version", + label="Program version", + value=get_version(), + }) + status.status = cfe({ name="status", + label="Program status", + value=procps.pidof(processname), + }) + local opennhrpctl_show, opennhrpctl_status = opennhrpctl_show() + status.stats = cfe({ name="stats", + label="Programstatus reports", + value=opennhrpctl_status, + }) + status.show = cfe({ name="show", + label="Peers", + option=opennhrpctl_show, + }) + + return status +end + + diff --git a/opennhrp-status-html.lsp b/opennhrp-status-html.lsp new file mode 100644 index 0000000..6137246 --- /dev/null +++ b/opennhrp-status-html.lsp @@ -0,0 +1,74 @@ + +DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> + + 0) then io.write(" class='error'") end + io.write(">" .. val.label .. "\n") + + io.write("\t\t
" .. val.value .. "\n") + if (val.descr) and (#val.descr > 0) then io.write("\t\t

" .. string.gsub(val.descr, "\n", "
") .. "

\n") end + if (#val.errtxt > 0) then io.write("\t\t

" .. string.gsub(val.errtxt, "\n", "
") .. "

\n") end + io.write("\t\t
\n") + end + end +end +?> + +

SYSTEM INFO

+
+ +
+ + +

PROGRAM SPECIFIC OPTIONS/INFORMATION

+
+ 0) then io.write(" class='error'") end +io.write(">" .. myform.label .. "\n") +io.write("\t\t
\n") +for k,v in pairs(myform.option or {}) do + io.write("\t\t\t") + io.write("\n\t\t\t\n") + for k1,v1 in pairs(v) do + if (k1 ~= "Protocol-Address") then + io.write("\n") + end + end + io.write("\t\t\t
Protocol-Address" .. v["Protocol-Address"] .. "
"..k1..""..v1.."
") +end +io.write("\t\t
\n") +?> +
+ + + + +DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(form)) +io.write("
") +--]] +?> + diff --git a/opennhrp.menu b/opennhrp.menu new file mode 100644 index 0000000..cb5d25d --- /dev/null +++ b/opennhrp.menu @@ -0,0 +1,3 @@ +#CAT GROUP/DESC TAB ACTION +Networking 45NHRP Status status + -- cgit v1.2.3