mirror of https://github.com/nextcloud/server.git
Remove the upload and memory setting
* Remove unneeded private method phpFileSize() * Bump autoloader * Remove setUploadLimit tests * Remove integrity check hacks for upload limit Signed-off-by: Joas Schilling <coding@schilljs.com> Signed-off-by: Morris Jobke <hey@morrisjobke.de>pull/14430/head
parent
814bf0de20
commit
c6a69ba925
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3
|
||||
* or later.
|
||||
*
|
||||
* See the COPYING-README file.
|
||||
*
|
||||
*/
|
||||
|
||||
(function() {
|
||||
if (!OCA.Files) {
|
||||
/**
|
||||
* Namespace for the files app
|
||||
* @namespace OCA.Files
|
||||
*/
|
||||
OCA.Files = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @namespace OCA.Files.Admin
|
||||
*/
|
||||
OCA.Files.Admin = {
|
||||
initialize: function() {
|
||||
$('#submitMaxUpload').on('click', _.bind(this._onClickSubmitMaxUpload, this));
|
||||
},
|
||||
|
||||
_onClickSubmitMaxUpload: function () {
|
||||
OC.msg.startSaving('#maxUploadSizeSettingsMsg');
|
||||
|
||||
var request = $.ajax({
|
||||
url: OC.generateUrl('/apps/files/settings/maxUpload'),
|
||||
type: 'POST',
|
||||
data: {
|
||||
maxUploadSize: $('#maxUploadSize').val()
|
||||
}
|
||||
});
|
||||
|
||||
request.done(function (data) {
|
||||
$('#maxUploadSize').val(data.maxUploadSize);
|
||||
OC.msg.finishedSuccess('#maxUploadSizeSettingsMsg', 'Saved');
|
||||
});
|
||||
|
||||
request.fail(function () {
|
||||
OC.msg.finishedError('#maxUploadSizeSettingsMsg', 'Error');
|
||||
});
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
function switchPublicFolder() {
|
||||
var publicEnable = $('#publicEnable').is(':checked');
|
||||
// find all radiobuttons of that group
|
||||
var sharingaimGroup = $('input:radio[name=sharingaim]');
|
||||
$.each(sharingaimGroup, function(index, sharingaimItem) {
|
||||
// set all buttons to the correct state
|
||||
sharingaimItem.disabled = !publicEnable;
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
OCA.Files.Admin.initialize();
|
||||
|
||||
// Execute the function after loading DOM tree
|
||||
switchPublicFolder();
|
||||
$('#publicEnable').click(function() {
|
||||
// To get rid of onClick()
|
||||
switchPublicFolder();
|
||||
});
|
||||
});
|
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @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 OCA\Files\Controller;
|
||||
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IRequest;
|
||||
use OCP\Util;
|
||||
|
||||
class SettingsController extends Controller {
|
||||
public function __construct($appName, IRequest $request) {
|
||||
parent::__construct($appName, $request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $maxUploadSize
|
||||
* @return JSONResponse
|
||||
*/
|
||||
public function setMaxUploadSize($maxUploadSize) {
|
||||
$setMaxSize = \OC_Files::setUploadLimit(Util::computerFileSize($maxUploadSize));
|
||||
|
||||
if ($setMaxSize === false) {
|
||||
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
|
||||
} else {
|
||||
return new JSONResponse([
|
||||
'maxUploadSize' => Util::humanFileSize($setMaxSize)
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
*
|
||||
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @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 OCA\Files\Settings;
|
||||
|
||||
use bantu\IniGetWrapper\IniGetWrapper;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\IRequest;
|
||||
use OCP\Settings\ISettings;
|
||||
use OCP\Util;
|
||||
|
||||
class Admin implements ISettings {
|
||||
|
||||
/** @var IniGetWrapper */
|
||||
private $iniWrapper;
|
||||
|
||||
/** @var IRequest */
|
||||
private $request;
|
||||
|
||||
public function __construct(IniGetWrapper $iniWrapper, IRequest $request) {
|
||||
$this->iniWrapper = $iniWrapper;
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function getForm() {
|
||||
$htaccessWorking = (getenv('htaccessWorking') === 'true');
|
||||
$htaccessWritable = is_writable(\OC::$SERVERROOT.'/.htaccess');
|
||||
$userIniWritable = is_writable(\OC::$SERVERROOT.'/.user.ini');
|
||||
|
||||
$upload_max_filesize = $this->iniWrapper->getBytes('upload_max_filesize');
|
||||
$post_max_size = $this->iniWrapper->getBytes('post_max_size');
|
||||
$maxUploadFilesize = Util::humanFileSize(min($upload_max_filesize, $post_max_size));
|
||||
|
||||
$parameters = [
|
||||
'uploadChangable' => ($htaccessWorking and $htaccessWritable) or $userIniWritable,
|
||||
'uploadMaxFilesize' => $maxUploadFilesize,
|
||||
// max possible makes only sense on a 32 bit system
|
||||
'displayMaxPossibleUploadSize' => PHP_INT_SIZE === 4,
|
||||
'maxPossibleUploadSize' => Util::humanFileSize(PHP_INT_MAX),
|
||||
];
|
||||
|
||||
return new TemplateResponse('files', 'admin', $parameters, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the section ID, e.g. 'sharing'
|
||||
*/
|
||||
public function getSection() {
|
||||
return 'server';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int whether the form should be rather on the top or bottom of
|
||||
* the admin section. The forms are arranged in ascending order of the
|
||||
* priority values. It is required to return a value between 0 and 100.
|
||||
*
|
||||
* E.g.: 70
|
||||
*/
|
||||
public function getPriority() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php OCP\Util::addScript('files', 'admin'); ?>
|
||||
|
||||
<div class="section">
|
||||
<h2><?php p($l->t('File handling')); ?></h2>
|
||||
<label for="maxUploadSize"><?php p($l->t( 'Maximum upload size' )); ?> </label>
|
||||
<span id="maxUploadSizeSettingsMsg" class="msg"></span>
|
||||
<br />
|
||||
<input type="text" name='maxUploadSize' id="maxUploadSize" value='<?php p($_['uploadMaxFilesize']) ?>' <?php if(!$_['uploadChangable']) { p('disabled'); } ?> />
|
||||
<?php if($_['displayMaxPossibleUploadSize']):?>
|
||||
(<?php p($l->t('max. possible: ')); p($_['maxPossibleUploadSize']) ?>)
|
||||
<?php endif;?>
|
||||
<input type="hidden" value="<?php p($_['requesttoken']); ?>" name="requesttoken" />
|
||||
<?php if($_['uploadChangable']): ?>
|
||||
<input type="submit" id="submitMaxUpload"
|
||||
value="<?php p($l->t( 'Save' )); ?>"/>
|
||||
<p><em><?php p($l->t('With PHP-FPM it might take 5 minutes for changes to be applied.')); ?></em></p>
|
||||
<?php else: ?>
|
||||
<p><em><?php p($l->t('Missing permissions to edit from here.')); ?></em></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
@ -1,84 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
|
||||
*
|
||||
* @author Lukas Reschke <lukas@statuscode.ch>
|
||||
* @author Morris Jobke <hey@morrisjobke.de>
|
||||
*
|
||||
* @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 OCA\Files\Tests\Settings;
|
||||
|
||||
use bantu\IniGetWrapper\IniGetWrapper;
|
||||
use OCA\Files\Settings\Admin;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\IRequest;
|
||||
use OCP\Util;
|
||||
use Test\TestCase;
|
||||
|
||||
class AdminTest extends TestCase {
|
||||
/** @var Admin */
|
||||
private $admin;
|
||||
/** @var IniGetWrapper */
|
||||
private $iniGetWrapper;
|
||||
/** @var IRequest */
|
||||
private $request;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
$this->iniGetWrapper = $this->getMockBuilder('\bantu\IniGetWrapper\IniGetWrapper')->disableOriginalConstructor()->getMock();
|
||||
$this->request = $this->getMockBuilder(IRequest::class)->getMock();
|
||||
$this->admin = new Admin(
|
||||
$this->iniGetWrapper,
|
||||
$this->request
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetForm() {
|
||||
$htaccessWorking = (getenv('htaccessWorking') == 'true');
|
||||
$htaccessWritable = is_writable(\OC::$SERVERROOT.'/.htaccess');
|
||||
$userIniWritable = is_writable(\OC::$SERVERROOT.'/.user.ini');
|
||||
|
||||
$this->iniGetWrapper
|
||||
->expects($this->at(0))
|
||||
->method('getBytes')
|
||||
->with('upload_max_filesize')
|
||||
->willReturn(1234);
|
||||
$this->iniGetWrapper
|
||||
->expects($this->at(1))
|
||||
->method('getBytes')
|
||||
->with('post_max_size')
|
||||
->willReturn(1234);
|
||||
$params = [
|
||||
'uploadChangable' => (($htaccessWorking and $htaccessWritable) or $userIniWritable ),
|
||||
'uploadMaxFilesize' => '1 KB',
|
||||
'displayMaxPossibleUploadSize' => PHP_INT_SIZE === 4,
|
||||
'maxPossibleUploadSize' => Util::humanFileSize(PHP_INT_MAX),
|
||||
];
|
||||
$expected = new TemplateResponse('files', 'admin', $params, '');
|
||||
$this->assertEquals($expected, $this->admin->getForm());
|
||||
}
|
||||
|
||||
public function testGetSection() {
|
||||
$this->assertSame('server', $this->admin->getSection());
|
||||
}
|
||||
|
||||
public function testGetPriority() {
|
||||
$this->assertSame(5, $this->admin->getPriority());
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
upload_max_filesize=519M
|
||||
post_max_size=519M
|
||||
memory_limit=512M
|
||||
mbstring.func_overload=0
|
||||
always_populate_raw_post_data=-1
|
||||
default_charset='UTF-8'
|
||||
output_buffering=0
|
@ -1,137 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Robin McCorkell <rmccorkell@karoshi.org.uk>
|
||||
*
|
||||
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or any later version.
|
||||
*
|
||||
* This library 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 library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Test;
|
||||
|
||||
class FilesTest extends \Test\TestCase {
|
||||
|
||||
const UPLOAD_LIMIT_DEFAULT_STR = '511M';
|
||||
const UPLOAD_LIMIT_SETTING_STR = '2M';
|
||||
const UPLOAD_LIMIT_SETTING_BYTES = 2097152;
|
||||
|
||||
/** @var array $tmpDirs */
|
||||
private $tmpDirs = [];
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getUploadLimitTestFiles() {
|
||||
$dir = \OC::$server->getTempManager()->getTemporaryFolder();
|
||||
$this->tmpDirs[] = $dir;
|
||||
$result = [
|
||||
'.htaccess' => $dir . '/htaccess',
|
||||
'.user.ini' => $dir . '/user.ini'
|
||||
];
|
||||
copy(\OC::$SERVERROOT . '/tests/data/setUploadLimit/htaccess', $result['.htaccess']);
|
||||
copy(\OC::$SERVERROOT . '/tests/data/setUploadLimit/user.ini', $result['.user.ini']);
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
foreach ($this->tmpDirs as $dir) {
|
||||
\OC_Helper::rmdirr($dir);
|
||||
}
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testSetUploadLimitSizeSanity() {
|
||||
$this->assertFalse(\OC_Files::setUploadLimit(PHP_INT_MAX + 10));
|
||||
$this->assertFalse(\OC_Files::setUploadLimit(\OC_Files::UPLOAD_MIN_LIMIT_BYTES - 10));
|
||||
$this->assertFalse(\OC_Files::setUploadLimit('foobar'));
|
||||
}
|
||||
|
||||
public function setUploadLimitWriteProvider() {
|
||||
return [
|
||||
[
|
||||
// both files writable
|
||||
true, true,
|
||||
self::UPLOAD_LIMIT_SETTING_BYTES, self::UPLOAD_LIMIT_SETTING_BYTES,
|
||||
self::UPLOAD_LIMIT_SETTING_STR, self::UPLOAD_LIMIT_SETTING_STR
|
||||
],
|
||||
[
|
||||
// neither file writable
|
||||
false, false,
|
||||
self::UPLOAD_LIMIT_SETTING_BYTES, false,
|
||||
self::UPLOAD_LIMIT_DEFAULT_STR, self::UPLOAD_LIMIT_DEFAULT_STR
|
||||
],
|
||||
[
|
||||
// only .htaccess writable
|
||||
true, false,
|
||||
self::UPLOAD_LIMIT_SETTING_BYTES, false,
|
||||
self::UPLOAD_LIMIT_SETTING_STR, self::UPLOAD_LIMIT_DEFAULT_STR
|
||||
],
|
||||
[
|
||||
// only .user.ini writable
|
||||
false, true,
|
||||
self::UPLOAD_LIMIT_SETTING_BYTES, false,
|
||||
self::UPLOAD_LIMIT_DEFAULT_STR, self::UPLOAD_LIMIT_SETTING_STR
|
||||
],
|
||||
[
|
||||
// test rounding of values
|
||||
true, true,
|
||||
self::UPLOAD_LIMIT_SETTING_BYTES + 20, self::UPLOAD_LIMIT_SETTING_BYTES,
|
||||
self::UPLOAD_LIMIT_SETTING_STR, self::UPLOAD_LIMIT_SETTING_STR
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider setUploadLimitWriteProvider
|
||||
*/
|
||||
public function testSetUploadLimitWrite(
|
||||
$htaccessWritable, $userIniWritable,
|
||||
$setSize, $expectedSize,
|
||||
$htaccessStr, $userIniStr
|
||||
) {
|
||||
$this->markTestSkipped('TODO: Disable because fails on drone');
|
||||
|
||||
$files = $this->getUploadLimitTestFiles();
|
||||
chmod($files['.htaccess'], ($htaccessWritable ? 0644 : 0444));
|
||||
chmod($files['.user.ini'], ($userIniWritable ? 0644 : 0444));
|
||||
|
||||
$htaccessSize = filesize($files['.htaccess']);
|
||||
$userIniSize = filesize($files['.user.ini']);
|
||||
$htaccessSizeMod = 2*(strlen($htaccessStr) - strlen(self::UPLOAD_LIMIT_DEFAULT_STR));
|
||||
$userIniSizeMod = 2*(strlen($userIniStr) - strlen(self::UPLOAD_LIMIT_DEFAULT_STR));
|
||||
|
||||
$this->assertEquals($expectedSize, \OC_Files::setUploadLimit($setSize, $files));
|
||||
|
||||
// check file contents
|
||||
$htaccess = file_get_contents($files['.htaccess']);
|
||||
$this->assertEquals(1,
|
||||
preg_match('/php_value upload_max_filesize '.$htaccessStr.'/', $htaccess)
|
||||
);
|
||||
$this->assertEquals(1,
|
||||
preg_match('/php_value post_max_size '.$htaccessStr.'/', $htaccess)
|
||||
);
|
||||
$this->assertEquals($htaccessSize + $htaccessSizeMod, filesize($files['.htaccess']));
|
||||
|
||||
$userIni = file_get_contents($files['.user.ini']);
|
||||
$this->assertEquals(1,
|
||||
preg_match('/upload_max_filesize='.$userIniStr.'/', $userIni)
|
||||
);
|
||||
$this->assertEquals(1,
|
||||
preg_match('/post_max_size='.$userIniStr.'/', $userIni)
|
||||
);
|
||||
$this->assertEquals($userIniSize + $userIniSizeMod, filesize($files['.user.ini']));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue