Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c68e797f31 | |||
| fc2be88915 | |||
| cd0b725f3e |
@@ -291,7 +291,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')
|
||||||
@@ -539,10 +539,16 @@ def api_avatar():
|
|||||||
|
|
||||||
# Build a safe cache filename from the username (alphanumeric + - _ .)
|
# Build a safe cache filename from the username (alphanumeric + - _ .)
|
||||||
safe_name = re.sub(r'[^a-zA-Z0-9._-]', '_', username)
|
safe_name = re.sub(r'[^a-zA-Z0-9._-]', '_', username)
|
||||||
cache_dir = ldap_cfg.get('cache_dir', os.path.join(tempfile.gettempdir(), 'gandalf_avatars'))
|
cache_dir = os.path.abspath(
|
||||||
|
ldap_cfg.get('cache_dir', os.path.join(tempfile.gettempdir(), 'gandalf_avatars'))
|
||||||
|
)
|
||||||
os.makedirs(cache_dir, exist_ok=True)
|
os.makedirs(cache_dir, exist_ok=True)
|
||||||
cache_file = os.path.join(cache_dir, f'user_{safe_name}.jpg')
|
cache_file = os.path.abspath(os.path.join(cache_dir, f'user_{safe_name}.jpg'))
|
||||||
sentinel = os.path.join(cache_dir, f'user_{safe_name}.none')
|
sentinel = os.path.abspath(os.path.join(cache_dir, f'user_{safe_name}.none'))
|
||||||
|
# Guard against path escape (shouldn't happen with sanitised safe_name, but be explicit)
|
||||||
|
if not cache_file.startswith(cache_dir + os.sep) or not sentinel.startswith(cache_dir + os.sep):
|
||||||
|
logger.error(f'Avatar path escape detected for user {username!r}')
|
||||||
|
return '', 404
|
||||||
try:
|
try:
|
||||||
cache_ttl = int(ldap_cfg.get('cache_ttl', 3600))
|
cache_ttl = int(ldap_cfg.get('cache_ttl', 3600))
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
@@ -557,8 +563,11 @@ def api_avatar():
|
|||||||
max_age=cache_ttl, conditional=True)
|
max_age=cache_ttl, conditional=True)
|
||||||
|
|
||||||
# Skip LDAP if we already know this user has no avatar
|
# Skip LDAP if we already know this user has no avatar
|
||||||
if os.path.exists(sentinel) and now - os.path.getmtime(sentinel) < cache_ttl:
|
try:
|
||||||
return '', 404
|
if os.path.exists(sentinel) and now - os.path.getmtime(sentinel) < cache_ttl:
|
||||||
|
return '', 404
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
# Query lldap
|
# Query lldap
|
||||||
bind_pw = ldap_cfg.get('bind_pw', '')
|
bind_pw = ldap_cfg.get('bind_pw', '')
|
||||||
|
|||||||
@@ -365,7 +365,7 @@ def is_suppressed(target_type: str, target_name: str, target_detail: str = '') -
|
|||||||
"""SELECT id FROM suppression_rules
|
"""SELECT id FROM suppression_rules
|
||||||
WHERE active=TRUE AND (expires_at IS NULL OR expires_at > NOW())
|
WHERE active=TRUE AND (expires_at IS NULL OR expires_at > NOW())
|
||||||
AND target_type=%s AND target_name=%s
|
AND target_type=%s AND target_name=%s
|
||||||
AND (target_detail IS NULL OR target_detail='') LIMIT 1""",
|
AND target_detail='' LIMIT 1""",
|
||||||
(target_type, target_name),
|
(target_type, target_name),
|
||||||
)
|
)
|
||||||
if cur.fetchone():
|
if cur.fetchone():
|
||||||
|
|||||||
@@ -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">
|
||||||
|
|||||||
+29
-13
@@ -107,10 +107,8 @@ function portBlockHtml(idx, port, swName, sfpBlock) {
|
|||||||
const sfpCls = sfpBlock ? ' sfp-block' : '';
|
const sfpCls = sfpBlock ? ' sfp-block' : '';
|
||||||
const speedTxt = portSpeedLabel(port);
|
const speedTxt = portSpeedLabel(port);
|
||||||
// LLDP neighbor: first 6 chars of hostname
|
// LLDP neighbor: first 6 chars of hostname
|
||||||
const lldpName = (port && port.lldp_table && port.lldp_table.length)
|
const lldpName = (port && port.lldp && (port.lldp.system_name || port.lldp.chassis_id))
|
||||||
? escHtml((port.lldp_table[0].chassis_id_subtype === 'local'
|
? escHtml((port.lldp.system_name || port.lldp.chassis_id || '').slice(0, 6))
|
||||||
? port.lldp_table[0].chassis_id
|
|
||||||
: port.lldp_table[0].system_name || port.lldp_table[0].chassis_id || '').slice(0, 6))
|
|
||||||
: '';
|
: '';
|
||||||
const lldpHtml = lldpName ? `<span class="port-lldp">${lldpName}</span>` : '';
|
const lldpHtml = lldpName ? `<span class="port-lldp">${lldpName}</span>` : '';
|
||||||
const speedHtml = speedTxt ? `<span class="port-speed">${speedTxt}</span>` : '';
|
const speedHtml = speedTxt ? `<span class="port-speed">${speedTxt}</span>` : '';
|
||||||
@@ -162,10 +160,8 @@ function renderChassis(swName, sw) {
|
|||||||
const state = portBlockState(port);
|
const state = portBlockState(port);
|
||||||
const title = port ? escHtml(port.name) : `Port ${idx}`;
|
const title = port ? escHtml(port.name) : `Port ${idx}`;
|
||||||
const speedTxt = portSpeedLabel(port);
|
const speedTxt = portSpeedLabel(port);
|
||||||
const lldpName = (port && port.lldp_table && port.lldp_table.length)
|
const lldpName = (port && port.lldp && (port.lldp.system_name || port.lldp.chassis_id))
|
||||||
? escHtml((port.lldp_table[0].chassis_id_subtype === 'local'
|
? escHtml((port.lldp.system_name || port.lldp.chassis_id || '').slice(0, 6))
|
||||||
? port.lldp_table[0].chassis_id
|
|
||||||
: port.lldp_table[0].system_name || port.lldp_table[0].chassis_id || '').slice(0, 6))
|
|
||||||
: '';
|
: '';
|
||||||
const speedHtml = speedTxt ? `<span class="port-speed">${speedTxt}</span>` : '';
|
const speedHtml = speedTxt ? `<span class="port-speed">${speedTxt}</span>` : '';
|
||||||
const lldpHtml = lldpName ? `<span class="port-lldp">${lldpName}</span>` : '';
|
const lldpHtml = lldpName ? `<span class="port-lldp">${lldpName}</span>` : '';
|
||||||
@@ -263,7 +259,7 @@ function renderPanel(swName, idx) {
|
|||||||
const poeCurStr = (d.poe_power != null && d.poe_power > 0) ? ` / draw <span class="val-amber">${d.poe_power.toFixed(1)}W</span>` : '';
|
const poeCurStr = (d.poe_power != null && d.poe_power > 0) ? ` / draw <span class="val-amber">${d.poe_power.toFixed(1)}W</span>` : '';
|
||||||
poeHtml = `
|
poeHtml = `
|
||||||
<div class="lt-divider"><span class="lt-divider-label">PoE</span></div>
|
<div class="lt-divider"><span class="lt-divider-label">PoE</span></div>
|
||||||
<div class="panel-row"><span class="panel-label">Class</span><span class="panel-val">class ${d.poe_class}${poeMaxStr}</span></div>
|
<div class="panel-row"><span class="panel-label">Class</span><span class="panel-val">class ${escHtml(String(d.poe_class))}${poeMaxStr}</span></div>
|
||||||
${d.poe_power != null ? `<div class="panel-row"><span class="panel-label">Draw</span><span class="panel-val">${d.poe_power > 0 ? `<span class="val-amber">${d.poe_power.toFixed(1)}W</span>` : '0W'}</span></div>` : ''}
|
${d.poe_power != null ? `<div class="panel-row"><span class="panel-label">Draw</span><span class="panel-val">${d.poe_power > 0 ? `<span class="val-amber">${d.poe_power.toFixed(1)}W</span>` : '0W'}</span></div>` : ''}
|
||||||
${d.poe_mode ? `<div class="panel-row"><span class="panel-label">Mode</span><span class="panel-val">${escHtml(d.poe_mode)}</span></div>` : ''}`;
|
${d.poe_mode ? `<div class="panel-row"><span class="panel-label">Mode</span><span class="panel-val">${escHtml(d.poe_mode)}</span></div>` : ''}`;
|
||||||
}
|
}
|
||||||
@@ -491,7 +487,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 ─────────────────────────────────────────────────
|
||||||
@@ -514,7 +516,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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -524,7 +529,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}`)
|
||||||
@@ -539,7 +550,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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user