logger = OC::$server->get(LoggerInterface::class); $this->userId = $userId; $this->application = new Application( OC::$server->get(\OCP\ServerVersion::class), OC::$server->getConfig(), OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class), new FakeRequest(), $this->logger, OC::$server->query(MemoryInfo::class), OC::$server->get(\OCP\App\IAppManager::class), // Obtain the IAppManager OC::$server->get(\OCP\Defaults::class) ); $this->application->setAutoExit(false); $this->output = new OccOutput(OutputInterface::VERBOSITY_NORMAL, true); $this->application->loadCommands(new StringInput(""), $this->output); $reflectionProperty = new \ReflectionProperty(Application::class, 'application'); $reflectionProperty->setAccessible(true); $this->symphonyApplication = $reflectionProperty->getValue($this->application); } /** * @NoCSRFRequired */ public function index() { return new TemplateResponse('occweb', 'index'); } /** * @param $input * @return string */ private function run($input) { try { $this->application->run($input, $this->output); return $this->output->fetch(); } catch (Exception $ex) { $this->logger->error($ex->getMessage(), ['exception' => $ex]); return "error: " . $ex->getMessage(); } } /** * @param string $command * @return DataResponse */ public function cmd($command) { $this->logger->debug($command); $input = new StringInput($command); $response = $this->run($input); $this->logger->debug($response); return new DataResponse($response); } public function list() { $defs = $this->symphonyApplication->all(); $cmds = array(); foreach ($defs as $d) { array_push($cmds, $d->getName()); } return new DataResponse($cmds); } }