<%# LuCI - Lua Configuration Interface Copyright 2010 Kentarou Mastuyama -%> <%- 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%>

MeshCruzer - <%:status%>

<%:mz_status_desc%>

<% if req == "link" then %>
Link Status
<% parse_meshz_link(function(e) %> <% style = not style; end) %>
<%:ipaddr IP%> <%:macaddr MAC%> <%:intf Interface%> <%:type Type%> <%:channel Channel%> <%:state State%> <%:qt Quality%> <%:dbm dBm%> <%:rssi RSSI%> <%:rate Rate%> <%:svl Service Level%> <%:seqno SeqNo%> <%:age1 Age%> <%:age2 Age2%>
<%=e.ip%> <%=e.mac%> <%=e.intf%> <%=e.type%> <%=e.channel%> <%=e.state%> <%=e.qt%> <%=e.dbm%> <%=e.rssi%> <%=e.rate%> <%=e.svl%> <%=e.seqno%> <%=e.age1%> <%=e.age2%>
<% elseif req == "intf" then %>
Interfaces Status
<% parse_meshz_intf(function(e) %> <% style = not style; end) %>
<%:index Index%> <%:intfname Name%> <%:ipaddr IP address%> <%:macaddr MAC address%> <%:type Media Type%> <%:mesh Mesh%> <%:channel Channel%> <%:essid ESSID%>
<%=e.index%> <%=e.name%> <%=e.ip%> <%=e.mac%> <%=e.type%> <%=e.mesh%> <%=e.channel%> <%=e.essid%>
<% elseif req == "stub" then %>
Stub Subnet Status
<% parse_meshz_stub(function(e) %> <% style = not style; end) %>
<%:ip IP address%> <%:egress Egress%> <%:seqno Seqno%> <%:state State%> <%:type Type%> <%:expire Expire Time%> <%:macaddr MAC address%>
<%=e.ip%> <%=e.egress%> <%=e.seqno%> <%=e.state%> <%=e.type%> <%=e.expire%> <%=e.mac%>
<% elseif req == "aodv" then %>
AODV Routing Table
<% parse_meshz_aodv(function(e) %> <% style = not style; end) %>
<%:destip Destination IP%> <%:nexthop Next Hop%> <%:status Status%> <%:hopcount Hop Count%> <%:metric Metric%> <%:seqno Seqno%> <%:expire Expire Time%>
<%=e.dest%> <%=e.nexthop%> <%=e.status%> <%=e.hops%> <%=e.metric%> <%=e.seqno%> <%=e.expire%>
<% elseif req == "route" then %>
Routing Table
<% parse_meshz_route(function(e) %> <% style = not style; end) %>
<%:ipaddr IP address%> <%:nexthop Next Hop%> <%:egress Egress%> <%:state State%> <%:hopcount Hop Count%> <%:act Act%> <%:xmit Xmit%> <%:time Time%>
<%=e.ip%> <%=e.nexthop%> <%=e.egress%> <%=e.state%> <%=e.hop%> <%=e.act%> <%=e.xmit%> <%=e.time%>
<% elseif req == "kroute" then %>
Kernel Module Routing Table
<% parse_meshz_kroute(function(e) %> <% style = not style; end) %>
<%:ipaddr IP address%> <%:nexthop Nexthop%> <%:hopcount Hop Count%> <%:intf Interface%>
<%=e.ip%> <%=e.nexthop%> <%=e.hop_count%> <%=e.intf%>
<% end %>
<%+footer%>