Skip to content

Instantly share code, notes, and snippets.

@VicDeo
Last active October 25, 2016 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VicDeo/b423a50776440c7b4a10f55ce0068845 to your computer and use it in GitHub Desktop.
Save VicDeo/b423a50776440c7b4a10f55ce0068845 to your computer and use it in GitHub Desktop.
diff -Naur updater/src/Command/PostUpgradeCleanupCommand.php updater/src/Command/PostUpgradeCleanupCommand.php
--- updater/src/Command/PostUpgradeCleanupCommand.php 2016-07-18 20:41:11.000000000 +0300
+++ updater/src/Command/PostUpgradeCleanupCommand.php 2016-10-25 14:48:30.000000000 +0300
@@ -57,6 +57,14 @@
//Cleanup Filesystem
$fsHelper->removeIfExists($locator->getExtractionBaseDir());
+ //Retrigger integrity check
+ try {
+ $this->container['utils.occrunner']->run('integrity:check-core');
+ } catch (\Exception $e){
+ $this->getApplication()->getLogger()->error('Integrity check failed');
+ $this->getApplication()->logException($e);
+ }
+
//Cleanup updater cache
$registry->clearAll();
diff -Naur updater/src/Console/Application.php updater/src/Console/Application.php
--- updater/src/Console/Application.php 2016-07-18 20:41:11.000000000 +0300
+++ updater/src/Console/Application.php 2016-10-25 14:48:30.000000000 +0300
@@ -150,7 +150,23 @@
$configReader = $this->diContainer['utils.configReader'];
$commandName = $this->getCommandName($input);
try{
- $configReader->init();
+ try {
+ $configReader->init();
+ } catch (\UnexpectedValueException $e){
+ // try fallback to localhost
+ preg_match_all('/https?:\/\/([^\/]*).*$/', $this->getEndpoint(), $matches);
+ if (isset($matches[1][0])){
+ $newEndPoint = str_replace($matches[1][0], 'localhost', $this->getEndpoint());
+ $this->setEndpoint($newEndPoint);
+ try {
+ $configReader->init();
+ } catch (\UnexpectedValueException $e){
+ // fallback to CLI
+ $this->diContainer['utils.occrunner']->setCanUseProcess(true);
+ $configReader->init();
+ }
+ }
+ }
} catch (ProcessFailedException $e){
if (!in_array($commandName, $this->allowFailure)){
$this->logException($e);
@@ -184,7 +200,7 @@
$command->setContainer($this->getContainer());
$commandName = $this->getCommandName($input);
$this->getLogger()->info('Execution of ' . $commandName . ' command started');
- if (!empty($command->getMessage())){
+ if ($command->getMessage() !== ''){
$message = sprintf('<info>%s</info>', $command->getMessage());
$output->writeln($message);
}
diff -Naur updater/src/Utils/OccRunner.php updater/src/Utils/OccRunner.php
--- updater/src/Utils/OccRunner.php 2016-07-18 20:41:11.000000000 +0300
+++ updater/src/Utils/OccRunner.php 2016-10-25 14:48:30.000000000 +0300
@@ -49,13 +49,17 @@
$this->canUseProcess = $canUseProcess;
}
+ public function setCanUseProcess($canUseProcess){
+ $this->canUseProcess = $canUseProcess;
+ }
+
public function run($command, $args = [], $asJson = false){
if ($this->canUseProcess){
$extra = $asJson ? '--output=json' : '';
$cmdLine = trim($command . ' ' . $extra);
foreach ($args as $optionTitle => $optionValue){
if (strpos($optionTitle, '--') === 0){
- $line = trim("$optionTitle $optionValue");
+ $line = trim("$optionTitle=$optionValue");
} else {
$line = $optionValue;
}
--- core/controller/occcontroller.php 2016-07-18 20:40:58.000000000 +0300
+++ core/controller/occcontroller.php 2016-10-25 14:48:22.000000000 +0300
@@ -25,6 +25,7 @@
use OCP\AppFramework\Http\JSONResponse;
use OC\Console\Application;
use OCP\IConfig;
+use OCP\ILogger;
use OCP\IRequest;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
@@ -40,6 +41,7 @@
'check',
'config:list',
'maintenance:mode',
+ 'integrity:check-core',
'status',
'upgrade'
];
@@ -48,6 +50,8 @@
private $config;
/** @var Application */
private $console;
+ /** @var ILogger */
+ private $logger;
/**
* OccController constructor.
@@ -56,12 +60,14 @@
* @param IRequest $request
* @param IConfig $config
* @param Application $console
+ * @param ILogger $logger
*/
public function __construct($appName, IRequest $request,
- IConfig $config, Application $console) {
+ IConfig $config, Application $console, ILogger $logger) {
parent::__construct($appName, $request);
$this->config = $config;
$this->console = $console;
+ $this->logger = $logger;
}
/**
@@ -108,6 +114,13 @@
];
} catch (\UnexpectedValueException $e){
+ $this->logger->warning(
+ 'Invalid request to occ controller. Details: "{details}"',
+ [
+ 'app' => 'core',
+ 'details' => $e->getMessage()
+ ]
+ );
$json = [
'exitCode' => 126,
'response' => 'Not allowed',
@@ -123,7 +136,12 @@
* @param $token
*/
protected function validateRequest($command, $token){
- if (!in_array($this->request->getRemoteAddress(), ['::1', '127.0.0.1', 'localhost'])) {
+ $allowedHosts = ['::1', '127.0.0.1', 'localhost'];
+ if (isset($this->request->server['SERVER_ADDR'])){
+ array_push($allowedHosts, $this->request->server['SERVER_ADDR']);
+ }
+
+ if (!in_array($this->request->getRemoteAddress(), $allowedHosts)) {
throw new \UnexpectedValueException('Web executor is not allowed to run from a different host');
}
--- core/application.php 2016-07-18 20:40:58.000000000 +0300
+++ core/application.php 2016-10-25 14:48:22.000000000 +0300
@@ -90,18 +90,6 @@
$c->query('Logger')
);
});
- $container->registerService('OccController', function(SimpleContainer $c) {
- return new OccController(
- $c->query('AppName'),
- $c->query('Request'),
- $c->query('Config'),
- new \OC\Console\Application(
- $c->query('Config'),
- $c->query('ServerContainer')->getEventDispatcher(),
- $c->query('Request')
- )
- );
- });
/**
* Core class wrappers
--- core/routes.php 2016-07-18 20:40:58.000000000 +0300
+++ core/routes.php 2016-10-25 14:48:22.000000000 +0300
@@ -42,7 +42,7 @@
['name' => 'avatar#postCroppedAvatar', 'url' => '/avatar/cropped', 'verb' => 'POST'],
['name' => 'avatar#getTmpAvatar', 'url' => '/avatar/tmp', 'verb' => 'GET'],
['name' => 'avatar#postAvatar', 'url' => '/avatar/', 'verb' => 'POST'],
- ['name' => 'occ#execute', 'url' => '/occ/{command}', 'verb' => 'POST'],
+ ['name' => 'OC\Core\Controller\Occ#execute', 'url' => '/occ/{command}', 'verb' => 'POST'],
]
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment