diff --git a/php/federator/api/fedusers.php b/php/federator/api/fedusers.php index d384366..6a71bee 100644 --- a/php/federator/api/fedusers.php +++ b/php/federator/api/fedusers.php @@ -70,6 +70,18 @@ class FedUsers implements APIInterface break; case 'outbox': $handler = new FedUsers\Outbox($this->main); + $user = $paths[1]; + if (!preg_match("#^([^@]+)@([^/]+)#", $user, $matches) === 1) { + $hostUrl = $this->main->getHost(); + if ($hostUrl !== false) { + $host = parse_url($hostUrl, PHP_URL_HOST); + $port = parse_url($hostUrl, PHP_URL_PORT); + if ($port !== null) { + $host .= `:$port`; + } + $user = `$user@$host`; + } + } break; } break; @@ -82,10 +94,10 @@ class FedUsers implements APIInterface $ret = false; switch ($method) { case 'GET': - $ret = $handler->get($paths[1]); + $ret = $handler->get($user); break; case 'POST': - $ret = $handler->post($paths[1]); + $ret = $handler->post($user); break; } if ($ret !== false) { diff --git a/php/federator/api/fedusers/outbox.php b/php/federator/api/fedusers/outbox.php index 8b11d0e..9665fae 100644 --- a/php/federator/api/fedusers/outbox.php +++ b/php/federator/api/fedusers/outbox.php @@ -70,6 +70,10 @@ class Outbox implements \Federator\Api\FedUsers\FedUsersInterface if ($page !== '') { $id .= '?page=' . urlencode($page); } + if ($page === '' || $outbox->count() == 0) { + $outbox->setFirst($id); + $outbox->setLast($id . '&min=0'); + } if (sizeof($items)>0) { $newestId = $items[0]->getPublished(); $oldestId = $items[sizeof($items)-1]->getPublished(); diff --git a/php/federator/api/wellknown/webfinger.php b/php/federator/api/wellknown/webfinger.php index 61dadc3..4eaef6a 100644 --- a/php/federator/api/wellknown/webfinger.php +++ b/php/federator/api/wellknown/webfinger.php @@ -46,9 +46,11 @@ class WebFinger { $_resource = $this->main->extractFromURI('resource'); $matches = []; - if (preg_match("/^acct:([^@]+)@(.*)$/", $_resource, $matches) != 1) { + $config = $this->main->getConfig(); + $domain = $config['generic']['externaldomain']; + if (preg_match("/^acct:([^@]+)@(.*)$/", $_resource, $matches) != 1 || $matches[2] !== $domain) { throw new \Federator\Exceptions\InvalidArgument(); - } + } $domain = $matches[2]; $user = \Federator\DIO\User::getUserByName( $this->main->getDatabase(), diff --git a/php/federator/data/user.php b/php/federator/data/user.php index ef255e3..efb829d 100644 --- a/php/federator/data/user.php +++ b/php/federator/data/user.php @@ -145,7 +145,7 @@ class User */ public function hasPermission(string $p) { - return in_array(strtolower($p), array_map('strtolower', $this->permissions), true); + return in_array($p, $this->permissions, false); } /** diff --git a/php/federator/main.php b/php/federator/main.php index ddb5acf..8721e9b 100644 --- a/php/federator/main.php +++ b/php/federator/main.php @@ -33,6 +33,12 @@ class Main * @var Connector\Connector $connector */ protected $connector = null; + /** + * remote host (f.e. https://contentnation.net) + * + * @var string $host + */ + protected $host = null; /** * response content type * @@ -148,6 +154,15 @@ class Main { return $this->connector; } + /** + * get host (f.e. https://contentnation.net) + * + * @return string + */ + public function getHost() + { + return $this->host; + } /** * get config @@ -252,6 +267,19 @@ class Main $this->connector = $connector; } + /** + * set host + * + * @param string $host the new host url + */ + public function setHost(string $host) : void + { + if ($this->host) { + echo "main::setHost Setting new host will override old one.\n"; // TODO CHANGE TO LOG WARNING + } + $this->host = $host; + } + /** * set response code * diff --git a/plugins/federator/contentnation.php b/plugins/federator/contentnation.php index 77826bc..3f116f8 100644 --- a/plugins/federator/contentnation.php +++ b/plugins/federator/contentnation.php @@ -47,6 +47,7 @@ class ContentNation implements Connector } $this->service = $config['contentnation']['service-uri']; $this->main = $main; + $this->main->setHost($this->service); } /** diff --git a/plugins/federator/dummyconnector.php b/plugins/federator/dummyconnector.php index ed699bf..0459db0 100644 --- a/plugins/federator/dummyconnector.php +++ b/plugins/federator/dummyconnector.php @@ -70,7 +70,7 @@ class DummyConnector implements Connector // validate $_session and $user $user = new \Federator\Data\User(); $user->externalid = $_user; - $user->permissions = ['PUBLISH']; + $user->permissions = ['publish']; $user->session = $_session; return $user; } diff --git a/plugins/federator/mastodon.php b/plugins/federator/mastodon.php index be9f5e0..c176d5b 100644 --- a/plugins/federator/mastodon.php +++ b/plugins/federator/mastodon.php @@ -47,6 +47,7 @@ class Mastodon implements Connector } $this->service = $config['mastodon']['service-uri']; $this->main = $main; + $this->main->setHost($this->service); } /**