diff options
Diffstat (limited to 'bgp-model.lua')
-rw-r--r-- | bgp-model.lua | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/bgp-model.lua b/bgp-model.lua index 07c5b24..1166837 100644 --- a/bgp-model.lua +++ b/bgp-model.lua @@ -12,11 +12,31 @@ 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() local cmd_output_result, cmd_output_error - local cmd = path .. "echo -e 'zebpasswd\nshow ip bgp\nquit\n' | nc localhost bgpd 2>/dev/null" + local cmd = path .. "echo -e '" .. (configfile.password or "") .. "\nshow ip bgp\nquit\n' | nc localhost bgpd 2>/dev/null" local f = io.popen( cmd ) local line = f:read("*l") local validoutput |