Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 111 additions & 69 deletions misc/sysinfo.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,46 @@
#!/bin/sh
#
# sysinfo.sh dla OpenWRT AA Cezary Jackiewicz 2013
#
# 1.00 CJ Pierwsza wersja kodu
# 1.01 RD Drobna przebudowa
# 1.02 RD Korekta b��du wy�w. zajeto�ci Flash-a, dodanie kolor�w
# 1.03 RD Dodanie nazwy routera, zmiana formatowania
# 1.04 RD Kosmetyka, sugestie @mikhnal. Zmiana przetwarzania info. o wan.
# 1.05 RD Zmiana algorytmu pobierania danych dla wan i lan
# 1.06 RD Parametryzacja kolor�w i pojawiania si� podkre�le�
# 1.07 RD Modyfikacja zwi�zana z poprawnym wy�wietlaniem interfejsu dla prot.3g
# 1.08 RD Modyfikacja wy�wietlania DNS-�w dla wan, dodanie uptime dla interfejs�w
# 1.09 RD Dodanie statusu "Down" dla wy��czonego wifi, zmiana wy�wietlania dla WLAN(sta)
# 1.10 RD Korekta wy�wietlania dla WLAN(sta)
# 1.11 RD Korekta wy�wietlania stanu pami�ci, sugestie @dopsz
# 1.12 RD Zmiana kolejno�ci wy�wietlania warto�ci stanu pami�ci + kosmetyka
# 1.13 RD Dodanie info o dhcp w LAN, zmiana sposobu wy�wietlania informacji o LAN
# 1.14 RD Dodanie informacji o ostatnich 5 b��dach
# 1.15 RD Zmiana stderr
# 1.16 RD Dodanie wy�wietlania informacji o swap
# 1.17 RD Zmiana wyliczania informacji o flash
# 1.18 RD Zmiana wy�wietlania informacji o flash
# 1.19 RD Zmiana wy�wietlania informacji o sprz�cie
# 1.20 RD Zmiana wy�wietlania informacji o sprz�cie
# 1.21 RD Dopasowyanie szeroko�ci do zawarto�ci /etc/banner
# 1.22 RD Dodanie wy�wietlania w HTML-u
# 1.23 RD Poprawki w wy�wietlaniu LAN-DHCP i WLAN
# Destination /sbin/sysinfo.sh
# sysinfo.sh dla OpenWRT AA / for OpenWRT AA Cezary Jackiewicz 2013
#
# Format: # ver who PL original / EN translation
#
# 1.00 CJ Pierwsza wersja kodu / Initial version of the code
# 1.01 RD Drobna przebudowa / Minor restructuring
# 1.02 RD Korekta błędu wyśw. zajetości Flash-a, dodanie kolorów /
# Fix Flash usage display, added colors
# 1.03 RD Dodanie nazwy routera, zmiana formatowania /
# Added router name, changed formatting
# 1.04 RD Kosmetyka, sugestie @mikhnal. Zmiana przetwarzania info. o wan. /
# Cosmetic changes (suggestions by @mikhnal), reworked WAN info processing
# 1.05 RD Zmiana algorytmu pobierania danych dla wan i lan /
# Changed data-retrieval algorithm for WAN and LAN
# 1.06 RD Parametryzacja kolorów i pojawiania się podkreśleń /
# Parameterized colors and underline appearance
# 1.07 RD Modyfikacja związana z poprawnym wyświetlaniem interfejsu dla prot.3g /
# Fix display of the interface for proto=3g
# 1.08 RD Modyfikacja wyświetlania DNS-ów dla wan, dodanie uptime dla interfejsów /
# Reworked DNS display for WAN, added per-interface uptime
# 1.09 RD Dodanie statusu "Down" dla wyłączonego wifi, zmiana wyświetlania dla WLAN(sta) /
# Added "Down" status for disabled Wi-Fi, updated WLAN(sta) display
# 1.10 RD Korekta wyświetlania dla WLAN(sta) / Fix display for WLAN(sta)
# 1.11 RD Korekta wyświetlania stanu pamięci, sugestie @dopsz /
# Fix memory-status display (suggestions by @dopsz)
# 1.12 RD Zmiana kolejności wyświetlania wartości stanu pamięci + kosmetyka /
# Changed display order of memory values + cosmetics
# 1.13 RD Dodanie info o dhcp w LAN, zmiana sposobu wyświetlania informacji o LAN /
# Added DHCP info in LAN, changed LAN-info display
# 1.14 RD Dodanie informacji o ostatnich 5 błędach / Added info on the last 5 errors
# 1.15 RD Zmiana stderr / Changed stderr
# 1.16 RD Dodanie wyświetlania informacji o swap / Added swap-info display
# 1.17 RD Zmiana wyliczania informacji o flash / Changed Flash-info calculation
# 1.18 RD Zmiana wyświetlania informacji o flash / Changed Flash-info display
# 1.19 RD Zmiana wyświetlania informacji o sprzęcie / Changed hardware-info display
# 1.20 RD Zmiana wyświetlania informacji o sprzęcie / Changed hardware-info display
# 1.21 RD Dopasowyanie szerokości do zawartości /etc/banner /
# Match width to /etc/banner content
# 1.22 RD Dodanie wyświetlania w HTML-u / Added HTML output
# 1.23 RD Poprawki w wyświetlaniu LAN-DHCP i WLAN / Fixes in LAN-DHCP and WLAN display
# Destination /etc/profile.d/99-sysinfo.sh
#
. /usr/share/libubox/jshn.sh

