1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Bart Visscher <[email protected]> |
4
|
|
|
* @author Joas Schilling <[email protected]> |
5
|
|
|
* @author Lukas Reschke <[email protected]> |
6
|
|
|
* @author Morris Jobke <[email protected]> |
7
|
|
|
* @author Patrick Paysant <[email protected]> |
8
|
|
|
* @author Philipp Schaffrath <[email protected]> |
9
|
|
|
* @author RealRancor <[email protected]> |
10
|
|
|
* @author Thomas Müller <[email protected]> |
11
|
|
|
* @author Victor Dubiniuk <[email protected]> |
12
|
|
|
* |
13
|
|
|
* @copyright Copyright (c) 2018, ownCloud GmbH |
14
|
|
|
* @license AGPL-3.0 |
15
|
|
|
* |
16
|
|
|
* This code is free software: you can redistribute it and/or modify |
17
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
18
|
|
|
* as published by the Free Software Foundation. |
19
|
|
|
* |
20
|
|
|
* This program is distributed in the hope that it will be useful, |
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23
|
|
|
* GNU Affero General Public License for more details. |
24
|
|
|
* |
25
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
26
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
27
|
|
|
* |
28
|
|
|
*/ |
29
|
|
|
|
30
|
|
|
use OC\Console\Application; |
31
|
|
|
use Symfony\Component\Console\Input\ArgvInput; |
32
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput; |
33
|
|
|
|
34
|
|
|
\define('OC_CONSOLE', 1); |
35
|
|
|
|
36
|
|
|
// Show warning if a PHP version below 7.1.0 is used, this has to happen here |
37
|
|
|
// because base.php will already use 7.1 syntax. |
38
|
|
View Code Duplication |
if (\version_compare(PHP_VERSION, '7.1.0') === -1) { |
|
|
|
|
39
|
|
|
echo 'This version of ownCloud requires at least PHP 7.1.0'.PHP_EOL; |
40
|
|
|
echo 'You are currently running PHP ' . PHP_VERSION . '. Please update your PHP version.'.PHP_EOL; |
41
|
|
|
exit(1); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// Show warning if PHP 8 is used as ownCloud is not compatible with PHP 7.4 |
45
|
|
View Code Duplication |
if (\version_compare(PHP_VERSION, '7.4.0alpha1') !== -1) { |
|
|
|
|
46
|
|
|
echo 'This version of ownCloud is not compatible with PHP 7.4' . PHP_EOL; |
47
|
|
|
echo 'You are currently running PHP ' . PHP_VERSION . '.' . PHP_EOL; |
48
|
|
|
exit(1); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
// running oC on Windows is unsupported since 8.1, this has to happen here because |
52
|
|
|
// is seems that the autoloader on Windows fails later and just throws an exception. |
53
|
|
|
if (\stripos(PHP_OS, 'WIN') === 0) { |
54
|
|
|
echo 'ownCloud Server does not support Microsoft Windows.'; |
55
|
|
|
exit(1); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
function exceptionHandler($exception) { |
59
|
|
|
echo 'An unhandled exception has been thrown:' . PHP_EOL; |
60
|
|
|
echo $exception; |
61
|
|
|
exit(1); |
62
|
|
|
} |
63
|
|
|
try { |
64
|
|
|
require_once __DIR__ . '/lib/base.php'; |
65
|
|
|
|
66
|
|
|
// set to run indefinitely if needed |
67
|
|
|
\set_time_limit(0); |
68
|
|
|
|
69
|
|
|
if (!OC::$CLI) { |
70
|
|
|
echo 'This script can be run from the command line only' . PHP_EOL; |
71
|
|
|
exit(1); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
\set_exception_handler('exceptionHandler'); |
75
|
|
|
|
76
|
|
|
if (!\function_exists('posix_getuid')) { |
77
|
|
|
echo 'The posix extensions are required - see http://php.net/manual/en/book.posix.php' . PHP_EOL; |
78
|
|
|
exit(1); |
79
|
|
|
} |
80
|
|
|
$user = \posix_getpwuid(\posix_getuid()); |
81
|
|
|
$configUser = \posix_getpwuid(\fileowner(OC::$configDir . 'config.php')); |
82
|
|
|
if ($user['name'] !== $configUser['name']) { |
83
|
|
|
echo 'Console has to be executed with the user that owns the file config/config.php' . PHP_EOL; |
84
|
|
|
echo 'Current user: ' . $user['name'] . PHP_EOL; |
85
|
|
|
echo 'Owner of config.php: ' . $configUser['name'] . PHP_EOL; |
86
|
|
|
echo "Try adding 'sudo -u " . $configUser['name'] . " ' to the beginning of the command (without the single quotes)" . PHP_EOL; |
87
|
|
|
exit(1); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$oldWorkingDir = \getcwd(); |
91
|
|
|
if ($oldWorkingDir === false) { |
92
|
|
|
echo 'This script can be run from the ownCloud root directory only.' . PHP_EOL; |
93
|
|
|
echo "Can't determine current working dir - the script will continue to work but be aware of the above fact." . PHP_EOL; |
94
|
|
|
} elseif ($oldWorkingDir !== __DIR__ && !\chdir(__DIR__)) { |
95
|
|
|
echo 'This script can be run from the ownCloud root directory only.' . PHP_EOL; |
96
|
|
|
echo "Can't change to ownCloud root directory." . PHP_EOL; |
97
|
|
|
exit(1); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
if (!\function_exists('pcntl_signal') && !\in_array('--no-warnings', $argv, true)) { |
101
|
|
|
echo 'The process control (PCNTL) extensions are required in case you want to interrupt long running commands - see http://php.net/manual/en/book.pcntl.php' . PHP_EOL; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$application = new Application(\OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getRequest()); |
105
|
|
|
$application->loadCommands(new ArgvInput(), new ConsoleOutput()); |
106
|
|
|
$application->run(); |
107
|
|
|
} catch (Exception $ex) { |
108
|
|
|
exceptionHandler($ex); |
109
|
|
|
} catch (Error $ex) { |
110
|
|
|
exceptionHandler($ex); |
111
|
|
|
} |
112
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.