console.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @author Bart Visscher <bartv@thisnet.nl>
  4. * @author Christian Kampka <christian@kampka.net>
  5. * @author Jost Baron <Jost.Baron@gmx.de>
  6. * @author Lukas Reschke <lukas@owncloud.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Philippe Le Brouster <plb@nebkha.net>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. *
  11. * @copyright Copyright (c) 2015, ownCloud, Inc.
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. use OC\Console\Application;
  28. use Symfony\Component\Console\Output\ConsoleOutput;
  29. define('OC_CONSOLE', 1);
  30. // Show warning if a PHP version below 5.4.0 is used, this has to happen here
  31. // because base.php will already use 5.4 syntax.
  32. if (version_compare(PHP_VERSION, '5.4.0') === -1) {
  33. echo 'This version of ownCloud requires at least PHP 5.4.0'.PHP_EOL;
  34. echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.'.PHP_EOL;
  35. return;
  36. }
  37. try {
  38. require_once 'lib/base.php';
  39. // set to run indefinitely if needed
  40. set_time_limit(0);
  41. if (!OC::$CLI) {
  42. echo "This script can be run from the command line only" . PHP_EOL;
  43. exit(0);
  44. }
  45. if (!OC_Util::runningOnWindows()) {
  46. if (!function_exists('posix_getuid')) {
  47. echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
  48. exit(0);
  49. }
  50. $user = posix_getpwuid(posix_getuid());
  51. $configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php'));
  52. if ($user['name'] !== $configUser['name']) {
  53. echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL;
  54. echo "Current user: " . $user['name'] . PHP_EOL;
  55. echo "Owner of config.php: " . $configUser['name'] . PHP_EOL;
  56. exit(0);
  57. }
  58. }
  59. $application = new Application(\OC::$server->getConfig());
  60. $application->loadCommands(new ConsoleOutput());
  61. $application->run();
  62. } catch (Exception $ex) {
  63. echo "An unhandled exception has been thrown:" . PHP_EOL;
  64. echo $ex;
  65. exit(1);
  66. }