Expand All @@ -44,6 +58,11 @@ ExtraName=""
ExtraValue=""
HTML=""

clean_output() {
# Removes literal e[0;31m and e[0m from stdin
sed 's/e\[0;31m//g; s/e\[0m//g'
}

initialize() { # <Script Parameters>
local ColorMode="c"
if [ ! -z "$REQUEST_METHOD" ]; then
Expand Down Expand Up @@ -357,52 +376,74 @@ print_lan() {
for Zone in $(uci -q show firewall | grep []]=zone | cut -f2 -d. | cut -f1 -d=); do
if [ "$(uci -q get firewall.$Zone.masq)" != "1" ]; then
for Device in $(uci -q get firewall.$Zone.network); do
local Status="$(ubus call network.interface.$Device status 2>/dev/null)"
if [ "$Status" != "" ]; then
local State=""
local Iface=""
local IP4=""
local IP6=""
local Subnet4=""
local Subnet6=""
json_load "${Status:-{}}"
json_get_var State up
json_get_var Iface device
if json_get_type Status ipv4_address && [ "$Status" = array ]; then
json_select ipv4_address
json_get_type Status 1
if [ "$Status" = object ]; then
json_select 1
json_get_var IP4 address
json_get_var Subnet4 mask
[ "$IP4" != "" ] && [ "$Subnet4" != "" ] && IP4="$IP4/$Subnet4"
if [ "$(uci -q get dhcp.$Device.start)" != "" ]; then
local Status="$(ubus call network.interface.$Device status 2>/dev/null)"
if [ "$Status" != "" ]; then
local State=""
local Iface=""
local IP4=""
local IP6=""
local Subnet4=""
local Subnet6=""
json_load "${Status:-{}}"
json_get_var State up
json_get_var Iface device
if json_get_type Status ipv4_address && [ "$Status" = array ]; then
json_select ipv4_address
json_get_type Status 1
if [ "$Status" = object ]; then
json_select 1
json_get_var IP4 address
json_get_var Subnet4 mask
[ "$IP4" != "" ] && [ "$Subnet4" != "" ] && IP4="$IP4/$Subnet4"
fi
fi
fi
json_select
if json_get_type Status ipv6_address && [ "$Status" = array ]; then
json_select ipv6_address
json_get_type Status 1
if [ "$Status" = object ]; then
json_select 1
json_get_var IP6 address
json_get_var Subnet6 mask
[ "$IP6" != "" ] && [ "$Subnet6" != "" ] && IP6="$IP6/$Subnet6"
json_select
if json_get_type Status ipv6_address && [ "$Status" = array ]; then
json_select ipv6_address
json_get_type Status 1
if [ "$Status" = object ]; then
json_select 1
json_get_var IP6 address
json_get_var Subnet6 mask
[ "$IP6" != "" ] && [ "$Subnet6" != "" ] && IP6="$IP6/$Subnet6"
fi
fi
fi
local DHCPConfig=$(uci -q show dhcp | grep -E .interface=\.?$Device\.? | cut -d. -f2)
if [ "$DHCPConfig" != "" ] && [ "$(uci -q get dhcp.$DHCPConfig.ignore)" != "1" ]; then
local DHCPStart=$(uci -q get dhcp.$DHCPConfig.start)
local DHCPLimit=$(uci -q get dhcp.$DHCPConfig.limit)
[ "$DHCPStart" != "" ] && [ "$DHCPLimit" != "" ] && DHCP="$(echo $IP4 | cut -d. -f1-3).$DHCPStart-$(expr $DHCPStart + $DHCPLimit - 1)"
fi
[ "$IP4" != "" ] && print_line "LAN: $AddrColor$IP4$NormalColor($Iface), dhcp: $AddrColor${DHCP:-n/a}$NormalColor"
[ "$IP6" != "" ] && print_line "LAN: $AddrColor$IP6$NormalColor($Iface)"
# DHCPConfig=$(uci -q show dhcp | grep -E .interface=\.?$Device\.? | cut -d. -f2)
# if [ "$DHCPConfig" != "" ] && [ "$(uci -q get dhcp.$DHCPConfig.ignore)" != "1" ]; then
local DHCPStart=$(uci -q get dhcp.$Device.start)
local DHCPLimit=$(uci -q get dhcp.$Device.limit)
[ "$DHCPStart" != "" ] && [ "$DHCPLimit" != "" ] && DHCP="$(echo $IP4 | cut -d. -f1-3).$DHCPStart-$(expr $DHCPStart + $DHCPLimit - 1)"
# fi
[ "$IP4" != "" ] && print_line "LAN: $AddrColor$IP4$NormalColor($Iface), dhcp: $AddrColor${DHCP:-n/a}$NormalColor"
[ "$IP6" != "" ] && print_line "LAN: $AddrColor$IP6$NormalColor($Iface)"
fi
fi
done
fi
done
}

