1
0

console.php 3.6 KB

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