Compare commits

..

6 commits

9 changed files with 147 additions and 84 deletions

View file

@ -1,7 +1,7 @@
{
"require": {
"flashwave/index": "^0.2410",
"flashwave/aiwass": "^1.1",
"flashii/rpcii": "^2.0",
"erusev/parsedown": "~1.6",
"chillerlan/php-qrcode": "^4.3",
"symfony/mailer": "^6.0",

72
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "526f12235a073ac908e932627e1a16fa",
"content-hash": "33116c436dc775be3d0e0b1d33114224",
"packages": [
{
"name": "carbonphp/carbon-doctrine-types",
@ -417,12 +417,12 @@
"time": "2019-12-30T22:54:17+00:00"
},
{
"name": "flashwave/aiwass",
"version": "v1.1.0",
"name": "flashii/rpcii",
"version": "v2.0.0",
"source": {
"type": "git",
"url": "https://patchii.net/flashii/aiwass.git",
"reference": "cf6653ed4676d549b543eeba2b9db517c1feb356"
"url": "https://patchii.net/flashii/rpcii-php.git",
"reference": "93ec139171d023f210f0b7464266b6fc42b4d838"
},
"require": {
"ext-msgpack": ">=2.2",
@ -430,13 +430,13 @@
"php": ">=8.3"
},
"require-dev": {
"phpstan/phpstan": "^1.11",
"phpunit/phpunit": "^11.2"
"phpstan/phpstan": "^2.0",
"phpunit/phpunit": "^11.4"
},
"type": "library",
"autoload": {
"psr-4": {
"Aiwass\\": "src"
"RPCii\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
@ -451,9 +451,9 @@
"role": "mom"
}
],
"description": "Shared HTTP RPC client/server library.",
"homepage": "https://railgun.sh/aiwass",
"time": "2024-10-05T00:04:26+00:00"
"description": "HTTP RPC client/server library.",
"homepage": "https://railgun.sh/rpcii",
"time": "2024-11-13T23:17:29+00:00"
},
{
"name": "flashwave/index",
@ -810,20 +810,20 @@
},
{
"name": "nesbot/carbon",
"version": "3.8.0",
"version": "3.8.2",
"source": {
"type": "git",
"url": "https://github.com/briannesbitt/Carbon.git",
"reference": "bbd3eef89af8ba66a3aa7952b5439168fbcc529f"
"reference": "e1268cdbc486d97ce23fef2c666dc3c6b6de9947"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/bbd3eef89af8ba66a3aa7952b5439168fbcc529f",
"reference": "bbd3eef89af8ba66a3aa7952b5439168fbcc529f",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/e1268cdbc486d97ce23fef2c666dc3c6b6de9947",
"reference": "e1268cdbc486d97ce23fef2c666dc3c6b6de9947",
"shasum": ""
},
"require": {
"carbonphp/carbon-doctrine-types": "*",
"carbonphp/carbon-doctrine-types": "<100.0",
"ext-json": "*",
"php": "^8.1",
"psr/clock": "^1.0",
@ -912,7 +912,7 @@
"type": "tidelift"
}
],
"time": "2024-08-19T06:22:39+00:00"
"time": "2024-11-07T17:46:48+00:00"
},
{
"name": "psr/clock",
@ -1324,16 +1324,16 @@
},
{
"name": "sentry/sentry",
"version": "4.9.0",
"version": "4.10.0",
"source": {
"type": "git",
"url": "https://github.com/getsentry/sentry-php.git",
"reference": "788ec170f51ebb22f2809a1e3f78b19ccd39b70d"
"reference": "2af937d47d8aadb8dab0b1d7b9557e495dd12856"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/getsentry/sentry-php/zipball/788ec170f51ebb22f2809a1e3f78b19ccd39b70d",
"reference": "788ec170f51ebb22f2809a1e3f78b19ccd39b70d",
"url": "https://api.github.com/repos/getsentry/sentry-php/zipball/2af937d47d8aadb8dab0b1d7b9557e495dd12856",
"reference": "2af937d47d8aadb8dab0b1d7b9557e495dd12856",
"shasum": ""
},
"require": {
@ -1351,12 +1351,12 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.4",
"guzzlehttp/promises": "^1.0|^2.0",
"guzzlehttp/promises": "^2.0.3",
"guzzlehttp/psr7": "^1.8.4|^2.1.1",
"monolog/monolog": "^1.6|^2.0|^3.0",
"phpbench/phpbench": "^1.0",
"phpstan/phpstan": "^1.3",
"phpunit/phpunit": "^8.5.14|^9.4",
"phpunit/phpunit": "^8.5|^9.6",
"symfony/phpunit-bridge": "^5.2|^6.0|^7.0",
"vimeo/psalm": "^4.17"
},
@ -1397,7 +1397,7 @@
],
"support": {
"issues": "https://github.com/getsentry/sentry-php/issues",
"source": "https://github.com/getsentry/sentry-php/tree/4.9.0"
"source": "https://github.com/getsentry/sentry-php/tree/4.10.0"
},
"funding": [
{
@ -1409,7 +1409,7 @@
"type": "custom"
}
],
"time": "2024-08-08T14:40:50+00:00"
"time": "2024-11-06T07:44:19+00:00"
},
{
"name": "symfony/clock",
@ -2739,16 +2739,16 @@
},
{
"name": "twig/twig",
"version": "v3.14.0",
"version": "v3.14.2",
"source": {
"type": "git",
"url": "https://github.com/twigphp/Twig.git",
"reference": "126b2c97818dbff0cdf3fbfc881aedb3d40aae72"
"reference": "0b6f9d8370bb3b7f1ce5313ed8feb0fafd6e399a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/126b2c97818dbff0cdf3fbfc881aedb3d40aae72",
"reference": "126b2c97818dbff0cdf3fbfc881aedb3d40aae72",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/0b6f9d8370bb3b7f1ce5313ed8feb0fafd6e399a",
"reference": "0b6f9d8370bb3b7f1ce5313ed8feb0fafd6e399a",
"shasum": ""
},
"require": {
@ -2802,7 +2802,7 @@
],
"support": {
"issues": "https://github.com/twigphp/Twig/issues",
"source": "https://github.com/twigphp/Twig/tree/v3.14.0"
"source": "https://github.com/twigphp/Twig/tree/v3.14.2"
},
"funding": [
{
@ -2814,22 +2814,22 @@
"type": "tidelift"
}
],
"time": "2024-09-09T17:55:12+00:00"
"time": "2024-11-07T12:36:22+00:00"
}
],
"packages-dev": [
{
"name": "phpstan/phpstan",
"version": "1.12.7",
"version": "1.12.10",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "dc2b9976bd8b0f84ec9b0e50cc35378551de7af0"
"reference": "fc463b5d0fe906dcf19689be692c65c50406a071"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/dc2b9976bd8b0f84ec9b0e50cc35378551de7af0",
"reference": "dc2b9976bd8b0f84ec9b0e50cc35378551de7af0",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/fc463b5d0fe906dcf19689be692c65c50406a071",
"reference": "fc463b5d0fe906dcf19689be692c65c50406a071",
"shasum": ""
},
"require": {
@ -2874,7 +2874,7 @@
"type": "github"
}
],
"time": "2024-10-18T11:12:07+00:00"
"time": "2024-11-11T15:37:09+00:00"
}
],
"aliases": [],

