diff --git a/files/usr/sbin/owrt-remote b/files/usr/sbin/owrt-remote index e76e79b..90608f0 100644 --- a/files/usr/sbin/owrt-remote +++ b/files/usr/sbin/owrt-remote @@ -130,27 +130,40 @@ memory_text() { } flash_text() { - local text - text="$(df -h /overlay 2>/dev/null | awk 'NR == 2 { printf "%s free / %s (%s used)", $4, $2, $5; exit }')" - if [ -n "$text" ]; then - printf '%s' "$text" - return - fi - text="$(df -h / 2>/dev/null | awk 'NR == 2 { printf "%s free / %s (%s used)", $4, $2, $5; exit }')" - [ -n "$text" ] && { - printf '%s' "$text" - return - } + local mount text + for mount in /overlay /; do + text="$( + df -k "$mount" 2>/dev/null | awk ' + function mb(k) { + if (k == "" || k == 0) return "0 MB" + return sprintf("%.1f MB", k / 1024) + } + END { + if (NF >= 5) { + total=$(NF-4); avail=$(NF-2); pct=$(NF-1) + printf "%s free / %s (%s used)", mb(avail), mb(total), pct + } + } + ' + )" + if [ -n "$text" ]; then + printf '%s' "$text" + return + fi + done printf 'unknown' } temperature_text() { local file raw max max="" - for file in /sys/class/thermal/thermal_zone*/temp; do + for file in /sys/class/thermal/thermal_zone*/temp /sys/devices/virtual/thermal/thermal_zone*/temp /sys/class/hwmon/hwmon*/temp*_input; do [ -r "$file" ] || continue - raw="$(cat "$file" 2>/dev/null | tr -cd '0-9')" + raw="$(cat "$file" 2>/dev/null | tr -cd '0-9-')" [ -n "$raw" ] || continue + case "$raw" in + -*|'') continue ;; + esac [ -z "$max" ] && max="$raw" [ "$raw" -gt "$max" ] && max="$raw" done @@ -171,6 +184,10 @@ xray_running() { ps_all | grep '[x]ray' | grep -F "$config" >/dev/null 2>&1 } +ssh_running() { + ps_all | grep '[d]ropbear' >/dev/null 2>&1 +} + xray_bin_path() { local configured candidate configured="$(uci_get xray_bin /usr/bin/xray)" @@ -357,7 +374,7 @@ run_xray() { } heartbeat_json() { - local router_id router_name role public_url hub_url xray_state service_state + local router_id router_name role public_url hub_url xray_state service_state ssh_state router_id="$(safe_id "$(uci_get router_id main)")" router_name="$(uci_get router_name "$router_id")" role="$(uci_get role node)" @@ -374,6 +391,11 @@ heartbeat_json() { else service_state="disabled" fi + if ssh_running; then + ssh_state="running" + else + ssh_state="stopped" + fi cat <= 3 and parts[1] == "access" and parts[2]: + self.proxy_access(f"/access/{parts[2]}{path}") + return True + return False + def admin_ok(self): cookies = parse_cookies(self.headers.get("Cookie", "")) return secrets.compare_digest(cookies.get(SESSION_COOKIE, ""), self.app.session_token) @@ -1145,6 +1158,8 @@ class Handler(BaseHTTPRequestHandler): if path.startswith("/access/"): self.proxy_access(path) return + if self.maybe_proxy_luci_absolute(path): + return if not self.require_admin(): return if path == "/" or path == "": @@ -1187,6 +1202,8 @@ class Handler(BaseHTTPRequestHandler): if path.startswith("/access/"): self.proxy_access(path) return + if self.maybe_proxy_luci_absolute(path): + return if not self.require_admin(): return if path == "/api/auth": @@ -1357,24 +1374,44 @@ def rewrite_html(body, prefix): 'href="/': f'href="{prefix}/', 'src="/': f'src="{prefix}/', 'action="/': f'action="{prefix}/', + 'data-url="/': f'data-url="{prefix}/', "href='/": f"href='{prefix}/", "src='/": f"src='{prefix}/", "action='/": f"action='{prefix}/", + "data-url='/": f"data-url='{prefix}/", 'url("/': f'url("{prefix}/', "url('/": f"url('{prefix}/", "url(/": f"url({prefix}/", + '"/ubus"': f'"{prefix}/ubus"', + "'/ubus'": f"'{prefix}/ubus'", + "`/ubus`": f"`{prefix}/ubus`", + '"/cgi-bin/luci"': f'"{prefix}/cgi-bin/luci"', + "'/cgi-bin/luci'": f"'{prefix}/cgi-bin/luci'", + "`/cgi-bin/luci`": f"`{prefix}/cgi-bin/luci`", '"/cgi-bin/luci': f'"{prefix}/cgi-bin/luci', '"/ubus/': f'"{prefix}/ubus/', '"/luci-static/': f'"{prefix}/luci-static/', "'/cgi-bin/luci": f"'{prefix}/cgi-bin/luci", "'/ubus/": f"'{prefix}/ubus/", "'/luci-static/": f"'{prefix}/luci-static/", + "`/cgi-bin/luci": f"`{prefix}/cgi-bin/luci", + "`/ubus/": f"`{prefix}/ubus/", + "`/luci-static/": f"`{prefix}/luci-static/", + '"\\/ubus"': f'"{escaped_prefix}\\/ubus"', + "'\\/ubus'": f"'{escaped_prefix}\\/ubus'", + "`\\/ubus`": f"`{escaped_prefix}\\/ubus`", + '"\\/cgi-bin\\/luci"': f'"{escaped_prefix}\\/cgi-bin\\/luci"', + "'\\/cgi-bin\\/luci'": f"'{escaped_prefix}\\/cgi-bin\\/luci'", + "`\\/cgi-bin\\/luci`": f"`{escaped_prefix}\\/cgi-bin\\/luci`", '"\\/cgi-bin\\/luci': f'"{escaped_prefix}\\/cgi-bin\\/luci', '"\\/ubus\\/': f'"{escaped_prefix}\\/ubus\\/', '"\\/luci-static\\/': f'"{escaped_prefix}\\/luci-static\\/', "'\\/cgi-bin\\/luci": f"'{escaped_prefix}\\/cgi-bin\\/luci", "'\\/ubus\\/": f"'{escaped_prefix}\\/ubus\\/", "'\\/luci-static\\/": f"'{escaped_prefix}\\/luci-static\\/", + "`\\/cgi-bin\\/luci": f"`{escaped_prefix}\\/cgi-bin\\/luci", + "`\\/ubus\\/": f"`{escaped_prefix}\\/ubus\\/", + "`\\/luci-static\\/": f"`{escaped_prefix}\\/luci-static\\/", } for old, new in replacements.items(): text = text.replace(old, new)