Standalone Open OSCAR Server admin dashboard with login, user/session/room management, BART, buddy list, Gotify addon, audit log, and API console. Includes AI disclosure and open-source project docs.
108 lines
6.2 KiB
PHP
108 lines
6.2 KiB
PHP
<?php
|
|
// User menu dropdown - own file. Included by admin_page() when user is logged in.
|
|
if (!isset($user) || !is_array($user)) return;
|
|
$sn = (string) ($user['screen_name'] ?? '');
|
|
$gotifyAvailable = function_exists('admin_gotify_feature_enabled') && admin_gotify_feature_enabled();
|
|
|
|
if (!$gotifyAvailable) {
|
|
?>
|
|
<span class="nav-user" title="Signed in"><?= h((string) $user['screen_name']) ?></span>
|
|
<form method="post" action="logout.php" class="inline-form">
|
|
<input type="hidden" name="csrf" value="<?= h(admin_csrf_token()) ?>">
|
|
<button type="submit" class="btn btn-ghost btn-small">Logout</button>
|
|
</form>
|
|
<?php
|
|
return;
|
|
}
|
|
?>
|
|
<div class="user-menu" id="user-menu">
|
|
<button type="button" class="nav-user user-menu-trigger" id="user-menu-trigger" aria-haspopup="menu" aria-expanded="false">
|
|
<span><?= h($sn) ?></span>
|
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14" aria-hidden="true"><path d="M6 9l6 6 6-6"/></svg>
|
|
</button>
|
|
<div class="user-menu-dropdown" id="user-menu-dropdown" role="menu" hidden>
|
|
<div class="user-menu-head">
|
|
<div class="user-menu-name"><?= h($sn) ?></div>
|
|
<div class="muted small">Signed in</div>
|
|
</div>
|
|
|
|
<div class="user-menu-section">
|
|
<div class="user-menu-section-title">Gotify notifications <span class="tip" tabindex="0" data-tip="Optional: receive login codes via your personal Gotify server. Useful if you can't access AIM/ICQ. If a Gotify URL and token are saved, login codes will be sent to Gotify. To turn it off, clear the settings.">?</span></div>
|
|
<form id="gotify-self-form" class="stack-form compact">
|
|
<label class="field"><span>Gotify URL</span><input name="url" id="gotify-self-url" type="url" placeholder="https://gotify.example.com" autocomplete="off"></label>
|
|
<label class="field"><span>App token <span class="tip" tabindex="0" data-tip="Gotify application token. Saved token is not shown again; re-enter to replace it.">?</span></span><input name="token" id="gotify-self-token" type="password" placeholder="Token" autocomplete="off"></label>
|
|
<label class="field"><span>Priority</span><input name="priority" id="gotify-self-priority" type="number" min="0" max="10" value="5"></label>
|
|
<div class="field-row" style="flex-wrap:nowrap">
|
|
<button type="submit" class="btn btn-primary btn-small">Save</button>
|
|
<button type="button" class="btn btn-ghost btn-small" id="gotify-self-test">Test</button>
|
|
<button type="button" class="btn btn-ghost btn-small" id="gotify-self-clear">Clear</button>
|
|
</div>
|
|
<div id="gotify-self-status" class="muted small"></div>
|
|
</form>
|
|
</div>
|
|
|
|
<div class="user-menu-section user-menu-actions">
|
|
<form method="post" action="logout.php" class="inline-form">
|
|
<input type="hidden" name="csrf" value="<?= h(admin_csrf_token()) ?>">
|
|
<button type="submit" class="btn btn-ghost btn-small btn-block">Logout</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
(function(){
|
|
const trigger = document.getElementById('user-menu-trigger');
|
|
const menu = document.getElementById('user-menu-dropdown');
|
|
if (!trigger || !menu) return;
|
|
function close(){ menu.hidden = true; trigger.setAttribute('aria-expanded','false'); }
|
|
function open(){ menu.hidden = false; trigger.setAttribute('aria-expanded','true'); }
|
|
trigger.addEventListener('click', function(e){ e.stopPropagation(); menu.hidden ? open() : close(); });
|
|
document.addEventListener('click', function(e){ if (!menu.hidden && !e.target.closest('#user-menu')) close(); });
|
|
document.addEventListener('keydown', function(e){ if (e.key === 'Escape') close(); });
|
|
|
|
const form = document.getElementById('gotify-self-form');
|
|
if (!form) return;
|
|
const status = document.getElementById('gotify-self-status');
|
|
const urlIn = document.getElementById('gotify-self-url');
|
|
const tokenIn = document.getElementById('gotify-self-token');
|
|
const prioIn = document.getElementById('gotify-self-priority');
|
|
async function api(action, payload) {
|
|
const r = await fetch('action.php', {method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify(Object.assign({action, csrf: window.ADMIN_CSRF}, payload||{}))});
|
|
return r.json().catch(() => ({ok:false,error:'Bad response'}));
|
|
}
|
|
async function load() {
|
|
status.textContent = 'Loading...';
|
|
const r = await api('gotify.self.get');
|
|
if (r.ok && r.data) {
|
|
urlIn.value = r.data.url || '';
|
|
tokenIn.value = '';
|
|
tokenIn.placeholder = r.data.token_set ? 'Token set (re-enter to change)' : 'Token';
|
|
prioIn.value = r.data.priority ?? 5;
|
|
status.textContent = r.data.configured ? 'Gotify configured for your account.' : 'No personal Gotify configured yet.';
|
|
form.dataset.tokenSet = r.data.token_set ? '1' : '';
|
|
} else {
|
|
status.textContent = r.error || 'Failed to load.';
|
|
}
|
|
}
|
|
form.addEventListener('submit', async function(e){
|
|
e.preventDefault();
|
|
status.textContent = 'Saving...';
|
|
const payload = {url: urlIn.value.trim(), token: tokenIn.value, priority: parseInt(prioIn.value||'5',10)};
|
|
const r = await api('gotify.self.save', payload);
|
|
status.textContent = r.ok ? (r.data?.cleared ? 'Gotify settings cleared.' : 'Saved.') : (r.error || 'Save failed');
|
|
if (r.ok) { tokenIn.value = ''; await load(); }
|
|
});
|
|
document.getElementById('gotify-self-test')?.addEventListener('click', async function(){
|
|
status.textContent = 'Sending test notification...';
|
|
const r = await api('gotify.self.test');
|
|
status.textContent = r.ok ? 'Test notification sent.' : (r.error || 'Test failed');
|
|
});
|
|
document.getElementById('gotify-self-clear')?.addEventListener('click', async function(){
|
|
if (!confirm('Clear your Gotify settings?')) return;
|
|
const r = await api('gotify.self.save', {url:'', token:'', priority:5});
|
|
status.textContent = r.ok ? 'Cleared.' : (r.error || 'Failed');
|
|
if (r.ok) await load();
|
|
});
|
|
trigger.addEventListener('click', function(){ if (!menu.hidden) load(); });
|
|
})();
|
|
</script>
|