Example #1
0
 /**
  * @PublicPage
  * @NoCSRFRequired
  *
  * Execute occ command
  * Sample request
  *	POST http://domain.tld/index.php/occ/status',
  * 		{
  *			'params': {
  * 					'--no-warnings':'1',
  *		 			'--output':'json'
  * 			},
  * 			'token': 'someToken'
  * 		}
  *
  * @param string $command
  * @param string $token
  * @param array $params
  *
  * @return JSONResponse
  * @throws \Exception
  */
 public function execute($command, $token, $params = [])
 {
     try {
         $this->validateRequest($command, $token);
         $output = new BufferedOutput();
         $formatter = $output->getFormatter();
         $formatter->setDecorated(false);
         $this->console->setAutoExit(false);
         $this->console->loadCommands(new ArrayInput([]), $output);
         $inputArray = array_merge(['command' => $command], $params);
         $input = new ArrayInput($inputArray);
         $exitCode = $this->console->run($input, $output);
         $response = $output->fetch();
         $json = ['exitCode' => $exitCode, 'response' => $response];
     } catch (\UnexpectedValueException $e) {
         $json = ['exitCode' => 126, 'response' => 'Not allowed', 'details' => $e->getMessage()];
     }
     return new JSONResponse($json);
 }
Example #2
0
 public function ajaxAction()
 {
     $application = $this->container['application'];
     $input = new StringInput($this->command);
     $input->setInteractive(false);
     $output = new BufferedOutput();
     $formatter = $output->getFormatter();
     $formatter->setDecorated(true);
     $output->setFormatter(new HtmlOutputFormatter($formatter));
     $application->setAutoExit(false);
     // Some commands  dump things out instead of returning a value
     ob_start();
     $errorCode = $application->run($input, $output);
     if (!($result = $output->fetch())) {
         $result = ob_get_contents();
         // If empty, replace it by the catched output
     }
     ob_end_clean();
     $result = nl2br($result);
     $result = preg_replace('|<br />\\r.*<br />(\\r.*?)<br />|', '$1<br />', $result);
     return ['input' => $this->command, 'output' => $result, 'environment' => '', 'error_code' => $errorCode];
 }
 public function ajaxAction()
 {
     $application = $this->container['application'];
     $input = new StringInput($this->command);
     $input->setInteractive(false);
     $output = new BufferedOutput();
     $formatter = $output->getFormatter();
     $formatter->setDecorated(true);
     $output->setFormatter(new HtmlOutputFormatter($formatter));
     $application->setAutoExit(false);
     $endpoint = preg_replace('/(updater\\/|updater\\/index.php)$/', '', $this->request->getRequestUri());
     $fullEndpoint = sprintf('%s://%s%sindex.php/occ/', $this->request->getServerProtocol(), $this->request->getHost(), $endpoint !== '' ? $endpoint : '/');
     $application->setEndpoint($fullEndpoint);
     $application->setAuthToken($this->request->header('X_Updater_Auth'));
     // Some commands dump things out instead of returning a value
     ob_start();
     $errorCode = $application->run($input, $output);
     if (!($result = $output->fetch())) {
         $result = ob_get_contents();
         // If empty, replace it by the catched output
     }
     ob_end_clean();
     $result = nl2br($result);
     $result = preg_replace('|<br />\\r.*<br />(\\r.*?)<br />|', '$1<br />', $result);
     return ['input' => $this->command, 'output' => $result, 'environment' => '', 'error_code' => $errorCode];
 }