Compare commits
No commits in common. "a32220442c8c4d36f343e7b08ba9a30ff8cfe951" and "6ea9c2728f20aee4a023eedbf70a6e60de54be04" have entirely different histories.
a32220442c
...
6ea9c2728f
|
@ -359,9 +359,6 @@ return [
|
|||
'directory_list' => [
|
||||
'vendor/phan/phan/src/Phan',
|
||||
'vendor/smarty/smarty/src',
|
||||
'php/',
|
||||
'plugins',
|
||||
'htdocs',
|
||||
],
|
||||
|
||||
// A list of individual files to include in analysis
|
||||
|
|
|
@ -25,12 +25,6 @@ Needed SQL commands:
|
|||
|
||||
This will be changed, but works for the current develop verison.
|
||||
|
||||
If the include redis cache is enabled, create a users.acl for redis with the content:
|
||||
|
||||
user federator on ~u_* +get +set >redis*change*password
|
||||
|
||||
change password in the rediscache.ini to match your given password.
|
||||
|
||||
To configure an apache server, add the following rewrite rules:
|
||||
|
||||
<Directory /where/ever/you/put/it>
|
||||
|
|
|
@ -11,7 +11,7 @@ if (! array_key_exists('_call', $_REQUEST)) {
|
|||
exit();
|
||||
}
|
||||
date_default_timezone_set("Europe/Berlin");
|
||||
spl_autoload_register(static function (string $className) {
|
||||
spl_autoload_register(function ($className) {
|
||||
// strip Federator from class path
|
||||
$className = str_replace('Federator\\', '', $className);
|
||||
include '../php/' . str_replace("\\", "/", strtolower($className)) . '.php';
|
||||
|
|
16
php/api.php
16
php/api.php
|
@ -30,7 +30,7 @@ class Api extends Main
|
|||
/**
|
||||
* current user
|
||||
*
|
||||
* @var Data\User|false $user
|
||||
* @var Data\User $user
|
||||
* */
|
||||
private $user;
|
||||
|
||||
|
@ -56,9 +56,8 @@ class Api extends Main
|
|||
*
|
||||
* @param string $call
|
||||
* path of called function
|
||||
* @return void
|
||||
*/
|
||||
public function setPath($call)
|
||||
public function setPath(string $call) : void
|
||||
{
|
||||
$this->path = $call;
|
||||
while ($this->path[0] === '/') {
|
||||
|
@ -72,7 +71,7 @@ class Api extends Main
|
|||
*/
|
||||
public function run() : void
|
||||
{
|
||||
$this->setPath((string)$_REQUEST['_call']);
|
||||
$this->setPath($_REQUEST["_call"]);
|
||||
$this->openDatabase();
|
||||
$this->loadPlugins();
|
||||
$retval = "";
|
||||
|
@ -132,7 +131,6 @@ class Api extends Main
|
|||
if ($this->redirect !== null) {
|
||||
header("Location: $this->redirect");
|
||||
}
|
||||
// @phan-suppress-next-line PhanSuspiciousValueComparison
|
||||
if ($this->responseCode != 200) {
|
||||
http_response_code($this->responseCode);
|
||||
}
|
||||
|
@ -170,9 +168,6 @@ class Api extends Main
|
|||
public function checkPermission($permission, $exception = "\Exceptions\PermissionDenied", $message = null) : void
|
||||
{
|
||||
// generic check first
|
||||
if ($this->user === false) {
|
||||
throw new Exceptions\PermissionDenied();
|
||||
}
|
||||
if ($this->user->id == 0) {
|
||||
throw new Exceptions\PermissionDenied();
|
||||
}
|
||||
|
@ -233,7 +228,10 @@ class Api extends Main
|
|||
if ($int === true) {
|
||||
return intval($_POST[$key]);
|
||||
}
|
||||
$ret = $this->dbh->escape_string($this->stripHTML((string)$_POST[$key]));
|
||||
$ret = $this->dbh->escape_string($this->stripHTML($_POST[$key]));
|
||||
if ($ret === false) {
|
||||
return $int ? 0 : "";
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ class Dummy implements \Federator\Api\V1
|
|||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param \Federator\Main $main main instance
|
||||
* @param \Main $main main instance
|
||||
*/
|
||||
public function __construct(\Federator\Main $main)
|
||||
{
|
||||
|
|
|
@ -15,10 +15,9 @@ interface Cache extends \Federator\Connector\Connector
|
|||
{
|
||||
/**
|
||||
* save remote user by given session
|
||||
*
|
||||
* @param string $_session session id
|
||||
* @param string $_user user/profile name
|
||||
* @param \Federator\Data\User $user user data
|
||||
* @aramm \Federator\Data\User $user user data
|
||||
* @return void
|
||||
*/
|
||||
public function saveRemoteUserBySession($_session, $_user, $user);
|
||||
|
|
|
@ -15,7 +15,6 @@ interface Connector
|
|||
{
|
||||
/**
|
||||
* get remote user by given session
|
||||
*
|
||||
* @param string $_session session id
|
||||
* @param string $_user user/profile name
|
||||
* @return \Federator\Data\User | false
|
||||
|
|
|
@ -38,25 +38,6 @@ class User
|
|||
* */
|
||||
public $session;
|
||||
|
||||
/**
|
||||
* create new user object from json string
|
||||
*
|
||||
* @param string $input input string
|
||||
* @return User|false
|
||||
*/
|
||||
public static function createFromJson($input)
|
||||
{
|
||||
$data = json_decode($input, true);
|
||||
if ($data === null) {
|
||||
return false;
|
||||
}
|
||||
$user = new User();
|
||||
$user->id = $data['id'];
|
||||
/// TODO: replace with enums
|
||||
$user->permissions = $data['permissions'];
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if use has asked permission
|
||||
* @param string $p @unused-param
|
||||
|
@ -67,20 +48,6 @@ class User
|
|||
*/
|
||||
public function hasPermission(string $p)
|
||||
{
|
||||
return in_array($p, $this->permissions, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* convert internal data to json string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toJson()
|
||||
{
|
||||
$data = [
|
||||
'id' => $this->id,
|
||||
'permissions' => $this->permissions
|
||||
];
|
||||
return json_encode($data) | '';
|
||||
return in_array($p, $this->permissions);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,32 +33,28 @@ class User
|
|||
* session
|
||||
* @param string $_user
|
||||
* user/profile name
|
||||
* @param \Federator\Connector\Connector $connector
|
||||
* @param \Connector\Connector? $connector @unused-param
|
||||
* connector to fetch use with
|
||||
* @param \Federator\Cache\Cache|null $cache
|
||||
* @param \Cache\Cache? $cache
|
||||
* optional caching service
|
||||
* @return \Federator\Data\User|false
|
||||
* @return \Data\User|bool
|
||||
*/
|
||||
public static function getUserBySession($dbh, $_session, $_user, $connector, $cache)
|
||||
{
|
||||
$saveToCache = false;
|
||||
$user = false;
|
||||
if ($cache !== null) {
|
||||
if ($cache) {
|
||||
$user = $cache->getRemoteUserBySession($_session, $_user);
|
||||
}
|
||||
|
||||
if ($user === false) {
|
||||
// ask connector for user-id
|
||||
$user = $connector->getRemoteUserBySession($_session, $_user);
|
||||
$saveToCache = true;
|
||||
}
|
||||
if ($user === false) {
|
||||
return false;
|
||||
}
|
||||
self::extendUser($dbh, $user);
|
||||
if ($cache !== null && $saveToCache) {
|
||||
if ($cache) {
|
||||
$cache->saveRemoteUserBySession($_session, $_user, $user);
|
||||
}
|
||||
self::extendUser($dbh, $user);
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ class Language
|
|||
}
|
||||
}
|
||||
if ($uselang === null && array_key_exists('_lang', $_REQUEST)) {
|
||||
$language = (string)$_REQUEST['_lang'];
|
||||
$language = $_REQUEST['_lang'];
|
||||
if (array_key_exists($language, $this->validLanguages)) {
|
||||
$uselang = $language;
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ class Language
|
|||
*
|
||||
* @param string $group
|
||||
* group name to fetch keys
|
||||
* @return list<string> list of keys
|
||||
* @return array<string> list of keys
|
||||
*/
|
||||
public function getKeys(string $group)
|
||||
{
|
||||
|
@ -135,7 +135,6 @@ class Language
|
|||
require_once($_SERVER['DOCUMENT_ROOT'] . '/../lang/' . $this->uselang . "/$group.inc");
|
||||
$this->lang[$group] = $l;
|
||||
}
|
||||
// @phan-suppress-next-line PhanPartialTypeMismatchReturn
|
||||
return array_keys($this->lang[$group]);
|
||||
}
|
||||
|
||||
|
@ -264,11 +263,11 @@ function smarty_function_printlang($params, $template) : string
|
|||
{
|
||||
$lang = $template->getTemplateVars("language");
|
||||
<<<'PHAN'
|
||||
@phan-var \Federator\Language $lang
|
||||
@phan-var \Language $lang
|
||||
PHAN;
|
||||
$forcelang = array_key_exists('lang', $params) ? $params['lang'] : null;
|
||||
if ($forcelang !== null) {
|
||||
$lang = new \Federator\Language($forcelang);
|
||||
$lang = new Language($forcelang);
|
||||
}
|
||||
if (isset($params['var'])) {
|
||||
return $lang->printlang($params['group'], $params['key'], $params['var']);
|
||||
|
|
11
php/main.php
11
php/main.php
|
@ -53,7 +53,7 @@ class Main
|
|||
/**
|
||||
* languange instance
|
||||
*
|
||||
* @var Language $lang
|
||||
* @var \Language $lang
|
||||
*/
|
||||
protected $lang = null;
|
||||
/**
|
||||
|
@ -80,11 +80,7 @@ class Main
|
|||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->responseCode = 200;
|
||||
$config = parse_ini_file('../config.ini', true);
|
||||
if ($config !== false) {
|
||||
$this->config = $config;
|
||||
}
|
||||
$this->config = parse_ini_file('../config.ini', true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,9 +92,6 @@ class Main
|
|||
public static function getFromRemote(string $remoteURL, $headers)
|
||||
{
|
||||
$ch = curl_init();
|
||||
if ($ch === false) {
|
||||
return ['', null];
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_URL, $remoteURL);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
|
|
@ -23,7 +23,7 @@ class DummyConnector implements Connector
|
|||
* get remote user by given session
|
||||
* @param string $_session session id
|
||||
* @param string $_user user or profile name
|
||||
* @return \Federator\Data\User | false
|
||||
* @return Data\User | false
|
||||
*/
|
||||
public function getRemoteUserBySession(string $_session, string $_user)
|
||||
{
|
||||
|
|
|
@ -13,20 +13,6 @@ namespace Federator\Cache;
|
|||
*/
|
||||
class RedisCache implements Cache
|
||||
{
|
||||
/**
|
||||
* config data
|
||||
*
|
||||
* @var array<string, mixed> $config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* connection to redis open flag
|
||||
*
|
||||
* @var bool $connected
|
||||
*/
|
||||
private $connected = false;
|
||||
|
||||
/**
|
||||
* connection handle
|
||||
*
|
||||
|
@ -39,72 +25,20 @@ class RedisCache implements Cache
|
|||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$config = parse_ini_file('../rediscache.ini');
|
||||
if ($config !== false) {
|
||||
$this->config = $config;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* connect to redis
|
||||
* @return void
|
||||
*/
|
||||
private function connect()
|
||||
{
|
||||
$this->redis = new \Redis();
|
||||
$this->redis->pconnect($this->config['host'], intval($this->config['port'], 10));
|
||||
// @phan-suppress-next-line PhanTypeMismatchArgumentInternalProbablyReal
|
||||
$this->redis->auth([$this->config['username'], $this->config['password']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* create key from session and user
|
||||
*
|
||||
* @param string $prefix prefix to create name spaces
|
||||
* @param string $_session session id
|
||||
* @param string $_user user/profile name
|
||||
* @return string key
|
||||
*/
|
||||
private static function createKey($prefix, $_session, $_user)
|
||||
{
|
||||
$key = $prefix . '_';
|
||||
$key .= md5($_session . $_user);
|
||||
return $key;
|
||||
}
|
||||
/**
|
||||
* get remote user by given session
|
||||
*
|
||||
* @param string $_session session id
|
||||
* @param string $_user user/profile name
|
||||
* @return \Federator\Data\User | false
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getRemoteUserBySession($_session, $_user)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
$this->connect();
|
||||
}
|
||||
$key = self::createKey('u', $_session, $_user);
|
||||
$data = $this->redis->get($key);
|
||||
if ($data === false) {
|
||||
return false;
|
||||
}
|
||||
$user = \Federator\Data\User::createFromJson($data);
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* save remote user by given session
|
||||
*
|
||||
* @param string $_session session id
|
||||
* @param string $_user user/profile name
|
||||
* @param \Federator\Data\User $user user data
|
||||
* @return void
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function saveRemoteUserBySession($_session, $_user, $user)
|
||||
{
|
||||
$key = self::createKey('u', $_session, $_user);
|
||||
$serialized = $user->toJson();
|
||||
$this->redis->set($key, $serialized);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,9 +14,8 @@ primary goal is to connect ContentNation via ActivityPub again.
|
|||
## roadmap to v1.0
|
||||
- [X] API framework
|
||||
- [X] interfact to connect to existing service
|
||||
- [X] cache layer for users minmal version
|
||||
- [ ] overlay to extend with needed info like private keys, urls, ...
|
||||
- [ ] full cache for users
|
||||
- [ ] cache layer for users
|
||||
- [ ] webfinger
|
||||
- [ ] discovery endpoints
|
||||
- [ ] ap outbox
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
[redis]
|
||||
host = localhost
|
||||
port = 6379
|
||||
username = federator
|
||||
password = redis*change*password
|
Loading…
Reference in New Issue