get_sta_count() {
# Number of associated stations on a wireless AP iface.
# Prefer hostapd_cli (works on MLD setups where iw dev station dump misses
# MLO-bound clients); fall back to iw dev. Returns 0 when unsure.
local iface="$1"
local count=""
if [ -S "/var/run/hostapd/$iface" ]; then
count=$(hostapd_cli -p /var/run/hostapd -i "$iface" status 2>/dev/null \
| awk -F= '/^num_sta\[/ {sum+=$2; n++} END {if (n) print sum; else print ""}')
fi
if [ -z "$count" ] && [ -S "/var/run/hostapd-$iface/$iface" ]; then
count=$(hostapd_cli -p "/var/run/hostapd-$iface" -i "$iface" status 2>/dev/null \
| awk -F= '/^num_sta\[/ {sum+=$2; n++} END {if (n) print sum; else print ""}')
fi
if [ -z "$count" ]; then
count=$(iw dev "$iface" station dump 2>/dev/null | grep -c '^Station')
fi
echo "${count:-0}"
}

print_wlan() {
local Status="$(ubus call network.wireless status 2>/dev/null)"
if [ "$Status" != "" ]; then
Expand Down Expand Up @@ -431,7 +472,8 @@ print_wlan() {
json_select $Interface
json_get_var Iface section
json_get_var RadioIface ifname
json_select "config"
json_select "config"
[ -z "$RadioIface" ] && json_get_var RadioIface ifname
json_get_var SSID ssid
json_get_var Mode mode
local IfaceDisabled=$(uci -q get wireless.$Iface.disabled)
Expand All @@ -440,7 +482,7 @@ print_wlan() {
local Connection="Down"
if [ -n "$RadioIface" ]; then
if [ "$Mode" == "ap" ]; then
Connection="$(iw dev $RadioIface station dump | grep Station | wc -l 2>/dev/null)"
Connection="$(get_sta_count "$RadioIface")"
else
Connection="$(iw dev $RadioIface link | awk 'BEGIN{FS=": ";Signal="";Bitrate=""} $1~/signal/ {Signal=$2} $1~/tx bitrate/ {Bitrate=$2}END{print Signal" "Bitrate}' 2>/dev/null)"
fi
Expand Down Expand Up @@ -511,7 +553,7 @@ print_wlan
print_vpn
print_extra
[ "$EndRuler" == "1" ] && print_horizontal_ruler
[ "$LastErrors" == "1" ] && print_error
[ "$LastErrors" == "1" ] && print_error | clean_output
finalize
exit 0
#exit 0
# Done.