Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate set_time_limit setup check to new API #42814

Merged
merged 1 commit into from
Jan 18, 2024
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
1 change: 1 addition & 0 deletions apps/settings/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
'OCA\\Settings\\SetupChecks\\MemcacheConfigured' => $baseDir . '/../lib/SetupChecks/MemcacheConfigured.php',
'OCA\\Settings\\SetupChecks\\OverwriteCliUrl' => $baseDir . '/../lib/SetupChecks/OverwriteCliUrl.php',
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => $baseDir . '/../lib/SetupChecks/PhpDefaultCharset.php',
'OCA\\Settings\\SetupChecks\\PhpDisabledFunctions' => $baseDir . '/../lib/SetupChecks/PhpDisabledFunctions.php',
'OCA\\Settings\\SetupChecks\\PhpFreetypeSupport' => $baseDir . '/../lib/SetupChecks/PhpFreetypeSupport.php',
'OCA\\Settings\\SetupChecks\\PhpGetEnv' => $baseDir . '/../lib/SetupChecks/PhpGetEnv.php',
'OCA\\Settings\\SetupChecks\\PhpMemoryLimit' => $baseDir . '/../lib/SetupChecks/PhpMemoryLimit.php',
Expand Down
1 change: 1 addition & 0 deletions apps/settings/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class ComposerStaticInitSettings
'OCA\\Settings\\SetupChecks\\MemcacheConfigured' => __DIR__ . '/..' . '/../lib/SetupChecks/MemcacheConfigured.php',
'OCA\\Settings\\SetupChecks\\OverwriteCliUrl' => __DIR__ . '/..' . '/../lib/SetupChecks/OverwriteCliUrl.php',
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDefaultCharset.php',
'OCA\\Settings\\SetupChecks\\PhpDisabledFunctions' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDisabledFunctions.php',
'OCA\\Settings\\SetupChecks\\PhpFreetypeSupport' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpFreetypeSupport.php',
'OCA\\Settings\\SetupChecks\\PhpGetEnv' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpGetEnv.php',
'OCA\\Settings\\SetupChecks\\PhpMemoryLimit' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpMemoryLimit.php',
Expand Down
2 changes: 2 additions & 0 deletions apps/settings/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
use OCA\Settings\SetupChecks\MemcacheConfigured;
use OCA\Settings\SetupChecks\OverwriteCliUrl;
use OCA\Settings\SetupChecks\PhpDefaultCharset;
use OCA\Settings\SetupChecks\PhpDisabledFunctions;
use OCA\Settings\SetupChecks\PhpFreetypeSupport;
use OCA\Settings\SetupChecks\PhpGetEnv;
use OCA\Settings\SetupChecks\PhpMemoryLimit;
Expand Down Expand Up @@ -191,6 +192,7 @@ public function register(IRegistrationContext $context): void {
$context->registerSetupCheck(MemcacheConfigured::class);
$context->registerSetupCheck(OverwriteCliUrl::class);
$context->registerSetupCheck(PhpDefaultCharset::class);
$context->registerSetupCheck(PhpDisabledFunctions::class);
$context->registerSetupCheck(PhpFreetypeSupport::class);
$context->registerSetupCheck(PhpGetEnv::class);
$context->registerSetupCheck(PhpMemoryLimit::class);
Expand Down
15 changes: 0 additions & 15 deletions apps/settings/lib/Controller/CheckSetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,6 @@ private function isFairUseOfFreePushService(): bool {
return $this->manager->isFairUseOfFreePushService();
}

/**
* Checks if set_time_limit is not disabled.
*
* @return bool
*/
private function isSettimelimitAvailable() {
if (function_exists('set_time_limit')
&& !str_contains(ini_get('disable_functions'), 'set_time_limit')) {
return true;
}

return false;
}

/**
* @NoCSRFRequired
* @return RedirectResponse
Expand Down Expand Up @@ -275,7 +261,6 @@ public function check() {
[
'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService(),
'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'),
'isSettimelimitAvailable' => $this->isSettimelimitAvailable(),
'areWebauthnExtensionsEnabled' => $this->areWebauthnExtensionsEnabled(),
'isMysqlUsedWithoutUTF8MB4' => $this->isMysqlUsedWithoutUTF8MB4(),
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => $this->isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(),
Expand Down
56 changes: 56 additions & 0 deletions apps/settings/lib/SetupChecks/PhpDisabledFunctions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com>
*
* @author Côme Chilliet <come.chilliet@nextcloud.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\Settings\SetupChecks;

use OCP\IL10N;
use OCP\SetupCheck\ISetupCheck;
use OCP\SetupCheck\SetupResult;

class PhpDisabledFunctions implements ISetupCheck {

public function __construct(
private IL10N $l10n,
) {
}

public function getName(): string {
return $this->l10n->t('PHP set_time_limit');
}

public function getCategory(): string {
return 'php';
}

public function run(): SetupResult {
if (function_exists('set_time_limit') && !str_contains(ini_get('disable_functions'), 'set_time_limit')) {
return SetupResult::success($this->l10n->t('The function is available.'));
} else {
return SetupResult::warning(
$this->l10n->t('The PHP function "set_time_limit" is not available. This could result in scripts being halted mid-execution, breaking your installation. Enabling this function is strongly recommended.'),
);
}
}
}
2 changes: 1 addition & 1 deletion apps/settings/lib/SetupChecks/PhpModules.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getName(): string {
}

public function getCategory(): string {
return 'system';
return 'php';
}

public function run(): SetupResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ public function testCheck() {
$expected = new DataResponse(
[
'reverseProxyDocs' => 'reverse-proxy-doc-link',
'isSettimelimitAvailable' => true,
'areWebauthnExtensionsEnabled' => false,
'isMysqlUsedWithoutUTF8MB4' => false,
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => true,
Expand Down
6 changes: 0 additions & 6 deletions core/js/setupchecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,6 @@
type: OC.SetupChecks.MESSAGE_TYPE_ERROR
});
}
if(!data.isSettimelimitAvailable) {
messages.push({
msg: t('core', 'The PHP function "set_time_limit" is not available. This could result in scripts being halted mid-execution, breaking your installation. Enabling this function is strongly recommended.'),
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
});
}
if (!data.areWebauthnExtensionsEnabled) {
messages.push({
msg: t(
Expand Down
50 changes: 0 additions & 50 deletions core/js/tests/specs/setupchecksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -263,7 +262,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -302,7 +300,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -331,44 +328,6 @@ describe('OC.SetupChecks tests', function() {
});
});

it('should return an error if set_time_limit is unavailable', function(done) {
var async = OC.SetupChecks.checkSetup();

suite.server.requests[0].respond(
200,
{
'Content-Type': 'application/json',
},
JSON.stringify({
isFairUseOfFreePushService: true,
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
isSettimelimitAvailable: false,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
reverseProxyGeneratedURL: 'https://server',
temporaryDirectoryWritable: true,
generic: {
network: {
"Internet connectivity": {
severity: "success",
description: null,
linkToDoc: null
}
},
},
})
);

async.done(function( data, s, x ){
expect(data).toEqual([{
msg: 'The PHP function "set_time_limit" is not available. This could result in scripts being halted mid-execution, breaking your installation. Enabling this function is strongly recommended.',
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
}]);
done();
});
});

it('should return a warning if the memory limit is below the recommended value', function(done) {
var async = OC.SetupChecks.checkSetup();

Expand All @@ -380,7 +339,6 @@ describe('OC.SetupChecks tests', function() {
JSON.stringify({
isFairUseOfFreePushService: true,
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -449,7 +407,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -493,7 +450,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: true,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -534,7 +490,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -572,7 +527,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -607,7 +561,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: false,
Expand Down Expand Up @@ -644,7 +597,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: false,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -681,7 +633,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down Expand Up @@ -725,7 +676,6 @@ describe('OC.SetupChecks tests', function() {
},
JSON.stringify({
isFairUseOfFreePushService: true,
isSettimelimitAvailable: true,
areWebauthnExtensionsEnabled: true,
isMysqlUsedWithoutUTF8MB4: false,
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
Expand Down
Loading