Issues (2553)

console.php (1 issue)

1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Bart Visscher <[email protected]>
6
 * @author Christoph Wurst <[email protected]>
7
 * @author hoellen <[email protected]>
8
 * @author J0WI <[email protected]>
9
 * @author Joas Schilling <[email protected]>
10
 * @author Ko- <[email protected]>
11
 * @author Lukas Reschke <[email protected]>
12
 * @author Michael Weimann <[email protected]>
13
 * @author Morris Jobke <[email protected]>
14
 * @author Patrick Paysant <[email protected]>
15
 * @author Roeland Jago Douma <[email protected]>
16
 * @author Thomas Müller <[email protected]>
17
 * @author Victor Dubiniuk <[email protected]>
18
 *
19
 * @license AGPL-3.0
20
 *
21
 * This code is free software: you can redistribute it and/or modify
22
 * it under the terms of the GNU Affero General Public License, version 3,
23
 * as published by the Free Software Foundation.
24
 *
25
 * This program is distributed in the hope that it will be useful,
26
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28
 * GNU Affero General Public License for more details.
29
 *
30
 * You should have received a copy of the GNU Affero General Public License, version 3,
31
 * along with this program. If not, see <http://www.gnu.org/licenses/>
32
 *
33
 */
34
require_once __DIR__ . '/lib/versioncheck.php';
35
36
use OC\Console\Application;
37
use Symfony\Component\Console\Input\ArgvInput;
38
use Symfony\Component\Console\Output\ConsoleOutput;
39
40
define('OC_CONSOLE', 1);
41
42
function exceptionHandler($exception) {
43
	echo "An unhandled exception has been thrown:" . PHP_EOL;
44
	echo $exception;
45
	exit(1);
46
}
47
try {
48
	require_once __DIR__ . '/lib/base.php';
49
50
	// set to run indefinitely if needed
51
	if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
52
		@set_time_limit(0);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for set_time_limit(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

52
		/** @scrutinizer ignore-unhandled */ @set_time_limit(0);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
53
	}
54
55
	if (!OC::$CLI) {
56
		echo "This script can be run from the command line only" . PHP_EOL;
57
		exit(1);
58
	}
59
60
	set_exception_handler('exceptionHandler');
61
62
	if (!function_exists('posix_getuid')) {
63
		echo "The posix extensions are required - see https://www.php.net/manual/en/book.posix.php" . PHP_EOL;
64
		exit(1);
65
	}
66
	$user = posix_getuid();
67
	$configUser = fileowner(OC::$configDir . 'config.php');
68
	if ($user !== $configUser) {
69
		echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
70
		echo "Current user id: " . $user . PHP_EOL;
71
		echo "Owner id of config.php: " . $configUser . PHP_EOL;
72
		echo "Try adding 'sudo -u #" . $configUser . "' to the beginning of the command (without the single quotes)" . PHP_EOL;
73
		echo "If running with 'docker exec' try adding the option '-u " . $configUser . "' to the docker command (without the single quotes)" . PHP_EOL;
74
		exit(1);
75
	}
76
77
	$oldWorkingDir = getcwd();
78
	if ($oldWorkingDir === false) {
79
		echo "This script can be run from the Nextcloud root directory only." . PHP_EOL;
80
		echo "Can't determine current working dir - the script will continue to work but be aware of the above fact." . PHP_EOL;
81
	} elseif ($oldWorkingDir !== __DIR__ && !chdir(__DIR__)) {
82
		echo "This script can be run from the Nextcloud root directory only." . PHP_EOL;
83
		echo "Can't change to Nextcloud root directory." . PHP_EOL;
84
		exit(1);
85
	}
86
87
	if (!(function_exists('pcntl_signal') && function_exists('pcntl_signal_dispatch')) && !in_array('--no-warnings', $argv)) {
88
		echo "The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see https://www.php.net/manual/en/book.pcntl.php" . PHP_EOL;
89
		echo "Additionally the function 'pcntl_signal' and 'pcntl_signal_dispatch' need to be enabled in your php.ini." . PHP_EOL;
90
	}
91
92
	$application = new Application(
93
		\OC::$server->getConfig(),
94
		\OC::$server->getEventDispatcher(),
95
		\OC::$server->getRequest(),
96
		\OC::$server->get(\Psr\Log\LoggerInterface::class),
97
		\OC::$server->query(\OC\MemoryInfo::class)
98
	);
99
	$application->loadCommands(new ArgvInput(), new ConsoleOutput());
100
	$application->run();
101
} catch (Exception $ex) {
102
	exceptionHandler($ex);
103
} catch (Error $ex) {
104
	exceptionHandler($ex);
105
}
106