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 2.4KB

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