summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2008-07-11 20:46:35 +0000
committerTed Trask <ttrask01@yahoo.com>2008-07-11 20:46:35 +0000
commitaff09ec85031849e3f626f19e776e42953310363 (patch)
tree8b0425b636749fdc5f5e1e52f054b20aafb197eb
parent21412c6fc93671faf917f3c4fefba915a39f9fac (diff)
downloadacf-quagga-aff09ec85031849e3f626f19e776e42953310363.tar.bz2
acf-quagga-aff09ec85031849e3f626f19e776e42953310363.tar.xz
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
-rw-r--r--quagga-bgpexpert-html.lsp16
l---------quagga-bgpstartstop-html.lsp1
l---------quagga-bgpstatus-html.lsp1
-rw-r--r--quagga-controller.lua118
l---------[-rw-r--r--]quagga-expert-html.lsp59
-rw-r--r--quagga-logfile-html.lsp31
-rw-r--r--quagga-model.lua170
l---------quagga-startstop-html.lsp1
l---------[-rw-r--r--]quagga-status-html.lsp39
-rw-r--r--quagga.menu4
-rw-r--r--quagga.roles4
11 files changed, 80 insertions, 364 deletions
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 @@
+<? local form, viewlibrary, page_info, session = ... ?>
+<? require("viewfunctions") ?>
+
+<? if viewlibrary and viewlibrary.dispatch_component then
+ viewlibrary.dispatch_component("bgpstatus")
+end ?>
+
+<?
+local pattern = string.gsub(page_info.prefix..page_info.controller, "[%(%)%.%%%+%-%*%?%[%]%^%$]", "%%%1")
+local func = haserl.loadfile(page_info.viewfile:gsub(pattern..".*$", "/") .. "filedetails-html.lsp")
+func(form, viewlibrary, page_info, session)
+?>
+
+<? if viewlibrary and viewlibrary.dispatch_component and session.permissions[page_info.controller].startstop then
+ viewlibrary.dispatch_component("bgpstartstop")
+end ?>
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
index 4f77e5e..207f324 100644..120000
--- a/quagga-expert-html.lsp
+++ b/quagga-expert-html.lsp
@@ -1,58 +1 @@
-<? 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>
-
+../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 @@
-<? local form = ... ?>
-<?
-require("viewfunctions")
-?>
-
-<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>LOGFILE</h1>
-<h2>Details</h2>
-<DL>
-<?
-local myform = form.logfile
-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/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
index 6f882d9..b2f8480 100644..120000
--- a/quagga-status-html.lsp
+++ b/quagga-status-html.lsp
@@ -1,38 +1 @@
-<? 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 tags ={ "bgpstats", "iproute", }
-for k,v in pairs(tags) do
- local myform = form.status[v]
- if (myform) then
- 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")
- io.write("\t\t<PRE>"..myform.value.."</PRE>\n")
- io.write("\t\t</DD>\n")
- end
-end
-?>
-
-</DL>
+../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