Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bcc2ad7f5c | |||
| d4f159ee7c | |||
| 61019418d3 | |||
| 1a53718cc5 | |||
| afaeb64636 | |||
| b6ee45a842 | |||
| 9c4dd5df51 | |||
| 4e3d0a1f0a | |||
| 49869fd9f7 | |||
| c68e797f31 |
@@ -155,6 +155,17 @@ def require_auth(f):
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
def require_admin(f):
|
||||||
|
"""Decorator: require require_auth AND membership in the 'admin' group."""
|
||||||
|
@wraps(f)
|
||||||
|
def wrapper(*args, **kwargs):
|
||||||
|
user = _get_user()
|
||||||
|
if 'admin' not in user.get('groups', []):
|
||||||
|
return jsonify({'error': 'Admin access required'}), 403
|
||||||
|
return f(*args, **kwargs)
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Helpers
|
# Helpers
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@@ -228,6 +239,7 @@ def inspector():
|
|||||||
|
|
||||||
@app.route('/suppressions')
|
@app.route('/suppressions')
|
||||||
@require_auth
|
@require_auth
|
||||||
|
@require_admin
|
||||||
def suppressions_page():
|
def suppressions_page():
|
||||||
user = _get_user()
|
user = _get_user()
|
||||||
active = db.get_active_suppressions()
|
active = db.get_active_suppressions()
|
||||||
@@ -291,7 +303,7 @@ def api_links():
|
|||||||
return jsonify(json.loads(raw))
|
return jsonify(json.loads(raw))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f'Failed to parse link_stats JSON: {e}')
|
logger.error(f'Failed to parse link_stats JSON: {e}')
|
||||||
return jsonify({'hosts': {}, 'updated': None})
|
return jsonify({'hosts': {}, 'unifi_switches': {}, 'updated': None})
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/events')
|
@app.route('/api/events')
|
||||||
@@ -323,6 +335,7 @@ def api_get_suppressions():
|
|||||||
|
|
||||||
@app.route('/api/suppressions', methods=['POST'])
|
@app.route('/api/suppressions', methods=['POST'])
|
||||||
@require_auth
|
@require_auth
|
||||||
|
@require_admin
|
||||||
def api_create_suppression():
|
def api_create_suppression():
|
||||||
user = _get_user()
|
user = _get_user()
|
||||||
data = request.get_json(silent=True) or {}
|
data = request.get_json(silent=True) or {}
|
||||||
@@ -371,6 +384,7 @@ def api_create_suppression():
|
|||||||
|
|
||||||
@app.route('/api/suppressions/<int:sup_id>', methods=['DELETE'])
|
@app.route('/api/suppressions/<int:sup_id>', methods=['DELETE'])
|
||||||
@require_auth
|
@require_auth
|
||||||
|
@require_admin
|
||||||
def api_delete_suppression(sup_id: int):
|
def api_delete_suppression(sup_id: int):
|
||||||
user = _get_user()
|
user = _get_user()
|
||||||
db.deactivate_suppression(sup_id)
|
db.deactivate_suppression(sup_id)
|
||||||
@@ -612,7 +626,8 @@ def api_avatar():
|
|||||||
avatar_data = avatar_data.encode('latin-1')
|
avatar_data = avatar_data.encode('latin-1')
|
||||||
if avatar_data[:3] != b'\xFF\xD8\xFF':
|
if avatar_data[:3] != b'\xFF\xD8\xFF':
|
||||||
logger.warning(f'Non-JPEG avatar data for {username}')
|
logger.warning(f'Non-JPEG avatar data for {username}')
|
||||||
open(sentinel, 'w').close()
|
with open(sentinel, 'w'):
|
||||||
|
pass
|
||||||
return '', 404
|
return '', 404
|
||||||
|
|
||||||
with open(cache_file, 'wb') as f:
|
with open(cache_file, 'wb') as f:
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ def get_active_events(limit: int = 200, offset: int = 0) -> list:
|
|||||||
for r in rows:
|
for r in rows:
|
||||||
for k in ('first_seen', 'last_seen'):
|
for k in ('first_seen', 'last_seen'):
|
||||||
if r.get(k) and hasattr(r[k], 'isoformat'):
|
if r.get(k) and hasattr(r[k], 'isoformat'):
|
||||||
r[k] = r[k].isoformat()
|
r[k] = r[k].isoformat() + 'Z'
|
||||||
return rows
|
return rows
|
||||||
|
|
||||||
|
|
||||||
@@ -210,7 +210,7 @@ def get_recent_resolved(hours: int = 24, limit: int = 50) -> list:
|
|||||||
for r in rows:
|
for r in rows:
|
||||||
for k in ('first_seen', 'last_seen', 'resolved_at'):
|
for k in ('first_seen', 'last_seen', 'resolved_at'):
|
||||||
if r.get(k) and hasattr(r[k], 'isoformat'):
|
if r.get(k) and hasattr(r[k], 'isoformat'):
|
||||||
r[k] = r[k].isoformat()
|
r[k] = r[k].isoformat() + 'Z'
|
||||||
return rows
|
return rows
|
||||||
|
|
||||||
|
|
||||||
@@ -252,7 +252,7 @@ def get_active_suppressions() -> list:
|
|||||||
for r in rows:
|
for r in rows:
|
||||||
for k in ('created_at', 'expires_at'):
|
for k in ('created_at', 'expires_at'):
|
||||||
if r.get(k) and hasattr(r[k], 'isoformat'):
|
if r.get(k) and hasattr(r[k], 'isoformat'):
|
||||||
r[k] = r[k].isoformat()
|
r[k] = r[k].isoformat() + 'Z'
|
||||||
return rows
|
return rows
|
||||||
|
|
||||||
|
|
||||||
@@ -267,7 +267,7 @@ def get_suppression_history(limit: int = 50) -> list:
|
|||||||
for r in rows:
|
for r in rows:
|
||||||
for k in ('created_at', 'expires_at'):
|
for k in ('created_at', 'expires_at'):
|
||||||
if r.get(k) and hasattr(r[k], 'isoformat'):
|
if r.get(k) and hasattr(r[k], 'isoformat'):
|
||||||
r[k] = r[k].isoformat()
|
r[k] = r[k].isoformat() + 'Z'
|
||||||
return rows
|
return rows
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -78,7 +78,7 @@ class DiagnosticsRunner:
|
|||||||
f'ssh -o StrictHostKeyChecking=accept-new -o ConnectTimeout=5 '
|
f'ssh -o StrictHostKeyChecking=accept-new -o ConnectTimeout=5 '
|
||||||
f'-o BatchMode=yes -o LogLevel=ERROR '
|
f'-o BatchMode=yes -o LogLevel=ERROR '
|
||||||
f'-o ServerAliveInterval=10 -o ServerAliveCountMax=2 '
|
f'-o ServerAliveInterval=10 -o ServerAliveCountMax=2 '
|
||||||
f'root@{ip_q} \'{remote_cmd}\''
|
f'root@{ip_q} {shlex.quote(remote_cmd)}'
|
||||||
)
|
)
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
@@ -221,8 +221,6 @@ class DiagnosticsRunner:
|
|||||||
data['auto_neg'] = (val.lower() == 'on')
|
data['auto_neg'] = (val.lower() == 'on')
|
||||||
elif key == 'Link detected':
|
elif key == 'Link detected':
|
||||||
data['link_detected'] = (val.lower() == 'yes')
|
data['link_detected'] = (val.lower() == 'yes')
|
||||||
elif 'Supported link modes' in key:
|
|
||||||
data.setdefault('supported_modes', []).append(val)
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
+6
-3
@@ -215,7 +215,10 @@ class TicketClient:
|
|||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
if data.get('success'):
|
if data.get('success'):
|
||||||
tid = data['ticket_id']
|
tid = data.get('ticket_id')
|
||||||
|
if not tid:
|
||||||
|
logger.warning(f'Ticket API success but no ticket_id in response: {data}')
|
||||||
|
return None
|
||||||
logger.info(f'Created ticket #{tid}: {title}')
|
logger.info(f'Created ticket #{tid}: {title}')
|
||||||
return tid
|
return tid
|
||||||
if data.get('existing_ticket_id'):
|
if data.get('existing_ticket_id'):
|
||||||
@@ -377,7 +380,7 @@ class LinkStatsCollector:
|
|||||||
f'ssh -o StrictHostKeyChecking=accept-new -o ConnectTimeout=5 '
|
f'ssh -o StrictHostKeyChecking=accept-new -o ConnectTimeout=5 '
|
||||||
f'-o BatchMode=yes -o LogLevel=ERROR '
|
f'-o BatchMode=yes -o LogLevel=ERROR '
|
||||||
f'-o ServerAliveInterval=10 -o ServerAliveCountMax=2 '
|
f'-o ServerAliveInterval=10 -o ServerAliveCountMax=2 '
|
||||||
f'root@{ip} "{shell_cmd}"'
|
f'root@{ip} {shlex.quote(shell_cmd)}'
|
||||||
)
|
)
|
||||||
output = self.pulse.run_command(ssh_cmd)
|
output = self.pulse.run_command(ssh_cmd)
|
||||||
if output is None:
|
if output is None:
|
||||||
@@ -918,7 +921,7 @@ class NetworkMonitor:
|
|||||||
return {
|
return {
|
||||||
'hosts': hosts,
|
'hosts': hosts,
|
||||||
'unifi': display_unifi,
|
'unifi': display_unifi,
|
||||||
'updated': datetime.utcnow().isoformat(),
|
'updated': datetime.utcnow().isoformat() + 'Z',
|
||||||
}
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|||||||
+20
-5
@@ -220,7 +220,7 @@ function updateEventsTable(events, totalActive) {
|
|||||||
? GANDALF_CONFIG.ticket_web_url : 'http://t.lotusguild.org/ticket/';
|
? GANDALF_CONFIG.ticket_web_url : 'http://t.lotusguild.org/ticket/';
|
||||||
const ticket = e.ticket_id
|
const ticket = e.ticket_id
|
||||||
? `<a href="${lt.escHtml(ticketBase)}${lt.escHtml(String(e.ticket_id))}" target="_blank"
|
? `<a href="${lt.escHtml(ticketBase)}${lt.escHtml(String(e.ticket_id))}" target="_blank"
|
||||||
class="ticket-link">#${e.ticket_id}</a>`
|
class="ticket-link">#${lt.escHtml(String(e.ticket_id))}</a>`
|
||||||
: '–';
|
: '–';
|
||||||
const supBadge = e.is_suppressed
|
const supBadge = e.is_suppressed
|
||||||
? `<span class="lt-badge badge-suppressed" title="Alert suppressed">🔕 sup</span>`
|
? `<span class="lt-badge badge-suppressed" title="Alert suppressed">🔕 sup</span>`
|
||||||
@@ -294,18 +294,33 @@ function updateSuppressForm() {
|
|||||||
const type = document.getElementById('sup-type').value;
|
const type = document.getElementById('sup-type').value;
|
||||||
const nameGrp = document.getElementById('sup-name-group');
|
const nameGrp = document.getElementById('sup-name-group');
|
||||||
const detailGrp = document.getElementById('sup-detail-group');
|
const detailGrp = document.getElementById('sup-detail-group');
|
||||||
|
const nameInput = document.getElementById('sup-name');
|
||||||
|
const detailInput = document.getElementById('sup-detail');
|
||||||
if (nameGrp) nameGrp.style.display = (type === 'all') ? 'none' : '';
|
if (nameGrp) nameGrp.style.display = (type === 'all') ? 'none' : '';
|
||||||
if (detailGrp) detailGrp.style.display = (type === 'interface') ? '' : 'none';
|
if (detailGrp) detailGrp.style.display = (type === 'interface') ? '' : 'none';
|
||||||
|
if (nameInput) {
|
||||||
|
const req = (type !== 'all');
|
||||||
|
nameInput.required = req;
|
||||||
|
nameInput.setAttribute('aria-required', String(req));
|
||||||
|
}
|
||||||
|
if (detailInput) {
|
||||||
|
const req = (type === 'interface');
|
||||||
|
detailInput.required = req;
|
||||||
|
detailInput.setAttribute('aria-required', String(req));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setDuration(mins, el) {
|
function setDuration(mins, el, opts) {
|
||||||
document.getElementById('sup-expires').value = mins || '';
|
const o = opts || {};
|
||||||
document.querySelectorAll('#suppress-modal .pill').forEach(p => {
|
const expiresEl = document.getElementById(o.expiresId || 'sup-expires');
|
||||||
|
const pillSel = o.pillSel || '#suppress-modal .pill';
|
||||||
|
const hint = document.getElementById(o.hintId || 'duration-hint');
|
||||||
|
if (expiresEl) expiresEl.value = mins || '';
|
||||||
|
document.querySelectorAll(pillSel).forEach(p => {
|
||||||
p.classList.remove('active');
|
p.classList.remove('active');
|
||||||
p.setAttribute('aria-pressed', 'false');
|
p.setAttribute('aria-pressed', 'false');
|
||||||
});
|
});
|
||||||
if (el) { el.classList.add('active'); el.setAttribute('aria-pressed', 'true'); }
|
if (el) { el.classList.add('active'); el.setAttribute('aria-pressed', 'true'); }
|
||||||
const hint = document.getElementById('duration-hint');
|
|
||||||
if (hint) {
|
if (hint) {
|
||||||
if (mins) {
|
if (mins) {
|
||||||
const h = Math.floor(mins / 60), m = mins % 60;
|
const h = Math.floor(mins / 60), m = mins % 60;
|
||||||
|
|||||||
@@ -217,6 +217,7 @@
|
|||||||
.sev-pills { display: flex; gap: 4px; }
|
.sev-pills { display: flex; gap: 4px; }
|
||||||
.g-page-sub { font-size: .78em; color: var(--text-muted); margin-top: 4px; }
|
.g-page-sub { font-size: .78em; color: var(--text-muted); margin-top: 4px; }
|
||||||
.g-page-sub-aside { font-size: .78em; color: var(--text-muted); margin-left: 8px; }
|
.g-page-sub-aside { font-size: .78em; color: var(--text-muted); margin-left: 8px; }
|
||||||
|
.g-stale-warn { color: var(--orange); font-weight: 600; }
|
||||||
|
|
||||||
/* ── Badge severity color variants (used with lt-badge) ───────────── */
|
/* ── Badge severity color variants (used with lt-badge) ───────────── */
|
||||||
.badge-critical { color: var(--red); border-color: var(--red); text-shadow: var(--glow-red); }
|
.badge-critical { color: var(--red); border-color: var(--red); text-shadow: var(--glow-red); }
|
||||||
|
|||||||
+6
-6
@@ -227,16 +227,16 @@
|
|||||||
<div class="lt-form-group">
|
<div class="lt-form-group">
|
||||||
<label class="lt-label" for="sup-reason">Reason <span class="required">*</span></label>
|
<label class="lt-label" for="sup-reason">Reason <span class="required">*</span></label>
|
||||||
<input type="text" class="lt-input" id="sup-reason" name="reason"
|
<input type="text" class="lt-input" id="sup-reason" name="reason"
|
||||||
placeholder="e.g. Planned switch reboot" required>
|
placeholder="e.g. Planned switch reboot" required aria-required="true">
|
||||||
</div>
|
</div>
|
||||||
<div class="lt-form-group lt-form-group--last">
|
<div class="lt-form-group lt-form-group--last">
|
||||||
<label class="lt-label">Duration</label>
|
<label class="lt-label">Duration</label>
|
||||||
<div class="duration-pills" role="group" aria-label="Select suppression duration">
|
<div class="duration-pills" role="group" aria-label="Select suppression duration">
|
||||||
<button type="button" class="pill" data-duration="30" aria-pressed="false">30 min</button>
|
<button type="button" class="pill" data-duration="30" aria-pressed="false" aria-label="30 minutes">30 min</button>
|
||||||
<button type="button" class="pill" data-duration="60" aria-pressed="false">1 hr</button>
|
<button type="button" class="pill" data-duration="60" aria-pressed="false" aria-label="1 hour">1 hr</button>
|
||||||
<button type="button" class="pill" data-duration="240" aria-pressed="false">4 hr</button>
|
<button type="button" class="pill" data-duration="240" aria-pressed="false" aria-label="4 hours">4 hr</button>
|
||||||
<button type="button" class="pill" data-duration="480" aria-pressed="false">8 hr</button>
|
<button type="button" class="pill" data-duration="480" aria-pressed="false" aria-label="8 hours">8 hr</button>
|
||||||
<button type="button" class="pill pill-manual active" data-duration="" aria-pressed="true">Manual ∞</button>
|
<button type="button" class="pill pill-manual active" data-duration="" aria-pressed="true" aria-label="Manual, no expiry">Manual ∞</button>
|
||||||
</div>
|
</div>
|
||||||
<input type="hidden" id="sup-expires" name="expires_minutes" value="">
|
<input type="hidden" id="sup-expires" name="expires_minutes" value="">
|
||||||
<div class="lt-field-hint" id="duration-hint">Persists until manually removed.</div>
|
<div class="lt-field-hint" id="duration-hint">Persists until manually removed.</div>
|
||||||
|
|||||||
@@ -92,7 +92,7 @@
|
|||||||
<div id="events-table-wrap">
|
<div id="events-table-wrap">
|
||||||
{% if events %}
|
{% if events %}
|
||||||
{% if total_active is defined and total_active > events|length %}
|
{% if total_active is defined and total_active > events|length %}
|
||||||
<div class="pagination-notice">Showing {{ events|length }} of {{ total_active }} active alerts — <a href="/api/events?limit=1000">view all via API</a></div>
|
<div class="pagination-notice">Showing {{ events|length }} of {{ total_active }} active alerts — use the search box to filter, or <a href="/api/events?limit=1000" target="_blank" rel="noopener">export all as JSON</a></div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="lt-table-wrap">
|
<div class="lt-table-wrap">
|
||||||
<table class="lt-table" id="events-table">
|
<table class="lt-table" id="events-table">
|
||||||
|
|||||||
@@ -428,7 +428,14 @@ function renderInspector(data) {
|
|||||||
|
|
||||||
const updEl = document.getElementById('inspector-updated');
|
const updEl = document.getElementById('inspector-updated');
|
||||||
if (updEl && data.updated) {
|
if (updEl && data.updated) {
|
||||||
updEl.textContent = 'Updated: ' + new Date(data.updated + (data.updated.includes('Z') ? '' : 'Z')).toLocaleTimeString();
|
const updMs = new Date(_toIso(data.updated));
|
||||||
|
const ageMin = (Date.now() - updMs) / 60000;
|
||||||
|
const timeStr = updMs.toLocaleTimeString();
|
||||||
|
if (ageMin > 15) {
|
||||||
|
updEl.innerHTML = `<span class="g-stale-warn" title="Data is ${Math.floor(ageMin)} minutes old — monitor may be down">⚠ Stale: ${timeStr}</span>`;
|
||||||
|
} else {
|
||||||
|
updEl.textContent = 'Updated: ' + timeStr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Object.keys(switches).length) {
|
if (!Object.keys(switches).length) {
|
||||||
@@ -487,7 +494,13 @@ document.addEventListener('click', e => {
|
|||||||
if (diagBtn) { runDiagnostic(diagBtn.dataset.sw, parseInt(diagBtn.dataset.idx, 10)); return; }
|
if (diagBtn) { runDiagnostic(diagBtn.dataset.sw, parseInt(diagBtn.dataset.idx, 10)); return; }
|
||||||
|
|
||||||
const toggleDiag = e.target.closest('[data-action="toggle-diag"]');
|
const toggleDiag = e.target.closest('[data-action="toggle-diag"]');
|
||||||
if (toggleDiag) { toggleDiag.parentElement.classList.toggle('diag-open'); return; }
|
if (toggleDiag) {
|
||||||
|
const section = toggleDiag.parentElement;
|
||||||
|
const nowOpen = section.classList.toggle('diag-open');
|
||||||
|
const hint = toggleDiag.querySelector('.diag-toggle-hint');
|
||||||
|
if (hint) hint.textContent = nowOpen ? '[collapse]' : '[expand]';
|
||||||
|
return;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── Link Diagnostics ─────────────────────────────────────────────────
|
// ── Link Diagnostics ─────────────────────────────────────────────────
|
||||||
@@ -510,7 +523,10 @@ function runDiagnostic(swName, portIdx) {
|
|||||||
pollDiagnostic(resp.job_id, statusEl, resultsEl);
|
pollDiagnostic(resp.job_id, statusEl, resultsEl);
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
statusEl.textContent = 'Error: ' + (e.message || 'Request failed');
|
const msg = (e && e.status === 429)
|
||||||
|
? 'Rate limit reached — max 5 diagnostics per minute. Please wait.'
|
||||||
|
: 'Error: ' + (e && e.message || 'Request failed');
|
||||||
|
statusEl.textContent = msg;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -520,7 +536,13 @@ function pollDiagnostic(jobId, statusEl, resultsEl) {
|
|||||||
attempts++;
|
attempts++;
|
||||||
if (attempts > 120) { // 2min timeout
|
if (attempts > 120) { // 2min timeout
|
||||||
clearInterval(_diagPollTimer);
|
clearInterval(_diagPollTimer);
|
||||||
statusEl.textContent = 'Timed out waiting for results.';
|
_diagPollTimer = null;
|
||||||
|
statusEl.innerHTML = 'Timed out waiting for results. '
|
||||||
|
+ '<button class="lt-btn lt-btn-ghost lt-btn-sm" id="diag-retry-btn">Retry</button>';
|
||||||
|
document.getElementById('diag-retry-btn')?.addEventListener('click', () => {
|
||||||
|
const sel = document.querySelector('.switch-port-block.selected');
|
||||||
|
if (sel) runDiagnostic(sel.dataset.switch, parseInt(sel.dataset.portIdx));
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lt.api.get(`/api/diagnose/${jobId}`)
|
lt.api.get(`/api/diagnose/${jobId}`)
|
||||||
@@ -535,7 +557,12 @@ function pollDiagnostic(jobId, statusEl, resultsEl) {
|
|||||||
.catch(() => {
|
.catch(() => {
|
||||||
clearInterval(_diagPollTimer);
|
clearInterval(_diagPollTimer);
|
||||||
_diagPollTimer = null;
|
_diagPollTimer = null;
|
||||||
statusEl.textContent = 'Error: lost connection while collecting diagnostics.';
|
statusEl.innerHTML = 'Error: lost connection while collecting diagnostics. '
|
||||||
|
+ '<button class="lt-btn lt-btn-ghost lt-btn-sm" id="diag-retry-btn">Retry</button>';
|
||||||
|
document.getElementById('diag-retry-btn')?.addEventListener('click', () => {
|
||||||
|
const sel = document.querySelector('.switch-port-block.selected');
|
||||||
|
if (sel) runDiagnostic(sel.dataset.switch, parseInt(sel.dataset.portIdx));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,6 @@
|
|||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
<script>
|
<script>
|
||||||
const escHtml = s => lt.escHtml(s);
|
const escHtml = s => lt.escHtml(s);
|
||||||
const _toIso = s => s ? s.replace(' UTC', 'Z').replace(' ', 'T') : s;
|
|
||||||
|
|
||||||
// ── Formatting helpers ────────────────────────────────────────────
|
// ── Formatting helpers ────────────────────────────────────────────
|
||||||
function fmtRate(bytesPerSec) {
|
function fmtRate(bytesPerSec) {
|
||||||
@@ -527,7 +526,7 @@ function expandAll() {
|
|||||||
// ── Stale data warning ────────────────────────────────────────────
|
// ── Stale data warning ────────────────────────────────────────────
|
||||||
function checkLinksStale(updatedStr) {
|
function checkLinksStale(updatedStr) {
|
||||||
if (!updatedStr) return;
|
if (!updatedStr) return;
|
||||||
const age = (Date.now() - new Date(updatedStr + (updatedStr.includes('Z') ? '' : 'Z'))) / 1000;
|
const age = (Date.now() - new Date(_toIso(updatedStr))) / 1000;
|
||||||
let banner = document.getElementById('links-stale-banner');
|
let banner = document.getElementById('links-stale-banner');
|
||||||
if (age > 120) {
|
if (age > 120) {
|
||||||
if (!banner) {
|
if (!banner) {
|
||||||
@@ -556,7 +555,7 @@ async function loadLinks() {
|
|||||||
}
|
}
|
||||||
const updEl = document.getElementById('links-updated');
|
const updEl = document.getElementById('links-updated');
|
||||||
if (updEl && data.updated) {
|
if (updEl && data.updated) {
|
||||||
updEl.textContent = 'Updated: ' + new Date(data.updated + (data.updated.includes('Z') ? '' : 'Z')).toLocaleTimeString();
|
updEl.textContent = 'Updated: ' + new Date(_toIso(data.updated)).toLocaleTimeString();
|
||||||
}
|
}
|
||||||
renderLinks(data);
|
renderLinks(data);
|
||||||
checkLinksStale(data.updated);
|
checkLinksStale(data.updated);
|
||||||
|
|||||||
+15
-24
@@ -32,7 +32,7 @@
|
|||||||
<label class="lt-label" for="s-name">Target Name <span class="required">*</span></label>
|
<label class="lt-label" for="s-name">Target Name <span class="required">*</span></label>
|
||||||
<input type="text" class="lt-input" id="s-name" name="target_name"
|
<input type="text" class="lt-input" id="s-name" name="target_name"
|
||||||
placeholder="hostname or device name" autocomplete="off"
|
placeholder="hostname or device name" autocomplete="off"
|
||||||
list="target-name-list">
|
required aria-required="true" list="target-name-list">
|
||||||
<datalist id="target-name-list">
|
<datalist id="target-name-list">
|
||||||
{% for name in snapshot.hosts.keys() | sort %}
|
{% for name in snapshot.hosts.keys() | sort %}
|
||||||
<option value="{{ name }}">
|
<option value="{{ name }}">
|
||||||
@@ -51,7 +51,7 @@
|
|||||||
<label class="lt-label" for="s-reason">Reason <span class="required">*</span></label>
|
<label class="lt-label" for="s-reason">Reason <span class="required">*</span></label>
|
||||||
<input type="text" class="lt-input" id="s-reason" name="reason"
|
<input type="text" class="lt-input" id="s-reason" name="reason"
|
||||||
placeholder="e.g. Planned switch maintenance, replacing SFP on large1/enp43s0"
|
placeholder="e.g. Planned switch maintenance, replacing SFP on large1/enp43s0"
|
||||||
required>
|
required aria-required="true">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -59,11 +59,11 @@
|
|||||||
<div class="lt-form-group">
|
<div class="lt-form-group">
|
||||||
<label class="lt-label">Duration</label>
|
<label class="lt-label">Duration</label>
|
||||||
<div class="duration-pills" role="group" aria-label="Select suppression duration">
|
<div class="duration-pills" role="group" aria-label="Select suppression duration">
|
||||||
<button type="button" class="pill" data-duration="30" aria-pressed="false">30 min</button>
|
<button type="button" class="pill" data-duration="30" aria-pressed="false" aria-label="30 minutes">30 min</button>
|
||||||
<button type="button" class="pill" data-duration="60" aria-pressed="false">1 hr</button>
|
<button type="button" class="pill" data-duration="60" aria-pressed="false" aria-label="1 hour">1 hr</button>
|
||||||
<button type="button" class="pill" data-duration="240" aria-pressed="false">4 hr</button>
|
<button type="button" class="pill" data-duration="240" aria-pressed="false" aria-label="4 hours">4 hr</button>
|
||||||
<button type="button" class="pill" data-duration="480" aria-pressed="false">8 hr</button>
|
<button type="button" class="pill" data-duration="480" aria-pressed="false" aria-label="8 hours">8 hr</button>
|
||||||
<button type="button" class="pill pill-manual active" data-duration="" aria-pressed="true">Manual ∞</button>
|
<button type="button" class="pill pill-manual active" data-duration="" aria-pressed="true" aria-label="Manual, no expiry">Manual ∞</button>
|
||||||
</div>
|
</div>
|
||||||
<input type="hidden" id="s-expires" name="expires_minutes" value="">
|
<input type="hidden" id="s-expires" name="expires_minutes" value="">
|
||||||
<div class="lt-field-hint" id="s-dur-hint">Persists until manually removed.</div>
|
<div class="lt-field-hint" id="s-dur-hint">Persists until manually removed.</div>
|
||||||
@@ -217,23 +217,16 @@
|
|||||||
const t = document.getElementById('s-type').value;
|
const t = document.getElementById('s-type').value;
|
||||||
document.getElementById('name-group').style.display = (t==='all') ? 'none' : '';
|
document.getElementById('name-group').style.display = (t==='all') ? 'none' : '';
|
||||||
document.getElementById('detail-group').style.display = (t==='interface') ? '' : 'none';
|
document.getElementById('detail-group').style.display = (t==='interface') ? '' : 'none';
|
||||||
document.getElementById('s-name').required = (t!=='all');
|
const nameInput = document.getElementById('s-name');
|
||||||
|
if (nameInput) {
|
||||||
|
const req = (t !== 'all');
|
||||||
|
nameInput.required = req;
|
||||||
|
nameInput.setAttribute('aria-required', String(req));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setDur(mins, el) {
|
function setDur(mins, el) {
|
||||||
document.getElementById('s-expires').value = mins || '';
|
setDuration(mins, el, { expiresId: 's-expires', pillSel: '#create-suppression-form .pill', hintId: 's-dur-hint' });
|
||||||
document.querySelectorAll('.duration-pills .pill').forEach(p => {
|
|
||||||
p.classList.remove('active');
|
|
||||||
p.setAttribute('aria-pressed', 'false');
|
|
||||||
});
|
|
||||||
if (el) { el.classList.add('active'); el.setAttribute('aria-pressed', 'true'); }
|
|
||||||
const hint = document.getElementById('s-dur-hint');
|
|
||||||
if (mins) {
|
|
||||||
const h = Math.floor(mins/60), m = mins%60;
|
|
||||||
hint.textContent = `Expires in ${h?h+'h ':''}${m?m+'m':''}`.trim()+'.';
|
|
||||||
} else {
|
|
||||||
hint.textContent = 'Persists until manually removed.';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderActiveRows(rows) {
|
function renderActiveRows(rows) {
|
||||||
@@ -302,9 +295,7 @@
|
|||||||
showToast('Suppression applied', 'success');
|
showToast('Suppression applied', 'success');
|
||||||
form.reset();
|
form.reset();
|
||||||
onTypeChange();
|
onTypeChange();
|
||||||
document.querySelectorAll('.duration-pills .pill').forEach(p => p.classList.remove('active'));
|
setDur(null, document.querySelector('#create-suppression-form .pill-manual'));
|
||||||
document.querySelector('.duration-pills .pill-manual')?.classList.add('active');
|
|
||||||
document.getElementById('s-dur-hint').textContent = 'Persists until manually removed.';
|
|
||||||
await refreshActive();
|
await refreshActive();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
showToast(err.message || 'Error', 'error');
|
showToast(err.message || 'Error', 'error');
|
||||||
|
|||||||
Reference in New Issue
Block a user