Skip to content

Commit 98e5922

Browse files
author
HAL
committed
feat: hide reset button for remote connections
Instead of showing an error when remote users try to reset, the button is now hidden entirely for Cloudflare connections. - Button starts hidden by default - Server injects __IS_REMOTE__ flag based on Cloudflare headers - JS shows button only for local connections
1 parent 0308249 commit 98e5922

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

webstatuspi/_dashboard/_js_core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,10 @@
648648
}
649649
650650
// Button event listeners (CSP-compliant, no inline handlers)
651+
// Show reset button only for local connections (hidden by default)
652+
if (!window.__IS_REMOTE__) {
653+
document.getElementById('resetDataBtn').hidden = false;
654+
}
651655
document.getElementById('resetDataBtn').addEventListener('click', showResetModal);
652656
document.getElementById('historyModalClose').addEventListener('click', closeModal);
653657
document.getElementById('resetModalClose').addEventListener('click', cancelReset);

webstatuspi/_dashboard/dashboard.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ <h1><span class="logo-bracket">&lt;</span><span class="logo-text">WebStatusπ</s
4444
<span class="updated-time" id="updatedTime" role="status" aria-live="polite">// INITIALIZING...</span>
4545
<button class="install-button" id="installBtn" hidden
4646
aria-label="Install WebStatusπ app" type="button">// INSTALL APP</button>
47-
<button class="reset-button" id="resetDataBtn"
47+
<button class="reset-button" id="resetDataBtn" hidden
4848
aria-label="Reset all monitoring data" type="button">// RESET DATA</button>
49+
<script nonce="__CSP_NONCE__">window.__IS_REMOTE__=__IS_REMOTE__;</script>
4950
</div>
5051
</nav>
5152
<main id="cardsContainer" role="main" aria-label="Service status cards">

webstatuspi/api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,9 @@ def _handle_dashboard(self) -> None:
807807
# get_dashboard() supports hot-reload: detects template file changes
808808
html = get_dashboard().replace(CSP_NONCE_PLACEHOLDER, nonce)
809809
html = html.replace("__INITIAL_DATA__", initial_data)
810+
# Hide reset button for remote (Cloudflare) connections
811+
is_remote = "true" if self._is_cloudflare_request() else "false"
812+
html = html.replace("__IS_REMOTE__", is_remote)
810813
body = html.encode("utf-8")
811814

812815
self._send_html_bytes(200, body, nonce)

0 commit comments

Comments
 (0)