console.php 2.4 KB

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