Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 1 addition & 29 deletions apps/updatenotification/controller/admincontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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]);
Expand All @@ -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, '');
Expand Down
25 changes: 25 additions & 0 deletions apps/updatenotification/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 0 additions & 3 deletions apps/updatenotification/lib/updatechecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 1 addition & 5 deletions apps/updatenotification/templates/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@
$channels = $_['channels'];
/** @var string $currentChannel */
$currentChannel = $_['currentChannel'];
/** @var bool $updaterRequirementsFulfilled */
$updaterRequirementsFulfilled = $_['updaterRequirementsFulfilled'];
?>
<form id="oca_updatenotification_section" class="section">
<h2><?php p($l->t('Updater')); ?></h2>

<?php if($isNewVersionAvailable === true): ?>
<strong><?php p($l->t('A new version is available: %s', [$newVersionString])); ?></strong>
<?php if ($_['downloadLink']): ?>
<a href="<?php p($_['downloadLink']); ?>" class="button"><?php p($l->t('Download now')) ?></a>
<?php endif; ?>
<input type="button" id="oca_updatenotification_button" value="<?php p($l->t('Open updater')) ?>">
<?php else: ?>
<strong><?php print_unescaped($l->t('Your version is up to date.')); ?></strong>
<span class="icon-info svg" title="<?php p($l->t('Checked on %s', [$lastCheckedDate])) ?>"></span>
Expand Down
15 changes: 6 additions & 9 deletions apps/updatenotification/tests/UpdateCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand Down
90 changes: 11 additions & 79 deletions apps/updatenotification/tests/controller/AdminControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -115,69 +109,13 @@ 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,
'lastChecked' => 'LastCheckedReturnValue',
'currentChannel' => \OCP\Util::getChannel(),
'channels' => $channels,
'newVersionString' => '8.1.2',
'updaterRequirementsFulfilled' => false,
'downloadLink' => 'https://downloads.nextcloud.org/server',
];

$expected = new TemplateResponse('updatenotification', 'admin', $params, '');
Expand Down Expand Up @@ -212,19 +150,13 @@ public function testDisplayPanelWithoutUpdate() {
->expects($this->once())
->method('getUpdateState')
->willReturn([]);
$this->adminController
->expects($this->once())
->method('isCompatibleWithUpdater')
->willReturn(true);

$params = [
'isNewVersionAvailable' => false,
'lastChecked' => 'LastCheckedReturnValue',
'currentChannel' => \OCP\Util::getChannel(),
'channels' => $channels,
'newVersionString' => '',
'updaterRequirementsFulfilled' => true,
'downloadLink' => '',
];

$expected = new TemplateResponse('updatenotification', 'admin', $params, '');
Expand Down
2 changes: 2 additions & 0 deletions lib/private/repair.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()),
];
}

Expand Down
81 changes: 81 additions & 0 deletions lib/private/repair/moveupdaterstepfile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/**
* @copyright Copyright (c) 2016 Morris Jobke <[email protected]>
*
* @author Morris Jobke <[email protected]>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/

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'));
}
}
}
}