From 2acea3b4c25f843f4292da4fe9eea78cf97ca736 Mon Sep 17 00:00:00 2001 From: skel Date: Thu, 30 Jun 2011 15:13:54 -0400 Subject: Interface for OSPF --- Makefile | 1 + ospf-controller.lua | 23 ++++++++++++++ ospf-details-html.lsp | 9 ++++++ ospf-expert-html.lsp | 12 +++++++ ospf-model.lua | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ ospf-startstop-html.lsp | 22 +++++++++++++ ospf-status-html.lsp | 33 +++++++++++++++++++ ospf-welcome-html.lsp | 10 ++++++ ospf.menu | 4 +++ ospf.roles | 3 ++ 10 files changed, 201 insertions(+) mode change 100644 => 100755 Makefile create mode 100755 ospf-controller.lua create mode 100755 ospf-details-html.lsp create mode 100755 ospf-expert-html.lsp create mode 100755 ospf-model.lua create mode 100755 ospf-startstop-html.lsp create mode 100755 ospf-status-html.lsp create mode 100755 ospf-welcome-html.lsp create mode 100755 ospf.menu create mode 100755 ospf.roles diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 index 080b515..42cb19b --- 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") +%> + +

OSPF routes

+
+<%= html.html_escape(tostring(data.value.showip.value)) %>
+
+ 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 = ... %> + +

Management

+ +<% if data.value.result then %> +

Previous action result

+<% if data.value.result.value ~= "" then %> +

<%= string.gsub(html.html_escape(data.value.result.value), "\n", "
") %>

+<% end if data.value.result.errtxt then %> +

<%= string.gsub(html.html_escape(data.value.result.errtxt), "\n", "
") %>

+<% end end %> + +
+
" method="POST"> +
Program control-panel
+
+<% for i,act in ipairs(data.value.actions.value) do %> + +<% end %> +
+
+
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) %> + +

System Info

+
+<% +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 +%> +
Install package
+
+
+<% +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 +%> +
Enable autostart
+
+
+<% end %> +
+ +<% 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 -- cgit v1.2.3