Switched Mince config to Syokuhou format.

This commit is contained in:
flash 2023-12-15 02:14:55 +00:00
parent 3a280ddf5e
commit 4de59d9f3e
6 changed files with 176 additions and 124 deletions

1
.gitignore vendored
View file

@ -6,3 +6,4 @@
/public/robots.txt
/vendor
/public/textures
/mince.cfg

View file

@ -3,8 +3,9 @@
"prefer-stable": true,
"require": {
"flashwave/index": "*",
"ramsey/uuid": "^4.7",
"flashwave/sasae": "dev-master"
"flashwave/sasae": "dev-master",
"flashwave/syokuhou": "dev-master",
"ramsey/uuid": "^4.7"
},
"autoload": {
"classmap": [

262
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": "ff9d0183468159f0604580b95bf65a01",
"content-hash": "ffc7bd5dcde351eefd5f92d7b9e250d8",
"packages": [
{
"name": "brick/math",
@ -148,6 +148,45 @@
"homepage": "https://railgun.sh/sasae",
"time": "2023-11-20T19:09:35+00:00"
},
{
"name": "flashwave/syokuhou",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://patchii.net/flash/syokuhou.git",
"reference": "fdf3c38cc216bf7024af331cbe1758532355c22f"
},
"require": {
"flashwave/index": "dev-master",
"php": ">=8.2"
},
"require-dev": {
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^10.4"
},
"default-branch": true,
"type": "library",
"autoload": {
"psr-4": {
"Syokuhou\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"bsd-3-clause-clear"
],
"authors": [
{
"name": "flashwave",
"email": "packagist@flash.moe",
"homepage": "https://flash.moe",
"role": "mom"
}
],
"description": "Configuration library for PHP.",
"homepage": "https://railgun.sh/syokuhou",
"time": "2023-11-20T19:10:04+00:00"
},
{
"name": "ramsey/collection",
"version": "2.0.0",
@ -329,90 +368,22 @@
],
"time": "2023-11-08T05:53:05+00:00"
},
{
"name": "symfony/deprecation-contracts",
"version": "v3.4.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/deprecation-contracts.git",
"reference": "7c3aff79d10325257a001fcf92d991f24fc967cf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf",
"reference": "7c3aff79d10325257a001fcf92d991f24fc967cf",
"shasum": ""
},
"require": {
"php": ">=8.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "3.4-dev"
},
"thanks": {
"name": "symfony/contracts",
"url": "https://github.com/symfony/contracts"
}
},
"autoload": {
"files": [
"function.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.4.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2023-05-23T14:45:45+00:00"
},
{
"name": "symfony/mime",
"version": "v6.3.5",
"version": "v7.0.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/mime.git",
"reference": "d5179eedf1cb2946dbd760475ebf05c251ef6a6e"
"reference": "0a2fff95c1a10df97f571d67e76c7ae0f0d4f535"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/mime/zipball/d5179eedf1cb2946dbd760475ebf05c251ef6a6e",
"reference": "d5179eedf1cb2946dbd760475ebf05c251ef6a6e",
"url": "https://api.github.com/repos/symfony/mime/zipball/0a2fff95c1a10df97f571d67e76c7ae0f0d4f535",
"reference": "0a2fff95c1a10df97f571d67e76c7ae0f0d4f535",
"shasum": ""
},
"require": {
"php": ">=8.1",
"symfony/deprecation-contracts": "^2.5|^3",
"php": ">=8.2",
"symfony/polyfill-intl-idn": "^1.10",
"symfony/polyfill-mbstring": "^1.0"
},
@ -420,17 +391,17 @@
"egulias/email-validator": "~3.0.0",
"phpdocumentor/reflection-docblock": "<3.2.2",
"phpdocumentor/type-resolver": "<1.4.0",
"symfony/mailer": "<5.4",
"symfony/serializer": "<6.2.13|>=6.3,<6.3.2"
"symfony/mailer": "<6.4",
"symfony/serializer": "<6.4"
},
"require-dev": {
"egulias/email-validator": "^2.1.10|^3.1|^4",
"league/html-to-markdown": "^5.0",
"phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0",
"symfony/dependency-injection": "^5.4|^6.0",
"symfony/property-access": "^5.4|^6.0",
"symfony/property-info": "^5.4|^6.0",
"symfony/serializer": "~6.2.13|^6.3.2"
"symfony/dependency-injection": "^6.4|^7.0",
"symfony/property-access": "^6.4|^7.0",
"symfony/property-info": "^6.4|^7.0",
"symfony/serializer": "^6.4|^7.0"
},
"type": "library",
"autoload": {
@ -462,7 +433,7 @@
"mime-type"
],
"support": {
"source": "https://github.com/symfony/mime/tree/v6.3.5"
"source": "https://github.com/symfony/mime/tree/v7.0.0"
},
"funding": [
{
@ -478,7 +449,7 @@
"type": "tidelift"
}
],
"time": "2023-09-29T06:59:36+00:00"
"time": "2023-10-19T14:20:43+00:00"
},
{
"name": "symfony/polyfill-ctype",
@ -893,26 +864,109 @@
"time": "2023-01-26T09:26:14+00:00"
},
{
"name": "twig/html-extra",
"version": "v3.7.1",
"name": "symfony/polyfill-php80",
"version": "v1.28.0",
"source": {
"type": "git",
"url": "https://github.com/twigphp/html-extra.git",
"reference": "95ceb36e70fa8d07af08cf5135ecbf5e0bd8f386"
"url": "https://github.com/symfony/polyfill-php80.git",
"reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/html-extra/zipball/95ceb36e70fa8d07af08cf5135ecbf5e0bd8f386",
"reference": "95ceb36e70fa8d07af08cf5135ecbf5e0bd8f386",
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/6caa57379c4aec19c0a12a38b59b26487dcfe4b5",
"reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5",
"shasum": ""
},
"require": {
"php": ">=7.1.3",
"symfony/mime": "^5.4|^6.0",
"twig/twig": "^2.7|^3.0"
"php": ">=7.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.28-dev"
},
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
}
},
"autoload": {
"files": [
"bootstrap.php"
],
"psr-4": {
"Symfony\\Polyfill\\Php80\\": ""
},
"classmap": [
"Resources/stubs"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Ion Bazan",
"email": "ion.bazan@gmail.com"
},
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"polyfill",
"portable",
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php80/tree/v1.28.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2023-01-26T09:26:14+00:00"
},
{
"name": "twig/html-extra",
"version": "v3.8.0",
"source": {
"type": "git",
"url": "https://github.com/twigphp/html-extra.git",
"reference": "c04603bb3b71d8d2ece9e583dbf7bd77811df1f2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/html-extra/zipball/c04603bb3b71d8d2ece9e583dbf7bd77811df1f2",
"reference": "c04603bb3b71d8d2ece9e583dbf7bd77811df1f2",
"shasum": ""
},
"require": {
"php": ">=7.2.5",
"symfony/mime": "^5.4|^6.0|^7.0",
"twig/twig": "^3.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^5.4|^6.3"
"symfony/phpunit-bridge": "^6.4|^7.0"
},
"type": "library",
"autoload": {
@ -942,7 +996,7 @@
"twig"
],
"support": {
"source": "https://github.com/twigphp/html-extra/tree/v3.7.1"
"source": "https://github.com/twigphp/html-extra/tree/v3.8.0"
},
"funding": [
{
@ -954,30 +1008,31 @@
"type": "tidelift"
}
],
"time": "2023-07-29T15:34:56+00:00"
"time": "2023-11-21T14:02:01+00:00"
},
{
"name": "twig/twig",
"version": "v3.7.1",
"version": "v3.8.0",
"source": {
"type": "git",
"url": "https://github.com/twigphp/Twig.git",
"reference": "a0ce373a0ca3bf6c64b9e3e2124aca502ba39554"
"reference": "9d15f0ac07f44dc4217883ec6ae02fd555c6f71d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/a0ce373a0ca3bf6c64b9e3e2124aca502ba39554",
"reference": "a0ce373a0ca3bf6c64b9e3e2124aca502ba39554",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/9d15f0ac07f44dc4217883ec6ae02fd555c6f71d",
"reference": "9d15f0ac07f44dc4217883ec6ae02fd555c6f71d",
"shasum": ""
},
"require": {
"php": ">=7.2.5",
"symfony/polyfill-ctype": "^1.8",
"symfony/polyfill-mbstring": "^1.3"
"symfony/polyfill-mbstring": "^1.3",
"symfony/polyfill-php80": "^1.22"
},
"require-dev": {
"psr/container": "^1.0|^2.0",
"symfony/phpunit-bridge": "^5.4.9|^6.3"
"symfony/phpunit-bridge": "^5.4.9|^6.3|^7.0"
},
"type": "library",
"autoload": {
@ -1013,7 +1068,7 @@
],
"support": {
"issues": "https://github.com/twigphp/Twig/issues",
"source": "https://github.com/twigphp/Twig/tree/v3.7.1"
"source": "https://github.com/twigphp/Twig/tree/v3.8.0"
},
"funding": [
{
@ -1025,14 +1080,15 @@
"type": "tidelift"
}
],
"time": "2023-08-28T11:09:02+00:00"
"time": "2023-11-21T18:54:41+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "dev",
"stability-flags": {
"flashwave/sasae": 20
"flashwave/sasae": 20,
"flashwave/syokuhou": 20
},
"prefer-stable": true,
"prefer-lowest": false,

View file

@ -4,6 +4,7 @@ namespace Mince;
use Index\Environment;
use Index\Data\ConnectionFailedException;
use Index\Data\DbTools;
use Syokuhou\SharpConfig;
define('MCR_STARTUP', microtime(true));
define('MCR_ROOT', __DIR__);
@ -19,15 +20,7 @@ require_once MCR_ROOT . '/vendor/autoload.php';
Environment::setDebug(MCR_DEBUG);
$config = parse_ini_file(MCR_DIR_CFG . '/config.ini');
if($config === false)
die('Config sux.');
$cfg = SharpConfig::fromFile(MCR_ROOT . '/mince.cfg');
try {
$db = DbTools::create($config['dsn']);
} catch(ConnectionFailedException $ex) {
echo '<h3>Unable to connect to database</h3>';
die($ex->getMessage());
}
$db->execute('SET SESSION time_zone = "+00:00", sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"');
$db = DbTools::create($cfg->getString('database:dsn', 'null:'));
$db->execute('SET SESSION time_zone = \'+00:00\', sql_mode = \'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION\';');

View file

@ -9,7 +9,7 @@ require_once __DIR__ . '/../mince.php';
// replace this with id.flashii.net shit
$authToken = (string)filter_input(INPUT_COOKIE, 'msz_auth');
$authInfo = ChatAuth::attempt($config['chat_endpoint'], $config['chat_secret'], $authToken);
$authInfo = ChatAuth::attempt($cfg->scopeTo('cauth'), $authToken);
$users = new Users($db);
if($authInfo->success) {
@ -18,7 +18,7 @@ if($authInfo->success) {
} else $userInfo = null;
$csrfp = new CSRFP(
$config['csrf_secret'],
$cfg->getString('csrfp:secret', 'wowof'),
$authInfo->success ? $authToken : $_SERVER['REMOTE_ADDR']
);
@ -50,10 +50,10 @@ $router->setDefaultErrorHandler(function($response, $request, $code, $text) use
]));
});
(new RpcRoutes($users, $accountLinks, $authorisations, $verifications, $config['rpc_secret'], $config['clients_url']))->register($router);
(new HomeRoutes($templating, new Servers($db), $authInfo, $config['login_url']))->register($router);
(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);
(new ClientsRoutes($templating, $accountLinks, $authorisations, $verifications, $csrfp, $authInfo))->register($router);
(new SkinsRoutes($templating, $accountLinks, new Skins($db), new Capes($db), $csrfp, $authInfo, $config['skins_base_url']))->register($router);
(new SkinsRoutes($templating, $accountLinks, new Skins($db), new Capes($db), $csrfp, $authInfo, $cfg->getString('urls:skins_base')))->register($router);
MojangInterop::registerRoutes($router);

View file

@ -2,15 +2,16 @@
namespace Mince;
use stdClass;
use Syokuhou\IConfig;
final class ChatAuth {
public static function attempt(string $endPoint, string $secret, string $cookie): object {
public static function attempt(IConfig $config, string $cookie): object {
if(!empty($cookie)) {
$method = 'Misuzu';
$signature = sprintf('verify#%s#%s#%s', $method, $cookie, $_SERVER['REMOTE_ADDR']);
$signature = hash_hmac('sha256', $signature, $secret);
$signature = hash_hmac('sha256', $signature, $config->getString('secret'));
$login = curl_init($endPoint);
$login = curl_init($config->getString('endpoint'));
curl_setopt_array($login, [
CURLOPT_AUTOREFERER => false,
CURLOPT_FAILONERROR => false,