Delete sessions when user is edited/deleted and handle on UI

This commit is contained in:
Bofh 2022-12-10 17:19:51 +01:00
parent dcb536d38e
commit c0943cfad1
3 changed files with 21 additions and 0 deletions

View File

@ -20,6 +20,20 @@ if (isset($_SERVER['REQUEST_URI'])) {
unset($sessions);
}
function __session_delete($user) {
if (!file_exists('/tmp/apcontrol-sessions'))
return false;
$newsessions = [];
$sessions = explode("\n", trim(file_get_contents('/tmp/apcontrol-sessions')));
foreach ($sessions as $session) {
$ps = explode('.', $session);
if ($ps[0] !== $user)
$newsessions []= $session;
}
file_put_contents('/tmp/apcontrol-sessions', implode("\n", $newsessions));
return true;
}
if (!file_exists($GLOBALS['appconf']['data_dir']))
mkdir($GLOBALS['appconf']['data_dir']);

View File

@ -23,6 +23,7 @@ function cli__users($args) {
case 'add':
$args = array_slice($args, 1);
if (count($args) !== 2) $help();
__session_delete($args[0]);
$args[1] = hash_hmac('sha256', $args[1], $GLOBALS['appconf']['users_hash_secret']);
$users[$args[0]] = $args[1];
$msg = 'User "'.$args[0].'" has been succesfully saved.';
@ -36,6 +37,7 @@ function cli__users($args) {
$msg = 'User "'.$args[0].'" does not exist.';
else {
unset($users[$args[0]]);
__session_delete($args[0]);
$msg = 'User "'.$args[0].'" has been succesfully deleted.';
}
break;

View File

@ -248,6 +248,11 @@ const http = {
if (hit !== null) hit.remove();
}
if (callbk) {
if (this.status === 403) {
toast.error('Unautorized: session might have been closed');
setTimeout(function(){ window.location.href = '/' }, 4000);
return false;
}
const ps = _get_func_params(callbk);
if (ps.includes('data') || ps.includes('text') ||
ps.includes('html') || ps.includes('plain'))