This commit is contained in:
Meghdad committed 2026-10-08 22:31:59 +03:30
commit 17eba139bb
43 files changed
+2583

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
# Legacy LAN status dashboard
This independent BusyBox/Netcat example reports basic router status. It has no HTTPS or authentication and is restricted to a trusted LAN. It was removed from the original router.
Read the [standalone tutorial](../../docs/examples/status-dashboard.md) before using it. Copy `config.example.sh` to a private `config.sh` in this directory. Do not expose this service with RouterShelf's public gateway rules.
@@ -0,0 +1,8 @@
# Copy to config.sh and edit locally. Trusted shell configuration, not user input.
# These are illustrative addresses, not a working configuration for every router.
LAN_INTERFACE=br0
LAN_IP=192.168.50.1
LAN_SUBNET=192.168.50.0/24
GATEWAY_IP=192.168.50.2
PROBE_IP=1.1.1.1
PORT=8080
+42
View File
@@ -0,0 +1,42 @@
#!/bin/sh
# Fixed read-only response. No request content is executed.
SERVICE_DIR=${SERVICE_DIR:-/etc/storage/router-status}
. "$SERVICE_DIR/config.sh"
IFS= read -r -t 5 request || exit 0
case "$request" in
'GET / HTTP/'*|'GET /status HTTP/'*) ;;
*) printf 'HTTP/1.1 404 Not Found\r\nConnection: close\r\nContent-Length: 0\r\n\r\n'; exit 0 ;;
esac
while IFS= read -r -t 2 header; do
[ "$header" = "$(printf '\r')" ] || [ -z "$header" ] && break
done
up=$(awk '{d=int($1/86400);h=int($1%86400/3600);m=int($1%3600/60);printf "%dd %dh %dm",d,h,m}' /proc/uptime)
mem=$(awk '/MemTotal:/{t=$2}/MemFree:/{f=$2}/Buffers:/{b=$2}/^Cached:/{c=$2}END{printf "%.1f / %.1f MB (%.0f%%)",(t-f-b-c)/1024,t/1024,100*(t-f-b-c)/t}' /proc/meminfo)
load=$(awk '{print $1 " / " $2 " / " $3}' /proc/loadavg)
radio='No response'; ping -c 1 -W 1 "$GATEWAY_IP" >/dev/null 2>&1 && radio='Responding'
internet='No response'; ping -c 1 -W 2 "$PROBE_IP" >/dev/null 2>&1 && internet='Probe succeeded'
printf 'HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nCache-Control: no-store\r\nX-Content-Type-Options: nosniff\r\nContent-Security-Policy: default-src '\''none'\''; style-src '\''unsafe-inline'\''; frame-ancestors '\''none'\''\r\nConnection: close\r\n\r\n'
cat <<EOF
<!doctype html>
<html lang="en"><head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta http-equiv="refresh" content="30">
<title>Router status</title>
<style>
body{font:17px system-ui,sans-serif;background:#edf3f8;color:#183248;margin:0;padding:32px 16px}
main{max-width:700px;margin:auto}h1{font-size:29px}
p,footer{color:#51687b;line-height:1.7}
.card{background:white;border-radius:16px;padding:20px;margin:14px 0;display:flex;justify-content:space-between;gap:20px;flex-wrap:wrap}
.value{font-weight:600}footer{font-size:14px}
</style></head><body><main>
<h1>Router status</h1>
<p>Local network dashboard. Refreshes every 30 seconds.</p>
<div class="card"><span>Uptime</span><span class="value">$up</span></div>
<div class="card"><span>Memory used, excluding cache</span><span class="value">$mem</span></div>
<div class="card"><span>Load average: 1 / 5 / 15 minutes</span><span class="value">$load</span></div>
<div class="card"><span>Gateway probe</span><span class="value">$radio</span></div>
<div class="card"><span>Internet IP probe</span><span class="value">$internet</span></div>
<footer>Probes run on the router when this page is requested. A failed ICMP probe does not prove that Internet access is down. Load average is not CPU utilization.</footer>
</main></body></html>
EOF
+28
View File
@@ -0,0 +1,28 @@
#!/bin/sh
set -e
SERVICE_DIR=${SERVICE_DIR:-/etc/storage/router-status}
. "$SERVICE_DIR/config.sh"
rules() {
if ! iptables -S RS_STATUS >/dev/null 2>&1; then
iptables -N RS_STATUS
iptables -A RS_STATUS -j DROP
iptables -I RS_STATUS 1 -i "$LAN_INTERFACE" -s "$LAN_SUBNET" -d "$LAN_IP" -j ACCEPT
fi
# Refuse to silently reuse a chain configured for another LAN.
iptables -S RS_STATUS | grep -F -- "-s $LAN_SUBNET -d $LAN_IP/32 -i $LAN_INTERFACE -j ACCEPT" >/dev/null || {
echo "Review RS_STATUS: expected LAN allow rule not found" >&2
return 1
}
iptables -S RS_STATUS | grep -q -- '-A RS_STATUS -j DROP' || return 1
ip6tables -S INPUT | grep -q -- "--dport $PORT -j DROP" || ip6tables -I INPUT 1 -p tcp --dport "$PORT" -j DROP
iptables -S INPUT | grep -q -- "--dport $PORT -j RS_STATUS" || iptables -I INPUT 1 -p tcp --dport "$PORT" -j RS_STATUS
}
rules
[ "$1" = '--firewall' ] && exit 0
if [ -f /tmp/router-status.pid ]; then
pid=$(cat /tmp/router-status.pid)
case "$pid" in ''|*[!0-9]*) ;; *) kill -0 "$pid" 2>/dev/null && exit 0 ;; esac
fi
export SERVICE_DIR
nohup nc -ll -p "$PORT" -e "$SERVICE_DIR/status-response.sh" </dev/null >/tmp/router-status.log 2>&1 &
echo $! >/tmp/router-status.pid