2013-01-04 02:32:33 +00:00
|
|
|
<?php
|
2015-03-26 10:44:34 +00:00
|
|
|
/**
|
|
|
|
* @author Bart Visscher <bartv@thisnet.nl>
|
|
|
|
* @author Lukas Reschke <lukas@owncloud.com>
|
|
|
|
* @author Michael Gapczynski <GapczynskiM@gmail.com>
|
2015-06-25 09:43:55 +00:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Robin Appelman <icewind@owncloud.com>
|
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
* @author Victor Dubiniuk <dubiniuk@owncloud.com>
|
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
2013-01-04 02:32:33 +00:00
|
|
|
set_time_limit(0);
|
2014-08-22 09:39:05 +00:00
|
|
|
require_once '../../lib/base.php';
|
2013-01-04 02:32:33 +00:00
|
|
|
|
2015-08-26 08:30:24 +00:00
|
|
|
$l = \OC::$server->getL10N('core');
|
|
|
|
|
|
|
|
$eventSource = \OC::$server->createEventSource();
|
|
|
|
// need to send an initial message to force-init the event source,
|
|
|
|
// which will then trigger its own CSRF check and produces its own CSRF error
|
|
|
|
// message
|
|
|
|
$eventSource->send('success', (string)$l->t('Preparing update'));
|
Verify CSRF token already in update.php and not the EventSource code
Issue report:
> Hum, well I upgraded the package then visited the web interface to
trigger the update and it failed; the UI would say there was a
possible CSRF attack and after that it'd be stuck in maintenance mode.
Tried a few times (by editing maintenance to false in owncloud.conf)
and same result each time.
That smells partially like an issue caused by our EventSource implementation, due to legacy concerns the CSRF verification happens within the EventSource handling and not when the actual endpoint is called, what happens here then is:
1. User has somehow an invalid CSRF token in session (or none at all)
2. User clicks the update button
3. Invalid CSRF token is sent to update.php - no CSRF check there => Instance gets set in maintenance mode
4. Invalid CSRF token is processed by the EventSource code => Code Execution is stopped and ownCloud is stuck in maintenance mode
I have a work-around for this problem, basically it verifies the CSRF token already in step 3 and cancels execution then. The same error will be shown to the user however he can work around it by refreshing the page – as stated by the error. I think that’s an acceptable behaviour for now: INSERT LINK
To verify this test:
1. Delete your ownCloud cookies
2. Increment the version in version.php
3. Try to upgrade
=> Before the patch: Instance shows an error, is set to upgrade mode and a refresh does not help
=> After the patch: Instance shows an error, a refresh helps though.
This is not really the best fix as a better solution would be to catch such situations when bootstrapping ownCloud, however, I don’t dare to touch base.php for this sake only, you never know what breaks then…
That said: There might be other bugs as well, especially the stacktrace is somewhat confusing but then again it installing ownCloud under /usr/share/owncloud/ and I bet that is part of the whole issue ;-)
2015-03-09 09:07:30 +00:00
|
|
|
|
2013-01-04 02:32:33 +00:00
|
|
|
if (OC::checkUpgrade(false)) {
|
2014-09-02 12:30:46 +00:00
|
|
|
// if a user is currently logged in, their session must be ignored to
|
|
|
|
// avoid side effects
|
|
|
|
\OC_User::setIncognitoMode(true);
|
|
|
|
|
2015-07-03 12:06:40 +00:00
|
|
|
$logger = \OC::$server->getLogger();
|
2014-11-25 19:41:15 +00:00
|
|
|
$updater = new \OC\Updater(
|
2014-12-09 22:13:38 +00:00
|
|
|
\OC::$server->getHTTPHelper(),
|
2015-02-17 11:00:39 +00:00
|
|
|
\OC::$server->getConfig(),
|
2015-07-03 12:06:40 +00:00
|
|
|
$logger
|
2014-11-25 19:41:15 +00:00
|
|
|
);
|
2015-02-17 11:00:39 +00:00
|
|
|
$incompatibleApps = [];
|
|
|
|
$disabledThirdPartyApps = [];
|
|
|
|
|
2015-05-19 08:27:53 +00:00
|
|
|
$updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) {
|
2013-08-26 22:26:44 +00:00
|
|
|
$eventSource->send('success', (string)$l->t('Turned on maintenance mode'));
|
2013-07-06 15:00:00 +00:00
|
|
|
});
|
2015-05-19 08:27:53 +00:00
|
|
|
$updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) {
|
2013-08-26 22:26:44 +00:00
|
|
|
$eventSource->send('success', (string)$l->t('Turned off maintenance mode'));
|
2013-07-06 15:00:00 +00:00
|
|
|
});
|
2015-05-19 08:27:53 +00:00
|
|
|
$updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) {
|
|
|
|
$eventSource->send('success', (string)$l->t('Maintenance mode is kept active'));
|
|
|
|
});
|
2013-08-26 22:26:44 +00:00
|
|
|
$updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) {
|
|
|
|
$eventSource->send('success', (string)$l->t('Updated database'));
|
2013-07-06 15:00:00 +00:00
|
|
|
});
|
2014-06-04 14:40:53 +00:00
|
|
|
$updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) {
|
|
|
|
$eventSource->send('success', (string)$l->t('Checked database schema update'));
|
|
|
|
});
|
2014-07-24 15:51:41 +00:00
|
|
|
$updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) {
|
|
|
|
$eventSource->send('success', (string)$l->t('Checked database schema update for apps'));
|
|
|
|
});
|
|
|
|
$updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) {
|
|
|
|
$eventSource->send('success', (string)$l->t('Updated "%s" to %s', array($app, $version)));
|
|
|
|
});
|
2015-02-27 11:44:04 +00:00
|
|
|
$updater->listen('\OC\Updater', 'repairWarning', function ($description) use ($eventSource, $l) {
|
|
|
|
$eventSource->send('notice', (string)$l->t('Repair warning: ') . $description);
|
|
|
|
});
|
|
|
|
$updater->listen('\OC\Updater', 'repairError', function ($description) use ($eventSource, $l) {
|
|
|
|
$eventSource->send('notice', (string)$l->t('Repair error: ') . $description);
|
|
|
|
});
|
2015-02-17 11:00:39 +00:00
|
|
|
$updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) {
|
|
|
|
$incompatibleApps[]= $app;
|
|
|
|
});
|
|
|
|
$updater->listen('\OC\Updater', 'thirdPartyAppDisabled', function ($app) use (&$disabledThirdPartyApps) {
|
|
|
|
$disabledThirdPartyApps[]= $app;
|
2014-05-27 13:20:33 +00:00
|
|
|
});
|
2013-07-06 15:00:00 +00:00
|
|
|
$updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource) {
|
|
|
|
$eventSource->send('failure', $message);
|
|
|
|
$eventSource->close();
|
2013-04-09 18:51:43 +00:00
|
|
|
OC_Config::setValue('maintenance', false);
|
2013-07-06 15:00:00 +00:00
|
|
|
});
|
2015-09-29 12:35:32 +00:00
|
|
|
$updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($eventSource, $l) {
|
|
|
|
$eventSource->send('success', (string)$l->t('Set log level to debug - current level: "%s"', [ $logLevelName ]));
|
|
|
|
});
|
|
|
|
$updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($eventSource, $l) {
|
|
|
|
$eventSource->send('success', (string)$l->t('Reset log level to "%s"', [ $logLevelName ]));
|
|
|
|
});
|
2013-01-04 15:21:33 +00:00
|
|
|
|
2015-08-26 08:56:27 +00:00
|
|
|
try {
|
|
|
|
$updater->upgrade();
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$eventSource->send('failure', get_class($e) . ': ' . $e->getMessage());
|
|
|
|
$eventSource->close();
|
|
|
|
exit();
|
|
|
|
}
|
2013-01-04 15:21:33 +00:00
|
|
|
|
2015-02-17 11:00:39 +00:00
|
|
|
if (!empty($incompatibleApps)) {
|
|
|
|
$eventSource->send('notice',
|
|
|
|
(string)$l->t('Following incompatible apps have been disabled: %s', implode(', ', $incompatibleApps)));
|
|
|
|
}
|
|
|
|
if (!empty($disabledThirdPartyApps)) {
|
|
|
|
$eventSource->send('notice',
|
2015-07-07 13:00:19 +00:00
|
|
|
(string)$l->t('Following apps have been disabled: %s', implode(', ', $disabledThirdPartyApps)));
|
2015-02-17 11:00:39 +00:00
|
|
|
}
|
|
|
|
|
2015-08-26 08:30:24 +00:00
|
|
|
} else {
|
|
|
|
$eventSource->send('notice', (string)$l->t('Already up to date'));
|
2013-07-06 15:00:00 +00:00
|
|
|
}
|
2015-08-26 08:30:24 +00:00
|
|
|
|
|
|
|
$eventSource->send('done', '');
|
|
|
|
$eventSource->close();
|
|
|
|
|