console.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Edward Crompton <edward.crompton@gmail.com>
  5. * @author Joas Schilling <nickvergessen@owncloud.com>
  6. * @author Jost Baron <Jost.Baron@gmx.de>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Philippe Le Brouster <plb@nebkha.net>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  12. *
  13. * @copyright Copyright (c) 2016, ownCloud, Inc.
  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. use OC\Console\Application;
  30. use Symfony\Component\Console\Input\ArgvInput;
  31. use Symfony\Component\Console\Output\ConsoleOutput;
  32. define('OC_CONSOLE', 1);
  33. // Show warning if a PHP version below 5.4.0 is used, this has to happen here
  34. // because base.php will already use 5.4 syntax.
  35. if (version_compare(PHP_VERSION, '5.4.0') === -1) {
  36. echo 'This version of ownCloud requires at least PHP 5.4.0'.PHP_EOL;
  37. echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'.PHP_EOL;
  38. return;
  39. }
  40. function exceptionHandler($exception) {
  41. echo "An unhandled exception has been thrown:" . PHP_EOL;
  42. echo $exception;
  43. exit(1);
  44. }
  45. try {
  46. require_once 'lib/base.php';
  47. // set to run indefinitely if needed
  48. set_time_limit(0);
  49. if (!OC::$CLI) {
  50. echo "This script can be run from the command line only" . PHP_EOL;
  51. exit(0);
  52. }
  53. set_exception_handler('exceptionHandler');
  54. if (!OC_Util::runningOnWindows()) {
  55. if (!function_exists('posix_getuid')) {
  56. echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
  57. exit(0);
  58. }
  59. $user = posix_getpwuid(posix_getuid());
  60. $configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php'));
  61. if ($user['name'] !== $configUser['name']) {
  62. echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
  63. echo "Current user: " . $user['name'] . PHP_EOL;
  64. echo "Owner of config.php: " . $configUser['name'] . PHP_EOL;
  65. echo "Try adding 'sudo -u " . $configUser['name'] . " ' to the beginning of the command (without the single quotes)" . PHP_EOL;
  66. exit(0);
  67. }
  68. }
  69. $oldWorkingDir = getcwd();
  70. if ($oldWorkingDir === false) {
  71. echo "This script can be run from the ownCloud root directory only." . PHP_EOL;
  72. echo "Can't determine current working dir - the script will continue to work but be aware of the above fact." . PHP_EOL;
  73. } else if ($oldWorkingDir !== __DIR__ && !chdir(__DIR__)) {
  74. echo "This script can be run from the ownCloud root directory only." . PHP_EOL;
  75. echo "Can't change to ownCloud root directory." . PHP_EOL;
  76. exit(1);
  77. }
  78. if (!function_exists('pcntl_signal') && !in_array('--no-warnings', $argv)) {
  79. 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;
  80. }
  81. $application = new Application(\OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getRequest());
  82. $application->loadCommands(new ArgvInput(), new ConsoleOutput());
  83. $application->run();
  84. } catch (Exception $ex) {
  85. exceptionHandler($ex);
  86. } catch (Error $ex) {
  87. exceptionHandler($ex);
  88. }