|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Björn Schießle <[email protected]> |
|
6
|
|
|
* @author Lukas Reschke <[email protected]> |
|
7
|
|
|
* @author Morris Jobke <[email protected]> |
|
8
|
|
|
* @author Robin Appelman <[email protected]> |
|
9
|
|
|
* @author Roeland Jago Douma <[email protected]> |
|
10
|
|
|
* |
|
11
|
|
|
* @license AGPL-3.0 |
|
12
|
|
|
* |
|
13
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
14
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
15
|
|
|
* as published by the Free Software Foundation. |
|
16
|
|
|
* |
|
17
|
|
|
* This program is distributed in the hope that it will be useful, |
|
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20
|
|
|
* GNU Affero General Public License for more details. |
|
21
|
|
|
* |
|
22
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
24
|
|
|
* |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace OCA\Files_Sharing\Controllers; |
|
28
|
|
|
|
|
29
|
|
|
use OCP\AppFramework\Controller; |
|
30
|
|
|
use OCP\IRequest; |
|
31
|
|
|
use OCP\AppFramework\Http\JSONResponse; |
|
32
|
|
|
use OCP\Http\Client\IClientService; |
|
33
|
|
|
use OCP\AppFramework\Http\DataResponse; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Class ExternalSharesController |
|
37
|
|
|
* |
|
38
|
|
|
* @package OCA\Files_Sharing\Controllers |
|
39
|
|
|
*/ |
|
40
|
|
|
class ExternalSharesController extends Controller { |
|
41
|
|
|
|
|
42
|
|
|
/** @var \OCA\Files_Sharing\External\Manager */ |
|
43
|
|
|
private $externalManager; |
|
44
|
|
|
/** @var IClientService */ |
|
45
|
|
|
private $clientService; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param string $appName |
|
49
|
|
|
* @param IRequest $request |
|
50
|
|
|
* @param \OCA\Files_Sharing\External\Manager $externalManager |
|
51
|
|
|
* @param IClientService $clientService |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct($appName, |
|
54
|
|
|
IRequest $request, |
|
55
|
|
|
\OCA\Files_Sharing\External\Manager $externalManager, |
|
56
|
|
|
IClientService $clientService) { |
|
57
|
|
|
parent::__construct($appName, $request); |
|
58
|
|
|
$this->externalManager = $externalManager; |
|
59
|
|
|
$this->clientService = $clientService; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @NoAdminRequired |
|
64
|
|
|
* @NoOutgoingFederatedSharingRequired |
|
65
|
|
|
* |
|
66
|
|
|
* @return JSONResponse |
|
67
|
|
|
*/ |
|
68
|
|
|
public function index() { |
|
69
|
|
|
return new JSONResponse($this->externalManager->getOpenShares()); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @NoAdminRequired |
|
74
|
|
|
* @NoOutgoingFederatedSharingRequired |
|
75
|
|
|
* |
|
76
|
|
|
* @param int $id |
|
77
|
|
|
* @return JSONResponse |
|
78
|
|
|
*/ |
|
79
|
|
|
public function create($id) { |
|
80
|
|
|
$this->externalManager->acceptShare($id); |
|
81
|
|
|
return new JSONResponse(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @NoAdminRequired |
|
86
|
|
|
* @NoOutgoingFederatedSharingRequired |
|
87
|
|
|
* |
|
88
|
|
|
* @param integer $id |
|
89
|
|
|
* @return JSONResponse |
|
90
|
|
|
*/ |
|
91
|
|
|
public function destroy($id) { |
|
92
|
|
|
$this->externalManager->declineShare($id); |
|
93
|
|
|
return new JSONResponse(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Test whether the specified remote is accessible |
|
98
|
|
|
* |
|
99
|
|
|
* @param string $remote |
|
100
|
|
|
* @param bool $checkVersion |
|
101
|
|
|
* @return bool |
|
102
|
|
|
*/ |
|
103
|
|
|
protected function testUrl($remote, $checkVersion = false) { |
|
104
|
|
|
try { |
|
105
|
|
|
$client = $this->clientService->newClient(); |
|
106
|
|
|
$response = json_decode($client->get( |
|
107
|
|
|
$remote, |
|
108
|
|
|
[ |
|
109
|
|
|
'timeout' => 3, |
|
110
|
|
|
'connect_timeout' => 3, |
|
111
|
|
|
] |
|
112
|
|
|
)->getBody()); |
|
113
|
|
|
|
|
114
|
|
|
if ($checkVersion) { |
|
115
|
|
|
return !empty($response->version) && version_compare($response->version, '7.0.0', '>='); |
|
116
|
|
|
} else { |
|
117
|
|
|
return is_object($response); |
|
118
|
|
|
} |
|
119
|
|
|
} catch (\Exception $e) { |
|
120
|
|
|
return false; |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @PublicPage |
|
126
|
|
|
* @NoOutgoingFederatedSharingRequired |
|
127
|
|
|
* @NoIncomingFederatedSharingRequired |
|
128
|
|
|
* |
|
129
|
|
|
* @param string $remote |
|
130
|
|
|
* @return DataResponse |
|
131
|
|
|
*/ |
|
132
|
|
|
public function testRemote($remote) { |
|
133
|
|
|
if ( |
|
134
|
|
|
$this->testUrl('https://' . $remote . '/ocs-provider/') || |
|
135
|
|
|
$this->testUrl('https://' . $remote . '/ocs-provider/index.php') || |
|
136
|
|
|
$this->testUrl('https://' . $remote . '/status.php', true) |
|
137
|
|
|
) { |
|
138
|
|
|
return new DataResponse('https'); |
|
|
|
|
|
|
139
|
|
|
} elseif ( |
|
140
|
|
|
$this->testUrl('http://' . $remote . '/ocs-provider/') || |
|
141
|
|
|
$this->testUrl('http://' . $remote . '/ocs-provider/index.php') || |
|
142
|
|
|
$this->testUrl('http://' . $remote . '/status.php', true) |
|
143
|
|
|
) { |
|
144
|
|
|
return new DataResponse('http'); |
|
|
|
|
|
|
145
|
|
|
} else { |
|
146
|
|
|
return new DataResponse(false); |
|
|
|
|
|
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
} |
|
151
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: