From aff09ec85031849e3f626f19e776e42953310363 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Fri, 11 Jul 2008 20:46:35 +0000 Subject: Updated quagga to separate quagga functions from bgp functions. Implemented status, startstop, and expert. git-svn-id: svn://svn.alpinelinux.org/acf/quagga/trunk@1296 ab2d0c66-481e-0410-8bed-d214d4d58bed --- quagga-bgpexpert-html.lsp | 16 ++++ quagga-bgpstartstop-html.lsp | 1 + quagga-bgpstatus-html.lsp | 1 + quagga-controller.lua | 118 ++++-------------------------- quagga-expert-html.lsp | 59 +-------------- quagga-logfile-html.lsp | 31 -------- quagga-model.lua | 170 ++++++++++--------------------------------- quagga-startstop-html.lsp | 1 + quagga-status-html.lsp | 39 +--------- quagga.menu | 4 +- quagga.roles | 4 +- 11 files changed, 80 insertions(+), 364 deletions(-) create mode 100644 quagga-bgpexpert-html.lsp create mode 120000 quagga-bgpstartstop-html.lsp create mode 120000 quagga-bgpstatus-html.lsp mode change 100644 => 120000 quagga-expert-html.lsp delete mode 100644 quagga-logfile-html.lsp create mode 120000 quagga-startstop-html.lsp mode change 100644 => 120000 quagga-status-html.lsp diff --git a/quagga-bgpexpert-html.lsp b/quagga-bgpexpert-html.lsp new file mode 100644 index 0000000..9a2abe2 --- /dev/null +++ b/quagga-bgpexpert-html.lsp @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/quagga-bgpstartstop-html.lsp b/quagga-bgpstartstop-html.lsp new file mode 120000 index 0000000..0ea2627 --- /dev/null +++ b/quagga-bgpstartstop-html.lsp @@ -0,0 +1 @@ +../startstop-html.lsp \ No newline at end of file diff --git a/quagga-bgpstatus-html.lsp b/quagga-bgpstatus-html.lsp new file mode 120000 index 0000000..b2f8480 --- /dev/null +++ b/quagga-bgpstatus-html.lsp @@ -0,0 +1 @@ +../status-html.lsp \ No newline at end of file diff --git a/quagga-controller.lua b/quagga-controller.lua index 728377e..e2bb4b3 100644 --- a/quagga-controller.lua +++ b/quagga-controller.lua @@ -1,118 +1,30 @@ 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", - descr="When starting or restarting BGP, the web-page will freeze for some reason!", - }) - 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 +function startstop(self) + return controllerfunctions.handle_startstop(self, self.model.startstop_service, self.model.getstatus, self.clientdata) +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 - - return ( { - status = status, - file = file, - modifications = modifications, - management = management, - url = url, } ) +function expert(self) + return controllerfunctions.handle_form(self, self.model.getconfigfile, self.model.setconfigfile, self.clientdata, "Save", "Edit Quagga Config", "Quagga Configuration Saved") end -function logfile(self) +function bgpstatus(self) + return self.model.getbgpstatus() +end - local status=self.model.getstatus() - local logfile = self.model:get_logfile() +function bgpstartstop(self) + return controllerfunctions.handle_startstop(self, self.model.bgpstartstop_service, self.model.getbgpstatus, self.clientdata) +end - return ({ - status = status, - logfile = logfile, - url = url, - }) +function bgpexpert(self) + return controllerfunctions.handle_form(self, self.model.getbgpconfigfile, self.model.setbgpconfigfile, self.clientdata, "Save", "Edit BGP Config", "BGP Configuration Saved") end diff --git a/quagga-expert-html.lsp b/quagga-expert-html.lsp deleted file mode 100644 index 4f77e5e..0000000 --- a/quagga-expert-html.lsp +++ /dev/null @@ -1,58 +0,0 @@ - -DEBUGGING

DEBUG INFO: CFE

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

SYSTEM INFO

-
- -
- -
-

CONFIGURATION

-

Expert config

-

File details

-
- -
- -

FILE CONTENT

- - -

SAVE AND APPLY ABOVE SETTINGS

-
- -
- -MANAGEMENT\n
") - displaymanagement(myform,tags) - io.write("
") -end -?> -
- diff --git a/quagga-expert-html.lsp b/quagga-expert-html.lsp new file mode 120000 index 0000000..207f324 --- /dev/null +++ b/quagga-expert-html.lsp @@ -0,0 +1 @@ +../expert-html.lsp \ No newline at end of file diff --git a/quagga-logfile-html.lsp b/quagga-logfile-html.lsp deleted file mode 100644 index aa0b6e5..0000000 --- a/quagga-logfile-html.lsp +++ /dev/null @@ -1,31 +0,0 @@ - - - -

SYSTEM INFO

-
- -
- -
-

LOGFILE

-

Details

-
- -
- -

FILE CONTENT

- - -
diff --git a/quagga-model.lua b/quagga-model.lua index dd13d7d..73e9859 100644 --- a/quagga-model.lua +++ b/quagga-model.lua @@ -1,26 +1,23 @@ module(..., package.seeall) -- Load libraries -require("fs") -require("procps") -require("format") -require("posix") -require("daemoncontrol") -require("validator") ---require("socket") -require("processinfo") +require("modelfunctions") +--require("fs") +--require("format") +--require("posix") +--require("validator") -- Set variables -local configfile = "/etc/quagga/bgpd.conf" -local processname = "bgpd" +local configfile = "/etc/conf.d/zebra" +local processname = "zebra" local packagename = "quagga" -local baseurl = "/etc/quagga/" -local descr = { -} + +local bgpconfigfile = "/etc/quagga/bgpd.conf" +local bgpprocessname = "bgpd" -- ################################################################################ -- LOCAL FUNCTIONS - +--[[ local function get_routes() local cmd_output_result, cmd_output_error local cmd = "/sbin/route -n 2>/dev/null" @@ -54,40 +51,34 @@ local function process_status_text(procname) 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), - }) + return modelfunctions.getstatus(processname, packagename, "Quaga Status") +end - local autostart_sequense, autostart_errtxt = processinfo.process_botsequence(processname) - status.autostart = cfe({ name="autostart", - label="Autostart sequence", - value=autostart_sequense, - errtxt=autostart_errtxt, - }) +function getconfigfile() + return modelfunctions.getfiledetails(configfile) +end + +function setconfigfile(filedetails) + filedetails.value.filename.value = configfile + return modelfunctions.setfiledetails(filedetails) +end +function bgpstartstop_service(action) + return modelfunctions.startstop_service(bgpprocessname, action) +end + +function getbgpstatus() + return modelfunctions.getstatus(bgpprocessname, packagename, "BGP Status") +--[[ status.iproute = cfe({ name="iproute", label="ip route", value=get_iproute(), @@ -103,100 +94,19 @@ function getstatus() value=get_bgpinfo(), }) - return status + return status--]] 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 -end - +--[[ function getconfig() local config = {} return 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 - - 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 - - return file -end -function update_filecontent (self, modifications) - local path = configfile - local file_result,err = fs.write_file(path, format.dostounix(modifications)) - return file_result +--]] +function getbgpconfigfile() + return modelfunctions.getfiledetails(bgpconfigfile) end +function setbgpconfigfile(filedetails) + filedetails.value.filename.value = bgpconfigfile + return modelfunctions.setfiledetails(filedetails) +end diff --git a/quagga-startstop-html.lsp b/quagga-startstop-html.lsp new file mode 120000 index 0000000..0ea2627 --- /dev/null +++ b/quagga-startstop-html.lsp @@ -0,0 +1 @@ +../startstop-html.lsp \ No newline at end of file diff --git a/quagga-status-html.lsp b/quagga-status-html.lsp deleted file mode 100644 index 6f882d9..0000000 --- a/quagga-status-html.lsp +++ /dev/null @@ -1,38 +0,0 @@ - -DEBUGGING

DEBUG INFO: CFE

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

SYSTEM INFO

-
- -
- -

PROGRAM SPECIFIC OPTIONS/INFORMATION

-
-" .. myform.label .. "\n") - io.write("\t\t
\n") - io.write("\t\t
"..myform.value.."
\n") - io.write("\t\t
\n") - end -end -?> - -
diff --git a/quagga-status-html.lsp b/quagga-status-html.lsp new file mode 120000 index 0000000..b2f8480 --- /dev/null +++ b/quagga-status-html.lsp @@ -0,0 +1 @@ +../status-html.lsp \ No newline at end of file diff --git a/quagga.menu b/quagga.menu index d0d6b24..e2b3005 100644 --- a/quagga.menu +++ b/quagga.menu @@ -1,5 +1,5 @@ #CAT GROUP/DESC TAB ACTION Networking 46BGP Status status Networking 46BGP Expert expert -Networking 46BGP Logfile logfile - +Networking 46BGP BGP_Status bgpstatus +Networking 46BGP BGP_Expert bgpexpert diff --git a/quagga.roles b/quagga.roles index dc26ab0..c1f83ac 100644 --- a/quagga.roles +++ b/quagga.roles @@ -1,2 +1,2 @@ -READ=quagga:status,quagga:logfile -UPDATE=quagga:expert +READ=quagga:status,quagga:bgpstatus +UPDATE=quagga:startstop,quagga:expert,quagga:bgpstartstop,quagga:bgpexpert -- cgit v1.2.3