From 2b83bc701c24101c10e062cdbfff11498370389f Mon Sep 17 00:00:00 2001 From: Mika Havela Date: Tue, 16 Sep 2008 11:32:24 +0000 Subject: Adding zebra routes on statuspage to show some debugging details git-svn-id: svn://svn.alpinelinux.org/acf/quagga/trunk@1468 ab2d0c66-481e-0410-8bed-d214d4d58bed --- zebra-controller.lua | 4 ++++ zebra-details-html.lsp | 15 ++++++++++++++ zebra-model.lua | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ zebra-welcome-html.lsp | 10 ++++++++++ zebra.menu | 2 +- zebra.roles | 2 +- 6 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 zebra-details-html.lsp create mode 100644 zebra-welcome-html.lsp diff --git a/zebra-controller.lua b/zebra-controller.lua index 8e65d57..113a819 100644 --- a/zebra-controller.lua +++ b/zebra-controller.lua @@ -9,6 +9,10 @@ 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.model.getstatus, self.clientdata) end diff --git a/zebra-details-html.lsp b/zebra-details-html.lsp new file mode 100644 index 0000000..11b8da9 --- /dev/null +++ b/zebra-details-html.lsp @@ -0,0 +1,15 @@ +<% local data = ... +require("viewfunctions") +--[[ DEBUG INFORMATION +io.write("

DEBUGGING

DEBUG INFO: CFE

") +io.write(html.cfe_unpack(data)) +io.write("
") +--]] + +%> + +

Zebra routes

+
+<% io.write(tostring(data.value.showip.value)) %>
+
+ diff --git a/zebra-model.lua b/zebra-model.lua index 12d62b9..89bfc26 100644 --- a/zebra-model.lua +++ b/zebra-model.lua @@ -10,6 +10,52 @@ local configfile = "/etc/quagga/zebra.conf" local processname = "zebra" 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() + local cmd_output_result, cmd_output_error + local cmd = path .. "echo -e '" .. (configfile.password or "") .. "\nshow ip route\nquit\n' | nc localhost zebra 2>/dev/null" + local f = io.popen( cmd ) + local line = f:read("*l") + local validoutput + while line do + if (string.find(line, "^Codes")) then + validoutput = true + end + if (string.find(line, "> quit")) then + validoutput = false + end + if (validoutput) then + table.insert(output,line) + end + line = f:read("*l") + end + return table.concat(output,"\n"),cmd_output_error +-- return configfile.password +end + -- ################################################################################ -- PUBLIC FUNCTIONS @@ -30,3 +76,11 @@ function setconfigfile(filedetails) return modelfunctions.setfiledetails(filedetails) end +function getdetails() + local status = {} + status.showip = cfe({ label="Zebra routes" }) + status.showip.value,status.showip.errtxt = telnetshowip() + return cfe({ type="group", value=status, label="Zebra Details" }) +end + + diff --git a/zebra-welcome-html.lsp b/zebra-welcome-html.lsp new file mode 100644 index 0000000..3670b93 --- /dev/null +++ b/zebra-welcome-html.lsp @@ -0,0 +1,10 @@ +<% local data, viewlibrary, page_info, session = ... +require("viewfunctions") +%> + +<% if viewlibrary and viewlibrary.dispatch_component and session.permissions[page_info.controller].status then + viewlibrary.dispatch_component("status") +end %> +<% if viewlibrary and viewlibrary.dispatch_component and session.permissions[page_info.controller].details then + viewlibrary.dispatch_component("details") +end %> diff --git a/zebra.menu b/zebra.menu index 9a59eb8..2a7386e 100644 --- a/zebra.menu +++ b/zebra.menu @@ -1,4 +1,4 @@ #CAT GROUP/DESC TAB ACTION -Networking 46Zebra Status status +Networking 46Zebra Status welcome Networking 46Zebra Expert expert diff --git a/zebra.roles b/zebra.roles index c03bfdb..3c86963 100644 --- a/zebra.roles +++ b/zebra.roles @@ -1,2 +1,2 @@ -READ=zebra:status,zebra:details, +READ=zebra:welcome,zebra:status,zebra:details, UPDATE=zebra:startstop,zebra:expert, -- cgit v1.2.3