diff --git a/apps/updatenotification/controller/admincontroller.php b/apps/updatenotification/controller/admincontroller.php index 55ef26c59a73e..eddedb6c1b107 100644 --- a/apps/updatenotification/controller/admincontroller.php +++ b/apps/updatenotification/controller/admincontroller.php @@ -80,33 +80,6 @@ public function __construct($appName, $this->dateTimeFormatter = $dateTimeFormatter; } - /** - * Whether the instance is compatible with the updater - * - * @return bool - */ - protected function isCompatibleWithUpdater() { - $updaterCompatible = true; - if(!function_exists('proc_open') || !function_exists('shell_exec')) { - $updaterCompatible = false; - } else { - $whichUnzip = shell_exec('command -v unzip'); - if(!class_exists('ZipArchive') && empty($whichUnzip)) { - $updaterCompatible = false; - } - - $whichPhp = shell_exec('command -v php'); - if(empty($whichPhp)) { - $updaterCompatible = false; - } - } - if(!function_exists('curl_exec')) { - $updaterCompatible = false; - } - - return $updaterCompatible; - } - /** * @return TemplateResponse */ @@ -122,6 +95,7 @@ public function displayPanel() { 'production', ]; $currentChannel = \OCP\Util::getChannel(); + // Remove the currently used channel from the channels list if(($key = array_search($currentChannel, $channels)) !== false) { unset($channels[$key]); @@ -133,8 +107,6 @@ public function displayPanel() { 'currentChannel' => $currentChannel, 'channels' => $channels, 'newVersionString' => ($updateState === []) ? '' : $updateState['updateVersion'], - 'updaterRequirementsFulfilled' => $this->isCompatibleWithUpdater(), - 'downloadLink' => (empty($updateState['downloadLink'])) ? '' : $updateState['downloadLink'], ]; return new TemplateResponse($this->appName, 'admin', $params, ''); diff --git a/apps/updatenotification/js/admin.js b/apps/updatenotification/js/admin.js index 4332df7890954..3bc5dd21527e7 100644 --- a/apps/updatenotification/js/admin.js +++ b/apps/updatenotification/js/admin.js @@ -13,7 +13,32 @@ /** * Creates a new authentication token and loads the updater URL */ +var loginToken = ''; $(document).ready(function(){ + $('#oca_updatenotification_button').click(function() { + // Load the new token + $.ajax({ + url: OC.generateUrl('/apps/updatenotification/credentials') + }).success(function(data) { + loginToken = data; + $.ajax({ + url: OC.webroot+'/updater/', + headers: { + 'X-Updater-Auth': loginToken + }, + method: 'POST', + success: function(data){ + if(data !== 'false') { + var body = $('body'); + $('head').remove(); + body.html(data); + body.removeAttr('id'); + body.attr('id', 'body-settings'); + } + } + }); + }); + }); $('#release-channel').change(function() { var newChannel = $('#release-channel').find(":selected").val(); $.post( diff --git a/apps/updatenotification/lib/updatechecker.php b/apps/updatenotification/lib/updatechecker.php index 153a6ae4aa38f..32eab405a62f7 100644 --- a/apps/updatenotification/lib/updatechecker.php +++ b/apps/updatenotification/lib/updatechecker.php @@ -48,9 +48,6 @@ public function getUpdateState() { if(substr($data['web'], 0, 8) === 'https://') { $result['updateLink'] = $data['web']; } - if(substr($data['url'], 0, 8) === 'https://') { - $result['downloadLink'] = $data['url']; - } return $result; } diff --git a/apps/updatenotification/templates/admin.php b/apps/updatenotification/templates/admin.php index 32ad7ffd1ad57..534a3032d99f5 100644 --- a/apps/updatenotification/templates/admin.php +++ b/apps/updatenotification/templates/admin.php @@ -12,17 +12,13 @@ $channels = $_['channels']; /** @var string $currentChannel */ $currentChannel = $_['currentChannel']; - /** @var bool $updaterRequirementsFulfilled */ - $updaterRequirementsFulfilled = $_['updaterRequirementsFulfilled']; ?>

t('Updater')); ?>

