Add weekly report, multi-admin, docker health cmd, backup tail, openwrt filters

This commit is contained in:
2026-02-08 23:27:23 +03:00
parent b78dc3cd5c
commit 4d4e3767bc
12 changed files with 264 additions and 31 deletions

View File

@@ -308,7 +308,7 @@ def _parse_leases_fallback(raw: str) -> list[str]:
return out
async def get_openwrt_status(cfg: dict[str, Any]) -> str:
async def get_openwrt_status(cfg: dict[str, Any], mode: str = "full") -> str:
ow_cfg = cfg.get("openwrt", {})
host = ow_cfg.get("host")
user = ow_cfg.get("user", "root")
@@ -353,19 +353,11 @@ async def get_openwrt_status(cfg: dict[str, Any]) -> str:
if len(parts) < 4:
return "⚠️ OpenWrt response incomplete"
sys_info = None
wan_status = None
wireless = None
leases = None
leases_fallback = ""
sys_info = _safe_json_load(parts[0])
if sys_info is None:
sys_info = None
wan_status = _safe_json_load(parts[1]) or {}
wireless = _safe_json_load(parts[2]) or {}
leases = _safe_json_load(parts[3])
if leases is None:
leases_fallback = parts[3]
leases_fallback = "" if leases is not None else parts[3]
if isinstance(sys_info, dict):
uptime_raw = sys_info.get("uptime")
@@ -419,35 +411,40 @@ async def get_openwrt_status(cfg: dict[str, Any]) -> str:
else:
leases_list = _parse_leases_fallback(leases_fallback)
lines = [
header = [
"📡 OpenWrt",
f"🕒 Uptime: {uptime}",
f"⚙️ Load: {load}",
f"🌐 WAN: {wan_ip} ({wan_state})",
"",
]
wifi_section: list[str] = []
if wifi_net_counts:
lines.append("📶 Wi-Fi networks:")
wifi_section.append("📶 Wi-Fi networks:")
for label, count in sorted(wifi_net_counts.items()):
lines.append(f" - {label}: {count}")
lines.append("")
wifi_section.append(f" - {label}: {count}")
wifi_section.append("")
lines.append(f"📶 Wi-Fi clients: {len(wifi_clients)}")
wifi_section.append(f"📶 Wi-Fi clients: {len(wifi_clients)}")
if wifi_clients:
for line in wifi_clients[:20]:
lines.append(f" - {line}")
wifi_section.append(f" - {line}")
if len(wifi_clients) > 20:
lines.append(f" … and {len(wifi_clients) - 20} more")
wifi_section.append(f" … and {len(wifi_clients) - 20} more")
else:
lines.append(" (none)")
wifi_section.append(" (none)")
lines += ["", f"🧾 DHCP leases: {len(leases_list)}"]
lease_section: list[str] = ["", f"🧾 DHCP leases: {len(leases_list)}"]
if leases_list:
for line in leases_list[:20]:
lines.append(f" - {line}")
lease_section.append(f" - {line}")
if len(leases_list) > 20:
lines.append(f" … and {len(leases_list) - 20} more")
lease_section.append(f" … and {len(leases_list) - 20} more")
else:
lines.append(" (none)")
lease_section.append(" (none)")
return "\n".join(lines)
if mode == "wan":
return "\n".join(header)
if mode == "clients":
return "\n".join(header + wifi_section)
return "\n".join(header + wifi_section + lease_section)