summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorskel <skeliotis@yahoo.ca>2011-06-30 15:13:54 -0400
committerTed Trask <ttrask01@yahoo.com>2011-07-05 18:55:33 -0400
commit2acea3b4c25f843f4292da4fe9eea78cf97ca736 (patch)
treec17ea21cd41f98ba21f73897f3f3078c2dcf0113
parent4fa086725d176658d6991d8f88d7b7b283861767 (diff)
downloadacf-quagga-2acea3b4c25f843f4292da4fe9eea78cf97ca736.tar.bz2
acf-quagga-2acea3b4c25f843f4292da4fe9eea78cf97ca736.tar.xz
Interface for OSPF
-rwxr-xr-x[-rw-r--r--]Makefile1
-rwxr-xr-xospf-controller.lua23
-rwxr-xr-xospf-details-html.lsp9
-rwxr-xr-xospf-expert-html.lsp12
-rwxr-xr-xospf-model.lua84
-rwxr-xr-xospf-startstop-html.lsp22
-rwxr-xr-xospf-status-html.lsp33
-rwxr-xr-xospf-welcome-html.lsp10
-rwxr-xr-xospf.menu4
-rwxr-xr-xospf.roles3
10 files changed, 201 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 080b515..42cb19b 100644..100755
--- a/Makefile
+++ b/Makefile
@@ -5,6 +5,7 @@ VERSION=0.5.0
APP_DIST=\
bgp* \
zebra* \
+ ospf* \
EXTRA_DIST=README Makefile config.mk
diff --git a/ospf-controller.lua b/ospf-controller.lua
new file mode 100755
index 0000000..23b8fe3
--- /dev/null
+++ b/ospf-controller.lua
@@ -0,0 +1,23 @@
+module(..., package.seeall)
+
+-- Load libraries
+require("controllerfunctions")
+
+default_action = "status"
+
+function status(self)
+ return self.model.getstatus()
+end
+
+function details(self)
+ return self.model.getdetails()
+end
+
+function startstop(self)
+ return controllerfunctions.handle_startstop(self, self.model.startstop_service, self.clientdata)
+end
+
+function expert(self)
+ return controllerfunctions.handle_form(self, self.model.getconfigfile, self.model.setconfigfile, self.clientdata, "Save", "Edit OSPF Config", "OSPF Configuration Saved")
+end
+
diff --git a/ospf-details-html.lsp b/ospf-details-html.lsp
new file mode 100755
index 0000000..4458c03
--- /dev/null
+++ b/ospf-details-html.lsp
@@ -0,0 +1,9 @@
+<% local data = ...
+require("viewfunctions")
+%>
+
+<H2>OSPF routes</H2>
+<DL><PRE>
+<%= html.html_escape(tostring(data.value.showip.value)) %>
+</PRE></DL>
+
diff --git a/ospf-expert-html.lsp b/ospf-expert-html.lsp
new file mode 100755
index 0000000..5db9173
--- /dev/null
+++ b/ospf-expert-html.lsp
@@ -0,0 +1,12 @@
+<% local form, viewlibrary, page_info, session = ... %>
+<% require("viewfunctions") %>
+
+<% if viewlibrary and viewlibrary.dispatch_component then
+ viewlibrary.dispatch_component("status")
+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)
+%>
diff --git a/ospf-model.lua b/ospf-model.lua
new file mode 100755
index 0000000..eb9c96b
--- /dev/null
+++ b/ospf-model.lua
@@ -0,0 +1,84 @@
+module(..., package.seeall)
+
+-- Load libraries
+require("modelfunctions")
+require("format")
+
+-- Set variables
+local path="PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin "
+
+local configfile = "/etc/quagga/ospfd.conf"
+local processname = "ospfd"
+local packagename = "quagga"
+
+-- ################################################################################
+-- LOCAL FUNCTIONS
+local function parseconfigfile()
+ local conf = {}
+ local f = io.open(configfile, "r")
+ local line, key, _, k, v
+
+ if not f then
+ return nil
+ end
+
+ for line in f:lines() do
+ line = string.gsub(line, "%s*#.*", "")
+ local k,v = string.match(line, "^%s*(%S*)%s+(.*)")
+ if k then
+ conf[k] = v
+ end
+ end
+ f:close()
+ return conf
+end
+
+local function telnetshowip()
+ local output = {}
+ local configfile = parseconfigfile() or {}
+ local cmd = path .. "echo -e '" .. format.escapespecialcharacters(configfile.password) .. "\nshow ip ospf route\nquit\n' | nc localhost ospfd 2>/dev/null"
+ logevent(cmd)
+ local f = io.popen( cmd )
+ local result = f:read("*a") or ""
+ local validoutput
+ if result == "" then
+ result = "Failed to find routes"
+ end
+ local startout, stopout
+ for line in string.gmatch(result, "([^\n]*)\n?") do
+ table.insert(output,line)
+ if (string.find(line, "show ip ospf route")) then
+ startout = #output+1
+ elseif (string.find(line, "> quit")) then
+ stopout = #output-1
+ end
+ end
+ return table.concat(output,"\n",startout,stopout)
+end
+-- ################################################################################
+-- PUBLIC FUNCTIONS
+
+function startstop_service(action)
+ return modelfunctions.startstop_service(processname, action)
+end
+
+function getstatus()
+ return modelfunctions.getstatus(processname, packagename, "OSPF Status")
+end
+
+function getconfigfile()
+ return modelfunctions.getfiledetails(configfile)
+end
+
+function setconfigfile(filedetails)
+ return modelfunctions.setfiledetails(filedetails, {configfile})
+end
+
+function getdetails()
+ local status = {}
+ status.showip = cfe({ label="OSPF routes" })
+ status.showip.value = telnetshowip()
+ return cfe({ type="group", value=status, label="OSPF Details" })
+end
+
+
diff --git a/ospf-startstop-html.lsp b/ospf-startstop-html.lsp
new file mode 100755
index 0000000..c98208b
--- /dev/null
+++ b/ospf-startstop-html.lsp
@@ -0,0 +1,22 @@
+<% local data, viewlibrary, page_info = ... %>
+
+<H1>Management</H1>
+
+<% if data.value.result then %>
+<H2>Previous action result</H2>
+<% if data.value.result.value ~= "" then %>
+<P CLASS='descr'><%= string.gsub(html.html_escape(data.value.result.value), "\n", "<BR>") %></P>
+<% end if data.value.result.errtxt then %>
+<P CLASS='error'><%= string.gsub(html.html_escape(data.value.result.errtxt), "\n", "<BR>") %></P>
+<% end end %>
+
+<DL>
+<form action="<%= html.html_escape(page_info.script .. page_info.prefix .. page_info.controller .. "/" .. page_info.action) %>" method="POST">
+<DT>Program control-panel</DT>
+<DD>
+<% for i,act in ipairs(data.value.actions.value) do %>
+ <input class="submit" type="submit" name="action" value="<%= act %>">
+<% end %>
+</DD>
+</form>
+</DL>
diff --git a/ospf-status-html.lsp b/ospf-status-html.lsp
new file mode 100755
index 0000000..1f5e1f8
--- /dev/null
+++ b/ospf-status-html.lsp
@@ -0,0 +1,33 @@
+<% local data, viewlibrary, page_info, session = ...
+require("viewfunctions")
+%>
+
+<% displaycommandresults({"install","edit"}, session) %>
+<% displaycommandresults({"startstop"}, session) %>
+
+<H1>System Info</H1>
+<DL>
+<%
+displayitem(data.value.status)
+
+displayitem(data.value.version)
+if data.value.version and data.value.version.errtxt and viewlibrary.check_permission("apk-tools/apk/install") then
+%>
+ <DT>Install package</DT>
+ <DD><form action="<%= html.html_escape(page_info.script .. "/apk-tools/apk/install?package="..data.value.version.name) %>" method="POST">
+ <input class='submit' type='submit' value='Install'></form></DD>
+<%
+end
+
+displayitem(data.value.autostart)
+if not (data.value.version and data.value.version.errtxt) and data.value.autostart and data.value.autostart.errtxt and viewlibrary.check_permission("alpine-baselayout/rc/edit") then
+%>
+ <DT>Enable autostart</DT>
+ <DD><form action="<%= html.html_escape(page_info.script .. "/alpine-baselayout/rc/edit?servicename="..data.value.autostart.name.."&redir=".. page_info.orig_action) %>" method="POST">
+ <input class='submit' type='submit' value='Enable'></form></DD>
+<% end %>
+</DL>
+
+<% if viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("startstop") then
+ viewlibrary.dispatch_component("startstop")
+end %>
diff --git a/ospf-welcome-html.lsp b/ospf-welcome-html.lsp
new file mode 100755
index 0000000..251c503
--- /dev/null
+++ b/ospf-welcome-html.lsp
@@ -0,0 +1,10 @@
+<% local data, viewlibrary, page_info, session = ...
+require("viewfunctions")
+%>
+
+<% if viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("status") then
+ viewlibrary.dispatch_component("status")
+end %>
+<% if viewlibrary and viewlibrary.dispatch_component and viewlibrary.check_permission("details") then
+ viewlibrary.dispatch_component("details")
+end %>
diff --git a/ospf.menu b/ospf.menu
new file mode 100755
index 0000000..379f4d0
--- /dev/null
+++ b/ospf.menu
@@ -0,0 +1,4 @@
+#CAT GROUP/DESC TAB ACTION
+Networking OSPF Status welcome
+Networking OSPF Expert expert
+
diff --git a/ospf.roles b/ospf.roles
new file mode 100755
index 0000000..947eb53
--- /dev/null
+++ b/ospf.roles
@@ -0,0 +1,3 @@
+USER=ospf:welcome,ospf:status,ospf:details,ospf:startstop
+EXPERT=ospf:expert
+ADMIN=ospf:welcome,ospf:status,ospf:details,ospf:startstop,ospf:expert