Files
reflector-dashboard/auth/admin_control.js
T
bjorneandClaude Fable 5.1 25b481e2ae Public web-only release: SvxPortal front-end + auth backend, install templates and INSTALL.md
Stripped from the internal repo: per-box deploy trees, Go services (nodelist/astmeta/proxy/svxdr),
deploy/sync scripts and all secrets. Config templates for nginx, PHP-FPM, Redis and tmpfiles
live in install/ with CHANGEME placeholders.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-26 23:07:05 +02: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?'); });
});