kopia lustrzana https://github.com/nextcloud/social
				
				
				
			enable host-meta locally
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>feature/573/request-on-host-meta
							rodzic
							
								
									41a423138c
								
							
						
					
					
						commit
						ede7d0d732
					
				|  | @ -216,6 +216,7 @@ class AccountService { | |||
| 		} | ||||
| 
 | ||||
| 		$this->configService->setCoreValue('public_webfinger', 'social/lib/webfinger.php'); | ||||
| 		$this->configService->setCoreValue('public_host-meta', 'social/lib/hostmeta.php'); | ||||
| 
 | ||||
| 		$actor = new Person(); | ||||
| 		$actor->setUserId($userId); | ||||
|  | @ -320,8 +321,8 @@ class AccountService { | |||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @throws Exception | ||||
| 	 * @return int | ||||
| 	 * @throws Exception | ||||
| 	 */ | ||||
| 	public function manageCacheLocalActors(): int { | ||||
| 		$update = $this->actorsRequest->getAll(); | ||||
|  | @ -337,8 +338,8 @@ class AccountService { | |||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @throws Exception | ||||
| 	 * @return int | ||||
| 	 * @throws Exception | ||||
| 	 */ | ||||
| 	public function blindKeyRotation(): int { | ||||
| 		$update = $this->actorsRequest->getAll(); | ||||
|  |  | |||
|  | @ -50,17 +50,30 @@ class CheckService { | |||
| 	use TStringTools; | ||||
| 
 | ||||
| 
 | ||||
| 	const CACHE_PREFIX = 'social_check_'; | ||||
| 
 | ||||
| 
 | ||||
| 	/** @var ICache */ | ||||
| 	private $cache; | ||||
| 
 | ||||
| 	/** @var IConfig */ | ||||
| 	private $config; | ||||
| 
 | ||||
| 	/** @var IClientService */ | ||||
| 	private $clientService; | ||||
| 
 | ||||
| 	/** @var IRequest */ | ||||
| 	private $request; | ||||
| 
 | ||||
| 	/** @var IURLGenerator */ | ||||
| 	private $urlGenerator; | ||||
| 
 | ||||
| 	/** @var ConfigService */ | ||||
| 	private $configService; | ||||
| 
 | ||||
| 	/** @var FollowsRequest */ | ||||
| 	private $followRequest; | ||||
| 
 | ||||
| 	const CACHE_PREFIX = 'social_check_'; | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * CheckService constructor. | ||||
|  | @ -71,10 +84,11 @@ class CheckService { | |||
| 	 * @param IRequest $request | ||||
| 	 * @param IURLGenerator $urlGenerator | ||||
| 	 * @param FollowsRequest $followRequest | ||||
| 	 * @param ConfigService $configService | ||||
| 	 */ | ||||
| 	public function __construct( | ||||
| 		ICache $cache, IConfig $config, IClientService $clientService, IRequest $request, | ||||
| 		IURLGenerator $urlGenerator, FollowsRequest $followRequest | ||||
| 		IURLGenerator $urlGenerator, FollowsRequest $followRequest, ConfigService $configService | ||||
| 	) { | ||||
| 		$this->cache = $cache; | ||||
| 		$this->config = $config; | ||||
|  | @ -82,6 +96,7 @@ class CheckService { | |||
| 		$this->request = $request; | ||||
| 		$this->urlGenerator = $urlGenerator; | ||||
| 		$this->followRequest = $followRequest; | ||||
| 		$this->configService = $configService; | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
|  | @ -139,6 +154,8 @@ class CheckService { | |||
| 	 * | ||||
| 	 */ | ||||
| 	public function checkInstallationStatus() { | ||||
| 		$this->configService->setCoreValue('public_webfinger', 'social/lib/webfinger.php'); | ||||
| 		$this->configService->setCoreValue('public_host-meta', 'social/lib/hostmeta.php'); | ||||
| 		$this->checkStatusTableFollows(); | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
|  | @ -51,7 +51,8 @@ class ConfigService { | |||
| 	use TArrayTools; | ||||
| 
 | ||||
| 
 | ||||
| 	const SOCIAL_ADDRESS = 'address'; | ||||
| 	const CLOUD_ADDRESS = 'address'; | ||||
| 	const SOCIAL_ADDRESS = 'social_address'; | ||||
| 	const SOCIAL_SERVICE = 'service'; | ||||
| 	const SOCIAL_MAX_SIZE = 'max_size'; | ||||
| 	const SOCIAL_ACCESS_TYPE = 'access_type'; | ||||
|  | @ -64,6 +65,7 @@ class ConfigService { | |||
| 
 | ||||
| 	/** @var array */ | ||||
| 	public $defaults = [ | ||||
| 		self::CLOUD_ADDRESS      => '', | ||||
| 		self::SOCIAL_ADDRESS     => '', | ||||
| 		self::SOCIAL_SERVICE     => 1, | ||||
| 		self::SOCIAL_MAX_SIZE    => 10, | ||||
|  | @ -258,7 +260,7 @@ class ConfigService { | |||
| 	 * @param string $cloudAddress | ||||
| 	 */ | ||||
| 	public function setCloudAddress(string $cloudAddress) { | ||||
| 		$this->setAppValue(self::SOCIAL_ADDRESS, $cloudAddress); | ||||
| 		$this->setAppValue(self::CLOUD_ADDRESS, $cloudAddress); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
|  | @ -268,7 +270,7 @@ class ConfigService { | |||
| 	 * @throws SocialAppConfigException | ||||
| 	 */ | ||||
| 	public function getCloudAddress(bool $host = false) { | ||||
| 		$address = $this->getAppValue(self::SOCIAL_ADDRESS); | ||||
| 		$address = $this->getAppValue(self::CLOUD_ADDRESS); | ||||
| 		if ($address === '') { | ||||
| 			throw new SocialAppConfigException(); | ||||
| 		} | ||||
|  | @ -294,6 +296,28 @@ class ConfigService { | |||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param string $address | ||||
| 	 */ | ||||
| 	public function setSocialAddress(string $address) { | ||||
| 		$this->setAppValue(self::SOCIAL_ADDRESS, $address); | ||||
| 	} | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @return string | ||||
| 	 * @throws SocialAppConfigException | ||||
| 	 */ | ||||
| 	public function getSocialAddress(): string { | ||||
| 		$address = $this->getAppValue(self::SOCIAL_ADDRESS); | ||||
| 
 | ||||
| 		if ($address === '') { | ||||
| 			return $this->getCloudAddress(true); | ||||
| 		} | ||||
| 
 | ||||
| 		return $address; | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * @param string $path | ||||
| 	 * | ||||
|  |  | |||
|  | @ -0,0 +1,61 @@ | |||
| <?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; | ||||
| 
 | ||||
| 
 | ||||
| use Exception; | ||||
| use OC; | ||||
| use OCA\Social\Service\ConfigService; | ||||
| use OCA\Social\Service\FediverseService; | ||||
| 
 | ||||
| require_once(__DIR__ . '/../appinfo/autoload.php'); | ||||
| 
 | ||||
| try { | ||||
| 	$fediverseService = OC::$server->query(FediverseService::class); | ||||
| 	/** @var ConfigService $configService */ | ||||
| 	$configService = OC::$server->query(ConfigService::class); | ||||
| 	$fediverseService->jailed(); | ||||
| 
 | ||||
| } catch (Exception $e) { | ||||
| 	OC::$server->getLogger() | ||||
| 			   ->log(1, 'Exception on hostmeta - ' . $e->getMessage()); | ||||
| 	http_response_code(404); | ||||
| 	exit; | ||||
| } | ||||
| 
 | ||||
| header('Content-type: application/xdr+xml'); | ||||
| 
 | ||||
| try { | ||||
| 	$url = $configService->getCloudAddress() . '/.well-known/webfinger?resource={uri}'; | ||||
| 	echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; | ||||
| 	echo '<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">' . "\n"; | ||||
| 	echo '  <Link rel="lrdd" type="application/xrd+xml" template="' . $url . '"/>' . "\n"; | ||||
| 	echo '</XRD>' . "\n"; | ||||
| } catch (Exceptions\SocialAppConfigException $e) { | ||||
| } | ||||
|  | @ -62,10 +62,15 @@ try { | |||
| 
 | ||||
| 	$fediverseService->jailed(); | ||||
| 
 | ||||
| 	if ($configService->getCloudAddress(true) !== $instance) { | ||||
| 		throw new Exception( | ||||
| 			'instance is ' . $instance . ', expected ' . $configService->getCloudAddress(true) | ||||
| 		); | ||||
| 	if ($configService->getSocialAddress() !== $instance) { | ||||
| 
 | ||||
| 		if ($configService->getCloudAddress(true) === $instance) { | ||||
| 			$instance = $configService->getSocialAddress(); | ||||
| 		} else { | ||||
| 			throw new Exception( | ||||
| 				'instance is ' . $instance . ', expected ' . $configService->getSocialAddress() | ||||
| 			); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	$cacheActorService->getFromLocalAccount($username); | ||||
|  | @ -85,7 +90,7 @@ if (substr($href, -1) === '/') { | |||
| } | ||||
| 
 | ||||
| $finger = [ | ||||
| 	'subject' => $subject, | ||||
| 	'subject' => $username . '@' . $instance, | ||||
| 	'links'   => [ | ||||
| 		[ | ||||
| 			'rel'  => 'self', | ||||
|  |  | |||
		Ładowanie…
	
		Reference in New Issue
	
	 Maxence Lange
						Maxence Lange