code qr vehicule

This commit is contained in:
2026-05-28 11:31:57 -04:00
parent ef8304c617
commit 789ce4947d
2 changed files with 94 additions and 23 deletions

View File

@ -1,8 +1,8 @@
<?php
/**
* Outil temporaire : modifier key_chain_http pour un pk_key_chain.
* Accès : /ms1_kc_set.php?k=<KEYCHAIN_HTTP_EDIT_SECRET>
* Numéro affiché : saisie + KEYCHAIN_HTTP_EDIT_SHIFT (ex. 8 → pk 108).
* Accès 1 : /ms1_kc_set.php?k=<KEYCHAIN_HTTP_EDIT_SECRET>
* Accès 2 : compte connecté dont com_id est dans KEYCHAIN_HTTP_EDIT_ALLOWED_COM_IDS
*/
$blnNoMaintenance = true;
session_start();
@ -12,14 +12,46 @@ require_once __DIR__ . '/php/inc_fonctions.php';
header('X-Robots-Tag: noindex, nofollow');
header('Cache-Control: no-store, no-cache, must-revalidate');
global $objDatabase;
global $objDatabase, $vDomaine;
function kc_set_allowed_com_ids()
{
if (!defined('KEYCHAIN_HTTP_EDIT_ALLOWED_COM_IDS') || KEYCHAIN_HTTP_EDIT_ALLOWED_COM_IDS === '') {
return [];
}
$arr = array_map('intval', explode(',', KEYCHAIN_HTTP_EDIT_ALLOWED_COM_IDS));
return array_values(array_filter($arr, function ($id) {
return $id > 0;
}));
}
function kc_set_com_id_authorized()
{
if (!isset($_SESSION['com_id']) || (int) $_SESSION['com_id'] <= 0) {
return false;
}
return in_array((int) $_SESSION['com_id'], kc_set_allowed_com_ids(), true);
}
$strSecret = isset($_GET['k']) ? (string) $_GET['k'] : '';
$blnAuth = ($strSecret !== '' && hash_equals(KEYCHAIN_HTTP_EDIT_SECRET, $strSecret));
$blnAuthSecret = ($strSecret !== '' && hash_equals(KEYCHAIN_HTTP_EDIT_SECRET, $strSecret));
$blnAuthUser = kc_set_com_id_authorized();
$blnAuth = $blnAuthSecret || $blnAuthUser;
$blnUserMode = $blnAuthUser;
if (!$blnAuth) {
if (!isset($_SESSION['com_id']) && kc_set_allowed_com_ids() !== []) {
$_SESSION['redirect_after_login'] = $_SERVER['REQUEST_URI'];
header('Location: ' . $vDomaine . '/compte');
exit;
}
http_response_code(403);
echo '<!DOCTYPE html><html lang="fr"><head><meta charset="UTF-8"><title>403</title></head><body><p>Accès refusé.</p></body></html>';
echo '<!DOCTYPE html><html lang="fr"><head><meta charset="UTF-8"><title>403</title></head><body>';
echo '<p>Accès refusé.</p>';
if (kc_set_allowed_com_ids() !== []) {
echo '<p><a href="' . htmlspecialchars($vDomaine . '/compte', ENT_QUOTES, 'UTF-8') . '">Connexion compte</a></p>';
}
echo '</body></html>';
exit;
}
@ -27,7 +59,18 @@ if (empty($_SESSION['kc_edit_csrf'])) {
$_SESSION['kc_edit_csrf'] = bin2hex(random_bytes(16));
}
$strCsrf = $_SESSION['kc_edit_csrf'];
$strBaseUrl = htmlspecialchars($_SERVER['PHP_SELF'] . '?k=' . rawurlencode($strSecret), ENT_QUOTES, 'UTF-8');
$strBaseUrl = $_SERVER['PHP_SELF'];
if ($blnAuthSecret) {
$strBaseUrl .= '?k=' . rawurlencode($strSecret);
}
$strBaseUrl = htmlspecialchars($strBaseUrl, ENT_QUOTES, 'UTF-8');
$strUserName = '';
if ($blnUserMode && !empty($_SESSION['com_prenom'])) {
$strUserName = trim((string) $_SESSION['com_prenom']);
} elseif ($blnUserMode && !empty($_SESSION['com_info']['com_prenom'])) {
$strUserName = trim((string) $_SESSION['com_info']['com_prenom']);
}
$strMessage = '';
$strMessageClass = '';
@ -59,7 +102,7 @@ function kc_set_validate_url($url)
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$strPostedCsrf = isset($_POST['csrf']) ? (string) $_POST['csrf'] : '';
if (!hash_equals($strCsrf, $strPostedCsrf)) {
$strMessage = 'Jeton invalide. Rechargez la page.';
$strMessage = 'Session expirée. Rechargez la page.';
$strMessageClass = 'err';
} else {
$strAction = isset($_POST['action']) ? (string) $_POST['action'] : '';
@ -67,13 +110,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ($strAction === 'load') {
$intPk = kc_set_resolve_pk(isset($_POST['pk_input']) ? $_POST['pk_input'] : 0);
if ($intPk <= 0) {
$strMessage = 'Numéro invalide.';
$strMessage = $blnUserMode ? 'Numéro invalide.' : 'Numéro invalide.';
$strMessageClass = 'err';
} else {
$sql = 'SELECT key_chain_http FROM key_chain WHERE pk_key_chain = ' . $intPk;
$row = $objDatabase->fxGetRow($sql);
if ($row === null) {
$strMessage = 'Aucune ligne pour pk ' . $intPk . ' (saisie + ' . KEYCHAIN_HTTP_EDIT_SHIFT . ').';
if ($blnUserMode) {
$strMessage = 'Aucun lien trouvé pour ce numéro.';
} else {
$strMessage = 'Aucune ligne pour pk ' . $intPk . ' (saisie + ' . KEYCHAIN_HTTP_EDIT_SHIFT . ').';
}
$strMessageClass = 'err';
} else {
$strCurrentHttp = $row['key_chain_http'];
@ -84,23 +131,27 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$intPk = intval(isset($_POST['pk']) ? $_POST['pk'] : 0);
$strNewHttp = kc_set_validate_url(isset($_POST['key_chain_http']) ? $_POST['key_chain_http'] : '');
if ($intPk <= 0) {
$strMessage = 'PK invalide.';
$strMessage = 'Référence invalide.';
$strMessageClass = 'err';
} elseif ($strNewHttp === false) {
$strMessage = 'URL invalide (http ou https requis).';
$strMessage = 'Adresse Web invalide (http ou https requis).';
$strMessageClass = 'err';
} else {
$sqlCheck = 'SELECT pk_key_chain FROM key_chain WHERE pk_key_chain = ' . $intPk;
if ($objDatabase->fxGetRow($sqlCheck) === null) {
$strMessage = 'Ligne introuvable (pk ' . $intPk . ').';
$strMessage = $blnUserMode ? 'Lien introuvable.' : 'Ligne introuvable (pk ' . $intPk . ').';
$strMessageClass = 'err';
} else {
$sqlUpdate = "UPDATE key_chain SET key_chain_http = '" . $objDatabase->fxEscape($strNewHttp) . "' WHERE pk_key_chain = " . $intPk;
if ($objDatabase->fxQuery($sqlUpdate) === false) {
$strMessage = 'Erreur lors de la mise à jour.';
$strMessage = 'Erreur lors de lenregistrement.';
$strMessageClass = 'err';
} else {
$strMessage = 'Enregistré — pk ' . $intPk . ' → ' . htmlspecialchars($strNewHttp, ENT_QUOTES, 'UTF-8');
if ($blnUserMode) {
$strMessage = 'Adresse enregistrée.';
} else {
$strMessage = 'Enregistré — pk ' . $intPk . ' → ' . htmlspecialchars($strNewHttp, ENT_QUOTES, 'UTF-8');
}
$strMessageClass = 'ok';
$strCurrentHttp = $strNewHttp;
$blnShowUrlForm = true;
@ -118,10 +169,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<meta charset="UTF-8">
<meta name="robots" content="noindex, nofollow">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Key chain HTTP</title>
<title><?php echo $blnUserMode ? 'Modifier le lien de redirection' : 'Key chain HTTP'; ?></title>
<style>
body { font-family: system-ui, sans-serif; max-width: 560px; margin: 2rem auto; padding: 0 1rem; color: #222; }
h1 { font-size: 1.35rem; margin-bottom: 0.75rem; }
h1 { font-size: 1.35rem; margin-bottom: 0.5rem; }
.user-bar { color: #444; font-size: 0.95rem; margin-bottom: 1rem; }
label { display: block; margin-top: 1.25rem; font-weight: 600; font-size: 1.05rem; }
input[type="text"], input[type="number"] { width: 100%; box-sizing: border-box; padding: 0.6rem; font-size: 1.05rem; }
.credits {
@ -142,18 +194,33 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
.msg.err { background: #ffebee; color: #b71c1c; }
.pk-badge { font-family: monospace; background: #e8e8e8; padding: 0.15rem 0.45rem; border-radius: 3px; font-size: 1.05em; }
.pk-line { font-size: 1.05rem; margin: 0.5rem 0 1rem; }
.back { margin-top: 1.5rem; font-size: 0.95rem; }
</style>
</head>
<body>
<?php if ($blnUserMode) { ?>
<h1>Modifier le lien de redirection</h1>
<?php if ($strUserName !== '') { ?>
<p class="user-bar">Bonjour <?php echo htmlspecialchars($strUserName, ENT_QUOTES, 'UTF-8'); ?>.</p>
<?php } ?>
<div class="credits">
<strong>Comment faire</strong>
<ul>
<li>Entrez le <strong>numéro indiqué sur le QR</strong> (sans ajouter <?php echo (int) KEYCHAIN_HTTP_EDIT_SHIFT; ?> — le système sen charge).</li>
<li>Appuyez sur <strong>Entrée</strong> pour voir ladresse actuelle, modifiez-la, puis <strong>Entrée</strong> pour enregistrer.</li>
</ul>
</div>
<?php } else { ?>
<h1>Key chain — URL de destination</h1>
<div class="credits">
<strong>Indications</strong>
<ul>
<li>Numéro affiché <strong>+ <?php echo (int) KEYCHAIN_HTTP_EDIT_SHIFT; ?></strong> = <code>pk_key_chain</code> en base (ex.&nbsp;: vous tapez <span class="pk-badge">8</span> → enregistrement sur <span class="pk-badge">108</span>).</li>
<li>Numéro affiché <strong>+ <?php echo (int) KEYCHAIN_HTTP_EDIT_SHIFT; ?></strong> = <code>pk_key_chain</code> en base (ex.&nbsp;: vous tapez <span class="pk-badge">8</span> → <span class="pk-badge">108</span>).</li>
<li><strong>Entrée</strong> : charger lURL actuelle, puis enregistrer la nouvelle.</li>
<li>Seule la colonne <code>key_chain_http</code> est modifiée (outil temporaire MS1).</li>
</ul>
</div>
<?php } ?>
<?php if ($strMessage !== '') { ?>
<div class="msg <?php echo htmlspecialchars($strMessageClass, ENT_QUOTES, 'UTF-8'); ?>"><?php
@ -165,21 +232,23 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<form method="post" action="<?php echo $strBaseUrl; ?>" id="frm_load">
<input type="hidden" name="csrf" value="<?php echo htmlspecialchars($strCsrf, ENT_QUOTES, 'UTF-8'); ?>">
<input type="hidden" name="action" value="load">
<label for="pk_input">Numéro (sans le +<?php echo (int) KEYCHAIN_HTTP_EDIT_SHIFT; ?>)</label>
<label for="pk_input"><?php echo $blnUserMode ? 'Numéro du lien QR' : 'Numéro (sans le +' . (int) KEYCHAIN_HTTP_EDIT_SHIFT . ')'; ?></label>
<input type="number" id="pk_input" name="pk_input" min="1" step="1" required autofocus>
<p class="hint">Entrée pour charger lURL actuelle.</p>
<p class="hint"><?php echo $blnUserMode ? 'Entrée pour afficher ladresse actuelle.' : 'Entrée pour charger lURL actuelle.'; ?></p>
</form>
<?php } else { ?>
<p class="pk-line">pk_key_chain en base : <span class="pk-badge"><?php echo (int) $intPk; ?></span></p>
<?php if (!$blnUserMode) { ?>
<p class="pk-line">pk_key_chain en base : <span class="pk-badge"><?php echo (int) $intPk; ?></span></p>
<?php } ?>
<form method="post" action="<?php echo $strBaseUrl; ?>" id="frm_save">
<input type="hidden" name="csrf" value="<?php echo htmlspecialchars($strCsrf, ENT_QUOTES, 'UTF-8'); ?>">
<input type="hidden" name="action" value="save">
<input type="hidden" name="pk" value="<?php echo (int) $intPk; ?>">
<label for="key_chain_http">key_chain_http</label>
<input type="text" id="key_chain_http" name="key_chain_http" value="<?php echo htmlspecialchars($strCurrentHttp, ENT_QUOTES, 'UTF-8'); ?>" required autofocus>
<label for="key_chain_http"><?php echo $blnUserMode ? 'Adresse Web de destination' : 'key_chain_http'; ?></label>
<input type="url" id="key_chain_http" name="key_chain_http" value="<?php echo htmlspecialchars($strCurrentHttp, ENT_QUOTES, 'UTF-8'); ?>" required autofocus>
<p class="hint">Entrée pour enregistrer.</p>
</form>
<p><a href="<?php echo $strBaseUrl; ?>">← Autre numéro</a></p>
<p class="back"><a href="<?php echo $strBaseUrl; ?>">← <?php echo $blnUserMode ? 'Autre numéro' : 'Autre numéro'; ?></a></p>
<?php } ?>
<script>

View File

@ -14,8 +14,10 @@ define('QR_SECRET_KEY', 'ms1_qr_2026_cle_secrete_longue_et_fixe');
// Outil temporaire ms1_kc_set.php — modifier key_chain_http (lien /kc/{pk}/)
// KEYCHAIN_HTTP_EDIT_SECRET : paramètre ?k= dans lURL (mot de passe daccès à la page)
// KEYCHAIN_HTTP_EDIT_SHIFT : ajouté au numéro saisi (ex. 8 → pk 108 en base)
// KEYCHAIN_HTTP_EDIT_ALLOWED_COM_IDS : com_id autorisés (virgules) pour /ms1_kc_set.php sans ?k=
define('KEYCHAIN_HTTP_EDIT_SECRET', 'ms1_kc_http_edit_2026_c7e4a91f3b2d8e0f6a5c4b3d2e1f0a9');
define('KEYCHAIN_HTTP_EDIT_SHIFT', 100);
define('KEYCHAIN_HTTP_EDIT_ALLOWED_COM_IDS', '');
/**********************
*