diff --git a/files/www/cgi-bin/status b/files/www/cgi-bin/status index f7ae57df..4d8b249c 100755 --- a/files/www/cgi-bin/status +++ b/files/www/cgi-bin/status @@ -49,7 +49,8 @@ function mesh_ip_to_hostnames(ip) if not ip or ip == "" or ip == "none" then return "" end - local pattern = "^" .. ip .. "%s+([%w%-]+)" + local pattern = "^" .. ip .. "%s+([%w%-%.]+)" + local host = "none" for line in io.lines("/etc/hosts") do local host = line:match(pattern) @@ -57,35 +58,34 @@ function mesh_ip_to_hostnames(ip) return host.gsub("%s+", " / ") end end - local hosts = "" if nixio.fs.stat("/var/run/hosts_olsr.stable") then for line in io.lines("/var/run/hosts_olsr.stable") do local host = line:match(pattern) if host then - hosts = hosts .. " / " .. host + host = host:gsub("^dtdlink%.","") + host = host:gsub("^mid[0-9]*%.","") + host = host:gsub("%.local.mesh$","") + return host end end end - return hosts:sub(4, #hosts) + return host end -function get_default_gw() - -- a node with a wired default gw will route via this - local p = io.popen("ip route list table 254") - if p then - for line in p:lines() - do - local gw = line:match("^default%svia%s([%d%.]+)") - if gw then - p:close() - return gw - end - end - p:close() +function get_default_gw(iface) + -- wan will route via table 254 default gw + -- wifi will route via OLSR table 31 default gw + local rtable = "" + if iface == "wan" then + rtable = "ip route list table 254" + elseif iface == "wifi" then + rtable = "ip route list table 31" + else + return "none" end - -- table 31 is populated by OLSR - p = io.popen("ip route list table 31") + + local p = io.popen(rtable) if p then for line in p:lines() do @@ -320,7 +320,8 @@ local cidr = netmask_to_cidr(cursor:get("network", "wifi", "netmask")) if wifi_disabled then col1[#col1 + 1] = "primary address:" .. ip .. " / " .. cidr .. "
" else - col1[#col1 + 1] = "mesh RF address:
SSID:
channel:
channel width:" .. ip .. " / " .. cidr .. "
" .. wifi_ssid .. "
" .. wifi_channel .. "
" .. wifi_chanbw .. " MHz" + wifi_gw = get_default_gw("wifi") + col1[#col1 + 1] = "mesh RF address:
mesh gateway:
gateway node:
SSID:
channel:
channel width:" .. ip .. " / " .. cidr .. "
" .. wifi_gw .. "
" .. mesh_ip_to_hostnames(wifi_gw) .. "
" .. wifi_ssid .. "
" .. wifi_channel .. "
" .. wifi_chanbw .. " MHz" end ip = cursor:get("network", "lan", "ipaddr") @@ -337,80 +338,97 @@ if remote_ip then hide_local = true end end - if ip:match("^10%.") or not hide_local then cidr = netmask_to_cidr(mask) - col1[#col1 + 1] = "LAN address:" .. ip .. " / " .. cidr .. "
" -end - -local wan_iface = aredn.hardware.get_iface_name("wan") -if not hide_local and wan_iface then - local ip, bcast, mask = aredn.hardware.get_interface_ip4(wan_iface) - local wprefix = "" - local wan_wifi_sig = "none" - local wan_wifi_noi = "none" - local wan_wifi_snr = "none" - if wan_iface:match("^wlan%d+$") then - wprefix = "wifi " - local s, n = get_wifi_signal(wan_iface) - if s ~= "none" and n ~= "none" then - wan_wifi_sig = s - wan_wifi_noi = n - wan_wifi_snr = math.abs(s - n) - end - end - local wan_wifi_ssid + local lan_wifi_ssid = "none" cursor:foreach("wireless", "wifi-iface", function (section) - if section.network == "wan" then - wan_wifi_ssid = section.ssid + if section.network == "lan" then + lan_wifi_ssid = section.ssid return false end end ) - if not wan_wifi_ssid then -- if still nil then set default - wan_wifi_ssid = "none" - end - - if ip then - cidr = netmask_to_cidr(mask) - if wprefix == "" then - col1[#col1 + 1] = "WAN address:
" .. "" .. ip .. " / " .. cidr .. "" - else - if wan_wifi_ssid ~= "none" and wan_wifi_snr ~= "none" then - col1[#col1 + 1] = "" .. wprefix .. "WAN address:
" .. wprefix .. "WAN SSID / SNR:" .. ip .. " / " .. cidr .. "
" .. wan_wifi_ssid .. " / " .. wan_wifi_snr .. " dB" - else - col1[#col1 + 1] = "" .. wprefix .. "WAN address:" .. ip .. " / " .. cidr .. "" - end - end + if lan_wifi_ssid ~= "none" then + col1[#col1 + 1] = "LAN address:
LAN AP SSID:" .. ip .. " / " .. cidr .. "
" .. lan_wifi_ssid .. "" else - col1[#col1 + 1] = "WAN address:none" + col1[#col1 + 1] = "LAN address:" .. ip .. " / " .. cidr .. "" end end -ip = get_default_gw() -if ip:match("^10%.") or not hide_local then - col1[#col1 + 1] = "default gateway:" .. ip - if ip:match("^10%.") then - col1[#col1] = col1[#col1] .. "
" .. mesh_ip_to_hostnames(ip) .. "" +local wan_iface = aredn.hardware.get_iface_name("wan") +if wan_iface and not hide_local then + local ip, bcast, mask = aredn.hardware.get_interface_ip4(wan_iface) + if not ip then + col1[#col1 + 1] = "WAN address:
default gateway:
gateway node:none
" .. wifi_gw .. "
" .. mesh_ip_to_hostnames(wifi_gw) .. "" + else + local wprefix = "" + local wan_wifi_snr = "none" + local wan_wifi_ssid + if wan_iface:match("^wlan%d+$") then + wprefix = "wifi " + local s, n = get_wifi_signal(wan_iface) + if s ~= "none" and n ~= "none" then + wan_wifi_snr = math.abs(s - n) + end + cursor:foreach("wireless", "wifi-iface", + function (section) + if section.network == "wan" then + wan_wifi_ssid = section.ssid + return false + end + end + ) + if not wan_wifi_ssid then -- if still nil then set default + wan_wifi_ssid = "none" + end + end + + cidr = netmask_to_cidr(mask) + wan_gw = get_default_gw("wan") + if wprefix == "" then -- no wifi wan + if wan_gw:match("^10%.") or not hide_local then + if wan_gw:match("^10%.") then + col1[#col1 + 1] = "WAN address:
gateway:
gateway node:" .. ip .. " / " .. cidr .. "
" .. wan_gw .. "
" .. mesh_ip_to_hostnames(wan_gw) .. "" + else + col1[#col1 + 1] = "WAN address:
default gateway:" .. ip .. " / " .. cidr .. "
" .. wan_gw .. "" + end + end + else -- with wifi wan + if wan_wifi_ssid ~= "none" and wan_wifi_snr ~= "none" then + if wan_gw:match("^10%.") or not hide_local then + if wan_gw:match("^10%.") then + col1[#col1 + 1] = "" .. wprefix .. "WAN address:
SSID | SNR:
gateway:
gateway node:" .. ip .. " / " .. cidr .. "
" .. wan_wifi_ssid .. " | " .. wan_wifi_snr .. " dB
" .. wan_gw .. "
" .. mesh_ip_to_hostnames(wan_gw) .. "" + else + col1[#col1 + 1] = "" .. wprefix .. "WAN address:
SSID | SNR:
default gateway:" .. ip .. " / " .. cidr .. "
" .. wan_wifi_ssid .. " | " .. wan_wifi_snr .. " dB
" .. wan_gw .. "" + end + end + else + if wan_gw:match("^10%.") or not hide_local then + if wan_gw:match("^10%.") then + col1[#col1 + 1] = "
" .. wprefix .. "WAN address:
gateway:
gateway node:" .. ip .. " / " .. cidr .. "
" .. wan_gw .. "
" .. mesh_ip_to_hostnames(wan_gw) .. "" + else + col1[#col1 + 1] = "" .. wprefix .. "WAN address:
default gateway:" .. ip .. " / " .. cidr .. "
" .. wan_gw .. "" + end + end + end + end end - col1[#col1] = col1[#col1] .. "" end if browser_ip then col1[#col1 + 1] = "your address:" .. browser_ip .. "
" .. mesh_ip_to_hostnames(browser_ip) .. "" end - -- right column - system info if config == "mesh" and not wifi_disabled then - col2[#col2 + 1] = "signal / noise / SNR:" + col2[#col2 + 1] = "signal|noise|SNR:" local s, n = get_wifi_signal(wifi_iface) if s == "none" then col2[#col2] = col2[#col2] .. "no RF links" else - col2[#col2] = col2[#col2] .. "" .. s .. " / " .. n .. " / " .. math.abs(s - n) .. " dB" + col2[#col2] = col2[#col2] .. "" .. s .. " | " .. n .. " | " .. math.abs(s - n) .. " dB" col2[#col2] = col2[#col2] .. "   " end end