autocore: add eth info for arm/armv8 target

This commit is contained in:
lean 2021-10-11 17:12:01 +08:00
parent 983fdace9f
commit d48fb0f877
3 changed files with 74 additions and 1 deletions

View File

@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=autocore
PKG_VERSION:=1
PKG_RELEASE:=39
PKG_RELEASE:=41
include $(INCLUDE_DIR)/package.mk
@ -46,6 +46,7 @@ define Package/autocore-arm/install
$(INSTALL_BIN) ./files/arm/090-cover-index_htm $(1)/etc/uci-defaults/090-cover-index_htm
$(INSTALL_DIR) $(1)/sbin
$(INSTALL_BIN) ./files/arm/sbin/cpuinfo $(1)/sbin/cpuinfo
$(INSTALL_BIN) ./files/arm/sbin/ethinfo $(1)/sbin/ethinfo
endef
define Package/autocore-x86/install

View File

@ -9,10 +9,18 @@
local util = require "luci.util"
local stat = require "luci.tools.status"
local ver = require "luci.version"
local uci = require("luci.model.uci").cursor()
local has_ipv6 = fs.access("/usr/sbin/ip6tables")
local has_dhcp = fs.access("/etc/config/dhcp")
local has_wifi = ((fs.stat("/etc/config/wireless", "size") or 0) > 0)
local has_switch = false
uci:foreach("network", "switch",
function(s)
has_switch = true
return false
end)
local sysinfo = luci.util.ubus("system", "info") or { }
local boardinfo = luci.util.ubus("system", "board") or { }
@ -50,10 +58,12 @@
local cpu_usage = luci.sys.exec("top -n1 | awk '/^CPU/ { printf(\"%d%%\", 100 - $8) }'") or "6%"
local cpu_info = luci.sys.exec("/sbin/cpuinfo") or "ARM Processor x 0 (233MHz, 2.3°C)"
local eth_info = luci.sys.exec("ethinfo")
local rv = {
cpuinfo = cpu_info,
cpuusage = cpu_usage,
ethinfo = eth_info,
userinfo = user_info,
uptime = sysinfo.uptime or 0,
localtime = os.date(),
@ -642,6 +652,20 @@
<% end %>
var e;
if (e = document.getElementById('ethinfo')) {
var ports = eval('(' + info.ethinfo + ')');
var tmp = "";
for (var i in ports)
{
tmp = tmp + String.format(
'<td style="text-align:center"><span style="line-height:25px">%s</span><br /><small><img src="<%=resource%>/icons/%s" /><br />%s<br />%s</small></td>', ports[i].name,
ports[i].status ? 'port_up.png' : 'port_down.png',
ports[i].speed,
ports[i].duplex ? '<%:full-duplex%>' : '<%:half-duplex%>');
};
e.innerHTML = "<tr>" + tmp + "</tr>";
}
if (e = document.getElementById('localtime'))
e.innerHTML = info.localtime;
@ -738,6 +762,15 @@
</fieldset>
<% end %>
<% if not has_switch then %>
<fieldset class="cbi-section">
<legend><%:Interfaces%></legend>
<table width="100%" cellspacing="10" id="ethinfo">
</table>
</fieldset>
<% end %>
<fieldset class="cbi-section">
<legend><%:Network%></legend>

View File

@ -0,0 +1,39 @@
#!/bin/sh
a=$(ip address | grep ^[0-9] | awk -F: '{print $2}' | sed "s/ //g" | grep '^[e]' | grep -v "@" | grep -v "\.")
b=$(echo "$a" | wc -l)
rm -f /tmp/state/ethinfo
echo -n "[" > /tmp/state/ethinfo
for i in $(seq 1 $b)
do
h=$(echo '{"name":' )
c=$(echo "$a" | sed -n ${i}p)
d=$(ethtool $c)
e=$(echo "$d" | grep "Link detected" | awk -F: '{printf $2}' | sed 's/^[ \t]*//g')
if [ $e = yes ]; then
l=1
else
l=0
fi
f=$(echo "$d" | grep "Speed" | awk -F: '{printf $2}' | sed 's/^[ \t]*//g' | tr -d "Unknown!")
[ -z "$f" ] && f=" - "
g=$(echo "$d" | grep "Duplex" | awk -F: '{printf $2}' | sed 's/^[ \t]*//g')
if [ "$g" == "Full" ]; then
x=1
else
x=0
fi
echo -n "$h \"$c\", \"status\": $l, \"speed\": \"$f\", \"duplex\": $x}," >> /tmp/state/ethinfo
done
sed -i 's/.$//' /tmp/state/ethinfo
echo -n "]" >> /tmp/state/ethinfo
cat /tmp/state/ethinfo