mince/public/index.php

49 lines
1.3 KiB
PHP
Raw Normal View History

2022-07-03 22:07:00 +00:00
<?php
namespace Mince;
2023-08-16 22:39:35 +00:00
use Index\XString;
2022-07-03 22:07:00 +00:00
use Index\Http\HttpFx;
use Index\Security\CSRFP;
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');
$userInfo = ChatAuth::attempt($db, $config['chat_endpoint'], $config['chat_secret'], $authToken);
2023-08-16 22:39:35 +00:00
$csrfp = new CSRFP(
$config['csrf_secret'],
$userInfo->success ? $authToken : $_SERVER['REMOTE_ADDR']
);
2023-08-16 22:39:35 +00:00
$templating = new Templating;
$templating->addPath(MCR_DIR_TPL);
$templating->addVars([
2023-08-16 22:39:35 +00:00
'global' => [
'title' => 'Flashii Minecraft Servers',
'loginUrl' => $config['login_url'],
],
'auth' => $userInfo,
'csrfp' => $csrfp->createToken(),
]);
2022-07-03 22:07:00 +00:00
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
});
2023-08-16 23:45:46 +00:00
(new HomeRoutes($templating, $userInfo))->register($router);
(new WhitelistRoutes(new Whitelist($db), $csrfp, $userInfo))->register($router);
2022-07-03 22:07:00 +00:00
$router->dispatch();