<%# LuCI - Lua Configuration Interface Copyright 2008 Steven Barth Copyright 2008-2011 Jo-Philipp Wich Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 -%> <% require "luci.fs" require "luci.tools.status" require "luci.phicommproduct" data ={ lan_ipaddrs = {}, wan = {}, lan = {}, wlan2G = {}, wlan5G = {} } local has_network = luci.fs.stat("/etc/config/network") local has_wifi = luci.fs.stat("/etc/config/wireless") has_wifi = has_wifi and has_wifi.size > 0 local phicomm_lua = require "phic" local uci_t = require "luci.model.uci".cursor() local netm = require "luci.model.network".init() --[[获取lan port 数据 start 1]]-- local lan = netm:get_network("lan") data.lan.ipaddr = uci_t:get("network","lan","ipaddr") data.lan.netmask = uci_t:get("network","lan","netmask") data.lan.lan_macaddr = uci_t:get("network","lan","macaddr") --[[end 1]]-- --[[获取wan port 数据 start 2]]-- local cur = luci.model.uci.cursor() local wan_section = cur:get_all("network","wan") local opt_value = wan_section.peerdns local hw_ver --[[获取硬件版本号]]-- uci_t:foreach("system", "system", function(s) hw_ver = s.hw_ver or "" end ) wan2 = netm:get_wannet() if wan2 then data.wan.ipaddr = wan2:ipaddr() data.wan.gwaddr = wan2:gwaddr() data.wan.netmask = wan2:netmask() if opt_value == nil or opt_value == "1" then data.wan.dns = wan2:dnsaddrs() else data.wan.dns = {wan_section.dns1,wan_section.dns2} if not data.wan.dns[1] then data.wan.dns = {wan_section.static_dns1, wan_section.static_dns2} end end end if has_network then data.wan.ifname = uci_t:get("network","wan","ifname") if data.wan.ifname == "apcli0" then data.wan.macaddr = luci.sys.exec("ifconfig apcli0 | grep HWaddr | cut -c 39-55") elseif data.wan.ifname == "apclii0" then data.wan.macaddr = luci.sys.exec("ifconfig apclii0 | grep HWaddr | cut -c 39-55") else if uci_t:get("network","wan", "ignore") == "1" then data.wan.macaddr = uci_t:get("network","wan","macaddr") else data.wan.macaddr = uci_t:get("network","wan","mac_addr") end end data.wan.proto = uci_t:get("network","wan","proto") else data.wan.ifname = "eth0.2" data.wan.macaddr = "00:00:00:00:00:00" data.wan.proto = "dhcp" end local phicomm_lua = require "phic" --[[获取2.4G wireless 数据 start 3]]-- dev1 = netm:get_wifidev("mt7620") net1 = dev1:get_wifinets() local disable_2g=phicomm_lua.get_wifi_iface_config("ra0", "disabled") or {"0"} local radio_2g = disable_2g[1] == "1" and "0" or "1" data.wlan2G.status = radio_2g data.wlan2G.ssid = net1[1]:active_ssid() or "-" bssid_table = phicomm_lua.get_mac_addr("wlan_2") or {"unkown"} data.wlan2G.bssid = bssid_table[1] data.wlan2G.channel = net1[1]:channel() or "-" if has_wifi then data.wlan2G.mode = uci_t:get("wireless","mt7620", "wifimode") or "9" uci_t:foreach("wireless", "wifi-iface", function(s) if s.device == "mt7620" and s.ifname == "ra0" then data.wlan2G.enc = s.encryption or "psk2" end end ) else data.wlan2G.status = "0" data.wlan2G.mode = "-" data.wlan2G.enc = "-" end --[[end 3]] --[[获取5G wireless 数据 start 4]]-- dev2 = netm:get_wifidev("mt7612e") net2 = dev2:get_wifinets() --local iw_5g = luci.sys.wifi.getiwinfo("rai0") local disable_5g=phicomm_lua.get_wifi_iface_config("rai0", "disabled") or {"0"} local radio_5g = disable_5g[1] == "1" and "0" or "1" data.wlan5G.status = radio_5g data.wlan5G.ssid = net2[1]:active_ssid() or "-" bssid_table = phicomm_lua.get_mac_addr("wlan_5") or {"unkown"} data.wlan5G.bssid = bssid_table[1] data.wlan5G.channel = net2[1]:channel() or "-" if has_wifi then data.wlan5G.mode = uci_t:get("wireless","mt7612e", "wifimode") or "14" uci_t:foreach("wireless", "wifi-iface", function(s) if s.device == "mt7612e" and s.ifname == "rai0" then data.wlan5G.enc = s.encryption or "psk2" end end ) else data.wlan5G.status = "0" data.wlan5G.mode = "-" data.wlan5G.enc = "-" end --[[end 4]] require "luci.util" date = luci.util.exec("date +'%Y/%m/%d %H:%M'") time = luci.sys.uptime() updays = math.modf(time/(60*60*24)) upminutes = math.modf(time/60) uphours = math.modf(upminutes/60)%24 upminutes = upminutes%60 upsecs = time%60 function get_phy_connect() local stat, iwinfo = pcall(require, "iwinfo") local phy_status = 1 levle = iwinfo.get_phy_connect("wan") for k, v in ipairs(levle or { }) do if k or v then phy_status = v end end return phy_status end function get_wisp_connect(ifname) local stat, iwinfo = pcall(require, "iwinfo") local wisp_status = 0 levle = iwinfo.get_wisp_connect(ifname) for k, v in ipairs(levle or { }) do if k or v then wisp_status = v end end return wisp_status end local phy_status = get_phy_connect() local wisp_2g_status = get_wisp_connect("apcli0") local wisp_5g_status = get_wisp_connect("apclii0") function get_wan_ipaddr() local ipaddr = "0.0.0.0" if wan2 and data.wan.ipaddr and ((data.wan.ifname == "apcli0" or data.wan.ifname == "apclii0") or phy_status == 1) then if data.wan.ifname == "apcli0" or data.wan.ifname == "apclii0" then if data.wan.ifname == "apcli0" and wisp_2g_status == 0 then return ipaddr end if data.wan.ifname == "apclii0" and wisp_5g_status == 0 then return ipaddr end end ipaddr = data.wan.ipaddr end return ipaddr end function get_wan_netmask() local netmask = "0.0.0.0" if wan2 and data.wan.netmask and ((data.wan.ifname == "apcli0" or data.wan.ifname == "apclii0") or phy_status == 1) then if data.wan.ifname == "apcli0" or data.wan.ifname == "apclii0" then if data.wan.ifname == "apcli0" and wisp_2g_status == 0 then return netmask end if data.wan.ifname == "apclii0" and wisp_5g_status == 0 then return netmask end end netmask = data.wan.netmask end return netmask end function get_wan_gw() local gw = "0.0.0.0" if wan2 and data.wan.gwaddr and ((data.wan.ifname == "apcli0" or data.wan.ifname == "apclii0") or phy_status == 1) then if data.wan.ifname == "apcli0" or data.wan.ifname == "apclii0" then if data.wan.ifname == "apcli0" and wisp_2g_status == 0 then return gw end if data.wan.ifname == "apclii0" and wisp_5g_status == 0 then return gw end end gw = data.wan.gwaddr end return gw end function get_wan_mac() local mac = "00:00:00:00:00:00" if data.wan.macaddr then mac = data.wan.macaddr end return mac end function get_wan_dns() local dns = "0.0.0.0;0.0.0.0" if wan2 and data.wan.dns[1] and ((data.wan.ifname == "apcli0" or data.wan.ifname == "apclii0") or phy_status == 1) then if data.wan.ifname == "apcli0" or data.wan.ifname == "apclii0" then if data.wan.ifname == "apcli0" and wisp_2g_status == 0 then return dns end if data.wan.ifname == "apclii0" and wisp_5g_status == 0 then return dns end end dns = data.wan.dns[1] if data.wan.dns[2] then dns = dns..";"..data.wan.dns[2] else dns = dns..";".."0.0.0.0" end end return dns end -%> <%+header%>
<%:system status%>
<%:system info%>:
<%:now time%>: <%=date%>
<%:running time%>: <% if updays > 0 then %> <%=updays%><%:sysstatus day%>, <%=uphours%><%:sysstatus hour%>, <%=upminutes%><%:sysstatus min%>, <%=upsecs%><%:sysstatus sec%> <% elseif uphours > 0 then %> <%=uphours%><%:sysstatus hour%>,<%=upminutes%><%:sysstatus min%>,<%=upsecs%><%:sysstatus sec%> <% elseif upminutes > 0 then %> <%=upminutes%><%:sysstatus min%>,<%=upsecs%><%:sysstatus sec%> <% elseif upsecs > 0 then %> <%=upsecs%><%:sysstatus sec%> <% end %> <%:sysstatus software version%>: <%=pcdata(luci.phicommproduct.softversion)%>精简版
<%:equipment model%>: <%=luci.sys.hostname() or "?"%> <%:hardware version%>: <%=hw_ver%>
<%:wan status%>: <%:lan status%>:
<%:internet method%>: <%:IP address%>:
<%:IP address%>: <%=get_wan_ipaddr()%> <%:sub network mask%>:
<%:sub network mask%>: <%=get_wan_netmask()%> <%:mac address%>:
<%:default gateway%>: <%=get_wan_gw()%>
<%:dns server%>: <%=get_wan_dns()%>
<%:mac address%>: <%=get_wan_mac()%>
<%:2.4Gwireless status%>: <%:5Gwireless status%>:
<%:wireless status%>: <%:wireless status%>:
<%:network name%>: <%:network name%>:
<%:wireless mode%>: <%:wireless mode%>:
<%:wireless channel%>: <%:wireless channel%>:
<%:mac address%>: <%:mac address%>:
<%+footer%>