console.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 Symfony\Component\Console\Application;
  26. define('OC_CONSOLE', 1);
  27. try {
  28. require_once 'lib/base.php';
  29. // set to run indefinitely if needed
  30. set_time_limit(0);
  31. if (!OC::$CLI) {
  32. echo "This script can be run from the command line only" . PHP_EOL;
  33. exit(0);
  34. }
  35. if (!OC_Util::runningOnWindows()) {
  36. if (!function_exists('posix_getuid')) {
  37. echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL;
  38. exit(0);
  39. }
  40. $user = posix_getpwuid(posix_getuid());
  41. $configUser = posix_getpwuid(fileowner(OC::$SERVERROOT . '/config/config.php'));
  42. if ($user['name'] !== $configUser['name']) {
  43. echo "Console has to be executed with the same user as the web server is operated" . PHP_EOL;
  44. echo "Current user: " . $user['name'] . PHP_EOL;
  45. echo "Web server user: " . $configUser['name'] . PHP_EOL;
  46. exit(0);
  47. }
  48. }
  49. $defaults = new OC_Defaults;
  50. $application = new Application($defaults->getName(), \OC_Util::getVersionString());
  51. require_once 'core/register_command.php';
  52. if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
  53. if (!\OCP\Util::needUpgrade()) {
  54. OC_App::loadApps();
  55. foreach (OC_App::getAllApps() as $app) {
  56. $file = OC_App::getAppPath($app) . '/appinfo/register_command.php';
  57. if (file_exists($file)) {
  58. require $file;
  59. }
  60. }
  61. } else {
  62. echo "ownCloud or one of the apps require upgrade - only a limited number of commands are available" . PHP_EOL;
  63. }
  64. } else {
  65. echo "ownCloud is not installed - only a limited number of commands are available" . PHP_EOL;
  66. }
  67. $application->run();
  68. } catch (Exception $ex) {
  69. echo "An unhandled exception has been thrown:" . PHP_EOL;
  70. echo $ex;
  71. exit(1);
  72. }