Enhance session management and access control for super admins
This commit introduces improvements to session management by implementing a new check for super admin sessions, allowing them to bypass certain access restrictions. It updates the logout function to retain super admin session data and modifies event access functions to grant permissions based on super admin status. Additionally, the session timeout duration is adjusted for better alignment with site requirements. The version code is updated to reflect these changes.
This commit is contained in:
@ -344,7 +344,8 @@ if (isset($_GET['promoteur_eve_id'])) {
|
||||
header('Location: ' . $vDomaine . '/' . $strPage);
|
||||
exit;
|
||||
}
|
||||
} elseif (!fxIsPromoteur($_SESSION['com_id'], $intEveIdbase)
|
||||
} elseif (empty($_SESSION['usa_id'])
|
||||
&& !fxIsPromoteur($_SESSION['com_id'], $intEveIdbase)
|
||||
&& !fxEveAccesComHasV2ForEvent($_SESSION['com_id'], $intEveIdbase)) {
|
||||
header('Location: ' . $vDomaine . '/' . $strPage);
|
||||
exit;
|
||||
|
||||
@ -1292,32 +1292,45 @@ function fxLogout($strLangue = 'fr')
|
||||
{
|
||||
global $vDomaine;
|
||||
|
||||
$tabSuperAdmin = array();
|
||||
if (!empty($_SESSION['usa_id'])) {
|
||||
$tabSuperAdmin = array(
|
||||
'usa_id' => $_SESSION['usa_id'],
|
||||
'usa_info' => $_SESSION['usa_info'] ?? null,
|
||||
'logged' => $_SESSION['logged'] ?? time(),
|
||||
);
|
||||
}
|
||||
|
||||
unset($_SESSION['com_id']);
|
||||
unset($_SESSION['com_info']);
|
||||
unset($_SESSION['com_prenom']);
|
||||
//unset($_SESSION['logged']);
|
||||
unset($_SESSION['vadmin_texte']);
|
||||
unset($_SESSION['url_retour']);
|
||||
unset($_SESSION['msg_erreur']);
|
||||
unset($_SESSION['promoteur_eve_id']);
|
||||
unset($_SESSION['epr_id_bib']);
|
||||
unset($_SESSION['com_affilie']);
|
||||
//
|
||||
$_SESSION = []; // Vide toutes les variables de session
|
||||
|
||||
// Optionnel : détruit la session complètement (ID, fichier, etc.)
|
||||
session_destroy();
|
||||
$strNoPanier = $_SESSION['no_panier'] ?? null;
|
||||
|
||||
$_SESSION = array();
|
||||
$_SESSION['date_maj'] = time();
|
||||
|
||||
// session_unset();
|
||||
// session_destroy();
|
||||
foreach ($tabSuperAdmin as $strKey => $mixValue) {
|
||||
if ($mixValue !== null) {
|
||||
$_SESSION[$strKey] = $mixValue;
|
||||
}
|
||||
}
|
||||
|
||||
if ($strLangue == 'fr')
|
||||
if ($strLangue == 'fr') {
|
||||
$strPage = 'compte';
|
||||
else
|
||||
} else {
|
||||
$strPage = 'account';
|
||||
}
|
||||
|
||||
fxViderPanier($_SESSION['no_panier'], 1);
|
||||
if ($strNoPanier !== null && $strNoPanier !== '') {
|
||||
fxViderPanier($strNoPanier, 1);
|
||||
}
|
||||
|
||||
if (!empty($_GET['redirect']) && $_GET['redirect'] === 'mobile') {
|
||||
$strTarget = $vDomaine . ($strLangue === 'en' ? '/mobile/en' : '/mobile');
|
||||
|
||||
@ -9,14 +9,13 @@ function fxEveAccesIsEnabled()
|
||||
{
|
||||
static $blnEnabled = null;
|
||||
|
||||
if ($blnEnabled !== null) {
|
||||
return $blnEnabled;
|
||||
}
|
||||
|
||||
global $objDatabase;
|
||||
|
||||
if (!isset($objDatabase)) {
|
||||
$blnEnabled = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($blnEnabled !== null) {
|
||||
return $blnEnabled;
|
||||
}
|
||||
|
||||
@ -26,6 +25,12 @@ function fxEveAccesIsEnabled()
|
||||
return $blnEnabled;
|
||||
}
|
||||
|
||||
/** Super admin connecte (canal usa_id) — bypass total des droits v2 sur le site promoteur. */
|
||||
function fxEveAccesIsSuperAdminSession()
|
||||
{
|
||||
return !empty($_SESSION['usa_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Corps SELECT des acces actifs (remplace l'ancienne vue v_eve_acces_actif).
|
||||
* Pas de vue stockee : evite le DEFINER non copiable par Navicat / releve.
|
||||
@ -164,6 +169,10 @@ function fxEveAccesGetEventIds($intComId)
|
||||
/** Acces web gestion inscriptions : vue API/page OU au moins une permission action inscriptions_gestion.* */
|
||||
function fxEveAccesHasInscrGestionWebAccess($intComId, $intEveId)
|
||||
{
|
||||
if (fxEveAccesIsSuperAdminSession()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (fxEveAccesComEventHasGrantsAllKit(intval($intComId), intval($intEveId))) {
|
||||
return true;
|
||||
}
|
||||
@ -294,6 +303,10 @@ function fxEveAccesComEventHasGrantsAllKit($intComId, $intEveId)
|
||||
|
||||
function fxEveAccesHasPermission($intComId, $intEveId, $strPermKey)
|
||||
{
|
||||
if (fxEveAccesIsSuperAdminSession()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
global $objDatabase;
|
||||
|
||||
if (!fxEveAccesIsEnabled()) {
|
||||
@ -315,6 +328,10 @@ function fxEveAccesHasPermission($intComId, $intEveId, $strPermKey)
|
||||
|
||||
function fxEveAccesHasAnyPermission($intComId, $intEveId, $arrPermKeys)
|
||||
{
|
||||
if (fxEveAccesIsSuperAdminSession()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
global $objDatabase;
|
||||
|
||||
if (!fxEveAccesIsEnabled() || empty($arrPermKeys)) {
|
||||
@ -374,9 +391,13 @@ function fxEveAccesGetEventIdsWithAnyPermission($intComId, $arrPermKeys)
|
||||
return $arrIds;
|
||||
}
|
||||
|
||||
/** Outil debug QR — permission v2 tools.qr_test uniquement (pas de bypass super admin). */
|
||||
/** Outil debug QR — super admin : acces libre ; promoteur : permission v2 tools.qr_test. */
|
||||
function fxEveAccesCanQrTest($intComId)
|
||||
{
|
||||
if (fxEveAccesIsSuperAdminSession()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!fxEveAccesIsEnabled() || intval($intComId) <= 0) {
|
||||
return false;
|
||||
}
|
||||
@ -544,6 +565,10 @@ function fxEveAccesResolveEveIdFromParId($intParId)
|
||||
*/
|
||||
function fxEveAccesAssertPromoteurAction($intComId, $intEveId, $strPermKey)
|
||||
{
|
||||
if (fxEveAccesIsSuperAdminSession()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$intComId = intval($intComId);
|
||||
$intEveId = intval($intEveId);
|
||||
|
||||
|
||||
@ -97,11 +97,19 @@ function fxInscrGestionGetPromoteurEveIds($intComId) {
|
||||
}
|
||||
|
||||
function fxInscrGestionCanAccess($intComId, $intEveId) {
|
||||
if (!empty($_SESSION['usa_id'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
fxInscrGestionLoadEveAcces();
|
||||
return fxEveAccesHasInscrGestionWebAccess(intval($intComId), intval($intEveId));
|
||||
}
|
||||
|
||||
function fxInscrGestionCanScan($intComId, $intEveId) {
|
||||
if (!empty($_SESSION['usa_id'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
fxInscrGestionLoadEveAcces();
|
||||
return fxEveAccesHasAnyPermission(intval($intComId), intval($intEveId), fxInscrGestionPermKeysScan());
|
||||
}
|
||||
|
||||
@ -44,4 +44,8 @@ if (isset($_SESSION['date_maj']) && (time() - $_SESSION['date_maj'] > $inactive)
|
||||
/* if (!isset($_SESSION['no_panier']) && isset($_COOKIE['no_panier']))
|
||||
$_SESSION['no_panier'] = $_COOKIE['no_panier']; */
|
||||
|
||||
$_SESSION['date_maj'] = time();
|
||||
$_SESSION['date_maj'] = time();
|
||||
|
||||
if (!empty($_SESSION['usa_id'])) {
|
||||
$_SESSION['logged'] = time();
|
||||
}
|
||||
@ -230,7 +230,7 @@ function fxEveAccesAdminGetRoleAssignments($intRoleId, $strStatut = null)
|
||||
}
|
||||
|
||||
$sql = "SELECT ea.ea_id, ea.com_id, ea.eve_id, ea.ea_statut, ea.ea_created_at, ea.ea_revoked_at,
|
||||
c.com_nom, c.com_prenom, c.com_courriel,
|
||||
c.com_nom, c.com_prenom, c.com_courriel, c.com_lastvisit,
|
||||
e.eve_nom_fr, e.eve_date_fin
|
||||
FROM inscriptions_eve_acces ea
|
||||
INNER JOIN inscriptions_comptes c ON c.com_id = ea.com_id
|
||||
@ -314,14 +314,15 @@ function fxEveAccesAdminRenderRoleAssignmentsBlock($intRoleId, $arrOpts = array(
|
||||
<th>Compte</th>
|
||||
<th>Événement</th>
|
||||
<th class="text-center">Statut</th>
|
||||
<th>Depuis</th>
|
||||
<th>Assigné le</th>
|
||||
<th>Dernière connexion</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
if (count($arrRows) === 0) {
|
||||
echo '<tr><td colspan="5" class="text-muted">Aucune assignation.</td></tr>';
|
||||
echo '<tr><td colspan="6" class="text-muted">Aucune assignation.</td></tr>';
|
||||
} else {
|
||||
foreach ($arrRows as $arrAssign) {
|
||||
$strCompte = trim($arrAssign['com_prenom'] . ' ' . $arrAssign['com_nom']);
|
||||
@ -348,7 +349,8 @@ function fxEveAccesAdminRenderRoleAssignmentsBlock($intRoleId, $arrOpts = array(
|
||||
<td class="text-center">
|
||||
<span class="badge badge-<?= $strBadge ?>"><?= htmlspecialchars($strStatut, ENT_QUOTES, 'UTF-8') ?></span>
|
||||
</td>
|
||||
<td class="text-nowrap small"><?= htmlspecialchars(substr((string)$arrAssign['ea_created_at'], 0, 16), ENT_QUOTES, 'UTF-8') ?></td>
|
||||
<td class="text-nowrap small"><?= htmlspecialchars(fxEveAccesAdminFormatReportDatetime($arrAssign['ea_created_at']), ENT_QUOTES, 'UTF-8') ?></td>
|
||||
<td class="text-nowrap small"><?= htmlspecialchars(fxEveAccesAdminFormatReportDatetime($arrAssign['com_lastvisit']), ENT_QUOTES, 'UTF-8') ?></td>
|
||||
<td class="text-right text-nowrap">
|
||||
<a class="btn btn-sm btn-outline-primary" href="<?= htmlspecialchars($strCompteUrl, ENT_QUOTES, 'UTF-8') ?>">
|
||||
Fiche compte
|
||||
|
||||
@ -1,11 +1,26 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// Temps de la session = 60 min
|
||||
$inactive = 3600;
|
||||
$session_life = time() - $_SESSION['logged'];
|
||||
// Meme duree que le site public (MSIN-CON-259)
|
||||
$inactive = 10800;
|
||||
|
||||
if ($session_life > $inactive)
|
||||
header('Location: logout.php');
|
||||
|
||||
$_SESSION['logged'] = time();
|
||||
if (!empty($_SESSION['usa_id'])) {
|
||||
$intLastActivity = intval($_SESSION['logged'] ?? 0);
|
||||
if (!empty($_SESSION['date_maj'])) {
|
||||
$intLastActivity = max($intLastActivity, intval($_SESSION['date_maj']));
|
||||
}
|
||||
|
||||
if ($intLastActivity <= 0) {
|
||||
$_SESSION['logged'] = time();
|
||||
} elseif ((time() - $intLastActivity) > $inactive) {
|
||||
header('Location: logout.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$_SESSION['logged'] = time();
|
||||
} elseif (!empty($_SESSION['logged']) && (time() - intval($_SESSION['logged'])) > $inactive) {
|
||||
header('Location: logout.php');
|
||||
exit;
|
||||
} elseif (!empty($_SESSION['logged'])) {
|
||||
$_SESSION['logged'] = time();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user