kopia lustrzana https://github.com/nextcloud/social
request on host-meta
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/578/head
rodzic
20a4cb0b6f
commit
50fb954e66
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nextcloud - Social Support
|
||||||
|
*
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later. See the COPYING file.
|
||||||
|
*
|
||||||
|
* @author Maxence Lange <maxence@artificial-owl.com>
|
||||||
|
* @copyright 2018, Maxence Lange <maxence@artificial-owl.com>
|
||||||
|
* @license GNU AGPL version 3 or any later version
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
namespace OCA\Social\Exceptions;
|
||||||
|
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
|
||||||
|
class HostMetaException extends Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||||
use daita\MySmallPhpTools\Traits\TPathTools;
|
use daita\MySmallPhpTools\Traits\TPathTools;
|
||||||
use Exception;
|
use Exception;
|
||||||
use OCA\Social\AP;
|
use OCA\Social\AP;
|
||||||
|
use OCA\Social\Exceptions\HostMetaException;
|
||||||
use OCA\Social\Exceptions\InvalidOriginException;
|
use OCA\Social\Exceptions\InvalidOriginException;
|
||||||
use OCA\Social\Exceptions\InvalidResourceException;
|
use OCA\Social\Exceptions\InvalidResourceException;
|
||||||
use OCA\Social\Exceptions\RedundancyLimitException;
|
use OCA\Social\Exceptions\RedundancyLimitException;
|
||||||
|
@ -121,7 +122,13 @@ class CurlService {
|
||||||
throw new InvalidResourceException();
|
throw new InvalidResourceException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$request = new Request('/.well-known/webfinger');
|
try {
|
||||||
|
$path = $this->hostMeta($host);
|
||||||
|
} catch (HostMetaException $e) {
|
||||||
|
$path = '/.well-known/webfinger';
|
||||||
|
}
|
||||||
|
|
||||||
|
$request = new Request($path);
|
||||||
$request->addData('resource', 'acct:' . $account);
|
$request->addData('resource', 'acct:' . $account);
|
||||||
$request->setAddress($host);
|
$request->setAddress($host);
|
||||||
|
|
||||||
|
@ -138,6 +145,32 @@ class CurlService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $host
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @throws HostMetaException
|
||||||
|
*/
|
||||||
|
public function hostMeta(string &$host): string {
|
||||||
|
$request = new Request('/.well-known/host-meta');
|
||||||
|
$request->setAddress($host);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$result = $this->request($request);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->miscService->log(
|
||||||
|
'hostMeta Exception - ' . get_class($e) . ' - ' . $e->getMessage(), 0
|
||||||
|
);
|
||||||
|
throw new HostMetaException($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = $this->get('Link.@attributes.template', $result, '');
|
||||||
|
$host = parse_url($url, PHP_URL_HOST);
|
||||||
|
|
||||||
|
return parse_url($url, PHP_URL_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $account
|
* @param string $account
|
||||||
*
|
*
|
||||||
|
@ -252,9 +285,16 @@ class CurlService {
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->miscService->log(
|
$this->miscService->log(
|
||||||
'[>>] request: ' . json_encode($request) . ' - result: ' . $result, 1
|
'[>>] request: ' . json_encode($request) . ' - content-type: '
|
||||||
|
. $request->getContentType() . ' - result: ' . $result, 1
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (strpos($request->getContentType(), 'application/xrd') === 0) {
|
||||||
|
$xml = simplexml_load_string($result);
|
||||||
|
$result = json_encode($xml, JSON_UNESCAPED_SLASHES);
|
||||||
|
$this->miscService->log('XRD conversion to JSON: ' . $result, 1);
|
||||||
|
}
|
||||||
|
|
||||||
$result = json_decode((string)$result, true);
|
$result = json_decode((string)$result, true);
|
||||||
if (is_array($result)) {
|
if (is_array($result)) {
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -427,6 +467,8 @@ class CurlService {
|
||||||
$this->parseRequestResultCurl($curl, $request);
|
$this->parseRequestResultCurl($curl, $request);
|
||||||
|
|
||||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||||
|
$contentType = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
|
||||||
|
$request->setContentType(($contentType === null) ? '' : $contentType);
|
||||||
$request->setResultCode($code);
|
$request->setResultCode($code);
|
||||||
|
|
||||||
$this->parseRequestResultCode301($code, $request);
|
$this->parseRequestResultCode301($code, $request);
|
||||||
|
|
Ładowanie…
Reference in New Issue