1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Victor Dubiniuk <[email protected]> |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc. |
7
|
|
|
* @license AGPL-3.0 |
8
|
|
|
* |
9
|
|
|
* This code is free software: you can redistribute it and/or modify |
10
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
11
|
|
|
* as published by the Free Software Foundation. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Affero General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace Owncloud\Updater\Controller; |
24
|
|
|
|
25
|
|
|
use Symfony\Component\Console\Input\StringInput; |
26
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
27
|
|
|
use Owncloud\Updater\Formatter\HtmlOutputFormatter; |
28
|
|
|
use Owncloud\Updater\Http\Request; |
29
|
|
|
|
30
|
|
|
class IndexController { |
31
|
|
|
|
32
|
|
|
/** @var \Pimple\Container */ |
33
|
|
|
protected $container; |
34
|
|
|
|
35
|
|
|
/** @var Request */ |
36
|
|
|
protected $request; |
37
|
|
|
|
38
|
|
|
public function __construct(\Pimple\Container $container, $request = null){ |
39
|
|
|
$this->container = $container; |
40
|
|
|
if (is_null($request)){ |
41
|
|
|
$this->request = new Request(['post' => $_POST]); |
42
|
|
|
}else { |
43
|
|
|
$this->request = $request; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function ajaxAction(){ |
48
|
|
|
$application = $this->container['application']; |
49
|
|
|
|
50
|
|
|
$command = $this->request->postParameter('command'); |
51
|
|
|
|
52
|
|
|
$input = new StringInput($command); |
53
|
|
|
$input->setInteractive(false); |
54
|
|
|
|
55
|
|
|
$output = new BufferedOutput(); |
56
|
|
|
$formatter = $output->getFormatter(); |
57
|
|
|
$formatter->setDecorated(true); |
58
|
|
|
$output->setFormatter(new HtmlOutputFormatter($formatter)); |
59
|
|
|
|
60
|
|
|
$application->setAutoExit(false); |
61
|
|
|
// Some commands dump things out instead of returning a value |
62
|
|
|
ob_start(); |
63
|
|
|
$errorCode = $application->run($input, $output); |
64
|
|
|
if (!$result = $output->fetch()){ |
65
|
|
|
$result = ob_get_contents(); // If empty, replace it by the catched output |
66
|
|
|
} |
67
|
|
|
ob_end_clean(); |
68
|
|
|
|
69
|
|
|
return [ |
70
|
|
|
'input' => $command, |
71
|
|
|
'output' => $result, |
72
|
|
|
'environment' => '', |
73
|
|
|
'error_code' => $errorCode |
74
|
|
|
]; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
} |
78
|
|
|
|