summaryrefslogtreecommitdiffstats
path: root/zebra-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'zebra-model.lua')
-rw-r--r--zebra-model.lua32
1 files changed, 16 insertions, 16 deletions
diff --git a/zebra-model.lua b/zebra-model.lua
index 89bfc26..1b9b8b9 100644
--- a/zebra-model.lua
+++ b/zebra-model.lua
@@ -34,26 +34,26 @@ end
local function telnetshowip()
local output = {}
- local configfile = parseconfigfile()
- local cmd_output_result, cmd_output_error
+ local configfile = parseconfigfile() or {}
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 result = f:read("*a") or ""
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)
+ 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, "^Password:")) then
+ startout = #output+1
+ elseif (string.find(line, "^Codes:")) then
+ startout = #output
+ elseif (string.find(line, "> quit")) then
+ stopout = #output-1
end
- line = f:read("*l")
end
- return table.concat(output,"\n"),cmd_output_error
--- return configfile.password
+ return table.concat(output,"\n",startout,stopout)
end
-- ################################################################################
@@ -79,7 +79,7 @@ end
function getdetails()
local status = {}
status.showip = cfe({ label="Zebra routes" })
- status.showip.value,status.showip.errtxt = telnetshowip()
+ status.showip.value = telnetshowip()
return cfe({ type="group", value=status, label="Zebra Details" })
end