console.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * Copyright (c) 2013 Bart Visscher <bartv@thisnet.nl>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. use Symfony\Component\Console\Application;
  9. define('OC_CONSOLE', 1);
  10. try {
  11. require_once 'lib/base.php';
  12. // set to run indefinitely if needed
  13. set_time_limit(0);
  14. if (!OC::$CLI) {
  15. echo "This script can be run from the command line only" . PHP_EOL;
  16. exit(0);
  17. }
  18. if (!OC_Util::runningOnWindows()) {
  19. if (!function_exists('posix_getuid')) {
  20. echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
  21. exit(0);
  22. }
  23. $user = posix_getpwuid(posix_getuid());
  24. $configUser = posix_getpwuid(fileowner(OC::$SERVERROOT . '/config/config.php'));
  25. if ($user['name'] !== $configUser['name']) {
  26. echo "Console has to be executed with the same user as the web server is operated" . PHP_EOL;
  27. echo "Current user: " . $user['name'] . PHP_EOL;
  28. echo "Web server user: " . $configUser['name'] . PHP_EOL;
  29. exit(0);
  30. }
  31. }
  32. $defaults = new OC_Defaults;
  33. $application = new Application($defaults->getName(), \OC_Util::getVersionString());
  34. require_once 'core/register_command.php';
  35. if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
  36. if (!\OCP\Util::needUpgrade()) {
  37. OC_App::loadApps();
  38. foreach (OC_App::getAllApps() as $app) {
  39. $file = OC_App::getAppPath($app) . '/appinfo/register_command.php';
  40. if (file_exists($file)) {
  41. require $file;
  42. }
  43. }
  44. } else {
  45. echo "ownCloud or one of the apps require upgrade - only a limited number of commands are available" . PHP_EOL;
  46. }
  47. } else {
  48. echo "ownCloud is not installed - only a limited number of commands are available" . PHP_EOL;
  49. }
  50. $application->run();
  51. } catch (Exception $ex) {
  52. echo "An unhandled exception has been thrown:" . PHP_EOL;
  53. echo $ex;
  54. exit(1);
  55. }