summaryrefslogtreecommitdiffstats
path: root/ospf-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'ospf-model.lua')
-rwxr-xr-xospf-model.lua84
1 files changed, 84 insertions, 0 deletions
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
+
+