rewrite of the url/host config

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/627/head
Maxence Lange 2019-07-11 12:58:58 -01:00
rodzic b3e1c5a50c
commit a7f7c0368d
14 zmienionych plików z 177 dodań i 89 usunięć

Wyświetl plik

@ -382,7 +382,7 @@ class AP {
throw new ItemUnknownException();
}
$item->setUrlCloud($this->configService->getCloudAddress());
$item->setUrlCloud($this->configService->getCloudUrl());
return $item;
}

Wyświetl plik

@ -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>');
}

Wyświetl plik

@ -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([]);
}

Wyświetl plik

@ -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) {
}

Wyświetl plik

@ -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))

Wyświetl plik

@ -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());

Wyświetl plik

@ -50,9 +50,13 @@ class ConfigService {
use TPathTools;
use TArrayTools;
const CLOUD_ADDRESS = 'address';
const CLOUD_URL = 'cloud_url';
const SOCIAL_URL = 'social_url';
const SOCIAL_ADDRESS = 'social_address';
// deprecated -> CLOUD_URL
const CLOUD_ADDRESS = '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,45 +262,85 @@ class ConfigService {
}
/**
* @param string $cloudAddress
*/
public function setCloudAddress(string $cloudAddress) {
$this->setAppValue(self::CLOUD_ADDRESS, $cloudAddress);
}
//
//
//
//
//
/**
* @param bool $host
* getCloudHost - cloud.example.com
*
* @return string
* @throws SocialAppConfigException
*/
public function getCloudAddress(bool $host = false) {
$address = $this->getAppValue(self::CLOUD_ADDRESS);
public function getCloudHost(): string {
$url = $this->getCloudUrl();
return parse_url($url, PHP_URL_HOST);
}
/**
* getCloudUrl - https://cloud.example.com/index.php
* - https://cloud.example.com
*
* @param bool $noPhp
*
* @return string
* @throws SocialAppConfigException
*/
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 $cloudAddress
*/
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
*/
public function getSocialAddress(): string {
$address = $this->getAppValue(self::SOCIAL_ADDRESS);
if ($address === '') {
return $this->getCloudHost();
}
return $address;
}
/**
* @param string $address
@ -303,36 +349,82 @@ class ConfigService {
$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
* 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());
}

Wyświetl plik

@ -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);

Wyświetl plik

@ -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);
}

Wyświetl plik

@ -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

Wyświetl plik

@ -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));

Wyświetl plik

@ -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";

Wyświetl plik

@ -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";

Wyświetl plik

@ -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);