t('A new version is available: %s', [$newVersionString])); ?> - - t('Download now')) ?> - + t('Your version is up to date.')); ?> diff --git a/apps/updatenotification/tests/UpdateCheckerTest.php b/apps/updatenotification/tests/UpdateCheckerTest.php index d8818a2e60e3f..e83d4c9a24d9b 100644 --- a/apps/updatenotification/tests/UpdateCheckerTest.php +++ b/apps/updatenotification/tests/UpdateCheckerTest.php @@ -46,14 +46,13 @@ public function testGetUpdateStateWithUpdateAndInvalidLink() { ->method('check') ->willReturn([ 'version' => 123, - 'versionstring' => 'Nextcloud 123', + 'versionstring' => 'ownCloud 123', 'web'=> 'javascript:alert(1)', - 'url'=> 'javascript:alert(2)', ]); $expected = [ 'updateAvailable' => true, - 'updateVersion' => 'Nextcloud 123', + 'updateVersion' => 'ownCloud 123', ]; $this->assertSame($expected, $this->updateChecker->getUpdateState()); } @@ -64,16 +63,14 @@ public function testGetUpdateStateWithUpdateAndValidLink() { ->method('check') ->willReturn([ 'version' => 123, - 'versionstring' => 'Nextcloud 123', - 'web'=> 'https://docs.nextcloud.com/myUrl', - 'url'=> 'https://downloads.nextcloud.org/server', + 'versionstring' => 'ownCloud 123', + 'web'=> 'https://owncloud.org/myUrl', ]); $expected = [ 'updateAvailable' => true, - 'updateVersion' => 'Nextcloud 123', - 'updateLink' => 'https://docs.nextcloud.com/myUrl', - 'downloadLink' => 'https://downloads.nextcloud.org/server', + 'updateVersion' => 'ownCloud 123', + 'updateLink' => 'https://owncloud.org/myUrl', ]; $this->assertSame($expected, $this->updateChecker->getUpdateState()); } diff --git a/apps/updatenotification/tests/controller/AdminControllerTest.php b/apps/updatenotification/tests/controller/AdminControllerTest.php index ef07fbc498ba3..795c7979094c5 100644 --- a/apps/updatenotification/tests/controller/AdminControllerTest.php +++ b/apps/updatenotification/tests/controller/AdminControllerTest.php @@ -68,23 +68,17 @@ public function setUp() { ->disableOriginalConstructor()->getMock(); $this->dateTimeFormatter = $this->getMock('\\OCP\\IDateTimeFormatter'); - $this->adminController = $this->getMockBuilder('\OCA\UpdateNotification\Controller\AdminController') - ->setConstructorArgs( - [ - 'updatenotification', - $this->request, - $this->jobList, - $this->secureRandom, - $this->config, - $this->timeFactory, - $this->l10n, - $this->updateChecker, - $this->dateTimeFormatter, - ] - ) - ->setMethods(['isCompatibleWithUpdater']) - ->getMock() - ; + $this->adminController = new AdminController( + 'updatenotification', + $this->request, + $this->jobList, + $this->secureRandom, + $this->config, + $this->timeFactory, + $this->l10n, + $this->updateChecker, + $this->dateTimeFormatter + ); } public function testDisplayPanelWithUpdate() { @@ -115,60 +109,6 @@ public function testDisplayPanelWithUpdate() { ->expects($this->once()) ->method('getUpdateState') ->willReturn(['updateVersion' => '8.1.2']); - $this->adminController - ->expects($this->once()) - ->method('isCompatibleWithUpdater') - ->willReturn(true); - - $params = [ - 'isNewVersionAvailable' => true, - 'lastChecked' => 'LastCheckedReturnValue', - 'currentChannel' => \OCP\Util::getChannel(), - 'channels' => $channels, - 'newVersionString' => '8.1.2', - 'updaterRequirementsFulfilled' => true, - 'downloadLink' => '', - ]; - - $expected = new TemplateResponse('updatenotification', 'admin', $params, ''); - $this->assertEquals($expected, $this->adminController->displayPanel()); - } - - public function testDisplayPanelWithUpdateAndIncompatibleUpdaterApp() { - $channels = [ - 'daily', - 'beta', - 'stable', - 'production', - ]; - $currentChannel = \OCP\Util::getChannel(); - - // Remove the currently used channel from the channels list - if(($key = array_search($currentChannel, $channels)) !== false) { - unset($channels[$key]); - } - - $this->config - ->expects($this->once()) - ->method('getAppValue') - ->with('core', 'lastupdatedat') - ->willReturn('12345'); - $this->dateTimeFormatter - ->expects($this->once()) - ->method('formatDateTime') - ->with('12345') - ->willReturn('LastCheckedReturnValue'); - $this->updateChecker - ->expects($this->once()) - ->method('getUpdateState') - ->willReturn([ - 'updateVersion' => '8.1.2', - 'downloadLink' => 'https://downloads.nextcloud.org/server', - ]); - $this->adminController - ->expects($this->once()) - ->method('isCompatibleWithUpdater') - ->willReturn(false); $params = [ 'isNewVersionAvailable' => true, @@ -176,8 +116,6 @@ public function testDisplayPanelWithUpdateAndIncompatibleUpdaterApp() { 'currentChannel' => \OCP\Util::getChannel(), 'channels' => $channels, 'newVersionString' => '8.1.2', - 'updaterRequirementsFulfilled' => false, - 'downloadLink' => 'https://downloads.nextcloud.org/server', ]; $expected = new TemplateResponse('updatenotification', 'admin', $params, ''); @@ -212,10 +150,6 @@ public function testDisplayPanelWithoutUpdate() { ->expects($this->once()) ->method('getUpdateState') ->willReturn([]); - $this->adminController - ->expects($this->once()) - ->method('isCompatibleWithUpdater') - ->willReturn(true); $params = [ 'isNewVersionAvailable' => false, @@ -223,8 +157,6 @@ public function testDisplayPanelWithoutUpdate() { 'currentChannel' => \OCP\Util::getChannel(), 'channels' => $channels, 'newVersionString' => '', - 'updaterRequirementsFulfilled' => true, - 'downloadLink' => '', ]; $expected = new TemplateResponse('updatenotification', 'admin', $params, ''); diff --git a/lib/private/repair.php b/lib/private/repair.php index 1848eafd902e4..ee5cf8754d0c7 100644 --- a/lib/private/repair.php +++ b/lib/private/repair.php @@ -41,6 +41,7 @@ use OC\Repair\DropOldJobs; use OC\Repair\EncryptionCompatibility; use OC\Repair\MoveChannelToSystemConfig; +use OC\Repair\MoveUpdaterStepFile; use OC\Repair\OldGroupMembershipShares; use OC\Repair\RemoveGetETagEntries; use OC\Repair\SqliteAutoincrement; @@ -123,6 +124,7 @@ public static function getRepairSteps() { new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), new AvatarPermissions(\OC::$server->getDatabaseConnection()), new MoveChannelToSystemConfig(\OC::$server->getConfig()), + new MoveUpdaterStepFile(\OC::$server->getConfig()), ]; } diff --git a/lib/private/repair/moveupdaterstepfile.php b/lib/private/repair/moveupdaterstepfile.php new file mode 100644 index 0000000000000..e7d04f594b45d --- /dev/null +++ b/lib/private/repair/moveupdaterstepfile.php @@ -0,0 +1,81 @@ + + * + * @author Morris Jobke + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * 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 + * along with this program. If not, see . + * + */ + +namespace OC\Repair; + +use OC\Hooks\BasicEmitter; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; + +class MoveUpdaterStepFile extends BasicEmitter implements \OC\RepairStep { + + /** @var \OCP\IConfig */ + protected $config; + + /** + * @param \OCP\IConfig $config + */ + public function __construct($config) { + $this->config = $config; + } + + public function getName() { + return 'Move .step file of updater to backup location'; + } + + public function run() { + + $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT); + $instanceId = $this->config->getSystemValue('instanceid', null); + + if(!is_string($instanceId) || empty($instanceId)) { + return; + } + + $updaterFolderPath = $dataDir . '/updater-' . $instanceId; + $stepFile = $updaterFolderPath . '/.step'; + if(file_exists($stepFile)) { + $this->emit('\OC\Repair', 'info', array('.step file exists')); + + $previousStepFile = $updaterFolderPath . '/.step-previous-update'; + + // cleanup + if(file_exists($previousStepFile)) { + if(\OC_Helper::rmdirr($previousStepFile)) { + $this->emit('\OC\Repair', 'info', array('.step-previous-update removed')); + } else { + $this->emit('\OC\Repair', 'info', array('.step-previous-update can\'t be removed - abort move of .step file')); + return; + } + } + + // move step file + if(rename($stepFile, $previousStepFile)) { + $this->emit('\OC\Repair', 'info', array('.step file moved to .step-previous-update')); + } else { + $this->emit('\OC\Repair', 'warning', array('.step file can\'t be moved')); + } + } + } +} +