From a14ffeaf4ac7a070b87ef8767e759484a237dd54 Mon Sep 17 00:00:00 2001 From: kzolotarev95 Date: Tue, 30 Jun 2026 12:10:30 +0400 Subject: [PATCH] Sync stopped router status on hub --- files/etc/init.d/owrt-remote | 22 +++++++++++++++++++--- files/usr/sbin/owrt-remote | 26 ++++++++++++++++++++------ files/www/cgi-bin/owrt-remote | 3 ++- vps/owrt-remote-hub.py | 5 +++-- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/files/etc/init.d/owrt-remote b/files/etc/init.d/owrt-remote index 794c994..73e517b 100644 --- a/files/etc/init.d/owrt-remote +++ b/files/etc/init.d/owrt-remote @@ -23,10 +23,26 @@ config_enabled() { esac } -stop_xray_processes() { - local config pids pid +xray_pids() { + local config cmdline cmd pid config="$(uci_get xray_config /etc/xray/owrt-remote-client.json)" - pids="$( (ps w 2>/dev/null || ps 2>/dev/null) | grep '[x]ray' | grep -F "$config" | awk '{print $1}')" + [ -n "$config" ] || return 0 + for cmdline in /proc/[0-9]*/cmdline; do + [ -r "$cmdline" ] || continue + cmd="$(tr '\000' ' ' <"$cmdline" 2>/dev/null || true)" + case "$cmd" in + *xray*"$config"*|*xray-core*"$config"*) + pid="${cmdline%/cmdline}" + pid="${pid##*/}" + printf '%s\n' "$pid" + ;; + esac + done +} + +stop_xray_processes() { + local pids pid + pids="$(xray_pids)" for pid in $pids; do kill "$pid" >/dev/null 2>&1 || true done diff --git a/files/usr/sbin/owrt-remote b/files/usr/sbin/owrt-remote index 2547bde..634c931 100644 --- a/files/usr/sbin/owrt-remote +++ b/files/usr/sbin/owrt-remote @@ -179,16 +179,30 @@ ps_all() { ps w 2>/dev/null || ps 2>/dev/null || true } -xray_running() { - local config +xray_pids() { + local config cmdline cmd pid config="$(uci_get xray_config /etc/xray/owrt-remote-client.json)" - ps_all | grep '[x]ray' | grep -F "$config" >/dev/null 2>&1 + [ -n "$config" ] || return 0 + for cmdline in /proc/[0-9]*/cmdline; do + [ -r "$cmdline" ] || continue + cmd="$(tr '\000' ' ' <"$cmdline" 2>/dev/null || true)" + case "$cmd" in + *xray*"$config"*|*xray-core*"$config"*) + pid="${cmdline%/cmdline}" + pid="${pid##*/}" + printf '%s\n' "$pid" + ;; + esac + done +} + +xray_running() { + [ -n "$(xray_pids)" ] } stop_xray() { - local config pids pid alive - config="$(uci_get xray_config /etc/xray/owrt-remote-client.json)" - pids="$(ps_all | grep '[x]ray' | grep -F "$config" | awk '{print $1}')" + local pids pid alive + pids="$(xray_pids)" if [ -z "$pids" ]; then printf '%s\n' "OK: Xray уже остановлен" return 0 diff --git a/files/www/cgi-bin/owrt-remote b/files/www/cgi-bin/owrt-remote index 134484a..aafeb4e 100644 --- a/files/www/cgi-bin/owrt-remote +++ b/files/www/cgi-bin/owrt-remote @@ -2,7 +2,7 @@ KEY_FILE="${KEY_FILE:-/etc/owrt-remote/web.key}" AGENT="${AGENT:-/usr/sbin/owrt-remote}" -OWRT_REMOTE_UI_VERSION="2026-06-30-init-ash-fix-v20" +OWRT_REMOTE_UI_VERSION="2026-06-30-stop-sync-v21" PARAMS_FILE="${TMPDIR:-/tmp}/owrt-remote-cgi.$$" RESULT_TITLE="" RESULT_BODY="" @@ -190,6 +190,7 @@ run_action() { /etc/init.d/owrt-remote stop >>"$output" 2>&1 || rc=$? "$AGENT" stop-xray >>"$output" 2>&1 || rc=$? /etc/init.d/owrt-remote disable >>"$output" 2>&1 || rc=$? + "$AGENT" heartbeat >>"$output" 2>&1 || true set_result "Сервис остановлен" "$(cat "$output")" "warn" ;; restart) diff --git a/vps/owrt-remote-hub.py b/vps/owrt-remote-hub.py index e8ab36e..660ae13 100644 --- a/vps/owrt-remote-hub.py +++ b/vps/owrt-remote-hub.py @@ -282,7 +282,8 @@ def row_to_router(row): except json.JSONDecodeError: status = {} last_seen = data.get("last_seen") - online = bool(last_seen and now_ts() - int(last_seen) <= ONLINE_AFTER_SECONDS) + service_enabled = str(status.get("service") or "").lower() != "disabled" + online = bool(last_seen and service_enabled and now_ts() - int(last_seen) <= ONLINE_AFTER_SECONDS) data["status"] = status data["online"] = online data["last_seen_iso"] = iso_time(last_seen) @@ -816,7 +817,7 @@ h1{{margin:0;font-size:29px;line-height:1.2;letter-spacing:0}}.appBanner{{positi .authMenu{{position:absolute;right:0;top:calc(100% + 10px);z-index:5;width:min(520px,calc(100vw - 44px));padding:14px;background:linear-gradient(180deg,rgba(255,255,255,.09),rgba(255,255,255,.05)),rgba(19,14,32,.96);border:1px solid var(--line);border-radius:8px;box-shadow:0 24px 70px rgba(0,0,0,.36);backdrop-filter:blur(12px)}}.authMenu[hidden]{{display:none}}.authMenu h2{{margin:0 0 4px;font-size:18px}}.authMenu p{{margin:0 0 12px;color:var(--muted)}}.authGrid{{display:grid;grid-template-columns:1fr 1fr;gap:10px}}.authGrid .wide{{grid-column:1/-1}}.msg{{margin-top:10px;color:#bbf7d0;font-weight:750}}.msg.bad{{color:#fecdd3}}.formMsg{{margin:-8px 0 18px;padding:10px 12px;border:1px solid rgba(34,197,94,.34);border-radius:8px;background:rgba(34,197,94,.12);color:#bbf7d0;font-weight:800}}.formMsg.bad{{border-color:rgba(251,113,133,.4);background:rgba(251,113,133,.13);color:#fecdd3}} input,select{{min-width:0;border:1px solid var(--line);border-radius:8px;padding:10px 11px;background:rgba(8,5,18,.72);color:var(--text)}}button,.btn{{border:1px solid rgba(255,255,255,.10);border-radius:8px;padding:10px 13px;background:rgba(255,255,255,.10);color:#f7f2ff;font-weight:850;text-decoration:none;cursor:pointer;display:inline-flex;justify-content:center;align-items:center}}.authToggle{{border-radius:999px;padding:8px 14px;background:rgba(255,255,255,.08);color:#f3e8ff}}button.primary,.btn.primary{{background:var(--blue);color:#fff;box-shadow:0 10px 22px rgba(124,58,237,.22)}}button.bad,.btn.bad{{background:rgba(251,113,133,.16);color:#fecdd3}}.btn.good{{background:rgba(34,197,94,.16);color:#bbf7d0}}.btn.disabled{{opacity:.45;cursor:not-allowed}} .sectionHead{{display:flex;align-items:flex-end;justify-content:space-between;gap:16px;margin:24px 0 14px}}.sectionHead h2{{margin:0;font-size:22px}}.sectionHead p{{margin:3px 0 0;color:var(--muted)}}.summary{{display:flex;gap:10px;flex-wrap:wrap;justify-content:flex-end}}.miniStat{{border:1px solid var(--line);border-radius:999px;background:rgba(255,255,255,.07);padding:8px 12px;color:#ddd6fe;font-weight:750;white-space:nowrap}} -.cards{{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:14px}}.card{{position:relative;min-height:246px;overflow:hidden;background:linear-gradient(180deg,rgba(255,255,255,.08),rgba(255,255,255,.045)),var(--panel);border:1px solid var(--line);border-radius:8px;padding:14px;box-shadow:0 18px 46px rgba(0,0,0,.28);backdrop-filter:blur(10px)}}.card::before{{content:"";position:absolute;inset:0 0 auto 0;height:3px;background:var(--green)}}.card.online{{border-color:rgba(34,197,94,.45);box-shadow:0 18px 46px rgba(0,0,0,.28),0 0 0 1px rgba(34,197,94,.10),0 0 34px rgba(34,197,94,.10)}}.card.online::after{{content:"";position:absolute;right:-42px;top:-42px;width:108px;height:108px;border-radius:50%;background:radial-gradient(circle,rgba(34,197,94,.26),transparent 68%);animation:onlineGlow 2.4s ease-in-out infinite}}.card.off{{border-color:rgba(251,113,133,.42);box-shadow:0 18px 46px rgba(0,0,0,.28),0 0 0 1px rgba(251,113,133,.08),0 0 30px rgba(251,113,133,.08)}}.card.off::after{{content:"";position:absolute;right:-42px;top:-42px;width:108px;height:108px;border-radius:50%;background:radial-gradient(circle,rgba(251,113,133,.22),transparent 68%);animation:offlineGlow 2.8s ease-in-out infinite}}.card.off::before{{background:var(--red)}}.card.warn::before{{background:var(--amber)}}.card.main{{grid-column:span 2}} +.cards{{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:14px}}.card{{position:relative;min-height:246px;overflow:hidden;background:linear-gradient(180deg,rgba(255,255,255,.08),rgba(255,255,255,.045)),var(--panel);border:1px solid var(--line);border-radius:8px;padding:14px;box-shadow:0 18px 46px rgba(0,0,0,.28);backdrop-filter:blur(10px)}}.card::before{{content:"";position:absolute;inset:0 0 auto 0;height:3px;background:var(--green)}}.card.online{{border-color:rgba(34,197,94,.45);box-shadow:0 18px 46px rgba(0,0,0,.28),0 0 0 1px rgba(34,197,94,.10),0 0 34px rgba(34,197,94,.10)}}.card.off{{border-color:rgba(251,113,133,.42);box-shadow:0 18px 46px rgba(0,0,0,.28),0 0 0 1px rgba(251,113,133,.08),0 0 30px rgba(251,113,133,.08)}}.card.off::before{{background:var(--red)}}.card.warn::before{{background:var(--amber)}}.card.main{{grid-column:span 2}} @keyframes onlineGlow{{0%,100%{{transform:scale(.9);opacity:.55}}50%{{transform:scale(1.08);opacity:1}}}}@keyframes offlineGlow{{0%,100%{{transform:scale(.88);opacity:.34}}50%{{transform:scale(1.08);opacity:.9}}}} @keyframes bannerShine{{0%,45%{{transform:translateX(-120%)}}72%,100%{{transform:translateX(120%)}}}} .cardTop{{display:flex;align-items:flex-start;justify-content:space-between;gap:12px}}.routerMark{{display:grid;place-items:center;width:46px;height:46px;border-radius:8px;border:1px solid rgba(255,255,255,.14);background:rgba(255,255,255,.08)}}.routerIcon{{position:relative;width:28px;height:18px;border:2px solid #ddd6fe;border-radius:5px}}.routerIcon::before,.routerIcon::after{{content:"";position:absolute;top:-9px;width:9px;height:9px;border-top:2px solid #ddd6fe}}.routerIcon::before{{left:2px;transform:rotate(-34deg)}}.routerIcon::after{{right:2px;transform:rotate(34deg)}}.routerIcon span{{position:absolute;left:5px;right:5px;bottom:4px;display:flex;justify-content:space-between}}.routerIcon span::before,.routerIcon span::after{{content:"";width:4px;height:4px;border-radius:50%;background:#ddd6fe}}