code qr vehicule

This commit is contained in:
2026-05-28 11:18:58 -04:00
parent d9775ab315
commit 3ed9f8e1fc
2 changed files with 185 additions and 0 deletions

182
ms1_kc_set.php Normal file
View File

@ -0,0 +1,182 @@
<?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).
*/
$blnNoMaintenance = true;
session_start();
require_once __DIR__ . '/php/inc_fonctions.php';
header('X-Robots-Tag: noindex, nofollow');
header('Cache-Control: no-store, no-cache, must-revalidate');
global $objDatabase;
$strSecret = isset($_GET['k']) ? (string) $_GET['k'] : '';
$blnAuth = ($strSecret !== '' && hash_equals(KEYCHAIN_HTTP_EDIT_SECRET, $strSecret));
if (!$blnAuth) {
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>';
exit;
}
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');
$strMessage = '';
$strMessageClass = '';
$intPk = 0;
$strCurrentHttp = '';
$blnShowUrlForm = false;
function kc_set_resolve_pk($input)
{
return intval($input) + KEYCHAIN_HTTP_EDIT_SHIFT;
}
function kc_set_validate_url($url)
{
$url = trim($url);
if ($url === '') {
return false;
}
if (!filter_var($url, FILTER_VALIDATE_URL)) {
return false;
}
$parts = parse_url($url);
if (empty($parts['scheme']) || !in_array(strtolower($parts['scheme']), ['http', 'https'], true)) {
return false;
}
return $url;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$strPostedCsrf = isset($_POST['csrf']) ? (string) $_POST['csrf'] : '';
if (!hash_equals($strCsrf, $strPostedCsrf)) {
$strMessage = 'Jeton invalide. Rechargez la page.';
$strMessageClass = 'err';
} else {
$strAction = isset($_POST['action']) ? (string) $_POST['action'] : '';
if ($strAction === 'load') {
$intPk = kc_set_resolve_pk(isset($_POST['pk_input']) ? $_POST['pk_input'] : 0);
if ($intPk <= 0) {
$strMessage = '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 . ').';
$strMessageClass = 'err';
} else {
$strCurrentHttp = $row['key_chain_http'];
$blnShowUrlForm = true;
}
}
} elseif ($strAction === 'save') {
$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.';
$strMessageClass = 'err';
} elseif ($strNewHttp === false) {
$strMessage = 'URL 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 . ').';
$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.';
$strMessageClass = 'err';
} else {
$strMessage = 'Enregistré — pk ' . $intPk . ' → ' . htmlspecialchars($strNewHttp, ENT_QUOTES, 'UTF-8');
$strMessageClass = 'ok';
$strCurrentHttp = $strNewHttp;
$blnShowUrlForm = true;
}
}
}
}
}
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<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>
<style>
body { font-family: system-ui, sans-serif; max-width: 520px; margin: 2rem auto; padding: 0 1rem; }
h1 { font-size: 1.1rem; }
label { display: block; margin-top: 1rem; font-weight: 600; }
input[type="text"], input[type="number"] { width: 100%; box-sizing: border-box; padding: 0.5rem; font-size: 1rem; }
.hint { color: #666; font-size: 0.85rem; margin-top: 0.25rem; }
.msg { margin: 1rem 0; padding: 0.75rem; border-radius: 4px; }
.msg.ok { background: #e8f5e9; color: #1b5e20; }
.msg.err { background: #ffebee; color: #b71c1c; }
.pk-badge { font-family: monospace; background: #f5f5f5; padding: 0.2rem 0.4rem; }
</style>
</head>
<body>
<h1>Key chain — URL de destination</h1>
<p class="hint">Numéro saisi + <?php echo (int) KEYCHAIN_HTTP_EDIT_SHIFT; ?> = pk en base (ex. 8 → <span class="pk-badge">108</span>).</p>
<?php if ($strMessage !== '') { ?>
<div class="msg <?php echo htmlspecialchars($strMessageClass, ENT_QUOTES, 'UTF-8'); ?>"><?php
echo $strMessageClass === 'ok' ? $strMessage : htmlspecialchars($strMessage, ENT_QUOTES, 'UTF-8');
?></div>
<?php } ?>
<?php if (!$blnShowUrlForm) { ?>
<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>
<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>
</form>
<?php } else { ?>
<p>pk_key_chain : <span class="pk-badge"><?php echo (int) $intPk; ?></span></p>
<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>
<p class="hint">Entrée pour enregistrer.</p>
</form>
<p><a href="<?php echo $strBaseUrl; ?>">← Autre numéro</a></p>
<?php } ?>
<script>
(function () {
document.addEventListener('keydown', function (e) {
if (e.key !== 'Enter') return;
var load = document.getElementById('frm_load');
var save = document.getElementById('frm_save');
if (load && document.activeElement && load.contains(document.activeElement)) {
e.preventDefault();
load.submit();
} else if (save && document.activeElement && save.contains(document.activeElement)) {
e.preventDefault();
save.submit();
}
});
})();
</script>
</body>
</html>

View File

@ -11,6 +11,9 @@ define('_VERSION_CODE', '4.72.54');
define('_DATE_CODE', '2026-03-09');
//MSIN-4290
define('QR_SECRET_KEY', 'ms1_qr_2026_cle_secrete_longue_et_fixe');
// Outil temporaire key_chain HTTP (ms1_kc_set.php) — changer en prod si besoin
define('KEYCHAIN_HTTP_EDIT_SECRET', 'ms1_kc_http_edit_2026_c7e4a91f3b2d8e0f6a5c4b3d2e1f0a9');
define('KEYCHAIN_HTTP_EDIT_SHIFT', 100);
/**********************
*