2014-12-04 13:51:04 -05:00
|
|
|
<?php
|
|
|
|
|
/**
|
2016-07-21 10:49:16 -04:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
|
*
|
2016-05-26 13:56:05 -04:00
|
|
|
* @author Björn Schießle <bjoern@schiessle.org>
|
2020-03-31 04:49:10 -04:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2016-05-26 13:56:05 -04:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2016-07-21 12:13:36 -04:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-07-21 10:49:16 -04:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2015-03-26 06:44:34 -04:00
|
|
|
*
|
|
|
|
|
* @license AGPL-3.0
|
|
|
|
|
*
|
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 13:57:53 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2014-12-04 13:51:04 -05:00
|
|
|
*
|
|
|
|
|
*/
|
2016-10-24 05:46:25 -04:00
|
|
|
namespace OCA\Files_Sharing\Controller;
|
2014-12-04 13:51:04 -05:00
|
|
|
|
|
|
|
|
use OCP\AppFramework\Controller;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCP\AppFramework\Http\DataResponse;
|
2014-12-04 13:51:04 -05:00
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
2015-08-22 08:36:01 -04:00
|
|
|
use OCP\Http\Client\IClientService;
|
2023-10-11 05:52:10 -04:00
|
|
|
use OCP\IConfig;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCP\IRequest;
|
2014-12-04 13:51:04 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class ExternalSharesController
|
|
|
|
|
*
|
2016-10-24 05:46:25 -04:00
|
|
|
* @package OCA\Files_Sharing\Controller
|
2014-12-04 13:51:04 -05:00
|
|
|
*/
|
|
|
|
|
class ExternalSharesController extends Controller {
|
2023-10-11 05:52:10 -04:00
|
|
|
public function __construct(
|
|
|
|
|
string $appName,
|
|
|
|
|
IRequest $request,
|
|
|
|
|
private \OCA\Files_Sharing\External\Manager $externalManager,
|
|
|
|
|
private IClientService $clientService,
|
|
|
|
|
private IConfig $config,
|
|
|
|
|
) {
|
2014-12-04 13:51:04 -05:00
|
|
|
parent::__construct($appName, $request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @NoAdminRequired
|
2015-10-02 03:57:33 -04:00
|
|
|
* @NoOutgoingFederatedSharingRequired
|
2014-12-04 13:51:04 -05:00
|
|
|
*
|
|
|
|
|
* @return JSONResponse
|
|
|
|
|
*/
|
|
|
|
|
public function index() {
|
2015-10-02 03:57:33 -04:00
|
|
|
return new JSONResponse($this->externalManager->getOpenShares());
|
2014-12-04 13:51:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @NoAdminRequired
|
2015-10-02 03:57:33 -04:00
|
|
|
* @NoOutgoingFederatedSharingRequired
|
2014-12-04 13:51:04 -05:00
|
|
|
*
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return JSONResponse
|
|
|
|
|
*/
|
|
|
|
|
public function create($id) {
|
2015-10-02 03:57:33 -04:00
|
|
|
$this->externalManager->acceptShare($id);
|
2014-12-04 13:51:04 -05:00
|
|
|
return new JSONResponse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @NoAdminRequired
|
2015-10-02 03:57:33 -04:00
|
|
|
* @NoOutgoingFederatedSharingRequired
|
2014-12-04 13:51:04 -05:00
|
|
|
*
|
2015-12-07 07:05:27 -05:00
|
|
|
* @param integer $id
|
2014-12-04 13:51:04 -05:00
|
|
|
* @return JSONResponse
|
|
|
|
|
*/
|
|
|
|
|
public function destroy($id) {
|
2015-10-02 03:57:33 -04:00
|
|
|
$this->externalManager->declineShare($id);
|
2014-12-04 13:51:04 -05:00
|
|
|
return new JSONResponse();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-22 08:36:01 -04:00
|
|
|
/**
|
|
|
|
|
* Test whether the specified remote is accessible
|
|
|
|
|
*
|
|
|
|
|
* @param string $remote
|
2016-02-29 09:17:06 -05:00
|
|
|
* @param bool $checkVersion
|
2015-08-22 08:36:01 -04:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2016-02-29 09:17:06 -05:00
|
|
|
protected function testUrl($remote, $checkVersion = false) {
|
2015-08-22 08:36:01 -04:00
|
|
|
try {
|
|
|
|
|
$client = $this->clientService->newClient();
|
|
|
|
|
$response = json_decode($client->get(
|
|
|
|
|
$remote,
|
|
|
|
|
[
|
|
|
|
|
'timeout' => 3,
|
|
|
|
|
'connect_timeout' => 3,
|
2023-10-11 05:52:10 -04:00
|
|
|
'verify' => !$this->config->getSystemValueBool('sharing.federation.allowSelfSignedCertificates', false),
|
2015-08-22 08:36:01 -04:00
|
|
|
]
|
|
|
|
|
)->getBody());
|
|
|
|
|
|
2016-02-29 09:17:06 -05:00
|
|
|
if ($checkVersion) {
|
|
|
|
|
return !empty($response->version) && version_compare($response->version, '7.0.0', '>=');
|
|
|
|
|
} else {
|
|
|
|
|
return is_object($response);
|
|
|
|
|
}
|
2015-08-22 08:36:01 -04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @PublicPage
|
2015-10-02 03:57:33 -04:00
|
|
|
* @NoOutgoingFederatedSharingRequired
|
|
|
|
|
* @NoIncomingFederatedSharingRequired
|
2015-08-22 08:36:01 -04:00
|
|
|
*
|
|
|
|
|
* @param string $remote
|
|
|
|
|
* @return DataResponse
|
|
|
|
|
*/
|
|
|
|
|
public function testRemote($remote) {
|
2023-06-02 12:38:40 -04:00
|
|
|
if (str_contains($remote, '#') || str_contains($remote, '?') || str_contains($remote, ';')) {
|
2020-03-12 08:43:29 -04:00
|
|
|
return new DataResponse(false);
|
|
|
|
|
}
|
2020-03-13 06:11:00 -04:00
|
|
|
|
2016-02-29 09:17:06 -05:00
|
|
|
if (
|
2023-09-05 08:42:48 -04:00
|
|
|
$this->testUrl('https://' . $remote . '/ocm-provider/') ||
|
|
|
|
|
$this->testUrl('https://' . $remote . '/ocm-provider/index.php') ||
|
2016-02-29 09:17:06 -05:00
|
|
|
$this->testUrl('https://' . $remote . '/status.php', true)
|
|
|
|
|
) {
|
2015-08-22 08:36:01 -04:00
|
|
|
return new DataResponse('https');
|
2016-02-29 09:17:06 -05:00
|
|
|
} elseif (
|
2023-09-05 08:42:48 -04:00
|
|
|
$this->testUrl('http://' . $remote . '/ocm-provider/') ||
|
|
|
|
|
$this->testUrl('http://' . $remote . '/ocm-provider/index.php') ||
|
2016-02-29 09:17:06 -05:00
|
|
|
$this->testUrl('http://' . $remote . '/status.php', true)
|
|
|
|
|
) {
|
2015-08-22 08:36:01 -04:00
|
|
|
return new DataResponse('http');
|
|
|
|
|
} else {
|
|
|
|
|
return new DataResponse(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-12-04 13:51:04 -05:00
|
|
|
}
|