minor fixes
- permissions are always lower-case - revert webfinger changes to initial state - re-add setFirst and setLast for outbox - we now save the current host (f.e. https://contentnation.net) to save users with their respective host (a request to fedusers/grumpydevelop will then result in saving the user as grumpydevelop@contentnation.net)
This commit is contained in:
parent
721e37882d
commit
823283183e
8 changed files with 54 additions and 6 deletions
|
@ -70,6 +70,18 @@ class FedUsers implements APIInterface
|
||||||
break;
|
break;
|
||||||
case 'outbox':
|
case 'outbox':
|
||||||
$handler = new FedUsers\Outbox($this->main);
|
$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;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -82,10 +94,10 @@ class FedUsers implements APIInterface
|
||||||
$ret = false;
|
$ret = false;
|
||||||
switch ($method) {
|
switch ($method) {
|
||||||
case 'GET':
|
case 'GET':
|
||||||
$ret = $handler->get($paths[1]);
|
$ret = $handler->get($user);
|
||||||
break;
|
break;
|
||||||
case 'POST':
|
case 'POST':
|
||||||
$ret = $handler->post($paths[1]);
|
$ret = $handler->post($user);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ($ret !== false) {
|
if ($ret !== false) {
|
||||||
|
|
|
@ -70,6 +70,10 @@ class Outbox implements \Federator\Api\FedUsers\FedUsersInterface
|
||||||
if ($page !== '') {
|
if ($page !== '') {
|
||||||
$id .= '?page=' . urlencode($page);
|
$id .= '?page=' . urlencode($page);
|
||||||
}
|
}
|
||||||
|
if ($page === '' || $outbox->count() == 0) {
|
||||||
|
$outbox->setFirst($id);
|
||||||
|
$outbox->setLast($id . '&min=0');
|
||||||
|
}
|
||||||
if (sizeof($items)>0) {
|
if (sizeof($items)>0) {
|
||||||
$newestId = $items[0]->getPublished();
|
$newestId = $items[0]->getPublished();
|
||||||
$oldestId = $items[sizeof($items)-1]->getPublished();
|
$oldestId = $items[sizeof($items)-1]->getPublished();
|
||||||
|
|
|
@ -46,7 +46,9 @@ class WebFinger
|
||||||
{
|
{
|
||||||
$_resource = $this->main->extractFromURI('resource');
|
$_resource = $this->main->extractFromURI('resource');
|
||||||
$matches = [];
|
$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();
|
throw new \Federator\Exceptions\InvalidArgument();
|
||||||
}
|
}
|
||||||
$domain = $matches[2];
|
$domain = $matches[2];
|
||||||
|
|
|
@ -145,7 +145,7 @@ class User
|
||||||
*/
|
*/
|
||||||
public function hasPermission(string $p)
|
public function hasPermission(string $p)
|
||||||
{
|
{
|
||||||
return in_array(strtolower($p), array_map('strtolower', $this->permissions), true);
|
return in_array($p, $this->permissions, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -33,6 +33,12 @@ class Main
|
||||||
* @var Connector\Connector $connector
|
* @var Connector\Connector $connector
|
||||||
*/
|
*/
|
||||||
protected $connector = null;
|
protected $connector = null;
|
||||||
|
/**
|
||||||
|
* remote host (f.e. https://contentnation.net)
|
||||||
|
*
|
||||||
|
* @var string $host
|
||||||
|
*/
|
||||||
|
protected $host = null;
|
||||||
/**
|
/**
|
||||||
* response content type
|
* response content type
|
||||||
*
|
*
|
||||||
|
@ -148,6 +154,15 @@ class Main
|
||||||
{
|
{
|
||||||
return $this->connector;
|
return $this->connector;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* get host (f.e. https://contentnation.net)
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getHost()
|
||||||
|
{
|
||||||
|
return $this->host;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get config
|
* get config
|
||||||
|
@ -252,6 +267,19 @@ class Main
|
||||||
$this->connector = $connector;
|
$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
|
* set response code
|
||||||
*
|
*
|
||||||
|
|
|
@ -47,6 +47,7 @@ class ContentNation implements Connector
|
||||||
}
|
}
|
||||||
$this->service = $config['contentnation']['service-uri'];
|
$this->service = $config['contentnation']['service-uri'];
|
||||||
$this->main = $main;
|
$this->main = $main;
|
||||||
|
$this->main->setHost($this->service);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -70,7 +70,7 @@ class DummyConnector implements Connector
|
||||||
// validate $_session and $user
|
// validate $_session and $user
|
||||||
$user = new \Federator\Data\User();
|
$user = new \Federator\Data\User();
|
||||||
$user->externalid = $_user;
|
$user->externalid = $_user;
|
||||||
$user->permissions = ['PUBLISH'];
|
$user->permissions = ['publish'];
|
||||||
$user->session = $_session;
|
$user->session = $_session;
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ class Mastodon implements Connector
|
||||||
}
|
}
|
||||||
$this->service = $config['mastodon']['service-uri'];
|
$this->service = $config['mastodon']['service-uri'];
|
||||||
$this->main = $main;
|
$this->main = $main;
|
||||||
|
$this->main->setHost($this->service);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue