You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

console.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Christian Kampka <christian@kampka.net>
  5. * @author Edward Crompton <edward.crompton@gmail.com>
  6. * @author Joas Schilling <nickvergessen@owncloud.com>
  7. * @author Jost Baron <Jost.Baron@gmx.de>
  8. * @author Lukas Reschke <lukas@owncloud.com>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Philippe Le Brouster <plb@nebkha.net>
  11. * @author Thomas Müller <thomas.mueller@tmit.eu>
  12. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  13. *
  14. * @copyright Copyright (c) 2016, ownCloud, Inc.
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. use OC\Console\Application;
  31. use Symfony\Component\Console\Input\ArgvInput;
  32. use Symfony\Component\Console\Output\ConsoleOutput;
  33. define('OC_CONSOLE', 1);
  34. // Show warning if a PHP version below 5.4.0 is used, this has to happen here
  35. // because base.php will already use 5.4 syntax.
  36. if (version_compare(PHP_VERSION, '5.4.0') === -1) {
  37. echo 'This version of ownCloud requires at least PHP 5.4.0'.PHP_EOL;
  38. echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'.PHP_EOL;
  39. return;
  40. }
  41. function exceptionHandler($exception) {
  42. echo "An unhandled exception has been thrown:" . PHP_EOL;
  43. echo $exception;
  44. exit(1);
  45. }
  46. try {
  47. require_once 'lib/base.php';
  48. // set to run indefinitely if needed
  49. set_time_limit(0);
  50. if (!OC::$CLI) {
  51. echo "This script can be run from the command line only" . PHP_EOL;
  52. exit(0);
  53. }
  54. set_exception_handler('exceptionHandler');
  55. if (!OC_Util::runningOnWindows()) {
  56. if (!function_exists('posix_getuid')) {
  57. echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
  58. exit(0);
  59. }
  60. $user = posix_getpwuid(posix_getuid());
  61. $configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php'));
  62. if ($user['name'] !== $configUser['name']) {
  63. echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
  64. echo "Current user: " . $user['name'] . PHP_EOL;
  65. echo "Owner of config.php: " . $configUser['name'] . PHP_EOL;
  66. echo "Try adding 'sudo -u " . $configUser['name'] . " ' to the beginning of the command (without the single quotes)" . PHP_EOL;
  67. exit(0);
  68. }
  69. }
  70. $oldWorkingDir = getcwd();
  71. if ($oldWorkingDir === false) {
  72. echo "This script can be run from the ownCloud root directory only." . PHP_EOL;
  73. echo "Can't determine current working dir - the script will continue to work but be aware of the above fact." . PHP_EOL;
  74. } else if ($oldWorkingDir !== __DIR__ && !chdir(__DIR__)) {
  75. echo "This script can be run from the ownCloud root directory only." . PHP_EOL;
  76. echo "Can't change to ownCloud root directory." . PHP_EOL;
  77. exit(1);
  78. }
  79. if (!function_exists('pcntl_signal') && !in_array('--no-warnings', $argv)) {
  80. 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;
  81. }
  82. $application = new Application(\OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getRequest());
  83. $application->loadCommands(new ArgvInput(), new ConsoleOutput());
  84. $application->run();
  85. } catch (Exception $ex) {
  86. exceptionHandler($ex);
  87. } catch (Error $ex) {
  88. exceptionHandler($ex);
  89. }