Adds session expiration debug message

main
Yasen Pramatarov 2025-12-30 12:14:49 +02:00
parent d67e376220
commit bbceb44c3d
2 changed files with 77 additions and 7 deletions

View File

@ -4,13 +4,74 @@
</div>
</div>
<?php } ?>
<!-- Footer -->
<div id="footer">Jilo Web <?= htmlspecialchars($config['version']) ?> &copy;2024-<?= date('Y') ?> - web interface for <a href="https://lindeas.com/jilo">Jilo</a></div>
<!-- /Footer -->
</div>
<?php
// Preparing the remaining session time debug message
$sessionDebugMarkup = '';
if (Session::getUsername()) {
$canSeeSessionDebug = false;
if (isset($userId, $userObject) && method_exists($userObject, 'hasRight')) {
$canSeeSessionDebug = ($userId === 1) || (bool)$userObject->hasRight($userId, 'superuser');
}
if ($canSeeSessionDebug) {
Session::startSession();
$remember = !empty($_SESSION['REMEMBER_ME']);
$timeoutSeconds = $remember ? (30 * 24 * 60 * 60) : 7200;
$lastActivity = $_SESSION['LAST_ACTIVITY'] ?? null;
$remainingLabel = 'Session activity timestamp unavailable.';
$expiresAtLabel = 'unknown expiry';
if ($lastActivity !== null) {
$elapsed = time() - (int)$lastActivity;
$secondsRemaining = max(0, $timeoutSeconds - $elapsed);
$days = intdiv($secondsRemaining, 86400);
$hours = intdiv($secondsRemaining % 86400, 3600);
$minutes = intdiv($secondsRemaining % 3600, 60);
$seconds = $secondsRemaining % 60;
$parts = [];
if ($days > 0) {
$parts[] = $days . ' ' . ($days === 1 ? 'day' : 'days');
}
if ($hours > 0) {
$parts[] = $hours . ' ' . ($hours === 1 ? 'hour' : 'hours');
}
if ($minutes > 0) {
$parts[] = $minutes . ' ' . ($minutes === 1 ? 'minute' : 'minutes');
}
if ($seconds > 0 || empty($parts)) {
$parts[] = $seconds . ' ' . ($seconds === 1 ? 'second' : 'seconds');
}
$remainingLabel = implode(' ', $parts);
$expiresAtLabel = date('Y-m-d H:i:s', time() + $secondsRemaining);
}
ob_start();
?>
<span class="tm-session-debug">
<strong>Session debug:</strong>
<?= $remember ? 'Remember-me' : 'Standard' ?> session expires in <?= htmlspecialchars($remainingLabel) ?> (<?= htmlspecialchars($expiresAtLabel) ?>)
</span>
<?php
$sessionDebugMarkup = ob_get_clean();
}
}
?>
<!-- Footer -->
<div id="footer">
&laquo; <?= htmlspecialchars($config['site_name'] . (!empty($config['site_slogan']) ? ' - ' . ucfirst($config['site_slogan']) : '')) ?> &raquo;
v.<?= htmlspecialchars($config['version']) ?> &copy; 2024-<?= date('Y') ?> &mdash; web interface for <a href="https://lindeas.com/jilo">Jilo</a>
<?php if ($sessionDebugMarkup !== ''): ?>
<?= $sessionDebugMarkup ?>
<?php endif; ?>
</div>
<!-- /Footer -->
<?php if (Session::getUsername() && $page !== 'logout') { ?>
<script src="static/js/sidebar.js"></script>
@ -42,6 +103,5 @@ document.addEventListener('DOMContentLoaded', function() {
});
</script>
</body>
</body>
</html>

View File

@ -1,3 +1,13 @@
.tm-session-debug {
display: inline-block;
margin-left: 1rem;
background: #fff3cd;
color: #533f03;
border: 1px solid #ffe69c;
border-radius: 0.4rem;
font-size: 0.75rem;
}
.tm-profile-view {
display: flex;
flex-direction: column;