Files
reflector-dashboard/auth/admin_control.js
T
bjorne cb8b9af20e sync från dev (svx-web): lastheard paginering + separat live-feed, listen-vy, UI-uppdateringar
- lastheard 24h: client-side paginering (lib/pager.js), dynamisk sidstorlek
- lastheard: separat live-feed (lastheard_live_view.js), 24h loggar varje key-up
- listen_view.js + auth/admin_listen.*: Listen Live
- genomgående UI/auth-uppdateringar synkade från dev
Inga hårdkodade secrets/IP/login — endast hostnamn.
2026-11-18 22:07:16 +01:00

39 lines
2.0 KiB
JavaScript

'use strict';
var $ = function(id) { return document.getElementById(id); };
function setMsg(el, txt, err) {
if (!el) return;
if (!txt) { el.style.display='none'; return; }
el.style.display='block'; el.textContent=txt; el.style.color=err?'#ff8080':'#00ff80';
}
function esc(s) { var d=document.createElement('div'); d.textContent=s; return d.innerHTML; }
async function rapi(body) {
var r = await fetch('/auth/admin_reflector_api.php', { method:'POST', credentials:'same-origin', headers:{'Content-Type':'application/json','X-CSRF-Token':window._csrfToken||''}, body:JSON.stringify(body) });
return r.json().catch(function(){ return null; });
}
async function loadStatus() {
var j = await rapi({action:'service_status'});
var el = $('svcStatus');
if (j && j.ok) {
var s = (j.message||'').trim();
el.innerHTML = 'Service: <strong style="color:'+(s==='active'?'#00c864':'#ff4040')+';">'+esc(s)+'</strong>';
} else { el.textContent = 'Cannot check status'; }
}
async function svcAction(action, msg) {
if (msg && !confirm(msg)) return;
setMsg($('svcMsg'), null);
var j = await rapi({action: action});
if (j && j.ok) { setMsg($('svcMsg'), j.message||'OK', false); setTimeout(loadStatus, 2000); }
else setMsg($('svcMsg'), (j&&j.error)||'Failed', true);
}
document.addEventListener('DOMContentLoaded', function() {
fetch('/auth/me.php',{credentials:'same-origin'}).then(function(r){return r.json();}).then(function(j){if(j&&j.csrf_token)window._csrfToken=j.csrf_token;}).catch(function(){});
loadStatus();
var isSuperAdmin = (typeof ADMIN_LEVEL !== 'undefined') && ADMIN_LEVEL >= 3;
if (!isSuperAdmin) {
$('btnStop').style.display = 'none';
}
$('btnReload').addEventListener('click', function(){ svcAction('service_reload'); });
$('btnRestart').addEventListener('click', function(){ svcAction('service_restart', 'Restart reflector? All connections will be dropped.'); });
$('btnStop').addEventListener('click', function(){ svcAction('service_stop', 'Shutdown reflector?'); });
});