console.php 3.4 KB

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