diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2019-07-11 12:58:58 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2019-07-11 14:20:09 -0100 |
commit | a7f7c0368d8cda62bc3e587e1bc00b277f525d2c (patch) | |
tree | 39a797c501b68b472b474fe3691554e51414ad22 /lib | |
parent | b3e1c5a50c559116985001d4e799f88b29f0720b (diff) |
rewrite of the url/host config
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AP.php | 2 | ||||
-rw-r--r-- | lib/Command/Reset.php | 4 | ||||
-rw-r--r-- | lib/Controller/ConfigController.php | 2 | ||||
-rw-r--r-- | lib/Controller/NavigationController.php | 20 | ||||
-rw-r--r-- | lib/Db/ActorsRequest.php | 2 | ||||
-rw-r--r-- | lib/Db/ActorsRequestBuilder.php | 4 | ||||
-rw-r--r-- | lib/Service/ConfigService.php | 162 | ||||
-rw-r--r-- | lib/Service/CurlService.php | 14 | ||||
-rw-r--r-- | lib/Service/FediverseService.php | 2 | ||||
-rw-r--r-- | lib/Service/NoteService.php | 2 | ||||
-rw-r--r-- | lib/Service/PostService.php | 5 | ||||
-rw-r--r-- | lib/Service/SignatureService.php | 9 | ||||
-rw-r--r-- | lib/hostmeta.php | 2 | ||||
-rw-r--r-- | lib/webfinger.php | 10 |
14 files changed, 164 insertions, 76 deletions
@@ -382,7 +382,7 @@ class AP { throw new ItemUnknownException(); } - $item->setUrlCloud($this->configService->getCloudAddress()); + $item->setUrlCloud($this->configService->getCloudUrl()); return $item; } diff --git a/lib/Command/Reset.php b/lib/Command/Reset.php index d3f9e459..0ce23b1a 100644 --- a/lib/Command/Reset.php +++ b/lib/Command/Reset.php @@ -124,7 +124,7 @@ class Reset extends Base { $output->writeln(''); - $cloudAddress = $this->configService->getCloudAddress(); + $cloudAddress = $this->configService->getCloudUrl(); $question = new Question( '<info>Now is a good time to change the base address of your cloud: </info> (' . $cloudAddress . ') ', @@ -137,7 +137,7 @@ class Reset extends Base { return; } - $this->configService->setCloudAddress($newCloudAddress); + $this->configService->setCloudUrl($newCloudAddress); $output->writeln(''); $output->writeln('New address: <info>' . $newCloudAddress . '</info>'); } diff --git a/lib/Controller/ConfigController.php b/lib/Controller/ConfigController.php index 3059ec14..7a47d700 100644 --- a/lib/Controller/ConfigController.php +++ b/lib/Controller/ConfigController.php @@ -47,7 +47,7 @@ class ConfigController extends Controller { * @return DataResponse */ public function setCloudAddress(string $cloudAddress): DataResponse { - $this->configService->setCloudAddress($cloudAddress); + $this->configService->setCloudUrl($cloudAddress); return new DataResponse([]); } diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php index ae2418d5..1bb8a941 100644 --- a/lib/Controller/NavigationController.php +++ b/lib/Controller/NavigationController.php @@ -145,7 +145,7 @@ class NavigationController extends Controller { ]; try { - $data['serverData']['cloudAddress'] = $this->configService->getCloudAddress(); + $data['serverData']['cloudAddress'] = $this->configService->getCloudUrl(); } catch (SocialAppConfigException $e) { $this->checkService->checkInstallationStatus(); $cloudAddress = $this->setupCloudAddress(); @@ -157,7 +157,7 @@ class NavigationController extends Controller { if ($data['serverData']['isAdmin']) { $cloudAddress = $this->request->getParam('cloudAddress'); if ($cloudAddress !== null) { - $this->configService->setCloudAddress($cloudAddress); + $this->configService->setCloudUrl($cloudAddress); } else { return new TemplateResponse(Application::APP_NAME, 'main', $data); } @@ -188,16 +188,16 @@ class NavigationController extends Controller { } private function setupCloudAddress(): string { -// $frontControllerActive = -// ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true -// || getenv('front_controller_active') === 'true'); + $frontControllerActive = + ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true + || getenv('front_controller_active') === 'true'); $cloudAddress = rtrim($this->config->getSystemValue('overwrite.cli.url', ''), '/'); if ($cloudAddress !== '') { -// if (!$frontControllerActive) { -// $cloudAddress .= '/index.php'; -// } - $this->configService->setCloudAddress($cloudAddress); + if (!$frontControllerActive) { + $cloudAddress .= '/index.php'; + } + $this->configService->setCloudUrl($cloudAddress); return $cloudAddress; } @@ -229,7 +229,7 @@ class NavigationController extends Controller { $setup = false; try { - $this->configService->getCloudAddress(true); + $this->configService->getCloudUrl(); $setup = true; } catch (SocialAppConfigException $e) { } diff --git a/lib/Db/ActorsRequest.php b/lib/Db/ActorsRequest.php index 98451224..d0318d1a 100644 --- a/lib/Db/ActorsRequest.php +++ b/lib/Db/ActorsRequest.php @@ -67,7 +67,7 @@ class ActorsRequest extends ActorsRequestBuilder { */ public function create(Person $actor): string { - $id = $this->configService->getUrlSocial() . '@' . $actor->getPreferredUsername(); + $id = $this->configService->getSocialUrl() . '@' . $actor->getPreferredUsername(); $qb = $this->getActorsInsertSql(); $qb->setValue('id', $qb->createNamedParameter($id)) diff --git a/lib/Db/ActorsRequestBuilder.php b/lib/Db/ActorsRequestBuilder.php index b8aafb6c..99b1036c 100644 --- a/lib/Db/ActorsRequestBuilder.php +++ b/lib/Db/ActorsRequestBuilder.php @@ -108,7 +108,7 @@ class ActorsRequestBuilder extends CoreRequestBuilder { * @throws SocialAppConfigException */ protected function parseActorsSelectSql($data): Person { - $root = $this->configService->getUrlSocial(); + $root = $this->configService->getSocialUrl(); $actor = new Person(); $actor->importFromDatabase($data); @@ -122,7 +122,7 @@ class ActorsRequestBuilder extends CoreRequestBuilder { ->setLocal(true) ->setAvatarVersion($this->getInt('avatar_version', $data, -1)) ->setAccount( - $actor->getPreferredUsername() . '@' . $this->configService->getCloudAddress(true) + $actor->getPreferredUsername() . '@' . $this->configService->getSocialAddress() ); $actor->setUrlSocial($root) ->setUrl($actor->getId()); diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index 0e25ff09..206315b4 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -50,9 +50,13 @@ class ConfigService { use TPathTools; use TArrayTools; + const CLOUD_URL = 'cloud_url'; + const SOCIAL_URL = 'social_url'; + const SOCIAL_ADDRESS = 'social_address'; + // deprecated -> CLOUD_URL 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'; @@ -65,8 +69,10 @@ class ConfigService { /** @var array */ public $defaults = [ - self::CLOUD_ADDRESS => '', + self::CLOUD_URL => '', + self::SOCIAL_URL => '', self::SOCIAL_ADDRESS => '', + self::CLOUD_ADDRESS => '', self::SOCIAL_SERVICE => 1, self::SOCIAL_MAX_SIZE => 10, self::SOCIAL_ACCESS_TYPE => 'all_but', @@ -256,54 +262,73 @@ class ConfigService { } + // + // + // + // + // + /** - * @param string $cloudAddress + * getCloudHost - cloud.example.com + * + * @return string + * @throws SocialAppConfigException */ - public function setCloudAddress(string $cloudAddress) { - $this->setAppValue(self::CLOUD_ADDRESS, $cloudAddress); + public function getCloudHost(): string { + $url = $this->getCloudUrl(); + + return parse_url($url, PHP_URL_HOST); } + /** - * @param bool $host + * getCloudUrl - https://cloud.example.com/index.php + * - https://cloud.example.com + * + * @param bool $noPhp * * @return string * @throws SocialAppConfigException */ - public function getCloudAddress(bool $host = false) { - $address = $this->getAppValue(self::CLOUD_ADDRESS); + public function getCloudUrl(bool $noPhp = false) { + $address = $this->getAppValue(self::CLOUD_URL); if ($address === '') { throw new SocialAppConfigException(); } - // fixing address for alpha2 - if (substr($address, -10) === '/index.php') { - $address = substr($address, 0, -10); - $this->setCloudAddress($address); - } - - if ($host === true) { - $parsed = parse_url($address); - $result = $this->get('host', $parsed, ''); - $port = $this->get('port', $parsed, ''); -// if ($port !== '') { -// $result .= ':' . $port; -// } - - return $result; + if ($noPhp) { + $pos = strpos($address, '/index.php'); + if ($pos) { + $address = substr($address, 0, $pos); + } } return $this->withoutEndSlash($address, false, false); } - /** - * @param string $address + * @param string $cloudAddress */ - public function setSocialAddress(string $address) { - $this->setAppValue(self::SOCIAL_ADDRESS, $address); + public function setCloudUrl(string $cloudAddress) { + $this->setAppValue(self::CLOUD_URL, $cloudAddress); } + + +// +// /** +// * @return string +// */ +// public function getSocialUrl2(): string { +// $url = $this->urlGenerator->linkToRoute('social.Navigation.navigate'); +// +// return $url; +// } + + /** + * getSocialAddress - example.com + * * @return string * @throws SocialAppConfigException */ @@ -311,28 +336,95 @@ class ConfigService { $address = $this->getAppValue(self::SOCIAL_ADDRESS); if ($address === '') { - return $this->getCloudAddress(true); + return $this->getCloudHost(); } return $address; } + /** + * @param string $address + */ + public function setSocialAddress(string $address) { + $this->setAppValue(self::SOCIAL_ADDRESS, $address); + } + /** - * @param string $path + * getSocialUrl - https://cloud.example.com/apps/social/ * * @return string * @throws SocialAppConfigException */ - public function getUrlSocial(string $path = ''): string { - if ($path === '') { - $path = $this->urlGenerator->linkToRoute('social.Navigation.navigate'); + public function getSocialUrl(): string { + $socialUrl = $this->getAppValue(self::SOCIAL_URL); + if ($socialUrl === '') { + throw new SocialAppConfigException(); } - return $this->getCloudAddress() . $path; -// return 'https://' . $this->getCloudAddress(true) . $path; + return $socialUrl; } + /** + * @param string $url + */ + public function setSocialUrl(string $url = '') { + if ($url === '') { + $url = $this->urlGenerator->linkToRoute('social.Navigation.navigate'); + } + + $this->setAppValue(self::SOCIAL_URL, $url); + } + + + // + // + // + // + // + // + // + + +// /** +// * @param string $cloudAddress +// */ +// public function setCloudUrl(string $cloudAddress) { +// $this->setAppValue(self::CLOUD_ADDRESS, $cloudAddress); +// } +// +// /** +// * @param bool $host +// * +// * @return string +// * @throws SocialAppConfigException +// */ +// public function getCloudUrl(bool $host = false) { +// $address = $this->getAppValue(self::CLOUD_ADDRESS); +// if ($address === '') { +// throw new SocialAppConfigException(); +// } +// +// // fixing address for alpha2 +// if (substr($address, -10) === '/index.php') { +// $address = substr($address, 0, -10); +// $this->setCloudUrl($address); +// } +// +// if ($host === true) { +// $parsed = parse_url($address); +// $result = $this->get('host', $parsed, ''); +// $port = $this->get('port', $parsed, ''); +//// if ($port !== '') { +//// $result .= ':' . $port; +//// } +// +// return $result; +// } +// +// return $this->withoutEndSlash($address, false, false); +// } + /** * @param string $path @@ -344,7 +436,7 @@ class ConfigService { public function generateId(string $path = '', $generateId = true): string { $path = $this->withoutBeginSlash($this->withEndSlash($path)); - $id = $this->getUrlSocial() . $path; + $id = $this->getSocialUrl() . $path; if ($generateId === true) { $id .= time() . crc32(uniqid()); } diff --git a/lib/Service/CurlService.php b/lib/Service/CurlService.php index 05d423e1..7baf5aa8 100644 --- a/lib/Service/CurlService.php +++ b/lib/Service/CurlService.php @@ -329,17 +329,15 @@ class CurlService { * @throws SocialAppConfigException */ public function asyncWithToken(string $token) { - $address = $this->configService->getUrlSocial(); - $parse = parse_url($address); - $host = $this->get('host', $parse, ''); - $path = $this->withEndSlash($this->get('path', $parse, '')) . $this->withoutBeginSlash( - self::ASYNC_REQUEST_TOKEN - ); + $address = $this->configService->getSocialUrl(); + + $path = $this->withEndSlash(parse_url($address, PHP_URL_PATH)); + $path .= $this->withoutBeginSlash(self::ASYNC_REQUEST_TOKEN); $path = str_replace('{token}', $token, $path); $request = new Request($path, Request::TYPE_POST); - $request->setAddress($host); - $request->setProtocol($this->get('scheme', $parse, 'https')); + $request->setAddress($this->configService->getCloudHost()); + $request->setProtocol($this->get('scheme', parse_url($address, PHP_URL_SCHEME), 'https')); try { $this->request($request); diff --git a/lib/Service/FediverseService.php b/lib/Service/FediverseService.php index c5d8664f..4b91bf0b 100644 --- a/lib/Service/FediverseService.php +++ b/lib/Service/FediverseService.php @@ -131,7 +131,7 @@ class FediverseService { * @throws SocialAppConfigException */ public function isLocal(string $address): bool { - $local = $this->configService->getCloudAddress(true); + $local = $this->configService->getCloudHost(); return ($local === $address); } diff --git a/lib/Service/NoteService.php b/lib/Service/NoteService.php index 0e807169..27327709 100644 --- a/lib/Service/NoteService.php +++ b/lib/Service/NoteService.php @@ -254,7 +254,7 @@ class NoteService { $note->addTag( [ 'type' => 'Hashtag', - 'href' => $this->configService->getCloudAddress() . '/tag/' . strtolower( + 'href' => $this->configService->getSocialUrl() . 'tag/' . strtolower( $hashtag ), 'name' => '#' . $hashtag diff --git a/lib/Service/PostService.php b/lib/Service/PostService.php index d94bdc58..a5baf010 100644 --- a/lib/Service/PostService.php +++ b/lib/Service/PostService.php @@ -109,9 +109,8 @@ class PostService { $actor = $post->getActor(); $this->noteService->assignItem($note, $actor, $post->getType()); - $note->setAttributedTo( - $this->configService->getUrlSocial() . '@' . $actor->getPreferredUsername() - ); + $note->setAttributedTo($actor->getId()); +// $this->configService->getSocialUrl() . '@' . $actor->getPreferredUsername() $note->setContent(htmlentities($post->getContent(), ENT_QUOTES)); diff --git a/lib/Service/SignatureService.php b/lib/Service/SignatureService.php index 65188a8d..637c2de8 100644 --- a/lib/Service/SignatureService.php +++ b/lib/Service/SignatureService.php @@ -154,8 +154,8 @@ class SignatureService { $localActor = $this->actorsRequest->getFromId($queue->getAuthor()); - $localActorLink = - $this->configService->getUrlSocial() . '@' . $localActor->getPreferredUsername(); +// $localActorLink = +// $this->configService->getSocialUrl() . '@' . $localActor->getPreferredUsername(); $digest = $this->generateDigest($request->getDataBody()); $contentSize = strlen($request->getDataBody()); @@ -170,11 +170,10 @@ class SignatureService { openssl_sign($signature, $signed, $localActor->getPrivateKey(), OPENSSL_ALGO_SHA256); $signed = base64_encode($signed); - $header = 'keyId="' . $localActorLink . '#main-key' + $header = 'keyId="' . $localActor->getId() . '#main-key' . '",algorithm="rsa-sha256",headers="content-length date digest host",signature="' . $signed . '"'; - $request->addHeader('Content-length: ' . $contentSize); $request->addHeader('Host: ' . $path->getAddress()); $request->addHeader('Date: ' . $date); @@ -396,7 +395,7 @@ class SignatureService { $value = $request->getHeader($key); if ($key === 'host') { - $value = $this->configService->getCloudAddress(true); + $value = $this->configService->getCloudHost(); } $estimated .= $key . ': ' . $value . "\n"; diff --git a/lib/hostmeta.php b/lib/hostmeta.php index 94dd8413..4965b37f 100644 --- a/lib/hostmeta.php +++ b/lib/hostmeta.php @@ -52,7 +52,7 @@ try { header('Content-type: application/xdr+xml'); try { - $url = $configService->getCloudAddress() . '/.well-known/webfinger?resource={uri}'; + $url = $configService->getCloudUrl(true) . '/.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"; diff --git a/lib/webfinger.php b/lib/webfinger.php index ca60fc10..b6113890 100644 --- a/lib/webfinger.php +++ b/lib/webfinger.php @@ -64,12 +64,12 @@ try { $fediverseService->jailed(); if ($configService->getSocialAddress() !== $instance) { - - if ($configService->getCloudAddress(true) === $instance) { + if ($configService->getCloudHost() === $instance) { $instance = $configService->getSocialAddress(); } else { throw new Exception( 'instance is ' . $instance . ', expected ' . $configService->getSocialAddress() + . ' or ' . $configService->getCloudHost() ); } } @@ -82,9 +82,9 @@ try { exit; } -$href = $configService->getUrlSocial( - $urlGenerator->linkToRoute('social.ActivityPub.actorAlias', ['username' => $username]) -); +$href = $configService->getSocialUrl() . '@' . $username; +// $urlGenerator->linkToRoute('social.ActivityPub.actorAlias', ['username' => $username]) +//); if (substr($href, -1) === '/') { $href = substr($href, 0, -1); |