misuzu/misuzu.php

60 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace Misuzu;
2018-04-30 21:39:43 +00:00
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/src/colour.php';
require_once __DIR__ . '/src/zalgo.php';
$app = new Application(
__DIR__ . '/config/config.ini',
IO\Directory::exists(__DIR__ . '/vendor/phpunit/phpunit')
);
$app->startDatabase();
if (PHP_SAPI !== 'cli') {
2018-03-24 04:31:42 +00:00
$storage_dir = $app->getStoragePath();
if (!$storage_dir->isReadable()
|| !$storage_dir->isWritable()) {
echo 'Cannot access storage directory.';
exit;
}
if (!$app->inDebugMode()) {
ob_start('ob_gzhandler');
}
if ($app->getConfig()->get('Auth', 'lockdown', 'bool', false)) {
2018-03-31 22:28:32 +00:00
http_response_code(503);
$app->startTemplating();
$app->getTemplating()->addPath('auth', __DIR__ . '/views/auth');
echo $app->getTemplating()->render('lockdown');
2018-03-31 22:28:32 +00:00
exit;
}
if (isset($_COOKIE['msz_uid'], $_COOKIE['msz_sid'])) {
$app->startSession((int)$_COOKIE['msz_uid'], $_COOKIE['msz_sid']);
$session = $app->getSession();
if ($session !== null) {
$session->user->last_seen = \Carbon\Carbon::now();
$session->user->last_ip = Net\IPAddress::remote();
$session->user->save();
}
2018-03-31 22:28:32 +00:00
}
2018-03-28 00:35:37 +00:00
$manage_mode = starts_with($_SERVER['REQUEST_URI'], '/manage');
$app->startTemplating();
$app->getTemplating()->addPath('mio', __DIR__ . '/views/mio');
2018-03-28 00:35:37 +00:00
if ($manage_mode) {
if ($app->getSession() === null || $app->getSession()->user->user_id !== 1) {
2018-03-28 00:35:37 +00:00
http_response_code(403);
echo $app->getTemplating()->render('errors.403');
2018-03-28 00:35:37 +00:00
exit;
}
$app->getTemplating()->addPath('manage', __DIR__ . '/views/manage');
2018-03-28 00:35:37 +00:00
}
}