mince/mince.php

47 lines
1.4 KiB
PHP
Raw Normal View History

2022-07-03 22:07:00 +00:00
<?php
namespace Mince;
use Index\Environment;
2023-02-25 20:17:06 +00:00
use Index\XString;
2022-07-03 22:07:00 +00:00
use Index\Data\ConnectionFailedException;
use Index\Data\DbTools;
define('MCR_STARTUP', microtime(true));
define('MCR_ROOT', __DIR__);
define('MCR_DEBUG', is_file(MCR_ROOT . '/.debug'));
define('MCR_DIR_SRC', MCR_ROOT . '/src');
define('MCR_DIR_PUB', MCR_ROOT . '/public');
define('MCR_DIR_PRV', MCR_ROOT . '/private');
define('MCR_DIR_CFG', MCR_ROOT . '/config');
2023-08-16 21:18:12 +00:00
define('MCR_DIR_MIG', MCR_ROOT . '/database');
2022-07-03 22:07:00 +00:00
2023-08-16 21:18:12 +00:00
require_once MCR_ROOT . '/vendor/autoload.php';
2022-07-03 22:07:00 +00:00
Environment::setDebug(MCR_DEBUG);
$config = parse_ini_file(MCR_DIR_CFG . '/config.ini');
if($config === false)
die('Config sux.');
try {
$db = DbTools::create($config['dsn']);
} catch(ConnectionFailedException $ex) {
echo '<h3>Unable to connect to database</h3>';
die($ex->getMessage());
}
2023-02-25 20:17:06 +00:00
$remote = new RemoteV2($config['remotev2_url'], $config['remotev2_secret']);
2022-07-03 22:07:00 +00:00
2023-02-25 20:17:06 +00:00
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');
2022-07-03 22:07:00 +00:00
2023-02-25 20:17:06 +00:00
$sVerification = hash('sha256', $sVerification);
2022-07-03 22:07:00 +00:00
2023-02-25 20:17:06 +00:00
// replace this with id.flashii.net shit
$userInfo = ChatAuth::attempt($db, $config['chat_endpoint'], $config['chat_secret'], (string)filter_input(INPUT_COOKIE, 'msz_auth'));
}