Changeset 3833943
- Timestamp:
- 11/29/2026 11:19:30 PM (5 hours ago)
- Location:
- sentinelo
- Files:
-
- 4 added
- 22 edited
- 1 copied
-
tags/1.6.7 (copied) (copied from sentinelo/trunk )
-
tags/1.6.7/includes/class-sentinelo-constants.php (modified) (1 diff)
-
tags/1.6.7/readme.txt (modified) (2 diffs)
-
tags/1.6.7/sentinelo.php (modified) (1 diff)
-
tags/1.6.7/src/Adapter/Wp/AsideFolder.php (added)
-
tags/1.6.7/src/Adapter/Wp/SwapJournal.php (added)
-
tags/1.6.7/src/Adapter/Wp/WpInventory.php (modified) (2 diffs)
-
tags/1.6.7/src/Adapter/Wp/WpPackageInstaller.php (modified) (13 diffs)
-
tags/1.6.7/src/Api/Endpoints/UpdateEndpoint.php (modified) (1 diff)
-
tags/1.6.7/src/Core/Plugin.php (modified) (1 diff)
-
tags/1.6.7/src/Core/PostUpdatePreload.php (modified) (1 diff)
-
tags/1.6.7/vendor/composer/autoload_classmap.php (modified) (1 diff)
-
tags/1.6.7/vendor/composer/autoload_static.php (modified) (1 diff)
-
tags/1.6.7/vendor/composer/installed.php (modified) (2 diffs)
-
trunk/includes/class-sentinelo-constants.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/sentinelo.php (modified) (1 diff)
-
trunk/src/Adapter/Wp/AsideFolder.php (added)
-
trunk/src/Adapter/Wp/SwapJournal.php (added)
-
trunk/src/Adapter/Wp/WpInventory.php (modified) (2 diffs)
-
trunk/src/Adapter/Wp/WpPackageInstaller.php (modified) (13 diffs)
-
trunk/src/Api/Endpoints/UpdateEndpoint.php (modified) (1 diff)
-
trunk/src/Core/Plugin.php (modified) (1 diff)
-
trunk/src/Core/PostUpdatePreload.php (modified) (1 diff)
-
trunk/vendor/composer/autoload_classmap.php (modified) (1 diff)
-
trunk/vendor/composer/autoload_static.php (modified) (1 diff)
-
trunk/vendor/composer/installed.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sentinelo/tags/1.6.7/includes/class-sentinelo-constants.php
r3807487 r3833943 9 9 // Version 10 10 if (!defined('SENTINELO_VERSION')) { 11 define('SENTINELO_VERSION', '1.6. 6');11 define('SENTINELO_VERSION', '1.6.7'); 12 12 } 13 13 -
sentinelo/tags/1.6.7/readme.txt
r3807487 r3833943 5 5 Tested up to: 7.1 6 6 Requires PHP: 8.2 7 Stable tag: 1.6. 67 Stable tag: 1.6.7 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 120 120 == Changelog == 121 121 122 = 1.6.7 = 123 * Fix: an interrupted rollback no longer leaves the site without the plugin it was restoring. When undoing a failed update, the agent moves the plugin's folder aside before putting the safety copy in place; a process killed between the two steps left the site without that plugin. The swap is now recorded in a journal before the first step, and the agent puts the plugin back by itself on its next start if it was interrupted. 124 * Fix: a folder set aside by a rollback is never treated as a plugin again. When the agent could not delete the old folder after a rollback (files owned by another user than PHP), the leftover was listed as a plugin and "updated" every night, which made WordPress delete the real plugin. Such folders are now ignored by the inventory and refused for updates, and an incomplete deletion is reported and retried instead of being ignored. 125 * Fix: an update that cannot succeed is refused before it starts. If PHP cannot modify the component's files, the agent says so (folder and owner) without touching anything, instead of failing halfway and rolling back. 126 * Fix: no rollback when nothing was changed (for example "already up to date"). 127 * The agent log now gives the cause of each failed update. 128 122 129 = 1.6.6 = 123 130 * Fix: the wp-config.php check no longer reports a blank page as a leak. A healthy server executes the file and returns an empty page; only a response that contains the file's source (an opening PHP tag, or a DB_NAME / DB_USER / DB_PASSWORD / DB_HOST definition) is now reported. -
sentinelo/tags/1.6.7/sentinelo.php
r3807487 r3833943 7 7 * Plugin URI: https://sentinelo.fr/maintenance-wordpress 8 8 * Description: Agent de maintenance silencieux — connecte votre site WordPress à la plateforme Sentinelo. 9 * Version: 1.6. 69 * Version: 1.6.7 10 10 * Author: Sentinelo 11 11 * Author URI: https://sentinelo.fr -
sentinelo/tags/1.6.7/src/Adapter/Wp/WpInventory.php
r3796462 r3833943 111 111 $components = []; 112 112 foreach ($installed as $file => $data) { 113 // Un ancien dossier mis de cote par un retour arriere n'est pas une extension : 114 // le lister ferait proposer sa « mise a jour », qui efface la vraie (AsideFolder). 115 if (AsideFolder::is((string) $file)) { 116 continue; 117 } 113 118 $version = (string) ($data['Version'] ?? ''); 114 119 $networkActive = function_exists('is_plugin_active_for_network') … … 166 171 $components = []; 167 172 foreach (wp_get_themes() as $slug => $theme) { 173 if (AsideFolder::is((string) $slug)) { 174 continue; 175 } 168 176 $version = (string) $theme->get('Version'); 169 177 $parent = $theme->parent(); -
sentinelo/tags/1.6.7/src/Adapter/Wp/WpPackageInstaller.php
r3796462 r3833943 26 26 final class WpPackageInstaller implements PackageInstaller 27 27 { 28 /** Suffixe du vivant mis de cote pendant un retour arriere ({@see swapIn()}). */ 29 private const ASIDE_MARKER = AsideFolder::MARKER; 30 31 /** 32 * Vrai des que la mise a jour a commence a toucher le disque (instantane pris, 33 * paquet en cours d'installation). Avant, un echec n'a rien modifie : il n'y a rien 34 * a remettre, et lancer quand meme le retour arriere echangeait des dossiers pour 35 * rien — c'est ce qu'il faisait sur « deja a jour ». 36 */ 37 private bool $upgradeStarted = false; 38 39 /** Emplacement du journal d'echange ; `null` = le magasin d'instantanes. Surcharge par les tests. */ 40 private ?string $swapJournalFile = null; 41 28 42 public function supports(string $type): bool 29 43 { … … 67 81 public function update(string $type, string $slug, ?string $version, bool $rollbackOnError): UpdateOutcome 68 82 { 83 $this->upgradeStarted = false; 84 85 if ('core' !== $type && AsideFolder::is($slug)) { 86 // Refus AVANT tout geste : WordPress installerait le paquet sous le vrai nom 87 // et effacerait d'abord la vraie extension (voir AsideFolder). 88 return UpdateOutcome::failed($type, $slug, '', sprintf( 89 'Mise à jour refusée : « %s » est un ancien dossier mis de côté par un retour arrière, pas un composant. ' 90 . 'Le mettre à jour ferait effacer par WordPress le dossier du vrai composant.', 91 $slug 92 )); 93 } 94 69 95 $this->requireUpgraderApi(); 70 71 96 $oldVersion = $this->currentVersion($type, $slug); 72 97 … … 79 104 }; 80 105 } catch (\Throwable $e) { 81 if (!$rollbackOnError || '' === $oldVersion) { 106 if (!$rollbackOnError || '' === $oldVersion || !$this->upgradeStarted) { 107 // Rien n'a touche le disque : il n'y a rien a remettre en place. 82 108 return UpdateOutcome::failed($type, $slug, $oldVersion, $e->getMessage()); 83 109 } … … 137 163 { 138 164 foreach (array_keys(get_plugins()) as $file) { 165 if (AsideFolder::is((string) $file)) { 166 continue; 167 } 139 168 if (str_starts_with((string) $file, $slug . '/') || $file === $slug . '.php') { 140 169 return (string) $file; … … 164 193 $newVersion = (string) ($transient->response[$plugin]->new_version ?? ''); 165 194 195 // Une extension a la racine (`hello.php`) n'a pas de repertoire propre. 196 if (str_contains($plugin, '/')) { 197 $this->assertReplaceable(dirname(WP_PLUGIN_DIR . '/' . $plugin)); 198 } 199 166 200 if ($rollbackOnError) { 167 201 $this->snapshot(dirname(WP_PLUGIN_DIR . '/' . $plugin), $this->rollbackPath('plugin', $slug, $oldVersion)); 168 202 } 203 // A partir d'ici, WordPress touche aux fichiers du composant. 204 $this->upgradeStarted = true; 169 205 170 206 $skin = new \WP_Ajax_Upgrader_Skin(); … … 193 229 $newVersion = (string) ($transient->response[$slug]['new_version'] ?? ''); 194 230 231 $this->assertReplaceable(get_theme_root() . '/' . $slug); 232 195 233 if ($rollbackOnError) { 196 234 $this->snapshot(get_theme_root() . '/' . $slug, $this->rollbackPath('theme', $slug, $oldVersion)); 197 235 } 236 // A partir d'ici, WordPress touche aux fichiers du composant. 237 $this->upgradeStarted = true; 198 238 199 239 $skin = new \WP_Ajax_Upgrader_Skin(); … … 344 384 345 385 $aside = null; 386 $journal = $this->swapJournal(); 346 387 if (file_exists($target)) { 347 $aside = $target . '.sentinelo-aside-' . bin2hex(random_bytes(4)); 388 $aside = $target . self::ASIDE_MARKER . bin2hex(random_bytes(4)); 389 390 // Inscrit AVANT d'ecarter : un processus tue entre l'ecartement et la mise 391 // en place ne laisse que ce journal, relu au demarrage pour remettre le 392 // vivant a sa place. Sans lui, on refuse — rien n'a encore bouge. 393 if (!$journal->begin($target, $aside, $backupDir, time())) { 394 $this->logger('Retour arriere refuse : journal d\'echange impossible a ecrire (' . $journal->file() . ') ; rien n\'a ete modifie.'); 395 396 return false; 397 } 398 348 399 if (!@rename($target, $aside)) { 400 $journal->end($aside); 349 401 $this->logger('Retour arriere refuse : impossible d\'ecarter ' . $target . ' ; rien n\'a ete modifie.'); 350 402 … … 359 411 $placed = $renamed; 360 412 if (!$renamed) { 413 if (null !== $aside) { 414 $journal->mark($aside, SwapJournal::PHASE_COPYING); 415 } 361 416 try { 362 417 $this->recursiveCopy($backupDir, $target); … … 379 434 if (null !== $aside) { 380 435 @rename($aside, $target); 436 if (is_dir($aside)) { 437 // Le vivant n'a pas pu revenir : l'inscription reste, la reprise 438 // au demarrage retentera. 439 $journal->postpone($aside, time()); 440 $this->logger('Retour arriere impossible ET vivant non remis en place : ' . $aside . ' ; reprise au prochain demarrage.'); 441 442 return false; 443 } 444 $journal->end($aside); 381 445 } 382 446 $this->logger('Retour arriere impossible : la copie n\'a pas pu etre mise en place ; version courante conservee.'); … … 386 450 387 451 if (null !== $aside) { 388 $this->recursiveDelete($aside); 452 $journal->mark($aside, SwapJournal::PHASE_PLACED); 453 if ($this->recursiveDelete($aside)) { 454 $journal->end($aside); 455 } else { 456 // La copie est en place : le retour arriere a reussi. Mais l'ancien dossier 457 // reste sur le disque, et il ressemble a un composant. On le DIT, on garde 458 // l'inscription pour retenter au demarrage, et l'inventaire l'ignore 459 // (AsideFolder) en attendant. Le taire est ce qui a coute api.auramur.fr. 460 $journal->postpone($aside, time()); 461 $this->logger('Retour arriere effectue, mais l\'ancien dossier mis de cote n\'a pas pu etre efface : ' 462 . $aside . ' (fichiers non modifiables par PHP). Nouvelle tentative au prochain demarrage.'); 463 } 389 464 } 390 465 if (!$renamed) { … … 393 468 394 469 return true; 470 } 471 472 /** 473 * Repare un echange interrompu — ecarte puis jamais remis — au demarrage de l'agent. 474 * 475 * Branche sur CHAQUE requete WordPress ({@see \Sentinelo\Core\Plugin::init()}) : un 476 * site dont une extension vient de disparaitre ne sera pas reparé par la plateforme, 477 * qui ne voit rien de ce qui manque. Cas ordinaire : un `is_file()`. Ne leve jamais. 478 */ 479 public static function recoverInterruptedSwaps(): void 480 { 481 try { 482 $installer = new self(); 483 if ($installer->swapJournal()->isEmpty()) { 484 return; 485 } 486 $roots = [WP_PLUGIN_DIR]; 487 if (function_exists('get_theme_root')) { 488 $roots[] = get_theme_root(); 489 } 490 $installer->recoverSwaps(time(), $roots); 491 } catch (\Throwable $e) { 492 Logger::error('update', 'Reprise d\'un echange interrompu impossible : ' . $e->getMessage()); 493 } 494 } 495 496 /** 497 * @param list<string> $allowedRoots Seuls repertoires sous lesquels on renomme quoi que ce soit. 498 */ 499 private function recoverSwaps(int $now, array $allowedRoots): void 500 { 501 $journal = $this->swapJournal(); 502 503 foreach ($journal->entries() as $entry) { 504 $target = $entry['target']; 505 $aside = $entry['aside']; 506 $backupDir = $entry['backup']; 507 508 // Le journal est un fichier sur disque : on ne renomme que ce qui a 509 // exactement la forme que swapIn() produit, sous une racine connue. 510 if (!$this->isRecoverableShape($target, $aside, $allowedRoots)) { 511 Logger::error('update', 'Echange interrompu ignore (chemins inattendus) : ' . $aside); 512 $journal->end($aside); 513 continue; 514 } 515 516 // Peut-etre en cours dans un autre processus : y toucher le casserait. 517 if ($now - $entry['since'] < SwapJournal::STALE_AFTER_SECONDS) { 518 continue; 519 } 520 521 // Rien n'a ete ecarte, ou quelqu'un l'a deja remis en place a la main. 522 if (!is_dir($aside)) { 523 $journal->end($aside); 524 continue; 525 } 526 527 // La copie etait en place et verifiee : seul l'effacement de l'ecarte manque. 528 if (SwapJournal::PHASE_PLACED === $entry['phase'] && $this->countFiles($target) > 0) { 529 if ($this->recursiveDelete($aside)) { 530 $journal->end($aside); 531 Logger::info('update', 'Echange interrompu termine : ' . $target . ' etait en place, ecarte efface.'); 532 } else { 533 $journal->postpone($aside, $now); 534 Logger::warning('update', 'Ancien dossier toujours impossible a effacer (fichiers non modifiables par PHP) : ' . $aside . '.'); 535 } 536 continue; 537 } 538 539 if (file_exists($target)) { 540 if (SwapJournal::PHASE_COPYING === $entry['phase']) { 541 // Une copie partielle ; l'instantane, lui, est intact a sa place. 542 $this->recursiveDelete($target); 543 } elseif (!file_exists($backupDir)) { 544 // rename(instantane -> cible) avait eu lieu : on rend l'instantane. 545 @rename($target, $backupDir); 546 } 547 } 548 549 if (file_exists($target)) { 550 // Quelque chose qu'on n'a pas pose occupe la place : on ne l'ecrase pas, 551 // et on ne retente pas a chaque requete. L'ecarte reste sur le disque. 552 $journal->end($aside); 553 Logger::error('update', 'Echange interrompu non repare : ' . $target . ' est occupe ; ' . $aside . ' laisse en place.'); 554 continue; 555 } 556 557 if (@rename($aside, $target)) { 558 $journal->end($aside); 559 Logger::warning('update', 'Echange interrompu repare : ' . $target . ' remis en place depuis ' . $aside . '.'); 560 } else { 561 $journal->postpone($aside, $now); 562 Logger::error('update', 'Echange interrompu : impossible de remettre ' . $aside . ' a sa place ; nouvelle tentative plus tard.'); 563 } 564 } 565 } 566 567 /** @param list<string> $allowedRoots */ 568 private function isRecoverableShape(string $target, string $aside, array $allowedRoots): bool 569 { 570 $marker = preg_quote(self::ASIDE_MARKER, '/'); 571 if (1 !== preg_match('/^' . preg_quote($target, '/') . $marker . '[0-9a-f]{8}$/', $aside)) { 572 return false; 573 } 574 575 $parent = rtrim(str_replace('\\', '/', dirname($target)), '/'); 576 foreach ($allowedRoots as $root) { 577 if ('' !== $root && rtrim(str_replace('\\', '/', $root), '/') === $parent) { 578 return true; 579 } 580 } 581 582 return false; 583 } 584 585 private function swapJournal(): SwapJournal 586 { 587 return new SwapJournal($this->swapJournalFile ?? SENTINELO_UPDATE_SNAPSHOT_DIR . '.swap-journal.json'); 395 588 } 396 589 … … 641 834 } 642 835 643 private function recursiveDelete(string $dir): void 836 /** 837 * Efface un repertoire et dit s'il a REELLEMENT disparu. 838 * 839 * `unlink()` et `rmdir()` ne levent pas : sur un fichier qui appartient a un autre 840 * utilisateur que PHP, ils rendent `false` avec un simple avertissement. Ignorer ce 841 * retour a laisse sur api.auramur.fr un ancien dossier d'extension que l'agent 842 * croyait efface (19 novembre 2026), et tout le reste en a decoule. 843 * 844 * Chemin du lien, jamais sa cible : `getRealPath()` sur un lien symbolique 845 * effacerait le fichier vise, hors du repertoire a effacer. 846 */ 847 private function recursiveDelete(string $dir): bool 644 848 { 645 849 if (!is_dir($dir)) { 646 return ;850 return true; 647 851 } 648 852 $items = new \RecursiveIteratorIterator( … … 650 854 \RecursiveIteratorIterator::CHILD_FIRST 651 855 ); 856 $complete = true; 652 857 foreach ($items as $item) { 653 $item->isDir() ? rmdir($item->getRealPath()) : unlink($item->getRealPath()); 654 } 655 rmdir($dir); 858 $path = $item->getPathname(); 859 $done = ($item->isDir() && !$item->isLink()) ? @rmdir($path) : @unlink($path); 860 $complete = $complete && $done; 861 } 862 863 return @rmdir($dir) && $complete; 864 } 865 866 /** 867 * Refuse une mise a jour que WordPress ne pourrait pas mener a terme. 868 * 869 * Le remplacement d'un composant efface ses fichiers, ce qui demande d'ecrire dans 870 * CHAQUE repertoire de son arbre (et dans son parent). Sur api.auramur.fr, les dossiers 871 * appartenaient a `ubuntu` quand PHP tournait sous un autre utilisateur : la mise a 872 * jour echouait a mi-chemin, puis le retour arriere echouait a son tour. Refuser avant 873 * de commencer ne coute rien et nomme la cause. 874 */ 875 private function assertReplaceable(string $dir): void 876 { 877 $blocked = $this->firstUnwritableDirectory($dir); 878 if (null === $blocked) { 879 return; 880 } 881 882 $uid = @fileowner($blocked); 883 $owner = false === $uid ? '?' : (string) $uid; 884 if (false !== $uid && function_exists('posix_getpwuid')) { 885 $info = @posix_getpwuid($uid); 886 if (is_array($info) && isset($info['name'])) { 887 $owner = $info['name']; 888 } 889 } 890 891 throw new \RuntimeException(sprintf( 892 'Mise à jour refusée avant de commencer : PHP ne peut pas modifier %s (propriétaire : %s). ' 893 . 'WordPress ne pourrait pas remplacer ces fichiers. Donnez ce dossier à l\'utilisateur du serveur web, puis relancez. ' 894 . 'Rien n\'a été modifié.', 895 $blocked, 896 $owner 897 )); 898 } 899 900 private function firstUnwritableDirectory(string $dir): ?string 901 { 902 if (!is_dir($dir)) { 903 return null; // Le composant introuvable a sa propre erreur, plus loin. 904 } 905 if (!is_writable(dirname($dir))) { 906 return dirname($dir); 907 } 908 if (!is_writable($dir)) { 909 return $dir; 910 } 911 foreach ($this->walkFiles($dir) as $item) { 912 if ($item->isDir() && !$item->isLink() && !is_writable($item->getPathname())) { 913 return $item->getPathname(); 914 } 915 } 916 917 return null; 656 918 } 657 919 -
sentinelo/tags/1.6.7/src/Api/Endpoints/UpdateEndpoint.php
r3773060 r3833943 122 122 } else { 123 123 $failCount++; 124 // La cause, pas seulement le compte : `failed=1` seul n'a rien appris de 125 // dix nuits d'echecs sur api.auramur.fr. 126 Logger::warning('update_endpoint', "Failed {$type}: {$slug} — " . ($outcome->error ?? 'cause inconnue') 127 . ($outcome->rolledBack ? ' (revenu en arrière)' : '') 128 . (null !== $outcome->rollbackError ? ' ; retour arrière : ' . $outcome->rollbackError : '')); 124 129 if ($outcome->rolledBack) { 125 130 $rollbackCount++; -
sentinelo/tags/1.6.7/src/Core/Plugin.php
r3786219 r3833943 43 43 // quelqu'un le lira encore. Coût ordinaire : un `is_file()`. 44 44 \Sentinelo\Backup\AttachmentJournal::recoverQuietly(); 45 46 // Même raison, autre geste : un retour arrière tué entre l'écartement d'une 47 // extension et la mise en place de sa copie laisse le site SANS cette extension 48 // (28 novembre 2026 : l'extension JWT, plus aucune connexion possible). Le 49 // journal posé avant l'écartement permet de la remettre. Coût ordinaire : un 50 // `is_file()`. 51 \Sentinelo\Adapter\Wp\WpPackageInstaller::recoverInterruptedSwaps(); 45 52 46 53 // Add custom cron interval -
sentinelo/tags/1.6.7/src/Core/PostUpdatePreload.php
r3796462 r3833943 47 47 \Sentinelo\AgentCore\Port\UpdatesNotSupported::class, 48 48 \Sentinelo\Adapter\Wp\WpPackageInstaller::class, 49 \Sentinelo\Adapter\Wp\SwapJournal::class, 50 \Sentinelo\Adapter\Wp\AsideFolder::class, 49 51 \Sentinelo\Adapter\Wp\UpdateOfferMemory::class, 50 52 \Sentinelo\Adapter\Wp\PackageDownloadRefused::class, -
sentinelo/tags/1.6.7/vendor/composer/autoload_classmap.php
r3800466 r3833943 8 8 return array( 9 9 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', 10 'Sentinelo\\Adapter\\Wp\\AsideFolder' => $baseDir . '/src/Adapter/Wp/AsideFolder.php', 10 11 'Sentinelo\\Adapter\\Wp\\PackageDownloadRefused' => $baseDir . '/src/Adapter/Wp/PackageDownloadRefused.php', 12 'Sentinelo\\Adapter\\Wp\\SwapJournal' => $baseDir . '/src/Adapter/Wp/SwapJournal.php', 11 13 'Sentinelo\\Adapter\\Wp\\UpdateOfferMemory' => $baseDir . '/src/Adapter/Wp/UpdateOfferMemory.php', 12 14 'Sentinelo\\Adapter\\Wp\\WpAuditRepository' => $baseDir . '/src/Adapter/Wp/WpAuditRepository.php', -
sentinelo/tags/1.6.7/vendor/composer/autoload_static.php
r3800466 r3833943 28 28 public static $classMap = array ( 29 29 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', 30 'Sentinelo\\Adapter\\Wp\\AsideFolder' => __DIR__ . '/../..' . '/src/Adapter/Wp/AsideFolder.php', 30 31 'Sentinelo\\Adapter\\Wp\\PackageDownloadRefused' => __DIR__ . '/../..' . '/src/Adapter/Wp/PackageDownloadRefused.php', 32 'Sentinelo\\Adapter\\Wp\\SwapJournal' => __DIR__ . '/../..' . '/src/Adapter/Wp/SwapJournal.php', 31 33 'Sentinelo\\Adapter\\Wp\\UpdateOfferMemory' => __DIR__ . '/../..' . '/src/Adapter/Wp/UpdateOfferMemory.php', 32 34 'Sentinelo\\Adapter\\Wp\\WpAuditRepository' => __DIR__ . '/../..' . '/src/Adapter/Wp/WpAuditRepository.php', -
sentinelo/tags/1.6.7/vendor/composer/installed.php
r3807487 r3833943 2 2 'root' => array( 3 3 'name' => 'sentinelo/sentinelo', 4 'pretty_version' => ' dev-main',5 'version' => ' dev-main',6 'reference' => 'dfe82c036b04a49b35eeb6f3eacf08397252577f',4 'pretty_version' => '1.0.0+no-version-set', 5 'version' => '1.0.0.0', 6 'reference' => null, 7 7 'type' => 'wordpress-plugin', 8 8 'install_path' => __DIR__ . '/../../', … … 21 21 ), 22 22 'sentinelo/sentinelo' => array( 23 'pretty_version' => ' dev-main',24 'version' => ' dev-main',25 'reference' => 'dfe82c036b04a49b35eeb6f3eacf08397252577f',23 'pretty_version' => '1.0.0+no-version-set', 24 'version' => '1.0.0.0', 25 'reference' => null, 26 26 'type' => 'wordpress-plugin', 27 27 'install_path' => __DIR__ . '/../../', -
sentinelo/trunk/includes/class-sentinelo-constants.php
r3807487 r3833943 9 9 // Version 10 10 if (!defined('SENTINELO_VERSION')) { 11 define('SENTINELO_VERSION', '1.6. 6');11 define('SENTINELO_VERSION', '1.6.7'); 12 12 } 13 13 -
sentinelo/trunk/readme.txt
r3807487 r3833943 5 5 Tested up to: 7.1 6 6 Requires PHP: 8.2 7 Stable tag: 1.6. 67 Stable tag: 1.6.7 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 120 120 == Changelog == 121 121 122 = 1.6.7 = 123 * Fix: an interrupted rollback no longer leaves the site without the plugin it was restoring. When undoing a failed update, the agent moves the plugin's folder aside before putting the safety copy in place; a process killed between the two steps left the site without that plugin. The swap is now recorded in a journal before the first step, and the agent puts the plugin back by itself on its next start if it was interrupted. 124 * Fix: a folder set aside by a rollback is never treated as a plugin again. When the agent could not delete the old folder after a rollback (files owned by another user than PHP), the leftover was listed as a plugin and "updated" every night, which made WordPress delete the real plugin. Such folders are now ignored by the inventory and refused for updates, and an incomplete deletion is reported and retried instead of being ignored. 125 * Fix: an update that cannot succeed is refused before it starts. If PHP cannot modify the component's files, the agent says so (folder and owner) without touching anything, instead of failing halfway and rolling back. 126 * Fix: no rollback when nothing was changed (for example "already up to date"). 127 * The agent log now gives the cause of each failed update. 128 122 129 = 1.6.6 = 123 130 * Fix: the wp-config.php check no longer reports a blank page as a leak. A healthy server executes the file and returns an empty page; only a response that contains the file's source (an opening PHP tag, or a DB_NAME / DB_USER / DB_PASSWORD / DB_HOST definition) is now reported. -
sentinelo/trunk/sentinelo.php
r3807487 r3833943 7 7 * Plugin URI: https://sentinelo.fr/maintenance-wordpress 8 8 * Description: Agent de maintenance silencieux — connecte votre site WordPress à la plateforme Sentinelo. 9 * Version: 1.6. 69 * Version: 1.6.7 10 10 * Author: Sentinelo 11 11 * Author URI: https://sentinelo.fr -
sentinelo/trunk/src/Adapter/Wp/WpInventory.php
r3796462 r3833943 111 111 $components = []; 112 112 foreach ($installed as $file => $data) { 113 // Un ancien dossier mis de cote par un retour arriere n'est pas une extension : 114 // le lister ferait proposer sa « mise a jour », qui efface la vraie (AsideFolder). 115 if (AsideFolder::is((string) $file)) { 116 continue; 117 } 113 118 $version = (string) ($data['Version'] ?? ''); 114 119 $networkActive = function_exists('is_plugin_active_for_network') … … 166 171 $components = []; 167 172 foreach (wp_get_themes() as $slug => $theme) { 173 if (AsideFolder::is((string) $slug)) { 174 continue; 175 } 168 176 $version = (string) $theme->get('Version'); 169 177 $parent = $theme->parent(); -
sentinelo/trunk/src/Adapter/Wp/WpPackageInstaller.php
r3796462 r3833943 26 26 final class WpPackageInstaller implements PackageInstaller 27 27 { 28 /** Suffixe du vivant mis de cote pendant un retour arriere ({@see swapIn()}). */ 29 private const ASIDE_MARKER = AsideFolder::MARKER; 30 31 /** 32 * Vrai des que la mise a jour a commence a toucher le disque (instantane pris, 33 * paquet en cours d'installation). Avant, un echec n'a rien modifie : il n'y a rien 34 * a remettre, et lancer quand meme le retour arriere echangeait des dossiers pour 35 * rien — c'est ce qu'il faisait sur « deja a jour ». 36 */ 37 private bool $upgradeStarted = false; 38 39 /** Emplacement du journal d'echange ; `null` = le magasin d'instantanes. Surcharge par les tests. */ 40 private ?string $swapJournalFile = null; 41 28 42 public function supports(string $type): bool 29 43 { … … 67 81 public function update(string $type, string $slug, ?string $version, bool $rollbackOnError): UpdateOutcome 68 82 { 83 $this->upgradeStarted = false; 84 85 if ('core' !== $type && AsideFolder::is($slug)) { 86 // Refus AVANT tout geste : WordPress installerait le paquet sous le vrai nom 87 // et effacerait d'abord la vraie extension (voir AsideFolder). 88 return UpdateOutcome::failed($type, $slug, '', sprintf( 89 'Mise à jour refusée : « %s » est un ancien dossier mis de côté par un retour arrière, pas un composant. ' 90 . 'Le mettre à jour ferait effacer par WordPress le dossier du vrai composant.', 91 $slug 92 )); 93 } 94 69 95 $this->requireUpgraderApi(); 70 71 96 $oldVersion = $this->currentVersion($type, $slug); 72 97 … … 79 104 }; 80 105 } catch (\Throwable $e) { 81 if (!$rollbackOnError || '' === $oldVersion) { 106 if (!$rollbackOnError || '' === $oldVersion || !$this->upgradeStarted) { 107 // Rien n'a touche le disque : il n'y a rien a remettre en place. 82 108 return UpdateOutcome::failed($type, $slug, $oldVersion, $e->getMessage()); 83 109 } … … 137 163 { 138 164 foreach (array_keys(get_plugins()) as $file) { 165 if (AsideFolder::is((string) $file)) { 166 continue; 167 } 139 168 if (str_starts_with((string) $file, $slug . '/') || $file === $slug . '.php') { 140 169 return (string) $file; … … 164 193 $newVersion = (string) ($transient->response[$plugin]->new_version ?? ''); 165 194 195 // Une extension a la racine (`hello.php`) n'a pas de repertoire propre. 196 if (str_contains($plugin, '/')) { 197 $this->assertReplaceable(dirname(WP_PLUGIN_DIR . '/' . $plugin)); 198 } 199 166 200 if ($rollbackOnError) { 167 201 $this->snapshot(dirname(WP_PLUGIN_DIR . '/' . $plugin), $this->rollbackPath('plugin', $slug, $oldVersion)); 168 202 } 203 // A partir d'ici, WordPress touche aux fichiers du composant. 204 $this->upgradeStarted = true; 169 205 170 206 $skin = new \WP_Ajax_Upgrader_Skin(); … … 193 229 $newVersion = (string) ($transient->response[$slug]['new_version'] ?? ''); 194 230 231 $this->assertReplaceable(get_theme_root() . '/' . $slug); 232 195 233 if ($rollbackOnError) { 196 234 $this->snapshot(get_theme_root() . '/' . $slug, $this->rollbackPath('theme', $slug, $oldVersion)); 197 235 } 236 // A partir d'ici, WordPress touche aux fichiers du composant. 237 $this->upgradeStarted = true; 198 238 199 239 $skin = new \WP_Ajax_Upgrader_Skin(); … … 344 384 345 385 $aside = null; 386 $journal = $this->swapJournal(); 346 387 if (file_exists($target)) { 347 $aside = $target . '.sentinelo-aside-' . bin2hex(random_bytes(4)); 388 $aside = $target . self::ASIDE_MARKER . bin2hex(random_bytes(4)); 389 390 // Inscrit AVANT d'ecarter : un processus tue entre l'ecartement et la mise 391 // en place ne laisse que ce journal, relu au demarrage pour remettre le 392 // vivant a sa place. Sans lui, on refuse — rien n'a encore bouge. 393 if (!$journal->begin($target, $aside, $backupDir, time())) { 394 $this->logger('Retour arriere refuse : journal d\'echange impossible a ecrire (' . $journal->file() . ') ; rien n\'a ete modifie.'); 395 396 return false; 397 } 398 348 399 if (!@rename($target, $aside)) { 400 $journal->end($aside); 349 401 $this->logger('Retour arriere refuse : impossible d\'ecarter ' . $target . ' ; rien n\'a ete modifie.'); 350 402 … … 359 411 $placed = $renamed; 360 412 if (!$renamed) { 413 if (null !== $aside) { 414 $journal->mark($aside, SwapJournal::PHASE_COPYING); 415 } 361 416 try { 362 417 $this->recursiveCopy($backupDir, $target); … … 379 434 if (null !== $aside) { 380 435 @rename($aside, $target); 436 if (is_dir($aside)) { 437 // Le vivant n'a pas pu revenir : l'inscription reste, la reprise 438 // au demarrage retentera. 439 $journal->postpone($aside, time()); 440 $this->logger('Retour arriere impossible ET vivant non remis en place : ' . $aside . ' ; reprise au prochain demarrage.'); 441 442 return false; 443 } 444 $journal->end($aside); 381 445 } 382 446 $this->logger('Retour arriere impossible : la copie n\'a pas pu etre mise en place ; version courante conservee.'); … … 386 450 387 451 if (null !== $aside) { 388 $this->recursiveDelete($aside); 452 $journal->mark($aside, SwapJournal::PHASE_PLACED); 453 if ($this->recursiveDelete($aside)) { 454 $journal->end($aside); 455 } else { 456 // La copie est en place : le retour arriere a reussi. Mais l'ancien dossier 457 // reste sur le disque, et il ressemble a un composant. On le DIT, on garde 458 // l'inscription pour retenter au demarrage, et l'inventaire l'ignore 459 // (AsideFolder) en attendant. Le taire est ce qui a coute api.auramur.fr. 460 $journal->postpone($aside, time()); 461 $this->logger('Retour arriere effectue, mais l\'ancien dossier mis de cote n\'a pas pu etre efface : ' 462 . $aside . ' (fichiers non modifiables par PHP). Nouvelle tentative au prochain demarrage.'); 463 } 389 464 } 390 465 if (!$renamed) { … … 393 468 394 469 return true; 470 } 471 472 /** 473 * Repare un echange interrompu — ecarte puis jamais remis — au demarrage de l'agent. 474 * 475 * Branche sur CHAQUE requete WordPress ({@see \Sentinelo\Core\Plugin::init()}) : un 476 * site dont une extension vient de disparaitre ne sera pas reparé par la plateforme, 477 * qui ne voit rien de ce qui manque. Cas ordinaire : un `is_file()`. Ne leve jamais. 478 */ 479 public static function recoverInterruptedSwaps(): void 480 { 481 try { 482 $installer = new self(); 483 if ($installer->swapJournal()->isEmpty()) { 484 return; 485 } 486 $roots = [WP_PLUGIN_DIR]; 487 if (function_exists('get_theme_root')) { 488 $roots[] = get_theme_root(); 489 } 490 $installer->recoverSwaps(time(), $roots); 491 } catch (\Throwable $e) { 492 Logger::error('update', 'Reprise d\'un echange interrompu impossible : ' . $e->getMessage()); 493 } 494 } 495 496 /** 497 * @param list<string> $allowedRoots Seuls repertoires sous lesquels on renomme quoi que ce soit. 498 */ 499 private function recoverSwaps(int $now, array $allowedRoots): void 500 { 501 $journal = $this->swapJournal(); 502 503 foreach ($journal->entries() as $entry) { 504 $target = $entry['target']; 505 $aside = $entry['aside']; 506 $backupDir = $entry['backup']; 507 508 // Le journal est un fichier sur disque : on ne renomme que ce qui a 509 // exactement la forme que swapIn() produit, sous une racine connue. 510 if (!$this->isRecoverableShape($target, $aside, $allowedRoots)) { 511 Logger::error('update', 'Echange interrompu ignore (chemins inattendus) : ' . $aside); 512 $journal->end($aside); 513 continue; 514 } 515 516 // Peut-etre en cours dans un autre processus : y toucher le casserait. 517 if ($now - $entry['since'] < SwapJournal::STALE_AFTER_SECONDS) { 518 continue; 519 } 520 521 // Rien n'a ete ecarte, ou quelqu'un l'a deja remis en place a la main. 522 if (!is_dir($aside)) { 523 $journal->end($aside); 524 continue; 525 } 526 527 // La copie etait en place et verifiee : seul l'effacement de l'ecarte manque. 528 if (SwapJournal::PHASE_PLACED === $entry['phase'] && $this->countFiles($target) > 0) { 529 if ($this->recursiveDelete($aside)) { 530 $journal->end($aside); 531 Logger::info('update', 'Echange interrompu termine : ' . $target . ' etait en place, ecarte efface.'); 532 } else { 533 $journal->postpone($aside, $now); 534 Logger::warning('update', 'Ancien dossier toujours impossible a effacer (fichiers non modifiables par PHP) : ' . $aside . '.'); 535 } 536 continue; 537 } 538 539 if (file_exists($target)) { 540 if (SwapJournal::PHASE_COPYING === $entry['phase']) { 541 // Une copie partielle ; l'instantane, lui, est intact a sa place. 542 $this->recursiveDelete($target); 543 } elseif (!file_exists($backupDir)) { 544 // rename(instantane -> cible) avait eu lieu : on rend l'instantane. 545 @rename($target, $backupDir); 546 } 547 } 548 549 if (file_exists($target)) { 550 // Quelque chose qu'on n'a pas pose occupe la place : on ne l'ecrase pas, 551 // et on ne retente pas a chaque requete. L'ecarte reste sur le disque. 552 $journal->end($aside); 553 Logger::error('update', 'Echange interrompu non repare : ' . $target . ' est occupe ; ' . $aside . ' laisse en place.'); 554 continue; 555 } 556 557 if (@rename($aside, $target)) { 558 $journal->end($aside); 559 Logger::warning('update', 'Echange interrompu repare : ' . $target . ' remis en place depuis ' . $aside . '.'); 560 } else { 561 $journal->postpone($aside, $now); 562 Logger::error('update', 'Echange interrompu : impossible de remettre ' . $aside . ' a sa place ; nouvelle tentative plus tard.'); 563 } 564 } 565 } 566 567 /** @param list<string> $allowedRoots */ 568 private function isRecoverableShape(string $target, string $aside, array $allowedRoots): bool 569 { 570 $marker = preg_quote(self::ASIDE_MARKER, '/'); 571 if (1 !== preg_match('/^' . preg_quote($target, '/') . $marker . '[0-9a-f]{8}$/', $aside)) { 572 return false; 573 } 574 575 $parent = rtrim(str_replace('\\', '/', dirname($target)), '/'); 576 foreach ($allowedRoots as $root) { 577 if ('' !== $root && rtrim(str_replace('\\', '/', $root), '/') === $parent) { 578 return true; 579 } 580 } 581 582 return false; 583 } 584 585 private function swapJournal(): SwapJournal 586 { 587 return new SwapJournal($this->swapJournalFile ?? SENTINELO_UPDATE_SNAPSHOT_DIR . '.swap-journal.json'); 395 588 } 396 589 … … 641 834 } 642 835 643 private function recursiveDelete(string $dir): void 836 /** 837 * Efface un repertoire et dit s'il a REELLEMENT disparu. 838 * 839 * `unlink()` et `rmdir()` ne levent pas : sur un fichier qui appartient a un autre 840 * utilisateur que PHP, ils rendent `false` avec un simple avertissement. Ignorer ce 841 * retour a laisse sur api.auramur.fr un ancien dossier d'extension que l'agent 842 * croyait efface (19 novembre 2026), et tout le reste en a decoule. 843 * 844 * Chemin du lien, jamais sa cible : `getRealPath()` sur un lien symbolique 845 * effacerait le fichier vise, hors du repertoire a effacer. 846 */ 847 private function recursiveDelete(string $dir): bool 644 848 { 645 849 if (!is_dir($dir)) { 646 return ;850 return true; 647 851 } 648 852 $items = new \RecursiveIteratorIterator( … … 650 854 \RecursiveIteratorIterator::CHILD_FIRST 651 855 ); 856 $complete = true; 652 857 foreach ($items as $item) { 653 $item->isDir() ? rmdir($item->getRealPath()) : unlink($item->getRealPath()); 654 } 655 rmdir($dir); 858 $path = $item->getPathname(); 859 $done = ($item->isDir() && !$item->isLink()) ? @rmdir($path) : @unlink($path); 860 $complete = $complete && $done; 861 } 862 863 return @rmdir($dir) && $complete; 864 } 865 866 /** 867 * Refuse une mise a jour que WordPress ne pourrait pas mener a terme. 868 * 869 * Le remplacement d'un composant efface ses fichiers, ce qui demande d'ecrire dans 870 * CHAQUE repertoire de son arbre (et dans son parent). Sur api.auramur.fr, les dossiers 871 * appartenaient a `ubuntu` quand PHP tournait sous un autre utilisateur : la mise a 872 * jour echouait a mi-chemin, puis le retour arriere echouait a son tour. Refuser avant 873 * de commencer ne coute rien et nomme la cause. 874 */ 875 private function assertReplaceable(string $dir): void 876 { 877 $blocked = $this->firstUnwritableDirectory($dir); 878 if (null === $blocked) { 879 return; 880 } 881 882 $uid = @fileowner($blocked); 883 $owner = false === $uid ? '?' : (string) $uid; 884 if (false !== $uid && function_exists('posix_getpwuid')) { 885 $info = @posix_getpwuid($uid); 886 if (is_array($info) && isset($info['name'])) { 887 $owner = $info['name']; 888 } 889 } 890 891 throw new \RuntimeException(sprintf( 892 'Mise à jour refusée avant de commencer : PHP ne peut pas modifier %s (propriétaire : %s). ' 893 . 'WordPress ne pourrait pas remplacer ces fichiers. Donnez ce dossier à l\'utilisateur du serveur web, puis relancez. ' 894 . 'Rien n\'a été modifié.', 895 $blocked, 896 $owner 897 )); 898 } 899 900 private function firstUnwritableDirectory(string $dir): ?string 901 { 902 if (!is_dir($dir)) { 903 return null; // Le composant introuvable a sa propre erreur, plus loin. 904 } 905 if (!is_writable(dirname($dir))) { 906 return dirname($dir); 907 } 908 if (!is_writable($dir)) { 909 return $dir; 910 } 911 foreach ($this->walkFiles($dir) as $item) { 912 if ($item->isDir() && !$item->isLink() && !is_writable($item->getPathname())) { 913 return $item->getPathname(); 914 } 915 } 916 917 return null; 656 918 } 657 919 -
sentinelo/trunk/src/Api/Endpoints/UpdateEndpoint.php
r3773060 r3833943 122 122 } else { 123 123 $failCount++; 124 // La cause, pas seulement le compte : `failed=1` seul n'a rien appris de 125 // dix nuits d'echecs sur api.auramur.fr. 126 Logger::warning('update_endpoint', "Failed {$type}: {$slug} — " . ($outcome->error ?? 'cause inconnue') 127 . ($outcome->rolledBack ? ' (revenu en arrière)' : '') 128 . (null !== $outcome->rollbackError ? ' ; retour arrière : ' . $outcome->rollbackError : '')); 124 129 if ($outcome->rolledBack) { 125 130 $rollbackCount++; -
sentinelo/trunk/src/Core/Plugin.php
r3786219 r3833943 43 43 // quelqu'un le lira encore. Coût ordinaire : un `is_file()`. 44 44 \Sentinelo\Backup\AttachmentJournal::recoverQuietly(); 45 46 // Même raison, autre geste : un retour arrière tué entre l'écartement d'une 47 // extension et la mise en place de sa copie laisse le site SANS cette extension 48 // (28 novembre 2026 : l'extension JWT, plus aucune connexion possible). Le 49 // journal posé avant l'écartement permet de la remettre. Coût ordinaire : un 50 // `is_file()`. 51 \Sentinelo\Adapter\Wp\WpPackageInstaller::recoverInterruptedSwaps(); 45 52 46 53 // Add custom cron interval -
sentinelo/trunk/src/Core/PostUpdatePreload.php
r3796462 r3833943 47 47 \Sentinelo\AgentCore\Port\UpdatesNotSupported::class, 48 48 \Sentinelo\Adapter\Wp\WpPackageInstaller::class, 49 \Sentinelo\Adapter\Wp\SwapJournal::class, 50 \Sentinelo\Adapter\Wp\AsideFolder::class, 49 51 \Sentinelo\Adapter\Wp\UpdateOfferMemory::class, 50 52 \Sentinelo\Adapter\Wp\PackageDownloadRefused::class, -
sentinelo/trunk/vendor/composer/autoload_classmap.php
r3800466 r3833943 8 8 return array( 9 9 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', 10 'Sentinelo\\Adapter\\Wp\\AsideFolder' => $baseDir . '/src/Adapter/Wp/AsideFolder.php', 10 11 'Sentinelo\\Adapter\\Wp\\PackageDownloadRefused' => $baseDir . '/src/Adapter/Wp/PackageDownloadRefused.php', 12 'Sentinelo\\Adapter\\Wp\\SwapJournal' => $baseDir . '/src/Adapter/Wp/SwapJournal.php', 11 13 'Sentinelo\\Adapter\\Wp\\UpdateOfferMemory' => $baseDir . '/src/Adapter/Wp/UpdateOfferMemory.php', 12 14 'Sentinelo\\Adapter\\Wp\\WpAuditRepository' => $baseDir . '/src/Adapter/Wp/WpAuditRepository.php', -
sentinelo/trunk/vendor/composer/autoload_static.php
r3800466 r3833943 28 28 public static $classMap = array ( 29 29 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', 30 'Sentinelo\\Adapter\\Wp\\AsideFolder' => __DIR__ . '/../..' . '/src/Adapter/Wp/AsideFolder.php', 30 31 'Sentinelo\\Adapter\\Wp\\PackageDownloadRefused' => __DIR__ . '/../..' . '/src/Adapter/Wp/PackageDownloadRefused.php', 32 'Sentinelo\\Adapter\\Wp\\SwapJournal' => __DIR__ . '/../..' . '/src/Adapter/Wp/SwapJournal.php', 31 33 'Sentinelo\\Adapter\\Wp\\UpdateOfferMemory' => __DIR__ . '/../..' . '/src/Adapter/Wp/UpdateOfferMemory.php', 32 34 'Sentinelo\\Adapter\\Wp\\WpAuditRepository' => __DIR__ . '/../..' . '/src/Adapter/Wp/WpAuditRepository.php', -
sentinelo/trunk/vendor/composer/installed.php
r3807487 r3833943 2 2 'root' => array( 3 3 'name' => 'sentinelo/sentinelo', 4 'pretty_version' => ' dev-main',5 'version' => ' dev-main',6 'reference' => 'dfe82c036b04a49b35eeb6f3eacf08397252577f',4 'pretty_version' => '1.0.0+no-version-set', 5 'version' => '1.0.0.0', 6 'reference' => null, 7 7 'type' => 'wordpress-plugin', 8 8 'install_path' => __DIR__ . '/../../', … … 21 21 ), 22 22 'sentinelo/sentinelo' => array( 23 'pretty_version' => ' dev-main',24 'version' => ' dev-main',25 'reference' => 'dfe82c036b04a49b35eeb6f3eacf08397252577f',23 'pretty_version' => '1.0.0+no-version-set', 24 'version' => '1.0.0.0', 25 'reference' => null, 26 26 'type' => 'wordpress-plugin', 27 27 'install_path' => __DIR__ . '/../../',
Note:
See TracChangeset
for help on using the changeset viewer.