%# LuCI support for MeshCruzer Copyright (C) 2010-2011 Thinktube Inc -%> <%- local sys = require "luci.sys" local util = require "luci.util" local fs = require "nixio.fs" local style = true -- "meshzctl link" function parse_meshz_link(callback) local entry = {} local tmpfile = "/tmp/mzstatus.tmp" local ret = util.exec("/usr/bin/meshzctl link > " .. tmpfile) if not fs.access(tmpfile, "r") then return -1 end local i = 0 for line in io.lines(tmpfile) do if i > 3 then -- line 0 to 3 are just header local ip, mac, intf, type, channel, state, qt, dbm, rssi, rate, svl, seqno, age1, age2 = line:match( "([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*" .. "([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)" ) -- this "TT_Tbl" message means "no output" if ip ~= "TT_Tbl" then local entry = { ip = ip, mac = mac, intf = intf, type = type, channel = channel, state = state, qt = qt, dbm = dbm, rssi = rssi, rate = rate, svl = svl, seqno = seqno, age1 = age1, age2 = age2 } if callback then callback(entry) end end end i = i + 1 end fs.remove(tmpfile) end -- "meshzctl intf" function parse_meshz_intf(callback) local entry = {} local tmpfile = "/tmp/mzstatus.tmp" local ret = util.exec("/usr/bin/meshzctl intf > " .. tmpfile) if not fs.access(tmpfile, "r") then return -1 end local i = 0 for line in io.lines(tmpfile) do if i > 3 then local index, name, ip, mac, type, mesh, channel, essid = line:match( "([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)" ) local entry = { index = index, name = name, ip = ip, mac = mac, type = type, mesh = mesh, channel = channel, essid = essid } if callback then callback(entry) end end i = i + 1 end fs.remove(tmpfile) end -- "meshzctl stub" -- "IP ADDRESS/MASK EGRESS SEQNO STATE TYPE EXPIRE MAC" function parse_meshz_stub(callback) local entry = {} local tmpfile = "/tmp/mzstatus.tmp" local ret = util.exec("/usr/bin/meshzctl stub > " .. tmpfile) if not fs.access(tmpfile, "r") then return -1 end local i = 0 for line in io.lines(tmpfile) do if i > 3 then local ip, egress, seqno, state, type, expire, mac = line:match( "([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)" ) if ip ~= "TT_Tbl" then local entry = { ip = ip, egress = egress, seqno = seqno, state = state, type = type, expire = expire, mac = mac } if callback then callback(entry) end end end i = i + 1 end fs.remove(tmpfile) end -- "meshzctl aodv" -- "DESTINATION NEXTHOP STATUS HOPS MTR SEQNUM EXPIRE" function parse_meshz_aodv(callback) local entry = {} local tmpfile = "/tmp/mzstatus.tmp" local ret = util.exec("/usr/bin/meshzctl aodv > " .. tmpfile) if not fs.access(tmpfile, "r") then return -1 end local i = 0 for line in io.lines(tmpfile) do if i > 3 then local dest, nexthop, status, hops, metric, seqno, expire = line:match( "([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)" ) if dest ~= "TT_Tbl" then local entry = { dest = dest, nexthop = nexthop, status = status, hops = hops, metric = metric, seqno = seqno, expire = expire } if callback then callback(entry) end end end i = i + 1 end fs.remove(tmpfile) end -- "meshzctl route" -- "IP ADDRESS/MASK NEXTHOP EGRESS ST HO ACT XMIT TIME" function parse_meshz_route(callback) local entry = {} local tmpfile = "/tmp/mzstatus.tmp" local ret = util.exec("/usr/bin/meshzctl route > " .. tmpfile) if not fs.access(tmpfile, "r") then return -1 end local i = 0 for line in io.lines(tmpfile) do if i > 3 then local ip, nexthop, egress, state, hop, act, xmit, time = line:match( "([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)" ) if ip ~= "TT_Tbl" then local entry = { ip = ip, nexthop = nexthop, egress = egress, state = state, hop = hop, act = act, xmit = xmit, time = time } if callback then callback(entry) end end end i = i + 1 end fs.remove(tmpfile) end -- "meshzctl kroute" -- "IP ADDRESS NEXTHOP HOPS INTERFACE" function parse_meshz_kroute(callback) local entry = {} local tmpfile = "/tmp/mzstatus.tmp" local ret = util.exec("/usr/bin/meshzctl kroute > " .. tmpfile) if not fs.access(tmpfile, "r") then return -1 end local i = 0 for line in io.lines(tmpfile) do if i > 3 then local ip, nexthop, hop_count, intf = line:match( "([^%s]+)%s*([^%s]+)%s*([^%s]+)%s*([^%s]+)" ) if ip ~= "TT_Tbl" then local entry = { ip = ip, nexthop = nexthop, hop_count = hop_count, intf = intf } if callback then callback(entry) end end end i = i + 1 end fs.remove(tmpfile) end -%> <%+header%>