summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile49
-rw-r--r--README0
-rw-r--r--config.mk10
-rw-r--r--dnscache-controller.lua130
-rw-r--r--dnscache-expert-html.lsp58
-rw-r--r--dnscache-logfile-html.lsp31
-rw-r--r--dnscache-model.lua203
-rw-r--r--dnscache-status-html.lsp38
-rw-r--r--dnscache.menu5
9 files changed, 524 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..05737da
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,49 @@
+APP_NAME=quagga
+PACKAGE=acf-$(APP_NAME)
+VERSION=0.2.0
+
+APP_DIST=\
+ quagga-controller.lua \
+ quagga-model.lua \
+ quagga-status-html.lsp \
+ quagga-logfile-html.lsp \
+ quagga-expert-html.lsp \
+ quagga.menu \
+
+
+EXTRA_DIST=README Makefile config.mk
+
+DISTFILES=$(APP_DIST) $(EXTRA_DIST)
+
+TAR=tar
+
+P=$(PACKAGE)-$(VERSION)
+tarball=$(P).tar.bz2
+install_dir=$(DESTDIR)/$(appdir)/$(APP_NAME)
+
+all:
+clean:
+ rm -rf $(tarball) $(P)
+
+dist: $(tarball)
+
+install:
+ mkdir -p "$(install_dir)"
+ cp -a $(APP_DIST) "$(install_dir)"
+
+$(tarball): $(DISTFILES)
+ rm -rf $(P)
+ mkdir -p $(P)
+ cp $(DISTFILES) $(P)
+ $(TAR) -jcf $@ $(P)
+ rm -rf $(P)
+
+# target that creates a tar package, unpacks is and install from package
+dist-install: $(tarball)
+ $(TAR) -jxf $(tarball)
+ $(MAKE) -C $(P) install DESTDIR=$(DESTDIR)
+ rm -rf $(P)
+
+include config.mk
+
+.PHONY: all clean dist install dist-install
diff --git a/README b/README
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/README
diff --git a/config.mk b/config.mk
new file mode 100644
index 0000000..45f4d21
--- /dev/null
+++ b/config.mk
@@ -0,0 +1,10 @@
+prefix=/usr
+datadir=${prefix}/share
+sysconfdir=${prefix}/etc
+localstatedir=${prefix}/var
+acfdir=${datadir}/acf
+wwwdir=${acfdir}/www
+cgibindir=${acfdir}/cgi-bin
+appdir=${acfdir}/app
+acflibdir=${acfdir}/lib
+sessionsdir=${localstatedir}/lib/acf/sessions
diff --git a/dnscache-controller.lua b/dnscache-controller.lua
new file mode 100644
index 0000000..fdaf6ad
--- /dev/null
+++ b/dnscache-controller.lua
@@ -0,0 +1,130 @@
+module(..., package.seeall)
+
+-- Load libraries
+require("format")
+
+-- Set variables
+local newrecordtxt = "[New]"
+
+-- ################################################################################
+-- LOCAL FUNCTIONS
+
+local function list_redir(self)
+ self.conf.action = "status"
+ self.conf.type = "redir"
+ error (self.conf)
+end
+
+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",
+ descr="", --Content of this variable is displayed as <PRE> ... </PRE> in BLACK text
+ errtxt="", --Content of this variable is displayed as <PRE> ... </PRE> in RED text
+ })
+
+ -- 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
+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
+
+function expert(self)
+ local modifications = self.clientdata.filecontent or ""
+ if ( self.clientdata.cmdsave ) then
+ modifications = self.model:update_filecontent(modifications)
+ end
+ local url = ENV["SCRIPT_NAME"] .. 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
+
+ return ( {
+ status = status,
+ file = file,
+ modifications = modifications,
+ management = management,
+ url = url, } )
+end
+
+function logfile(self)
+
+ local status=self.model.getstatus()
+ local logfile = self.model:get_logfile()
+
+ return ({
+ status = status,
+ logfile = logfile,
+ url = url,
+ })
+end
diff --git a/dnscache-expert-html.lsp b/dnscache-expert-html.lsp
new file mode 100644
index 0000000..4f77e5e
--- /dev/null
+++ b/dnscache-expert-html.lsp
@@ -0,0 +1,58 @@
+<? 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/dnscache-logfile-html.lsp b/dnscache-logfile-html.lsp
new file mode 100644
index 0000000..aa0b6e5
--- /dev/null
+++ b/dnscache-logfile-html.lsp
@@ -0,0 +1,31 @@
+<? 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/dnscache-model.lua b/dnscache-model.lua
new file mode 100644
index 0000000..d67f80d
--- /dev/null
+++ b/dnscache-model.lua
@@ -0,0 +1,203 @@
+module(..., package.seeall)
+
+-- Load libraries
+require("fs")
+require("procps")
+require("getopts")
+require("format")
+require("posix")
+require("daemoncontrol")
+require("validator")
+require("socket")
+require("processinfo")
+
+-- Set variables
+local configfile = "/etc/quagga/bgpd.conf"
+local processname = "bgpd"
+local packagename = "quagga"
+local baseurl = "/etc/quagga/"
+local descr = {
+}
+
+-- ################################################################################
+-- LOCAL FUNCTIONS
+
+local function get_routes()
+ local cmd_output_result, cmd_output_error
+ local cmd = "/sbin/route -n 2>/dev/null"
+ local f = io.popen( cmd )
+ local cmd_output_result = f:read("*a")
+ return cmd_output_result,cmd_output_error
+end
+
+local function get_iproute()
+ local cmd_output_result, cmd_output_error
+ local cmd = "/bin/ip route 2>/dev/null"
+ local f = io.popen( cmd )
+ local cmd_output_result = f:read("*a")
+ return cmd_output_result,cmd_output_error
+end
+
+local function get_bgpinfo()
+ local cmd_output_result, cmd_output_error
+ 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 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
+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,
+ })
+
+ 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
+
+function get_logfile ()
+ local file = {}
+ local cmdtxt = "cat /var/log/messages | grep " .. processname
+ 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
+end
+
diff --git a/dnscache-status-html.lsp b/dnscache-status-html.lsp
new file mode 100644
index 0000000..c70ea95
--- /dev/null
+++ b/dnscache-status-html.lsp
@@ -0,0 +1,38 @@
+<? 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 > 0) 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>
diff --git a/dnscache.menu b/dnscache.menu
new file mode 100644
index 0000000..d0d6b24
--- /dev/null
+++ b/dnscache.menu
@@ -0,0 +1,5 @@
+#CAT GROUP/DESC TAB ACTION
+Networking 46BGP Status status
+Networking 46BGP Expert expert
+Networking 46BGP Logfile logfile
+