diff options
author | Matthieu Napoli <matthieu@mnapoli.fr> | 2015-03-14 09:33:54 +0300 |
---|---|---|
committer | Matthieu Napoli <matthieu@mnapoli.fr> | 2015-03-16 00:37:33 +0300 |
commit | a69a60587bf5776c98d8b8a94ac3f62e8b8ef823 (patch) | |
tree | 9a4fe09384fd54e43cd1a54736cb83c69e4f1a9a /plugins | |
parent | 3f2d8e0bdcd62887dfa800c5391954f26bb98871 (diff) |
ref #6441 When Piwik fails to update over HTTPS, offer the user the possibility to update over HTTP
Diffstat (limited to 'plugins')
20 files changed, 129 insertions, 46 deletions
diff --git a/plugins/CoreUpdater/ArchiveDownloadException.php b/plugins/CoreUpdater/ArchiveDownloadException.php new file mode 100644 index 0000000000..0b68f30c18 --- /dev/null +++ b/plugins/CoreUpdater/ArchiveDownloadException.php @@ -0,0 +1,22 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\CoreUpdater; + +use Exception; + +/** + * Error while downloading the archive. + */ +class ArchiveDownloadException extends UpdaterException +{ + public function __construct(Exception $exception) + { + parent::__construct($exception, array()); + } +} diff --git a/plugins/CoreUpdater/Controller.php b/plugins/CoreUpdater/Controller.php index be860af8bd..49cb1080a2 100644 --- a/plugins/CoreUpdater/Controller.php +++ b/plugins/CoreUpdater/Controller.php @@ -80,28 +80,32 @@ class Controller extends \Piwik\Plugin\Controller { Piwik::checkUserHasSuperUserAccess(); + $view = new OneClickDone(Piwik::getCurrentUserTokenAuth()); + + $useHttps = Common::getRequestVar('https', 1, 'int'); + try { - $messages = $this->updater->updatePiwik(); - $errorMessage = false; + $messages = $this->updater->updatePiwik($useHttps); + } catch (ArchiveDownloadException $e) { + $view->httpsFail = $useHttps; + $view->error = $e->getMessage(); + $messages = $e->getUpdateLogMessages(); } catch (UpdaterException $e) { - $errorMessage = $e->getMessage(); + $view->error = $e->getMessage(); $messages = $e->getUpdateLogMessages(); } - $view = new OneClickDone(Piwik::getCurrentUserTokenAuth()); - $view->coreError = $errorMessage; $view->feedbackMessages = $messages; - $this->addCustomLogoInfo($view); - return $view->render(); } public function oneClickResults() { $view = new View('@CoreUpdater/oneClickResults'); - $view->coreError = Common::getRequestVar('error', '', 'string', $_POST); + $view->error = Common::getRequestVar('error', '', 'string', $_POST); $view->feedbackMessages = safe_unserialize(Common::unsanitizeInputValue(Common::getRequestVar('messages', '', 'string', $_POST))); + $view->httpsFail = (bool) Common::getRequestVar('httpsFail', 0, 'int', $_POST); $this->addCustomLogoInfo($view); return $view->render(); } diff --git a/plugins/CoreUpdater/tests/Fixtures/DbUpdaterTestFixture.php b/plugins/CoreUpdater/Test/Fixtures/DbUpdaterTestFixture.php index 0a4b0ceaa6..89a29126f2 100644 --- a/plugins/CoreUpdater/tests/Fixtures/DbUpdaterTestFixture.php +++ b/plugins/CoreUpdater/Test/Fixtures/DbUpdaterTestFixture.php @@ -6,7 +6,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Plugins\CoreUpdater\Tests\Fixtures; +namespace Piwik\Plugins\CoreUpdater\Test\Fixtures; use Piwik\Tests\Fixtures\SqlDump; diff --git a/plugins/CoreUpdater/tests/Fixtures/FailUpdateHttpsFixture.php b/plugins/CoreUpdater/Test/Fixtures/FailUpdateHttpsFixture.php index 13b8868eaa..5060c99320 100644 --- a/plugins/CoreUpdater/tests/Fixtures/FailUpdateHttpsFixture.php +++ b/plugins/CoreUpdater/Test/Fixtures/FailUpdateHttpsFixture.php @@ -6,7 +6,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Plugins\CoreUpdater\Tests\Fixtures; +namespace Piwik\Plugins\CoreUpdater\Test\Fixtures; use Piwik\Tests\Framework\Fixture; @@ -18,7 +18,7 @@ class FailUpdateHttpsFixture extends Fixture public function provideContainerConfig() { return array( - 'Piwik\Plugins\CoreUpdater\Updater' => \DI\object('Piwik\Plugins\CoreUpdater\tests\Mock\UpdaterMock'), + 'Piwik\Plugins\CoreUpdater\Updater' => \DI\object('Piwik\Plugins\CoreUpdater\Test\Mock\UpdaterMock'), ); } } diff --git a/plugins/CoreUpdater/tests/Integration/UpdateCommunicationTest.php b/plugins/CoreUpdater/Test/Integration/UpdateCommunicationTest.php index 91b6e2c2a1..6ec5fdaf83 100644 --- a/plugins/CoreUpdater/tests/Integration/UpdateCommunicationTest.php +++ b/plugins/CoreUpdater/Test/Integration/UpdateCommunicationTest.php @@ -6,7 +6,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Plugins\CoreUpdater\tests; +namespace Piwik\Plugins\CoreUpdater\Test; use Piwik\Config; use Piwik\Option; diff --git a/plugins/CoreUpdater/tests/Mock/UpdaterMock.php b/plugins/CoreUpdater/Test/Mock/UpdaterMock.php index e1eaee61a1..7a73129c5b 100644 --- a/plugins/CoreUpdater/tests/Mock/UpdaterMock.php +++ b/plugins/CoreUpdater/Test/Mock/UpdaterMock.php @@ -6,10 +6,10 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Plugins\CoreUpdater\tests\Mock; +namespace Piwik\Plugins\CoreUpdater\Test\Mock; +use Piwik\Plugins\CoreUpdater\ArchiveDownloadException; use Piwik\Plugins\CoreUpdater\Updater; -use Piwik\Plugins\CoreUpdater\UpdaterException; use Piwik\Translation\Translator; class UpdaterMock extends Updater @@ -38,7 +38,9 @@ class UpdaterMock extends Updater { // Simulate that the update over HTTPS fails if ($https) { - throw new UpdaterException(new \Exception('Error while downloading Piwik'), array()); + // The actual error message depends on the OS, the HTTP method etc. + // This is what I get on my machine, but it doesn't really matter + throw new ArchiveDownloadException(new \Exception('curl_exec: SSL certificate problem: Invalid certificate chain. Hostname requested was: piwik.org'), array()); } // Simulate that the update over HTTP succeeds diff --git a/plugins/CoreUpdater/tests/UI/DbUpdater_spec.js b/plugins/CoreUpdater/Test/UI/DbUpdater_spec.js index d21fd3a0d0..54a3e8305a 100644 --- a/plugins/CoreUpdater/tests/UI/DbUpdater_spec.js +++ b/plugins/CoreUpdater/Test/UI/DbUpdater_spec.js @@ -10,7 +10,7 @@ describe("DbUpdater", function () { this.timeout(0); - this.fixture = "Piwik\\Plugins\\CoreUpdater\\Tests\\Fixtures\\DbUpdaterTestFixture"; + this.fixture = "Piwik\\Plugins\\CoreUpdater\\Test\\Fixtures\\DbUpdaterTestFixture"; before(function () { testEnvironment.tablesPrefix = 'piwik_'; diff --git a/plugins/CoreUpdater/Test/UI/PiwikUpdater_spec.js b/plugins/CoreUpdater/Test/UI/PiwikUpdater_spec.js new file mode 100644 index 0000000000..0e0e52f433 --- /dev/null +++ b/plugins/CoreUpdater/Test/UI/PiwikUpdater_spec.js @@ -0,0 +1,34 @@ +/*! + * Piwik - free/libre analytics platform + * + * Installation screenshot tests. + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +describe("PiwikUpdater", function () { + this.timeout(0); + + this.fixture = "Piwik\\Plugins\\CoreUpdater\\Test\\Fixtures\\FailUpdateHttpsFixture"; + + var url = "?module=CoreUpdater&action=newVersionAvailable"; + + it("should show a new version is available", function (done) { + expect.screenshot("newVersion").to.be.capture(function (page) { + page.load(url); + }, done); + }); + + it("should offer to update over http when updating over https fails", function (done) { + expect.screenshot("httpsUpdateFail").to.be.capture(function (page) { + page.click('#updateAutomatically'); + }, done); + }); + + it("should show the update steps when updating over http succeeds", function (done) { + expect.screenshot("httpUpdateSuccess").to.be.capture(function (page) { + page.click('#updateUsingHttp'); + }, done); + }); +}); diff --git a/plugins/CoreUpdater/tests/UI/expected-ui-screenshots/DbUpdater_main.png b/plugins/CoreUpdater/Test/UI/expected-ui-screenshots/DbUpdater_main.png Binary files differindex dcf2f0a3ef..dcf2f0a3ef 100644 --- a/plugins/CoreUpdater/tests/UI/expected-ui-screenshots/DbUpdater_main.png +++ b/plugins/CoreUpdater/Test/UI/expected-ui-screenshots/DbUpdater_main.png diff --git a/plugins/CoreUpdater/tests/UI/expected-ui-screenshots/DbUpdater_updated.png b/plugins/CoreUpdater/Test/UI/expected-ui-screenshots/DbUpdater_updated.png Binary files differindex 2210de345e..2210de345e 100644 --- a/plugins/CoreUpdater/tests/UI/expected-ui-screenshots/DbUpdater_updated.png +++ b/plugins/CoreUpdater/Test/UI/expected-ui-screenshots/DbUpdater_updated.png diff --git a/plugins/CoreUpdater/Test/UI/expected-ui-screenshots/PiwikUpdater_httpUpdateSuccess.png b/plugins/CoreUpdater/Test/UI/expected-ui-screenshots/PiwikUpdater_httpUpdateSuccess.png Binary files differnew file mode 100644 index 0000000000..9854feef8d --- /dev/null +++ b/plugins/CoreUpdater/Test/UI/expected-ui-screenshots/PiwikUpdater_httpUpdateSuccess.png diff --git a/plugins/CoreUpdater/Test/UI/expected-ui-screenshots/PiwikUpdater_httpsUpdateFail.png b/plugins/CoreUpdater/Test/UI/expected-ui-screenshots/PiwikUpdater_httpsUpdateFail.png Binary files differnew file mode 100644 index 0000000000..61286650b2 --- /dev/null +++ b/plugins/CoreUpdater/Test/UI/expected-ui-screenshots/PiwikUpdater_httpsUpdateFail.png diff --git a/plugins/CoreUpdater/tests/UI/expected-ui-screenshots/PiwikUpdater_newVersion.png b/plugins/CoreUpdater/Test/UI/expected-ui-screenshots/PiwikUpdater_newVersion.png Binary files differindex 483dde95f8..483dde95f8 100644 --- a/plugins/CoreUpdater/tests/UI/expected-ui-screenshots/PiwikUpdater_newVersion.png +++ b/plugins/CoreUpdater/Test/UI/expected-ui-screenshots/PiwikUpdater_newVersion.png diff --git a/plugins/CoreUpdater/tests/Unit/ModelTest.php b/plugins/CoreUpdater/Test/Unit/ModelTest.php index 3098595b77..521aa8fc35 100644 --- a/plugins/CoreUpdater/tests/Unit/ModelTest.php +++ b/plugins/CoreUpdater/Test/Unit/ModelTest.php @@ -6,7 +6,8 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -namespace Piwik\Plugins\CoreUpdater\tests; +namespace Piwik\Plugins\CoreUpdater\Test\Unit; + use Piwik\Plugins\CoreUpdater\Model; /** diff --git a/plugins/CoreUpdater/Updater.php b/plugins/CoreUpdater/Updater.php index 18ed1e6e09..1adcbc6cc0 100644 --- a/plugins/CoreUpdater/Updater.php +++ b/plugins/CoreUpdater/Updater.php @@ -25,9 +25,9 @@ class Updater { const OPTION_LATEST_VERSION = 'UpdateCheck_LatestVersion'; const PATH_TO_EXTRACT_LATEST_VERSION = '/latest/'; - const LATEST_VERSION_URL = '://builds.piwik.org/piwik.zip'; const LATEST_BETA_VERSION_URL = '://builds.piwik.org/piwik-%s.zip'; + const DOWNLOAD_TIMEOUT = 120; /** * @var Translator @@ -80,8 +80,9 @@ class Updater * * @param bool $https Whether to use HTTPS if supported of not. If false, will use HTTP. * @return string[] Return an array of messages for the user. - * @throws Exception + * @throws ArchiveDownloadException * @throws UpdaterException + * @throws Exception */ public function updatePiwik($https = true) { @@ -128,7 +129,12 @@ class Updater $url .= '?cb=' . $version; - Http::fetchRemoteFile($url, $archiveFile, 0, 120); + try { + Http::fetchRemoteFile($url, $archiveFile, 0, self::DOWNLOAD_TIMEOUT); + } catch (Exception $e) { + // We throw a specific exception allowing to offer HTTP download if HTTPS failed + throw new ArchiveDownloadException($e); + } return $archiveFile; } diff --git a/plugins/CoreUpdater/UpdaterException.php b/plugins/CoreUpdater/UpdaterException.php index d9a543f30f..bd4599b111 100644 --- a/plugins/CoreUpdater/UpdaterException.php +++ b/plugins/CoreUpdater/UpdaterException.php @@ -1,4 +1,10 @@ <?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ namespace Piwik\Plugins\CoreUpdater; diff --git a/plugins/CoreUpdater/lang/en.json b/plugins/CoreUpdater/lang/en.json index 67bc20f27b..5519f43fbe 100644 --- a/plugins/CoreUpdater/lang/en.json +++ b/plugins/CoreUpdater/lang/en.json @@ -47,6 +47,11 @@ "UpdateAutomatically": "Update Automatically", "UpdateHasBeenCancelledExplanation": "Piwik One Click Update has been cancelled. If you can't fix the above error message, it is recommended that you manually update Piwik. %1$s Please check out the %2$sUpdate documentation%3$s to get started!", "UpdateTitle": "Update", + "UpdateUsingHttpsFailed": "The download of the latest version over HTTPS failed:", + "UpdateUsingHttpsFailedHelp": "Updating using HTTPS can fail because of a network error or a wrong system configuration, but it can also be a sign that someone is trying to make you download an altered version of Piwik.", + "UpdateUsingHttpsFailedHelpWhatToDo": "Proceed to update using HTTP only if you are sure of what you are doing.", + "UpdateUsingHttpMessage": "You can update using the non-secure HTTP method:", + "UpdateRetryUsingHttp": "Retry updating using HTTP", "UpgradeComplete": "Upgrade complete!", "UpgradePiwik": "Upgrade Piwik", "VerifyingUnpackedFiles": "Verifying the unpacked files", diff --git a/plugins/CoreUpdater/templates/newVersionAvailable.twig b/plugins/CoreUpdater/templates/newVersionAvailable.twig index cf87a949e6..8691d97595 100644 --- a/plugins/CoreUpdater/templates/newVersionAvailable.twig +++ b/plugins/CoreUpdater/templates/newVersionAvailable.twig @@ -29,7 +29,7 @@ <form id="oneclickupdate" action="index.php"> <input type="hidden" name="module" value="CoreUpdater"/> <input type="hidden" name="action" value="oneClickUpdate"/> - <input type="submit" class="submit" value="{{ 'CoreUpdater_UpdateAutomatically'|translate }}"/> + <input id="updateAutomatically" type="submit" class="submit" value="{{ 'CoreUpdater_UpdateAutomatically'|translate }}"/> {% endif %} <a style="margin-left:50px;" class="submit button" href="{{ piwik_latest_version_url }}?cb={{ piwik_new_version }}">{{ 'CoreUpdater_DownloadX'|translate(piwik_new_version) }}</a><br/> diff --git a/plugins/CoreUpdater/templates/oneClickResults.twig b/plugins/CoreUpdater/templates/oneClickResults.twig index d08378d6c3..fcefd72242 100644 --- a/plugins/CoreUpdater/templates/oneClickResults.twig +++ b/plugins/CoreUpdater/templates/oneClickResults.twig @@ -3,13 +3,38 @@ {% block content %} <br/> {% for message in feedbackMessages %} -<p>✓ {{ message }}</p> + <p>✓ {{ message }}</p> {% endfor %} -{% if coreError %} +{% if httpsFail %} <br/> <br/> - <div class="error"><img src="plugins/Morpheus/images/error_medium.png"/> {{ coreError }}</div> + <div class="error"> + <img src="plugins/Morpheus/images/error_medium.png"/> + {{ 'CoreUpdater_UpdateUsingHttpsFailed'|translate }}<br/> + {{ error }} + </div> + <p>{{ 'CoreUpdater_UpdateUsingHttpsFailedHelp'|translate }}</p> + <p>{{ 'CoreUpdater_UpdateUsingHttpsFailedHelpWhatToDo'|translate }}</p> + <div class="warning"> + <img src="plugins/Morpheus/images/warning_medium.png"/> + {{ 'CoreUpdater_UpdateUsingHttpMessage'|translate }} + <form id="oneclickupdate" action="index.php"> + <input type="hidden" name="module" value="CoreUpdater"/> + <input type="hidden" name="action" value="oneClickUpdate"/> + <input type="hidden" name="https" value="0"/> + <input id="updateUsingHttp" type="submit" class="submit" value="{{ 'CoreUpdater_UpdateRetryUsingHttp'|translate }}"/> + </form> + </div> + <br/> + <br/> +{% elseif error %} + <br/> + <br/> + <div class="error"> + <img src="plugins/Morpheus/images/error_medium.png"/> + {{ error }} + </div> <br/> <br/> <div class="warning"> diff --git a/plugins/CoreUpdater/tests/UI/PiwikUpdater_spec.js b/plugins/CoreUpdater/tests/UI/PiwikUpdater_spec.js deleted file mode 100644 index 4438c1b48b..0000000000 --- a/plugins/CoreUpdater/tests/UI/PiwikUpdater_spec.js +++ /dev/null @@ -1,22 +0,0 @@ -/*! - * Piwik - free/libre analytics platform - * - * Installation screenshot tests. - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - */ - -describe("PiwikUpdater", function () { - this.timeout(0); - - this.fixture = "Piwik\\Plugins\\CoreUpdater\\Tests\\Fixtures\\FailUpdateHttpsFixture"; - - var url = "?module=CoreUpdater&action=newVersionAvailable"; - - it("should show a new version is available", function (done) { - expect.screenshot("newVersion").to.be.capture(function (page) { - page.load(url); - }, done); - }); -}); |