From 1399eaf6058a96b178f4afa498995d4ab5db7638 Mon Sep 17 00:00:00 2001 From: igor04091968 Date: Thu, 14 May 2026 23:14:31 +0300 Subject: [PATCH] fix(webui): restore resilient aw-rus ui patching --- ansible/deploy_aw_server.yml | 13 +++++++++ aw-server/apply_webui_ru_patch.sh | 16 +++++++++++ aw-server/aw-ru-patch.js | 38 ++++++++++++++++++++++----- aw-server/settings/views-default.json | 5 ---- 4 files changed, 61 insertions(+), 11 deletions(-) diff --git a/ansible/deploy_aw_server.yml b/ansible/deploy_aw_server.yml index 7a21ebb..2d1dfc3 100644 --- a/ansible/deploy_aw_server.yml +++ b/ansible/deploy_aw_server.yml @@ -809,8 +809,21 @@ ansible.builtin.assert: that: - aw_webui_ru_index.stat.exists + - (aw_webui_ru_index.stat.size | default(0) | int) > 0 fail_msg: "Не найден index.html WebUI для применения RU patch." + - name: Проверить, что index.html не опустел после применения RU patch + ansible.builtin.stat: + path: "{{ aw_server_webui_dir }}/index.html" + register: aw_webui_ru_index_after_patch + + - name: Подтвердить, что index.html остался непустым + ansible.builtin.assert: + that: + - aw_webui_ru_index_after_patch.stat.exists + - (aw_webui_ru_index_after_patch.stat.size | default(0) | int) > 0 + fail_msg: "index.html WebUI пуст после RU patch." + - name: Удалить старые теги RU patch из index.html ansible.builtin.replace: path: "{{ aw_server_webui_dir }}/index.html" diff --git a/aw-server/apply_webui_ru_patch.sh b/aw-server/apply_webui_ru_patch.sh index 0899ac4..6160cce 100755 --- a/aw-server/apply_webui_ru_patch.sh +++ b/aw-server/apply_webui_ru_patch.sh @@ -37,6 +37,17 @@ CATEGORY_HELPER_REPLACEMENT='hostname:t.hostnameChoices.filter((function(t){retu [[ -f "$HOST_GROUPS_SRC" ]] || { echo "missing $HOST_GROUPS_SRC" >&2; exit 1; } [[ -f "$INDEX_HTML" ]] || { echo "missing $INDEX_HTML" >&2; exit 1; } +if [[ ! -s "$INDEX_HTML" ]]; then + latest_nonempty_backup="$(find "$WEBUI_DIR" -maxdepth 1 -type f -name 'index.html.bak.*' -size +0c | sort | tail -n 1 || true)" + if [[ -n "$latest_nonempty_backup" ]]; then + cp "$latest_nonempty_backup" "$INDEX_HTML" + echo "restored empty index.html from backup: $latest_nonempty_backup" + else + echo "index.html is empty and no non-empty backup exists: $INDEX_HTML" >&2 + exit 1 + fi +fi + install -d "$WEBUI_DIR/js" install -m 0644 "$PATCH_JS_SRC" "$PATCH_TARGET" install -m 0644 "$SW_CLEANUP_SRC" "$SW_TARGET" @@ -132,6 +143,11 @@ path.write_text(content) PY cp "$SW_CLEANUP_SRC" "$SERVICE_WORKER" +if [[ ! -s "$INDEX_HTML" ]]; then + echo "index.html became empty after RU patch: $INDEX_HTML" >&2 + exit 1 +fi + trends_chunk="$(grep -Rsl "$TRENDS_NEEDLE" "$WEBUI_DIR/js"/*.js 2>/dev/null | head -n 1 || true)" if [[ -n "$trends_chunk" ]]; then cp "$trends_chunk" "$trends_chunk.bak.$TS" diff --git a/aw-server/aw-ru-patch.js b/aw-server/aw-ru-patch.js index 4648c2a..8538e81 100755 --- a/aw-server/aw-ru-patch.js +++ b/aw-server/aw-ru-patch.js @@ -382,15 +382,23 @@ function enforceSafeActivityViewForPveHost() { const hash = window.location.hash || ""; - const match = hash.match(/^#\/activity\/([^/]+)\/day\/([^/]+)\/view\/([^/?#]+)/i); + const match = hash.match(/^#\/activity\/([^/]+)(?:\/day\/([^/]+))?\/view\/([^/?#]+)/i); if (!match) return; const host = decodeURIComponent(match[1] || ""); - const day = decodeURIComponent(match[2] || ""); + const day = match[2] ? decodeURIComponent(match[2]) : ""; const viewId = decodeURIComponent(match[3] || ""); - if (!isPveLikeHost(host)) return; - const safeHash = "#/activity/" + encodeURIComponent(host) + "/day/" + encodeURIComponent(day) + "/view/" + encodeURIComponent("pve_audit"); - if (safeHash !== hash && !/^pve_audit$/i.test(viewId)) { - window.location.replace(safeHash); + const prefix = day + ? "#/activity/" + encodeURIComponent(host) + "/day/" + encodeURIComponent(day) + "/view/" + : "#/activity/" + encodeURIComponent(host) + "/view/"; + if (isPveLikeHost(host)) { + const safeHash = prefix + encodeURIComponent("pve_audit"); + if (safeHash !== hash && !/^pve_audit$/i.test(viewId)) { + window.location.replace(safeHash); + } + return; + } + if (/^pve_audit$/i.test(viewId)) { + window.location.replace(prefix + encodeURIComponent("summary")); } } @@ -1542,6 +1550,16 @@ } } + function hidePveAuditTabForRegularHost(root) { + const hash = window.location.hash || ""; + const match = hash.match(/^#\/activity\/([^/]+)/i); + const host = match && match[1] ? decodeURIComponent(match[1]) : ""; + if (!host || isPveLikeHost(host)) return; + Array.from(root.querySelectorAll('a[href*="/view/pve_audit"]')).forEach(function (link) { + link.style.display = "none"; + }); + } + function injectDlpAlertsCenter(root) { if (!isAlertsRoute()) return; const host = window.__awRuPatchSettingsHost || getCurrentHostFromHash(); @@ -1578,6 +1596,10 @@ center.setAttribute("data-aw-ru-loaded", "1"); refreshDlpAlertsCenter(center, host); } + Array.from(heading.parentElement.children).forEach(function (child) { + if (child === heading || child === center) return; + child.style.display = "none"; + }); } let trendsRedirectInFlight = false; @@ -1646,6 +1668,9 @@ .finally(function () { settingsHostFetchInFlight = false; injectDlpNavigation(document.body); + if (isAlertsRoute()) { + scheduleApplyPatch(); + } }); } @@ -1854,6 +1879,7 @@ walk(document.body); translateAttributes(document.body); hideNoiseNavigation(document.body); + hidePveAuditTabForRegularHost(document.body); patchActivityHeading(document.body); patchCategoryBuilderHostLabel(document.body); staticPatchRouteKey = routeKey; diff --git a/aw-server/settings/views-default.json b/aw-server/settings/views-default.json index 439fce6..5421e98 100644 --- a/aw-server/settings/views-default.json +++ b/aw-server/settings/views-default.json @@ -30,10 +30,5 @@ { "type": "category_tree", "size": 3, "props": {} }, { "type": "top_apps", "size": 3, "props": {} } ] - }, - { - "id": "pve_audit", - "name": "PVE Audit", - "elements": [] } ]