summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2008-07-02 15:08:15 +0000
committerTed Trask <ttrask01@yahoo.com>2008-07-02 15:08:15 +0000
commitf2137fec9261e79f89ea2877e40bed72c3c70808 (patch)
tree59c64a5335976c5eba04c2746b734b947077922e
parentd00a84674c3d2e4d6b2b6ad870dbed7515a62678 (diff)
downloadacf-opennhrp-f2137fec9261e79f89ea2877e40bed72c3c70808.tar.bz2
acf-opennhrp-f2137fec9261e79f89ea2877e40bed72c3c70808.tar.xz
Started modifying opennhrp to simplify, use new cfes, ...
git-svn-id: svn://svn.alpinelinux.org/acf/opennhrp/trunk@1265 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--opennhrp-controller.lua115
-rw-r--r--opennhrp-expert-html.lsp58
-rw-r--r--opennhrp-logfile-html.lsp38
-rw-r--r--opennhrp-model.lua174
-rw-r--r--opennhrp-status-html.lsp71
-rw-r--r--opennhrp.menu5
-rw-r--r--opennhrp.roles4
7 files changed, 50 insertions, 415 deletions
diff --git a/opennhrp-controller.lua b/opennhrp-controller.lua
index 99450d7..7c18cf4 100644
--- a/opennhrp-controller.lua
+++ b/opennhrp-controller.lua
@@ -1,116 +1,25 @@
module(..., package.seeall)
--- Load libraries
-require("format")
-
--- Set variables
-local newrecordtxt = "[New]"
-
--- ################################################################################
--- LOCAL FUNCTIONS
-
-local function displaycmdmanagement(pidofstatus)
- -- 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",
- })
- -- next CFE can be used to present the result of the previous action
- management.actionresult = cfe({ name="actionresult",
- label="Previous action result",
- })
-
- -- Disable management buttons based on if the process is running or not
- if (pidofstatus) then
- management.start.disabled = "yes"
- else
- management.stop.disabled = "yes"
- management.restart.disabled = "yes"
- end
-
- return management
-end
--- ################################################################################
--- PUBLIC FUNCTIONS
+require("controllerfunctions")
default_action = "status"
function status(self)
- return { status=self.model.getstatus() }
+ return self.model.getstatus()
end
-function expert (self)
- local modifications = self.clientdata.filecontent or ""
- if ( self.clientdata.cmdsave ) then
- modifications = self.model:update_filecontent(modifications)
- end
- local url = self.conf.script .. self.conf.prefix .. self.conf.controller
-
- -- Start/Stop/Restart process
- local cmdmanagement, actionresult
- 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)
- }),
- })
- 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 (Hide/show buttons
- local pidofstatus
- if (string.lower(status.status.value) == "enabled" ) then pidofstatus = true end
- management = displaycmdmanagement(pidofstatus)
- if (actionresult) then
- management.actionresult.descr=cmdmanagement.descr
- management.actionresult.errtxt=cmdmanagement.errtxt
- end
+function show(self)
+ return self.model.getshowreport()
+end
- return ( {
- status = status,
- file = file,
- modifications = modifications,
- management = management,
- url = url, } )
+function startstop(self)
+ return controllerfunctions.handle_startstop(self, self.model.startstop_service, self.model.getstatus, self.clientdata)
end
-function logfile(self)
- local status=self.model.getstatus()
- local logfile = self.model:get_logfile()
+function config(self)
+ return controllerfunctions.handle_form(self, self.model.getconfig, self.model.setconfig, self.clientdata, "Save", "Edit Config", "Configuration Set")
+end
- return ({
- status = status,
- logfile = logfile,
- url = url,
- })
+function expert (self)
+ return controllerfunctions.handle_form(self, self.model.getconfigfile, self.model.setconfigfile, self.clientdata, "Save", "Edit Config", "Configuration Set")
end
diff --git a/opennhrp-expert-html.lsp b/opennhrp-expert-html.lsp
deleted file mode 100644
index 4f77e5e..0000000
--- a/opennhrp-expert-html.lsp
+++ /dev/null
@@ -1,58 +0,0 @@
-<? local form = ...
-require("viewfunctions")
-?>
-<?
---[[ DEBUG INFORMATION
-io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
-io.write(html.cfe_unpack(form))
-io.write("</span>")
---]]
-?>
-
-<H1>SYSTEM INFO</H1>
-<DL>
-<?
-local myform = form.status
-local tags = { "status", "version", "autostart", }
-displayinfo(myform,tags,"viewonly")
-?>
-</DL>
-
-<form name="myform" action="" method="POST">
-<h1>CONFIGURATION</h1>
-<H2>Expert config</H2>
-<h3>File details</h3>
-<DL>
-<?
-local myform = form.file
-local tags = { "filename", "filesize", "mtime", "sumerrors", }
-displayinfo(myform,tags,"viewonly")
-?>
-</DL>
-
-<H3>FILE CONTENT</H3>
-<?
-local myform = form.file
-io.write(html.form[myform.filecontent.type](myform.filecontent))
-?>
-
-<H2>SAVE AND APPLY ABOVE SETTINGS</H2>
-<DL>
-<?
-local tags = { "cmdsave", }
-displayinfo(myform,tags)
-?>
-</DL>
-
-<?
--- Management buttons
-local myform = form.management
-local tags = { "start", "stop", "restart" }
-if (myform) then
- io.write("<H1>MANAGEMENT</H1>\n<DL>")
- displaymanagement(myform,tags)
- io.write("</DL>")
-end
-?>
-</form>
-
diff --git a/opennhrp-logfile-html.lsp b/opennhrp-logfile-html.lsp
deleted file mode 100644
index 934494a..0000000
--- a/opennhrp-logfile-html.lsp
+++ /dev/null
@@ -1,38 +0,0 @@
-<? local form = ...
-require("viewfunctions")
-?>
-<?
---[[ DEBUG INFORMATION
-io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
-io.write(html.cfe_unpack(form))
-io.write("</span>")
---]]
-?>
-
-<H1>SYSTEM INFO</H1>
-<DL>
-<?
-local myform = form.status
-local tags = { "status", "version", "autostart", }
-displayinfo(myform,tags,"viewonly")
-?>
-</DL>
-
-
-<? local myform = form.logfile ?>
-<form name="myform" action="" method="POST">
-<h1>LOGFILE</h1>
-<h2>Details</h2>
-<DL>
-<?
-local tags = { "filename", "filesize", "mtime", "sumerrors", }
-displayinfo(myform,tags,"viewonly")
-?>
-</DL>
-
-<H3>FILE CONTENT</H3>
-<?
-io.write(html.form[myform.filecontent.type](myform.filecontent))
-?>
-
-</form>
diff --git a/opennhrp-model.lua b/opennhrp-model.lua
index 278234e..090b541 100644
--- a/opennhrp-model.lua
+++ b/opennhrp-model.lua
@@ -1,18 +1,15 @@
module(..., package.seeall)
-- Load libraries
-require("fs")
-require("procps")
-require("format")
-require("daemoncontrol")
+require("modelfunctions")
require("validator")
-require("processinfo")
-- Set variables
local configfile = "/etc/opennhrp/opennhrp.conf"
local processname = "opennhrp"
local packagename = "opennhrp"
-local baseurl = "/etc/opennhrp/"
+
+--[[
local descr = {
Type = {
['incomplete']="The protocol address is being resolved",
@@ -72,154 +69,51 @@ local function opennhrpctl_show()
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
- return cmdresult,action
+function startstop_service(action)
+ return modelfunctions.startstop_service(processname, action)
end
function getstatus()
- local status = {}
-
- local value, errtxt = processinfo.package_version(packagename)
- status.version = cfe({ name = "version",
- label="Program version",
- value=value,
- errtxt=errtxt,
- })
-
- status.status = cfe({ name="status",
- label="Program status",
- value=process_status_text(processname),
- })
-
- local autostart_sequense, autostart_errtxt = processinfo.process_botsequence(processname)
- status.autostart = cfe({ name="autostart",
- label="Autostart sequence",
- value=autostart_sequense,
- errtxt=autostart_errtxt,
- })
-
- 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
+ return modelfunctions.getstatus(processname, packagename, "Opennhrp Status")
+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") or ""
+ return show
end
function getconfig()
- local config = {}
- return config
+ return cfe({ type="table", value={}, label="Edit Config" })
end
-function get_filedetails(self,num)
- local path
- if (num == "2") then
- path = configfile2
- else
- path = configfile
- end
- local file = {}
- local filedetails = {}
- local config = {}
- local filenameerrtxt
- if (path) and (fs.is_file(path)) then
- filedetails = fs.stat(path)
- config = getconfig(path)
- else
- config = {}
- config.filename = {}
- config["filename"]["errtxt"]="Config file '".. path .. "' is missing!"
- end
+function setconfig(config)
+ return config
+end
- file["filename" .. (num or "")] = cfe({
- name="filename" .. (num or ""),
- label="File name",
- value=path,
- errtxt=filenameerrtxt
- })
- file["filesize" .. (num or "")] = cfe({
- name="filesize" .. (num or ""),
- label="File size",
- value=filedetails.size or 0,
- })
- file["mtime" .. (num or "")] = cfe({
- name="mtime" .. (num or ""),
- label="File date",
- value=filedetails.mtime or "---",
- })
- file["filecontent" .. (num or "")] = cfe({
- type="longtext",
- name="filecontent" .. (num or ""),
- label="File content",
- value=fs.read_file(path),
- })
-
- -- Sum all errors into one cfe
- local sumerrors = ""
- for k,v in pairs(config) do
- if (config[k]) and (config[k]["errtxt"]) and (config[k]["errtxt"] ~= "") then
- sumerrors = sumerrors .. config[k]["errtxt"] .. "\n"
- end
- end
- if (sumerrors ~= "") then
- file["sumerrors" .. (num or "")] = cfe ({
- name="sumerrors" .. (num or ""),
- label = "Configuration errors",
- errtxt = string.match(sumerrors, "(.-)\n$"),
- })
- end
+function getconfigfile()
+ local filedetails = modelfunctions.getfiledetails(configfile)
+
+ -- Validate
- return file
+ return filedetails
end
-function update_filecontent (self, modifications)
- local path = configfile
- local file_result,err = fs.write_file(path, format.dostounix(modifications))
- return file_result
-end
-function get_logfile ()
- local file = {}
- local cmdtxt = "grep " .. processname .. " /var/log/messages"
- local cmd, error = io.popen(cmdtxt ,r)
- local cmdoutput = cmd:read("*a")
- cmd:close()
-
- file["filename"] = cfe({
- name="filename",
- label="File name",
- value=cmdtxt,
- })
-
- file["filecontent"] = cfe({
- type="longtext",
- name="filecontent",
- label="File content",
- value=cmdoutput,
- })
-
- return file
+function setconfigfile(filedetails)
+ -- Validate
+ --local result, filedetails = validateconfigfile(filedetails)
+ local result = true
+
+ if result then
+ fs.write_file(configfile, format.dostounix(filedetails.value.filecontent.value))
+ end
+
+ return filedetails
end
diff --git a/opennhrp-status-html.lsp b/opennhrp-status-html.lsp
deleted file mode 100644
index 462e8bd..0000000
--- a/opennhrp-status-html.lsp
+++ /dev/null
@@ -1,71 +0,0 @@
-<? local form = ...
-require("viewfunctions")
-?>
-<?
---[[ DEBUG INFORMATION
-io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
-io.write(html.cfe_unpack(form))
-io.write("</span>")
---]]
-?>
-
-<H1>SYSTEM INFO</H1>
-<DL>
-<?
-local myform = form.status
-local tags = { "status", "version", "autostart", }
-displayinfo(myform,tags,"viewonly")
-?>
-</DL>
-
-<H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2>
-<DL>
-<?
-
-local myform = form.status.show
-io.write("\t<DT")
-if (myform.errtxt) then io.write(" class='error'") end
-io.write(">" .. myform.label .. "</DT>\n")
-io.write("\t\t<DD>\n")
-for k,v in pairs(myform.option or {}) do
- io.write("\t\t\t<TABLE STYLE='margin-bottom:10px;'>")
- io.write("\n\t\t\t<TR><TD STYLE='font-weight:bold;border:none;'><IMG SRC='/skins/static/tango/16x16/places/network-server.png' width='16' height='16' alt> " .. k .. "</TD><TD STYLE='border:none;'></TD></TR>\n")
- 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;border:none;'><IMG SRC='/skins/static/tango/16x16/status/")
-
- if (v1) and (v1['Type']) and (v1['Type']['value']) and (string.lower(v1['Type']['value']) == "incomplete") then
- io.write("network-error")
- elseif (v1) and (v1['Type']) and (v1['Type']['value']) and (string.lower(v1['Type']['value']) == "negative") then
- io.write("network-offline")
- elseif (v1) and (v1['Flags']) and (v1['Flags']['value']) and (string.lower(v1['Flags']['value']) == "up") then
- io.write("network-idle")
- elseif (v1) and (v1['Flags']) and (v1['Flags']['value']) and (string.lower(v1['Flags']['value']) == "used up") then
- io.write("network-transmit-receive")
- elseif (v1) and (v1['Flags']) and (v1['Flags']['value']) 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['Type']['descr'] or "") .. "'> " .. v1["Protocol-Address"]['value'] .. "</TD><TD STYLE='font-weight:bold;border:none;'></TD></TR>\n")
- for k2,v2 in pairs(v1) do
-
----[[
- if (k2) and not ((string.lower(k2) == "protocol-address") or
- (string.lower(k2) == "interface")) then
- io.write("<TR><TD STYLE='font-weight:bold;padding-left:40px;border:none;'>"..k2.."</TD><TD STYLE='border:none;'>"..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
-
- io.write("\t\t\t</TABLE>")
-end
-io.write("\t\t</DD>\n")
-?>
-</DL>
-
diff --git a/opennhrp.menu b/opennhrp.menu
index cf458c4..c8ce6cb 100644
--- a/opennhrp.menu
+++ b/opennhrp.menu
@@ -1,5 +1,4 @@
#CAT GROUP/DESC TAB ACTION
-Networking 45NHRP Status status
+Networking 45NHRP Status show
+Networking 45NHRP Config config
Networking 45NHRP Expert expert
-Networking 45NHRP Logfile logfile
-
diff --git a/opennhrp.roles b/opennhrp.roles
index 0a2a0cc..4879687 100644
--- a/opennhrp.roles
+++ b/opennhrp.roles
@@ -1,2 +1,2 @@
-READ=opennhrp:status,opennhrp:logfile
-UPDATE=opennhrp:expert
+READ=opennhrp:status,opennhrp:show
+UPDATE=opennhrp:expert,opennhrp:config,opennhrp:startstop