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.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. $application = new Application(\OC::$server->getConfig());
  71. $application->loadCommands(new ConsoleOutput());
  72. $application->run();
  73. } catch (Exception $ex) {
  74. echo "An unhandled exception has been thrown:" . PHP_EOL;
  75. echo $ex;
  76. exit(1);
  77. }