View file

@ -22,7 +22,7 @@ Below are a number of links to source code repositories related to Flashii.net a
## First-Party Libraries
- [Index](https://patchii.net/flash/index): Base library used in almost any component of the website that uses PHP.
- [Aiwass](https://patchii.net/flashii/aiwass): Internal RPC extension, mainly used to supply data to the API gateway.
- [RPCii](https://patchii.net/flashii/rpcii): Internal RPC extension, mainly used to supply data to the API gateway.
## Historical
- [AJAX Chat (fork)](https://patchii.net/flashii/ajax-chat): Old chat software (2013-2015). Still kept on life support for the nostalgia.

View file

@ -3,10 +3,12 @@ namespace Misuzu\Auth;
use RuntimeException;
use Misuzu\Users\{UsersContext,UserInfo};
use Aiwass\Server\{RpcActionHandler,RpcProcedure};
use RPCii\Server\{RpcHandler,RpcHandlerCommon,RpcAction};
use Index\Config\Config;
final class AuthRpcActions extends RpcActionHandler {
final class AuthRpcHandler implements RpcHandler {
use RpcHandlerCommon;
public function __construct(
private Config $impersonateConfig,
private UsersContext $usersCtx,
@ -21,7 +23,7 @@ final class AuthRpcActions extends RpcActionHandler {
return in_array($targetId, $whitelist, true);
}
#[RpcProcedure('misuzu:auth:attemptMisuzuAuth')]
#[RpcAction('misuzu:auth:attemptMisuzuAuth')]
public function procAttemptMisuzuAuth(string $remoteAddr, string $token): array {
$tokenInfo = $this->authCtx->createAuthTokenPacker()->unpack($token);
if(!$tokenInfo->isEmpty())

View file

@ -0,0 +1,40 @@
<?php
namespace Misuzu\Emoticons;
use Index\XArray;
use RPCii\Server\{RpcHandler,RpcHandlerCommon,RpcQuery};
final class EmotesRpcHandler implements RpcHandler {
use RpcHandlerCommon;
public function __construct(
private Emotes $emotes
) {}
#[RpcQuery('misuzu:emotes:all')]
public function queryAll(bool $includeId = false, bool $includeOrder = false): array {
return XArray::select(
$this->emotes->getEmotes(orderBy: 'order'),
function($emote) use ($includeId, $includeOrder) {
$info = [
'url' => $emote->getUrl(),
'strings' => XArray::select(
$this->emotes->getEmoteStrings($emote),
fn($string) => $string->getString()
),
];
if($includeId)
$info['id'] = $emote->getId();
if($includeOrder)
$info['order'] = $emote->getOrder();
$rank = $emote->getMinRank();
if($rank != 0)
$info['min_rank'] = $rank;
return $info;
}
);
}
}

View file

@ -5,12 +5,14 @@ use RuntimeException;
use Misuzu\CSRF;
use Misuzu\Auth\AuthContext;
use Misuzu\Users\{UsersContext,UserInfo};
use Aiwass\Server\{RpcActionHandler,RpcProcedure};
use RPCii\Server\{RpcHandler,RpcHandlerCommon,RpcAction};
use Index\Colour\Colour;
use Index\Config\Config;
use Index\Urls\UrlRegistry;
final class HanyuuRpcActions extends RpcActionHandler {
final class HanyuuRpcHandler implements RpcHandler {
use RpcHandlerCommon;
public function __construct(
private $getBaseUrl,
private Config $impersonateConfig,
@ -49,7 +51,7 @@ final class HanyuuRpcActions extends RpcActionHandler {
);
}
#[RpcProcedure('mszhau:authCheck')]
#[RpcAction('mszhau:authCheck')]
public function procAuthCheck(string $method, string $remoteAddr, string $token, string $avatars = '') {
if($method !== 'Misuzu')
return self::createErrorPayload('auth:check:method', 'Requested auth method is not supported.');

View file

@ -14,8 +14,8 @@ use Misuzu\News\News;
use Misuzu\Perms\Permissions;
use Misuzu\Profile\ProfileFields;
use Misuzu\Users\{UsersContext,UserInfo};
use Aiwass\HmacVerificationProvider;
use Aiwass\Server\RpcServer;
use RPCii\HmacVerificationProvider;
use RPCii\Server\HttpRpcServer;
use Index\Config\Config;
use Index\Db\DbConnection;
use Index\Db\Migration\{DbMigrationManager,DbMigrationRepo,FsDbMigrationRepo};
@ -269,7 +269,8 @@ class MisuzuContext {
$this->authCtx,
$this->emotes,
$this->perms,
$this->authInfo
$this->authInfo,
$this->counters
));
$routingCtx->register(new \Misuzu\Satori\SatoriRoutes(
@ -281,30 +282,34 @@ class MisuzuContext {
$routingCtx->register(new LegacyRoutes($this->urls));
$rpcServer = new RpcServer;
$rpcServer = new HttpRpcServer;
$routingCtx->getRouter()->register($rpcServer->createRouteHandler(
new HmacVerificationProvider(fn() => $this->config->getString('aleister.secret'))
));
$rpcServer->register(new Auth\AuthRpcActions(
$rpcServer->register(new Auth\AuthRpcHandler(
$this->config->scopeTo('impersonate'),
$this->usersCtx,
$this->authCtx
));
$rpcServer->register(new Users\UsersRpcActions(
$rpcServer->register(new Emoticons\EmotesRpcHandler(
$this->emotes
));
$rpcServer->register(new Users\UsersRpcHandler(
$this->siteInfo,
$this->urls,
$this->usersCtx
));
// This RPC server will eventually despawn when Hanyuu fully owns auth
$hanyuuRpcServer = new RpcServer;
$hanyuuRpcServer = new HttpRpcServer;
$routingCtx->getRouter()->scopeTo('/_hanyuu')->register($hanyuuRpcServer->createRouteHandler(
new HmacVerificationProvider(fn() => $this->config->getString('hanyuu.secret'))
));
$hanyuuRpcServer->register(new Hanyuu\HanyuuRpcActions(
$hanyuuRpcServer->register(new Hanyuu\HanyuuRpcHandler(
fn() => $this->config->getString('hanyuu.endpoint'),
$this->config->scopeTo('impersonate'),
$this->urls,

View file

@ -4,6 +4,7 @@ namespace Misuzu\SharpChat;
use RuntimeException;
use Misuzu\RoutingContext;
use Misuzu\Auth\{AuthContext,AuthInfo,Sessions};
use Misuzu\Counters\Counters;
use Misuzu\Emoticons\Emotes;
use Misuzu\Perms\Permissions;
use Misuzu\Users\{Bans,UsersContext,UserInfo};
@ -25,7 +26,8 @@ final class SharpChatRoutes implements RouteHandler {
private AuthContext $authCtx,
private Emotes $emotes,
private Permissions $perms,
private AuthInfo $authInfo
private AuthInfo $authInfo,
private Counters $counters
) {
$this->hashKey = $this->config->getString('hashKey', 'woomy');
}
@ -40,6 +42,8 @@ final class SharpChatRoutes implements RouteHandler {
if($request->getMethod() === 'OPTIONS')
return 204;
$this->counters->increment('dev:legacy_emotes_loads');
$emotes = $this->emotes->getEmotes(orderBy: 'order');
$out = [];

View file

@ -4,12 +4,14 @@ namespace Misuzu\Users;
use RuntimeException;
use Misuzu\SiteInfo;
use Misuzu\Users\Assets\UserAvatarAsset;
use Aiwass\Server\{RpcActionHandler,RpcQuery};
use RPCii\Server\{RpcHandler,RpcHandlerCommon,RpcQuery};
use Index\XArray;
use Index\Colour\{Colour,ColourRgb};
use Index\Urls\UrlRegistry;
final class UsersRpcActions extends RpcActionHandler {
final class UsersRpcHandler implements RpcHandler {
use RpcHandlerCommon;
public function __construct(
private SiteInfo $siteInfo,
private UrlRegistry $urls,
@ -17,7 +19,7 @@ final class UsersRpcActions extends RpcActionHandler {
) {}
#[RpcQuery('misuzu:users:getUser')]
public function queryGetUser(string $userId): array {
public function queryGetUser(string $userId, bool $includeEMailAddress = false): array {
try {
$userInfo = $this->usersCtx->getUserInfo($userId, Users::GET_USER_ID);
} catch(RuntimeException) {
@ -33,13 +35,45 @@ final class UsersRpcActions extends RpcActionHandler {
$colourRaw = null;
$colourCSS = (string)$colour;
} else {
// Index doesn't have a proper toRawRGB func???
$colourRaw = Colour::toMisuzu($colour) & 0xFFFFFF;
$colourRaw = Colour::toRawRgb($colour);
$colourCSS = (string)ColourRgb::convert($colour);
}
$baseUrl = $this->siteInfo->getURL();
$output = [];
$output['id'] = $userInfo->getId();
$output['name'] = $userInfo->getName();
if($includeEMailAddress)
$output['email'] = $userInfo->getEMailAddress();
$output['colour_raw'] = $colourRaw;
$output['colour_css'] = $colourCSS;
$output['rank'] = $rank;
$output['country_code'] = $userInfo->getCountryCode();
$roles = XArray::select(
$this->usersCtx->getRoles()->getRoles(userInfo: $userInfo, hasString: true, orderByRank: true),
fn($roleInfo) => $roleInfo->getString(),
);
if(!empty($roles))
$output['roles'] = $roles;
if($userInfo->isSuperUser())
$output['is_super'] = true;
if($userInfo->hasTitle())
$output['title'] = $userInfo->getTitle();
$output['created_at'] = $userInfo->getCreatedAt()->toIso8601ZuluString();
if($userInfo->hasLastActive())
$output['last_active_at'] = $userInfo->getLastActiveAt()->toIso8601ZuluString();
$output['profile_url'] = $baseUrl . $this->urls->format('user-profile', ['user' => $userInfo->getId()]);
$output['avatar_url'] = $baseUrl . $this->urls->format('user-avatar', ['user' => $userInfo->getId()]);
/* Remove the following later */
$avatars = [];
$formatAvatarUrl = fn($res = 0) => (
$baseUrl . $this->urls->format('user-avatar', ['user' => $userInfo->getId(), 'res' => $res])
@ -51,33 +85,9 @@ final class UsersRpcActions extends RpcActionHandler {
$avatars = array_reverse($avatars);
$output = [
'id' => $userInfo->getId(),
'name' => $userInfo->getName(),
'colour_raw' => $colourRaw,
'colour_css' => $colourCSS,
'rank' => $rank,
'country_code' => $userInfo->getCountryCode(),
'avatar_urls' => $avatars,
'profile_url' => $baseUrl . $this->urls->format('user-profile', ['user' => $userInfo->getId()]),
'created_at' => $userInfo->getCreatedAt()->toIso8601ZuluString(),
];
$output['avatar_urls'] = $avatars;
/* / */
if($userInfo->hasLastActive())
$output['last_active_at'] = $userInfo->getLastActiveAt()->toIso8601ZuluString();
$roles = XArray::select(
$this->usersCtx->getRoles()->getRoles(userInfo: $userInfo, hasString: true, orderByRank: true),
fn($roleInfo) => $roleInfo->getString(),
);
if(!empty($roles))
$output['roles'] = $roles;
if($userInfo->hasTitle())
$output['title'] = $userInfo->getTitle();
if($userInfo->isSuperUser())
$output['is_super'] = true;
if($userInfo->isDeleted())
$output['is_deleted'] = true;