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-model.lua | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'zebra-model.lua') 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 + + -- cgit v1.2.3