module(..., package.seeall) -- Load libraries require("modelfunctions") -- Set variables local path="PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin " 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 function startstop_service(action) return modelfunctions.startstop_service(processname, action) end function getstatus() return modelfunctions.getstatus(processname, packagename, "Zebra Status") end function getconfigfile() return modelfunctions.getfiledetails(configfile) end function setconfigfile(filedetails) filedetails.value.filename.value = configfile 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