From 5901c2a6bf7c6f17a32bc957772dda9ec456ed55 Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Tue, 8 Apr 2008 09:39:36 +0000 Subject: Cleaning up code. git-svn-id: svn://svn.alpinelinux.org/acf/quagga/trunk@952 ab2d0c66-481e-0410-8bed-d214d4d58bed --- quagga-controller.lua | 28 ++++++++++++++---------- quagga-expert-html.lsp | 15 ------------- quagga-logfile-html.lsp | 16 -------------- quagga-model.lua | 49 +++++++++++++---------------------------- quagga-status-html.lsp | 58 ++++++++++++++++++++++++------------------------- 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 @@ DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> -') end ?> -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> - 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 @@ - -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> - -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> 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 @@ 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") + io.write("\n\t 0) then + val.class = "error" + io.write(" class='error'") + end + io.write(">" .. val.label .. "") + io.write("\n\t\t
") + if (viewtype == "viewonly") then + io.write(val.value) + elseif (val.type == "radio") and (type(val.option) == "table") and (#val.option > 0) then + io.write("") + for k1,v1 in pairs(val.option) do + io.write(tostring(v1.label) .. ":") + io.write("") + end + io.write("") + else + io.write(html.form[val.type](val)) + end + if (val.descr) and (#val.descr > 0) then io.write("\n\t\t

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

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

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

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

SYSTEM INFO

PROGRAM SPECIFIC OPTIONS/INFORMATION

- -DEBUGGING

DEBUG INFO: CFE

") -io.write(html.cfe_unpack(form)) -io.write("
") ---]] -?> - -- cgit v1.2.3