summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-04-08 09:39:36 +0000
committerMika Havela <mika.havela@gmail.com>2008-04-08 09:39:36 +0000
commit5901c2a6bf7c6f17a32bc957772dda9ec456ed55 (patch)
treeb2c44bdd48bd96fd40422e2e7c7faa6179314f55
parentbfac3536373cdd298169019d80a0af7078ce37b9 (diff)
downloadacf-quagga-5901c2a6bf7c6f17a32bc957772dda9ec456ed55.tar.bz2
acf-quagga-5901c2a6bf7c6f17a32bc957772dda9ec456ed55.tar.xz
Cleaning up code.
git-svn-id: svn://svn.alpinelinux.org/acf/quagga/trunk@952 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--quagga-controller.lua28
-rw-r--r--quagga-expert-html.lsp15
-rw-r--r--quagga-logfile-html.lsp16
-rw-r--r--quagga-model.lua49
-rw-r--r--quagga-status-html.lsp58
5 files changed, 60 insertions, 106 deletions
diff --git a/quagga-controller.lua b/quagga-controller.lua
index 8550fb5..cb63668 100644
--- a/quagga-controller.lua
+++ b/quagga-controller.lua
@@ -1,24 +1,20 @@
module(..., package.seeall)
--- This is the object/text used when we want to add a new record
-
+-- Load libraries
require("format")
+-- Set variables
local newrecordtxt = "[New]"
-local list_redir = function (self)
+-- ################################################################################
+-- LOCAL FUNCTIONS
+
+local function list_redir(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 displaycmdmanagement(disablestart,disablestop,disablerestart)
-- Add a management buttons
local management = {}
@@ -48,11 +44,18 @@ end
-- ################################################################################
-- PUBLIC FUNCTIONS
+mvc = {}
+function mvc.on_load(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
+
function status(self)
return { status=self.model.getstatus() }
end
-expert = function (self)
+function expert(self)
local modifications = self.clientdata.filecontent or ""
if ( self.clientdata.cmdsave ) then
modifications = self.model:update_filecontent(modifications)
@@ -107,7 +110,8 @@ expert = function (self)
cmdmanagement = cmdmanagement,
url = url, } )
end
-logfile = function (self)
+
+function logfile(self)
local status=self.model.getstatus()
local logfile = self.model:get_logfile()
diff --git a/quagga-expert-html.lsp b/quagga-expert-html.lsp
index cf70091..19bda27 100644
--- a/quagga-expert-html.lsp
+++ b/quagga-expert-html.lsp
@@ -1,12 +1,5 @@
<? local form = ... ?>
<?
---[[ 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>")
---]]
-?>
-<?
function displayinfo(myform,tags,viewtype)
for k,v in pairs(tags) do
if (myform[v]) and (myform[v]["value"]) then
@@ -103,11 +96,3 @@ if (cmdform) and (cmdform[tags[1]]) then
io.write('</dl></form>')
end ?>
-<?
---[[ 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>")
---]]
-?>
-
diff --git a/quagga-logfile-html.lsp b/quagga-logfile-html.lsp
index 6f8f8f7..2d2b1b7 100644
--- a/quagga-logfile-html.lsp
+++ b/quagga-logfile-html.lsp
@@ -1,12 +1,4 @@
<? local form = ... ?>
-
-<?
---[[ 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>")
---]]
-?>
<?
function displayinfo(myform,tags,viewtype)
for k,v in pairs(tags) do
@@ -68,11 +60,3 @@ io.write(html.form[myform.filecontent.type](myform.filecontent))
?>
</form>
-
-<?
---[[ 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>")
---]]
-?>
diff --git a/quagga-model.lua b/quagga-model.lua
index 279a1a2..fa88a04 100644
--- a/quagga-model.lua
+++ b/quagga-model.lua
@@ -1,5 +1,6 @@
module(..., package.seeall)
+-- Load libraries
require("fs")
require("procps")
require("getopts")
@@ -7,28 +8,19 @@ require("format")
require("posix")
require("daemoncontrol")
require("validator")
+require("processinfo")
+require("socket")
+-- Set variables
local configfile = "/etc/quagga/bgpd.conf"
local processname = "bgpd"
local packagename = "quagga"
local baseurl = "/etc/quagga/"
-
local descr = {
}
-local function get_version()
- local cmd_output_result, cmd_output_error
- local cmd = "/sbin/apk_version -vs " .. packagename .." 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 FUNCTIONS
local function get_routes()
local cmd_output_result, cmd_output_error
@@ -51,24 +43,11 @@ local function get_bgpinfo()
local cmd = "/usr/sbin/bgpd --version 2>/dev/null"
local f = io.popen( cmd )
local cmd_output_result = f:read("*a")
+ -- bgpdport=179
return cmd_output_result,cmd_output_error
end
-local function autostarts()
- local cmd_output_result, cmd_output_error
- local cmd = "/sbin/rc_status | egrep '^S' | egrep '" .. processname .."' 2>/dev/null"
- local f = io.popen( cmd )
- local cmdresult = f:read("*a")
- if (cmdresult) and (#cmdresult > 0) then
- cmd_output_result = "Process will autostart at next boot (at sequence '" .. string.match(cmdresult,"^%a+(%d%d)") .. "')"
- else
- cmd_output_error = "Not programmed to autostart"
- end
- f:close()
- return cmd_output_result,cmd_output_error
-end
-
-function process_status_text(procname)
+local function process_status_text(procname)
local t = procps.pidof(procname)
if (t) and (#t > 0) then
return "Enabled"
@@ -85,13 +64,13 @@ function startstop_service ( self, action )
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 = {}
- local value, errtxt = get_version()
+
+ local value, errtxt = processinfo.package_version(packagename)
status.version = cfe({ name = "version",
label="Program version",
value=value,
@@ -102,28 +81,29 @@ function getstatus()
label="Program status",
value=process_status_text(processname),
})
- local autostart_sequense, autostart_errtxt = autostarts()
+
+ local autostart_sequense, autostart_errtxt = processinfo.process_botsequence(processname)
status.autostart = cfe({ name="autostart",
label="Autostart sequence",
value=autostart_sequense,
errtxt=autostart_errtxt,
})
- -- THIS IS WHERE WE PRESENT THE OUTPUT FROM TELNET
status.iproute = cfe({ name="iproute",
label="ip route",
value=get_iproute(),
})
+
status.routes = cfe({ name="routes",
label="route -n",
value=get_routes(),
})
+
status.bgpstats = cfe({ name="bgpstats",
label="BGP version",
value=get_bgpinfo(),
})
-
return status
end
@@ -149,6 +129,7 @@ function get_logfile ()
return file
end
+
function getconfig()
local config = {}
return config
diff --git a/quagga-status-html.lsp b/quagga-status-html.lsp
index 00f95b5..fb6172d 100644
--- a/quagga-status-html.lsp
+++ b/quagga-status-html.lsp
@@ -1,43 +1,52 @@
<? local form = ... ?>
<?
---[[ 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>")
---]]
-?>
-
-<?
-function informationform(myform,tags)
+function displayinfo(myform,tags,viewtype)
for k,v in pairs(tags) do
- if (myform[v]) then
+ if (myform[v]) and (myform[v]["value"]) then
local val = myform[v]
- io.write("\t<DT")
- if (#val.errtxt > 0) then io.write(" class='error'") end
- io.write(">" .. val.label .. "</DT>\n")
-
- io.write("\t\t<DD>" .. val.value .. "\n")
- if (val.descr) and (#val.descr > 0) then io.write("\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>\n") end
- if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end
- io.write("\t\t</DD>\n")
+ io.write("\n\t<DT")
+ if (#val.errtxt > 0) then
+ val.class = "error"
+ io.write(" class='error'")
+ end
+ io.write(">" .. val.label .. "</DT>")
+ io.write("\n\t\t<DD>")
+ if (viewtype == "viewonly") then
+ io.write(val.value)
+ elseif (val.type == "radio") and (type(val.option) == "table") and (#val.option > 0) then
+ io.write("<span style='display:inline' class='" .. ( val.class or "") .. "'>")
+ for k1,v1 in pairs(val.option) do
+ io.write(tostring(v1.label) .. ":")
+ io.write("<input style='margin-right:20px;margin-left:5px;' type='radio' class='" .. ( val.class or "") .. "' name='" .. val.name .. "'")
+ if (tostring(val.value) == tostring(v1.value)) then io.write(" checked='yes'") end
+ io.write(" value='" .. v1.value .. "'>")
+ end
+ io.write("</input></span>")
+ else
+ io.write(html.form[val.type](val))
+ end
+ if (val.descr) and (#val.descr > 0) then io.write("\n\t\t<P CLASS='descr'>" .. string.gsub(val.descr, "\n", "<BR>") .. "</P>") end
+ if (#val.errtxt > 0) then io.write("\n\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>") end
+ io.write("\n\t\t</DD>\n")
end
end
end
?>
+
<H1>SYSTEM INFO</H1>
<DL>
<?
local myform = form.status
local tags = { "status", "version", "autostart", }
-informationform(myform,tags)
+displayinfo(myform,tags,"viewonly")
?>
</DL>
<H2>PROGRAM SPECIFIC OPTIONS/INFORMATION</H2>
<DL>
<?
-local tags ={"routes", "iproute", "bgpstats", }
+local tags ={ "bgpstats", "iproute", }
for k,v in pairs(tags) do
local myform = form.status[v]
if (myform) then
@@ -52,12 +61,3 @@ end
?>
</DL>
-
-<?
---[[ 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>")
---]]
-?>
-