|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* ownCloud |
|
4
|
|
|
* |
|
5
|
|
|
* @author Artur Neumann <[email protected]> |
|
6
|
|
|
* @copyright 2017 Artur Neumann [email protected] |
|
7
|
|
|
* |
|
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
10
|
|
|
* as published by the Free Software Foundation. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace OCA\Testing; |
|
23
|
|
|
|
|
24
|
|
|
use \OCP\IRequest; |
|
25
|
|
|
use \OC\OCS\Result; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* run the occ command from an API call |
|
29
|
|
|
* |
|
30
|
|
|
* @author Artur Neumann <[email protected]> |
|
31
|
|
|
* |
|
32
|
|
|
*/ |
|
33
|
|
|
class Occ { |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* |
|
37
|
|
|
* @var IRequest |
|
38
|
|
|
*/ |
|
39
|
|
|
private $request; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* |
|
43
|
|
|
* @param IRequest $request |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct(IRequest $request) { |
|
46
|
|
|
$this->request = $request; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* |
|
51
|
|
|
* @return Result |
|
52
|
|
|
*/ |
|
53
|
|
|
public function execute() { |
|
54
|
|
|
$command = $this->request->getParam("command", ""); |
|
55
|
|
|
$args = preg_split("/[\s,]+/", $command); |
|
56
|
|
|
$args = array_map( |
|
57
|
|
|
function ($arg) { |
|
58
|
|
|
return escapeshellarg($arg); |
|
59
|
|
|
}, $args |
|
60
|
|
|
); |
|
61
|
|
|
|
|
62
|
|
|
$args = implode(' ', $args); |
|
63
|
|
|
$descriptor = [ |
|
64
|
|
|
0 => ['pipe', 'r'], |
|
65
|
|
|
1 => ['pipe', 'w'], |
|
66
|
|
|
2 => ['pipe', 'w'], |
|
67
|
|
|
]; |
|
68
|
|
|
$process = proc_open( |
|
69
|
|
|
'php console.php ' . $args, |
|
70
|
|
|
$descriptor, |
|
71
|
|
|
$pipes, |
|
72
|
|
|
realpath("../") |
|
73
|
|
|
); |
|
74
|
|
|
$lastStdOut = stream_get_contents($pipes[1]); |
|
75
|
|
|
$lastStdErr = stream_get_contents($pipes[2]); |
|
76
|
|
|
$lastCode = proc_close($process); |
|
77
|
|
|
$result = [ |
|
78
|
|
|
"code" => $lastCode, |
|
79
|
|
|
"stdOut" => $lastStdOut, |
|
80
|
|
|
"stdErr" => $lastStdErr |
|
81
|
|
|
]; |
|
82
|
|
|
|
|
83
|
|
|
$resultCode = $lastCode + 100; |
|
84
|
|
|
|
|
85
|
|
|
return new Result($result, $resultCode); |
|
86
|
|
|
} |
|
87
|
|
|
} |