mince/public/index.php

61 lines
2 KiB
PHP
Raw Normal View History

2022-07-03 22:07:00 +00:00
<?php
namespace Mince;
use Index\Http\HttpFx;
use Index\Security\CSRFP;
2023-08-24 23:13:29 +00:00
use Sasae\SasaeEnvironment;
2022-07-03 22:07:00 +00:00
require_once __DIR__ . '/../mince.php';
// replace this with id.flashii.net shit
$authToken = (string)filter_input(INPUT_COOKIE, 'msz_auth');
$authInfo = ChatAuth::attempt($cfg->scopeTo('cauth'), $authToken);
2023-08-22 23:47:37 +00:00
$users = new Users($db);
if($authInfo->success) {
$users->syncChatUser($authInfo);
$userInfo = $users->getUser($authInfo->user_id);
} else $userInfo = null;
2023-08-16 22:39:35 +00:00
$csrfp = new CSRFP(
$cfg->getString('csrfp:secret', 'wowof'),
2023-08-22 23:47:37 +00:00
$authInfo->success ? $authToken : $_SERVER['REMOTE_ADDR']
);
2023-08-16 22:39:35 +00:00
2023-08-24 23:13:29 +00:00
$templating = new SasaeEnvironment(MCR_DIR_TPL, ['Mince'], debug: MCR_DEBUG);
$templating->addGlobal('globals', [
'title' => 'Flashii Minecraft Servers',
2023-08-22 23:47:37 +00:00
'is_authed' => $userInfo !== null,
'user' => $userInfo,
'csrfp' => $csrfp->createToken(),
]);
2022-07-03 22:07:00 +00:00
2023-08-22 23:47:37 +00:00
$accountLinks = new AccountLinks($db);
$authorisations = new Authorisations($db);
$authorisations->prune();
$verifications = new Verifications($db);
$verifications->prune();
2023-08-16 22:39:35 +00:00
$router = new HttpFx;
2023-08-16 23:45:46 +00:00
$router->use('/', function($response, $request) {
$response->setPoweredBy('Mince');
});
2022-07-03 22:07:00 +00:00
2023-08-16 23:45:46 +00:00
$router->setDefaultErrorHandler(function($response, $request, $code, $text) use ($templating) {
$response->setContent($templating->render('http-error', [
2023-08-16 22:39:35 +00:00
'error' => [
'code' => sprintf('%03d', $code),
'text' => $text,
],
]));
2022-07-03 22:07:00 +00:00
});
(new RpcRoutes($users, $accountLinks, $authorisations, $verifications, $cfg->getString('rpc:secret'), $cfg->getString('urls:clients')))->register($router);
(new HomeRoutes($templating, new Servers($db), $authInfo, $cfg->getString('site:login')))->register($router);
2023-08-22 23:47:37 +00:00
(new ClientsRoutes($templating, $accountLinks, $authorisations, $verifications, $csrfp, $authInfo))->register($router);
(new SkinsRoutes($templating, $accountLinks, new Skins($db), new Capes($db), $csrfp, $authInfo, $cfg->getString('urls:skins_base')))->register($router);
2023-08-22 23:47:37 +00:00
MojangInterop::registerRoutes($router);
2022-07-03 22:07:00 +00:00
$router->dispatch();