From 907b27c94af64a1402e2f164dc875508437633e9 Mon Sep 17 00:00:00 2001 From: Matthias Gutjahr Date: Sat, 24 Aug 2019 16:53:01 +0200 Subject: [PATCH] Improve handling of failed integrity checks (#104) * [event_autoupdate] Add option to disable file integrity checks for one run of the auto updater. Signed-off-by: Matthias Gutjahr * [event_autoupdate] Add button to retry auto update without integrity checks after failure Signed-off-by: Matthias Gutjahr * [event_autoupdate] Remove wrong return statement Signed-off-by: Matthias Gutjahr * [event_autoupdate] Repeat file integrity check for text files that were treated as binary files in S9y versions < 2.3 Signed-off-by: Matthias Gutjahr * Automagic XML sync * [event_autoupdate] Show error message and list of files with wrong checksum Signed-off-by: Matthias Gutjahr --- serendipity_event_autoupdate/ChangeLog | 3 ++ .../UTF-8/lang_de.inc.php | 1 + .../UTF-8/lang_en.inc.php | 1 + serendipity_event_autoupdate/lang_de.inc.php | 1 + serendipity_event_autoupdate/lang_en.inc.php | 3 +- .../serendipity_event_autoupdate.php | 38 +++++++++---------- 6 files changed, 26 insertions(+), 21 deletions(-) diff --git a/serendipity_event_autoupdate/ChangeLog b/serendipity_event_autoupdate/ChangeLog index 7a0ccf17..51426ccb 100644 --- a/serendipity_event_autoupdate/ChangeLog +++ b/serendipity_event_autoupdate/ChangeLog @@ -1,3 +1,6 @@ +1.1.10: Repeat file integrity check for text files that were treated as binary + files in S9y versions < 2.3 + 1.1.9: Add config setting 'disable_integrity_checks' to disable file integrity checks for one run (see https://board.s9y.org/viewtopic.php?f=1&t=24492) diff --git a/serendipity_event_autoupdate/UTF-8/lang_de.inc.php b/serendipity_event_autoupdate/UTF-8/lang_de.inc.php index 1a2cc889..b5bf940a 100644 --- a/serendipity_event_autoupdate/UTF-8/lang_de.inc.php +++ b/serendipity_event_autoupdate/UTF-8/lang_de.inc.php @@ -3,6 +3,7 @@ @define('PLUGIN_EVENT_AUTOUPDATE_NAME', 'Serendipity Autoupdate'); @define('PLUGIN_EVENT_AUTOUPDATE_DESC', 'Sobald das Dashboard Plugin (einmal am Tag) ein Serendipity Update entdeckt, setzt dieses Plugin eine Ein-Klick Option in das Dashboard des Backends, um ein manuelles Download oder ein automatisches und gesichertes Upgrade der Blogsoftware zu starten.'); @define('PLUGIN_EVENT_AUTOUPDATE_UPDATEBUTTON', 'Automatisches Upgrade starten'); +@define('PLUGIN_EVENT_AUTOUPDATE_ERROR_INTEGRITY_CHECKS', 'Upgrade nicht erfolgreich, weil die Integritätsprüfung für folgende Dateien fehlgeschlagen ist:'); @define('PLUGIN_EVENT_AUTOUPDATE_DISABLE_INTEGRITY_CHECKS', 'Deaktiviere Integritätsprüfung (ACHTUNG!)'); @define( 'PLUGIN_EVENT_AUTOUPDATE_DISABLE_INTEGRITY_CHECKS_DESC', diff --git a/serendipity_event_autoupdate/UTF-8/lang_en.inc.php b/serendipity_event_autoupdate/UTF-8/lang_en.inc.php index 5415f700..edaf2443 100644 --- a/serendipity_event_autoupdate/UTF-8/lang_en.inc.php +++ b/serendipity_event_autoupdate/UTF-8/lang_en.inc.php @@ -3,6 +3,7 @@ @define('PLUGIN_EVENT_AUTOUPDATE_NAME', 'Serendipity Autoupdate'); @define('PLUGIN_EVENT_AUTOUPDATE_DESC', 'When the dashboard-plugin (once a day) detects an update, this plugin adds the option to manually download or start an automatic and secured upgrade of the blog directly with one click from within the adminarea.'); @define('PLUGIN_EVENT_AUTOUPDATE_UPDATEBUTTON', 'Start automatic upgrade'); +@define('PLUGIN_EVENT_AUTOUPDATE_ERROR_INTEGRITY_CHECKS', 'Updating failed, because the integrity-test for the following files failed:'); @define('PLUGIN_EVENT_AUTOUPDATE_DISABLE_INTEGRITY_CHECKS', 'Disable integrity checks (CAUTION!)'); @define( 'PLUGIN_EVENT_AUTOUPDATE_DISABLE_INTEGRITY_CHECKS_DESC', diff --git a/serendipity_event_autoupdate/lang_de.inc.php b/serendipity_event_autoupdate/lang_de.inc.php index 1a2cc889..b5bf940a 100644 --- a/serendipity_event_autoupdate/lang_de.inc.php +++ b/serendipity_event_autoupdate/lang_de.inc.php @@ -3,6 +3,7 @@ @define('PLUGIN_EVENT_AUTOUPDATE_NAME', 'Serendipity Autoupdate'); @define('PLUGIN_EVENT_AUTOUPDATE_DESC', 'Sobald das Dashboard Plugin (einmal am Tag) ein Serendipity Update entdeckt, setzt dieses Plugin eine Ein-Klick Option in das Dashboard des Backends, um ein manuelles Download oder ein automatisches und gesichertes Upgrade der Blogsoftware zu starten.'); @define('PLUGIN_EVENT_AUTOUPDATE_UPDATEBUTTON', 'Automatisches Upgrade starten'); +@define('PLUGIN_EVENT_AUTOUPDATE_ERROR_INTEGRITY_CHECKS', 'Upgrade nicht erfolgreich, weil die Integritätsprüfung für folgende Dateien fehlgeschlagen ist:'); @define('PLUGIN_EVENT_AUTOUPDATE_DISABLE_INTEGRITY_CHECKS', 'Deaktiviere Integritätsprüfung (ACHTUNG!)'); @define( 'PLUGIN_EVENT_AUTOUPDATE_DISABLE_INTEGRITY_CHECKS_DESC', diff --git a/serendipity_event_autoupdate/lang_en.inc.php b/serendipity_event_autoupdate/lang_en.inc.php index 8412b8e2..edaf2443 100644 --- a/serendipity_event_autoupdate/lang_en.inc.php +++ b/serendipity_event_autoupdate/lang_en.inc.php @@ -3,7 +3,8 @@ @define('PLUGIN_EVENT_AUTOUPDATE_NAME', 'Serendipity Autoupdate'); @define('PLUGIN_EVENT_AUTOUPDATE_DESC', 'When the dashboard-plugin (once a day) detects an update, this plugin adds the option to manually download or start an automatic and secured upgrade of the blog directly with one click from within the adminarea.'); @define('PLUGIN_EVENT_AUTOUPDATE_UPDATEBUTTON', 'Start automatic upgrade'); -@define('PLUGIN_EVENT_AUTOUPDATE_DISABLE_INTEGRITY_CHECKS', 'Disable integrity casdf hecks (CAUTION!)'); +@define('PLUGIN_EVENT_AUTOUPDATE_ERROR_INTEGRITY_CHECKS', 'Updating failed, because the integrity-test for the following files failed:'); +@define('PLUGIN_EVENT_AUTOUPDATE_DISABLE_INTEGRITY_CHECKS', 'Disable integrity checks (CAUTION!)'); @define( 'PLUGIN_EVENT_AUTOUPDATE_DISABLE_INTEGRITY_CHECKS_DESC', 'This setting disables the file integrity checks for one run of the auto updater. It will be automatically reset to `No` after the update.' diff --git a/serendipity_event_autoupdate/serendipity_event_autoupdate.php b/serendipity_event_autoupdate/serendipity_event_autoupdate.php index c420198e..c9b9c3ba 100644 --- a/serendipity_event_autoupdate/serendipity_event_autoupdate.php +++ b/serendipity_event_autoupdate/serendipity_event_autoupdate.php @@ -22,7 +22,7 @@ class serendipity_event_autoupdate extends serendipity_event { $propbag->add('description', PLUGIN_EVENT_AUTOUPDATE_DESC); $propbag->add('stackable', false); $propbag->add('author', 'onli, Ian'); - $propbag->add('version', '1.1.9'); + $propbag->add('version', '1.1.10'); $propbag->add('requirements', array( 'serendipity' => '0.8', 'php' => '5.2' @@ -580,56 +580,54 @@ EOS; function checkIntegrity($version) { global $serendipity; - $updateDir = (string)$serendipity['serendipityPath'] . 'templates_c/' . "serendipity-$version/"; - $checksumFile = (string)$updateDir . "serendipity/checksums.inc.php"; - - if (strpos($version, 'beta') !== FALSE) { + if (strpos($version, 'beta') !== false) { return true; } + $updateDir = $serendipity['serendipityPath'] . 'templates_c/' . "serendipity-$version/"; + $checksumFile = $updateDir .'serendipity/checksums.inc.php'; include_once $checksumFile; $checksums = $serendipity['checksums_' . $version]; foreach ($checksums as $file => $checksum) { - $check = serendipity_FTPChecksum($updateDir . "serendipity/" . $file); - if ($checksum != $check) { + $path = $updateDir.'serendipity/'.$file; + if ($checksum !== serendipity_FTPChecksum($path) && $checksum !== serendipity_FTPChecksum($path, 'text')) { return false; } } + return true; } /** - * checks updates checksum file array with updates realfiles + * shows error message and list of files with wrong checksum * @param string version - * @return error + * @return void */ function showChecksumErrors($version) { global $serendipity; - $updateDir = (string)$serendipity['serendipityPath'] . 'templates_c/' . "serendipity-$version/"; - $checksumFile = (string)$updateDir . "serendipity/checksums.inc.php"; - + $updateDir = $serendipity['serendipityPath'] . 'templates_c/' . "serendipity-$version/"; + $checksumFile = $updateDir .'serendipity/checksums.inc.php'; include_once $checksumFile; $checksums = $serendipity['checksums_' . $version]; $errors = array(); foreach ($checksums as $file => $checksum) { - $check = serendipity_FTPChecksum($updateDir . "serendipity/" . $file); - if ($checksum != $check) { - $errors[] = $updateDir . "serendipity/" . $file; + $path = $updateDir.'serendipity/'.$file; + if ($checksum !== serendipity_FTPChecksum($path) && $checksum !== serendipity_FTPChecksum($path, 'text')) { + $errors[] = $path; } } ob_start(); - echo '

Updating failed, because the integrity-test for the following files failed:

'; - echo "
    "; + echo '

    '.PLUGIN_EVENT_AUTOUPDATE_ERROR_INTEGRITY_CHECKS.'

    '; + echo '
      '; foreach ($errors as $file) { echo "
    • $file
    • "; } - echo "
    "; - $integrity_error = ob_get_contents(); - ob_end_clean(); + echo '
'; + $integrity_error = ob_get_clean(); $this->show_message($integrity_error); }