From f322be94b48ab2c7c34a6ee8a036646158361f08 Mon Sep 17 00:00:00 2001 From: flashwave Date: Sat, 25 Feb 2023 20:17:06 +0000 Subject: [PATCH] Rewrote remote interaction thing. --- mince.php | 22 +++--- public/index.php | 74 +++----------------- src/HTML.php | 8 +-- src/Remote.php | 45 ------------ src/RemoteV2.php | 131 ++++++++++++++++++++++++++++++++++ src/ServerQuery.php | 166 -------------------------------------------- src/Utils.php | 14 ---- src/Whitelist.php | 38 +++++----- tools/sync | 45 ++++++++++++ 9 files changed, 223 insertions(+), 320 deletions(-) delete mode 100644 src/Remote.php create mode 100644 src/RemoteV2.php delete mode 100644 src/ServerQuery.php delete mode 100644 src/Utils.php create mode 100755 tools/sync diff --git a/mince.php b/mince.php index c2bea0b..90138f0 100644 --- a/mince.php +++ b/mince.php @@ -3,6 +3,7 @@ namespace Mince; use Index\Autoloader; use Index\Environment; +use Index\XString; use Index\Data\ConnectionFailedException; use Index\Data\DbTools; @@ -31,16 +32,17 @@ try { die($ex->getMessage()); } -Remote::setUrl($config['remote_url']); -Remote::setSecret($config['remote_secret']); +$remote = new RemoteV2($config['remotev2_url'], $config['remotev2_secret']); -if(empty($_COOKIE['mc_random'])) { - $sVerification = Utils::generatePassKey(32); - setcookie('mc_random', $sVerification, strtotime('1 day'), '/', $_SERVER['HTTP_HOST']); -} else - $sVerification = (string)filter_input(INPUT_COOKIE, 'mc_random'); +if(PHP_SAPI !== 'cli') { + if(empty($_COOKIE['mc_random'])) { + $sVerification = XString::random(32); + setcookie('mc_random', $sVerification, strtotime('1 day'), '/', $_SERVER['HTTP_HOST']); + } else + $sVerification = (string)filter_input(INPUT_COOKIE, 'mc_random'); -$sVerification = hash('sha256', $sVerification); + $sVerification = hash('sha256', $sVerification); -// replace this with id.flashii.net shit -$userInfo = ChatAuth::attempt($db, $config['chat_endpoint'], $config['chat_secret'], (string)filter_input(INPUT_COOKIE, 'msz_auth')); + // replace this with id.flashii.net shit + $userInfo = ChatAuth::attempt($db, $config['chat_endpoint'], $config['chat_secret'], (string)filter_input(INPUT_COOKIE, 'msz_auth')); +} diff --git a/public/index.php b/public/index.php index 3ad7c11..8f65ae6 100644 --- a/public/index.php +++ b/public/index.php @@ -8,12 +8,8 @@ use Mince\HTML; require_once __DIR__ . '/../mince.php'; -$timing = new Timings; - $router = new HttpFx; -$timing->lap('httpfx', 'HttpFx Created'); - $loginUrl = $config['login_url']; $router->setDefaultErrorHandler(function($response, $request, $code, $text) use ($loginUrl, $userInfo) { @@ -26,19 +22,15 @@ $router->setDefaultErrorHandler(function($response, $request, $code, $text) use $response->setContent($body); }); -$router->use('/', function($response) use ($timing) { - $response->setPoweredBy('Mince+Index'); - $response->setServerTiming($timing); +$router->use('/', function($response) { + $response->setPoweredBy('Mince'); }); $router->get('/index.php', function($response) { $response->redirect('/', true); }); -$router->get('/map.php', function($response) { - $response->redirect('/maps/survival', true); -}); -$router->get('/', function($response, $request) use ($db, $loginUrl, $userInfo, $sVerification) { +$router->get('/', function($response, $request) use ($db, $remote, $loginUrl, $userInfo, $sVerification) { $name = (string)$request->getParam('name'); $error = (string)$request->getParam('error'); @@ -79,12 +71,12 @@ $router->get('/', function($response, $request) use ($db, $loginUrl, $userInfo, $body .= '

Add to Whitelist

'; $body .= '

This will give you access to the server.

'; $body .= '
'; - $body .= sprintf(' ', $sVerification); + $body .= sprintf(' ', $sVerification); $body .= ' '; - $body .= ' '; + $body .= ' '; $body .= '
'; $body .= ''; } @@ -113,8 +105,8 @@ $router->get('/', function($response, $request) use ($db, $loginUrl, $userInfo, $body .= '

This will revoke your access to the server.

'; $body .= sprintf('

You are currently whitelisted as %s on %s.

', $userInfo->mc_username, date('Y-m-d H:i:s T', $userInfo->mc_whitelisted)); $body .= '
'; - $body .= sprintf(' ', $sVerification); - $body .= ' '; + $body .= sprintf(' ', $sVerification); + $body .= ' '; $body .= '
'; $body .= ''; } @@ -146,21 +138,6 @@ $router->get('/', function($response, $request) use ($db, $loginUrl, $userInfo, return $body; }); -$router->get('/maps', function($response) { - $response->redirect('/maps/survival'); -}); -$router->get('/maps/survival', function($response) use ($loginUrl, $userInfo) { - $body = HTML::getHeader($userInfo, $loginUrl); - - $body .= '
'; - $body .= ' '; - $body .= '
'; - - $body .= HTML::getFooter(); - - return $body; -}); - $router->use('/whitelist', function($response, $request) use ($sVerification) { if(!$request->isFormContent()) { $response->redirect('/?error=request'); @@ -183,7 +160,7 @@ $router->post('/whitelist/add', function($response, $request) use ($db, $userInf $body = $request->getContent(); $name = (string)$body->getParam('name'); - $resp = Whitelist::add($db, $userInfo, $name); + $resp = (new Whitelist($db))->add($userInfo, $name); if($resp === '') $response->redirect('/'); @@ -195,7 +172,7 @@ $router->post('/whitelist/add', function($response, $request) use ($db, $userInf }); $router->post('/whitelist/remove', function($response) use ($db, $userInfo) { - $resp = Whitelist::remove($db, $userInfo); + $resp = (new Whitelist($db))->remove($userInfo); if($resp === '') $response->redirect('/'); @@ -203,35 +180,6 @@ $router->post('/whitelist/remove', function($response) use ($db, $userInfo) { $response->redirect("/?error={$resp}"); }); -$router->get('/status', function($response) { - $response->redirect('/status/survival'); -}); - -$router->get('/status/survival', function() { - return 'todo: make something here'; -}); - -$router->get('/status/survival.json', function() { - return ServerQuery::create('mc.flashii.net')->stats(); -}); - -$router->get('/status/survival.png', function($response) { - $stats = ServerQuery::create('mc.flashii.net')->stats(); - - $image = new \Imagick; - $image->newImage(100, 100, 'black', 'png'); - - $draw = new \ImagickDraw; - $draw->setFillColor('white'); - - $image->annotateImage($draw, 10, 10, 0, $stats->motd); - - $response->setContentType('image/png'); - $response->setContent((string)$image); - - $image->destroy(); -}); - $router->get('/errors/:code', function($res, $req, $code) { $code = intval($code); if($code < 100 || $code >= 600) @@ -239,6 +187,4 @@ $router->get('/errors/:code', function($res, $req, $code) { return $code; }); -$timing->lap('routes'); - $router->dispatch(); diff --git a/src/HTML.php b/src/HTML.php index d1da8e7..1ed4b03 100644 --- a/src/HTML.php +++ b/src/HTML.php @@ -13,16 +13,16 @@ final class HTML { - + {$title} - +