diff --git a/public/api.php b/public/api.php index c8792da..0c93022 100644 --- a/public/api.php +++ b/public/api.php @@ -136,8 +136,15 @@ try { $settings['local_networks'] = [$settings['local_net']]; } + $appDir = dirname(__DIR__); + $installedVerData = file_exists("{$appDir}/version.json") + ? json_decode((string)file_get_contents("{$appDir}/version.json"), true) + : []; + $installedVer = $installedVerData['version'] ?? '1.3.9'; + echo json_encode([ 'success' => true, + 'version' => $installedVer, 'user' => Auth::getUsername(), 'settings' => $settings, 'extensions' => $extensions, @@ -2233,23 +2240,28 @@ try { case 'check_update': $appDir = dirname(__DIR__); + clearstatcache(true, "{$appDir}/version.json"); $localVerJson = file_exists("{$appDir}/version.json") ? json_decode((string)file_get_contents("{$appDir}/version.json"), true) - : ['version' => '1.2.0', 'changelog' => []]; + : ['version' => '1.3.8', 'changelog' => []]; - $currentVer = $localVerJson['version'] ?? '1.2.0'; + $currentVer = $localVerJson['version'] ?? '1.3.8'; $remoteVer = $currentVer; $remoteChangelog = []; $remoteDate = ''; - // 1. Interrogation directe via HTTP Raw (indépendant de .git et ultra-rapide) - $rawHttp = @shell_exec("curl -k -s --connect-timeout 4 \"https://git.sorcier-research.com/sorcier/NexusPBX/raw/branch/main/version.json\" 2>/dev/null"); + // 1. Interrogation directe via HTTP Raw avec cache-busting strict (bypass OpenResty/Cloudflare max-age) + $ts = time(); + $rawHttp = @shell_exec("curl -k -s -H 'Cache-Control: no-cache, no-store' -H 'Pragma: no-cache' --connect-timeout 4 \"https://git.sorcier-research.com/sorcier/NexusPBX/raw/branch/main/version.json?_t={$ts}\" 2>/dev/null"); if (empty($rawHttp)) { $ctx = stream_context_create([ - 'http' => ['timeout' => 4], + 'http' => [ + 'timeout' => 4, + 'header' => "Cache-Control: no-cache\r\nPragma: no-cache\r\n" + ], 'ssl' => ['verify_peer' => false, 'verify_peer_name' => false] ]); - $rawHttp = @file_get_contents("https://git.sorcier-research.com/sorcier/NexusPBX/raw/branch/main/version.json", false, $ctx); + $rawHttp = @file_get_contents("https://git.sorcier-research.com/sorcier/NexusPBX/raw/branch/main/version.json?_t={$ts}", false, $ctx); } if (!empty($rawHttp)) { @@ -2274,11 +2286,6 @@ try { } $hasUpdate = version_compare($remoteVer, $currentVer, '>'); - $localHash = trim((string)shell_exec("git --git-dir={$appDir}/.git rev-parse HEAD 2>/dev/null")); - $remoteHash = trim((string)shell_exec("git --git-dir={$appDir}/.git rev-parse origin/main 2>/dev/null")); - if (!$hasUpdate && $localHash !== '' && $remoteHash !== '' && $localHash !== $remoteHash) { - $hasUpdate = true; - } echo json_encode([ 'success' => true, @@ -2297,13 +2304,18 @@ try { $outputStr = implode("\n", $output); $appDir = dirname(__DIR__); + clearstatcache(true, "{$appDir}/version.json"); + if (function_exists('opcache_reset')) { + @opcache_reset(); + } + $newVerJson = file_exists("{$appDir}/version.json") ? json_decode((string)file_get_contents("{$appDir}/version.json"), true) - : ['version' => '1.3.0']; + : ['version' => '1.3.8']; echo json_encode([ 'success' => ($code === 0), - 'new_version' => $newVerJson['version'] ?? '1.3.0', + 'new_version' => $newVerJson['version'] ?? '1.3.8', 'output' => $outputStr, 'message' => ($code === 0) ? "Mise à jour réussie !" : "Erreur lors de la mise à jour", ]); diff --git a/public/assets/app.js b/public/assets/app.js index 1e5a900..bb03d66 100644 --- a/public/assets/app.js +++ b/public/assets/app.js @@ -5735,15 +5735,26 @@ async function checkSystemUpdate(notify = false) { const TWENTY_FOUR_HOURS = 24 * 60 * 60 * 1000; // Si pas de clic explicite (notify === false), vérifier si un check a déjà été fait il y a moins de 24h + const installedVer = (appState && appState.version) ? appState.version : (document.querySelector('meta[name="nexus-app-version"]')?.content || ''); if (!notify) { const lastTs = parseInt(localStorage.getItem(STORAGE_KEY_TIME) || '0', 10); const cachedRaw = localStorage.getItem(STORAGE_KEY_DATA); if (lastTs && (Date.now() - lastTs < TWENTY_FOUR_HOURS) && cachedRaw) { try { const cached = JSON.parse(cachedRaw); - applyUpdateUI(cached); - return; - } catch (_) {} + // Si la version locale correspond et qu'on n'a pas un vieux flag "mise à jour dispo" vers la version déjà installée + if (installedVer && (cached.current_version !== installedVer || (cached.has_update && cached.latest_version === installedVer))) { + // Cache périmé suite à une mise à jour : on purge pour rafraîchir en direct + localStorage.removeItem(STORAGE_KEY_TIME); + localStorage.removeItem(STORAGE_KEY_DATA); + } else { + applyUpdateUI(cached); + return; + } + } catch (_) { + localStorage.removeItem(STORAGE_KEY_TIME); + localStorage.removeItem(STORAGE_KEY_DATA); + } } } else { localStorage.removeItem(STORAGE_KEY_TIME); @@ -5759,7 +5770,7 @@ async function checkSystemUpdate(notify = false) { } try { - const res = await fetch('/api.php?action=check_update'); + const res = await fetch('/api.php?action=check_update&_t=' + Date.now()); const data = await res.json(); // Enregistrement du timestamp de vérification et des données en cache local (24h) @@ -5860,8 +5871,12 @@ async function runSystemUpdate() { showToast("Mise à jour en cours d'exécution en arrière-plan...", 'info'); + // Purge préventive du cache local + localStorage.removeItem('nexus_update_last_check_ts'); + localStorage.removeItem('nexus_update_cached_data'); + try { - const res = await fetch('/api.php?action=run_update', { + const res = await fetch('/api.php?action=run_update&_t=' + Date.now(), { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({}) @@ -5869,14 +5884,41 @@ async function runSystemUpdate() { const data = await res.json(); if (data.success) { - showToast(`NexusPBX a été mis à jour avec succès en v${data.new_version} ! Rechargement...`, 'success'); + const newVer = data.new_version || ''; + + // 1. Mettre à jour immédiatement le cache avec l'état à jour + localStorage.setItem('nexus_update_last_check_ts', Date.now().toString()); + localStorage.setItem('nexus_update_cached_data', JSON.stringify({ + success: true, + current_version: newVer, + latest_version: newVer, + has_update: false, + changelog: [], + release_date: '' + })); + + // 2. Mettre à jour visuellement les badges immédiatement + const verTag = document.getElementById('system-version-tag'); + const appBadge = document.getElementById('app-version-badge'); + const headerUpdateBadge = document.getElementById('header-update-badge'); + const pingDot = document.getElementById('update-ping-dot'); + + if (verTag && newVer) verTag.textContent = `v${newVer}`; + if (appBadge && newVer) appBadge.textContent = `v${newVer}`; + if (headerUpdateBadge) headerUpdateBadge.style.display = 'none'; + if (btnRun) btnRun.style.display = 'none'; + if (pingDot) pingDot.classList.add('hidden'); + + showToast(`NexusPBX a été mis à jour avec succès en v${newVer} ! Rechargement...`, 'success'); if (statusText) { statusText.className = 'text-emerald-400 font-bold'; - statusText.textContent = `Mise à jour terminée avec succès (v${data.new_version}) ! Rechargement de la page...`; + statusText.textContent = `Mise à jour terminée avec succès (v${newVer}) ! Rechargement...`; } + + // 3. Rechargement avec paramètre anti-cache pour forcer le navigateur à récupérer le nouveau DOM setTimeout(() => { - window.location.reload(); - }, 2500); + window.location.href = window.location.origin + window.location.pathname + '?_t=' + Date.now(); + }, 2000); } else { alert("Erreur lors de la mise à jour :\n\n" + (data.output || data.message)); if (btnRun) { diff --git a/public/index.php b/public/index.php index 7522ad6..8a77a39 100644 --- a/public/index.php +++ b/public/index.php @@ -10,12 +10,16 @@ use App\Auth; Database::getConnection(); $isAuth = Auth::isAuthenticated(); $currentUser = Auth::getUsername(); + +$appVerData = file_exists(__DIR__ . '/../version.json') ? json_decode((string)file_get_contents(__DIR__ . '/../version.json'), true) : []; +$appVersion = $appVerData['version'] ?? '1.3.9'; ?> + NexusPBX — Supervision & Gestion PJSIP sur Debian