local mymodule = {} -- Load libraries modelfunctions = require("modelfunctions") format = require("acf.format") -- Set variables local path="PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin " local configfile = "/etc/quagga/bgpd.conf" local processname = "bgpd" 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 telnetshowipbgp() local output = {} local configfile = parseconfigfile() or {} local cmd = (configfile.password or "") .. "\nshow ip bgp\nquit\n" local result, errtxt = modelfunctions.run_executable({"nc", "localhost", "bgpd"}, false, cmd) 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, "^BGP")) then startout = #output elseif (string.find(line, "^Total number")) then stopout = #output end end return table.concat(output,"\n",startout,stopout) end -- ################################################################################ -- PUBLIC FUNCTIONS function mymodule.getstatus() return modelfunctions.getstatus(processname, packagename, "BGP Status") end function mymodule.getconfigfile() return modelfunctions.getfiledetails(configfile) end function mymodule.setconfigfile(self, filedetails) return modelfunctions.setfiledetails(self, filedetails, {configfile}) end function mymodule.get_startstop(self, clientdata) return modelfunctions.get_startstop(processname) end function mymodule.startstop_service(self, startstop, action) return modelfunctions.startstop_service(startstop, action) end function mymodule.getdetails() local status = {} status.showipbgp = cfe({ label="BGP routes" }) status.showipbgp.value = telnetshowipbgp() return cfe({ type="group", value=status, label="BGP Details" }) end return mymodule