2017-12-16 19:17:29 +00:00
|
|
|
<?php
|
|
|
|
namespace Misuzu;
|
|
|
|
|
2018-05-27 23:24:16 +00:00
|
|
|
date_default_timezone_set('UTC');
|
|
|
|
|
2018-04-30 21:39:43 +00:00
|
|
|
require_once __DIR__ . '/vendor/autoload.php';
|
2018-07-06 01:28:06 +00:00
|
|
|
require_once __DIR__ . '/src/changelog.php';
|
2018-04-30 21:39:43 +00:00
|
|
|
require_once __DIR__ . '/src/colour.php';
|
2018-07-10 21:24:00 +00:00
|
|
|
require_once __DIR__ . '/src/comments.php';
|
|
|
|
require_once __DIR__ . '/src/general.php';
|
2018-07-10 16:37:13 +00:00
|
|
|
require_once __DIR__ . '/src/git.php';
|
2018-07-07 23:24:34 +00:00
|
|
|
require_once __DIR__ . '/src/manage.php';
|
2018-07-08 19:24:59 +00:00
|
|
|
require_once __DIR__ . '/src/news.php';
|
2018-07-07 23:24:34 +00:00
|
|
|
require_once __DIR__ . '/src/perms.php';
|
2018-04-30 21:39:43 +00:00
|
|
|
require_once __DIR__ . '/src/zalgo.php';
|
2018-05-23 01:41:57 +00:00
|
|
|
require_once __DIR__ . '/src/Forum/forum.php';
|
|
|
|
require_once __DIR__ . '/src/Forum/post.php';
|
|
|
|
require_once __DIR__ . '/src/Forum/topic.php';
|
|
|
|
require_once __DIR__ . '/src/Forum/validate.php';
|
2018-05-16 02:58:21 +00:00
|
|
|
require_once __DIR__ . '/src/Users/login_attempt.php';
|
2018-05-27 00:20:35 +00:00
|
|
|
require_once __DIR__ . '/src/Users/profile.php';
|
|
|
|
require_once __DIR__ . '/src/Users/role.php';
|
|
|
|
require_once __DIR__ . '/src/Users/session.php';
|
|
|
|
require_once __DIR__ . '/src/Users/user.php';
|
2018-05-16 02:58:21 +00:00
|
|
|
require_once __DIR__ . '/src/Users/validation.php';
|
2018-01-02 19:37:13 +00:00
|
|
|
|
2018-04-24 22:55:46 +00:00
|
|
|
$app = new Application(
|
2018-01-04 20:01:55 +00:00
|
|
|
__DIR__ . '/config/config.ini',
|
|
|
|
IO\Directory::exists(__DIR__ . '/vendor/phpunit/phpunit')
|
|
|
|
);
|
2018-01-03 21:39:01 +00:00
|
|
|
$app->startDatabase();
|
2018-03-14 01:39:02 +00:00
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
2018-03-14 01:39:02 +00:00
|
|
|
|
2018-07-07 23:24:34 +00:00
|
|
|
$app->startTemplating();
|
|
|
|
$tpl = $app->getTemplating();
|
|
|
|
|
2018-04-24 22:55:46 +00:00
|
|
|
if ($app->getConfig()->get('Auth', 'lockdown', 'bool', false)) {
|
2018-03-31 22:28:32 +00:00
|
|
|
http_response_code(503);
|
2018-07-07 23:24:34 +00:00
|
|
|
$tpl->addPath('auth', __DIR__ . '/views/auth');
|
|
|
|
echo $tpl->render('lockdown');
|
2018-03-31 22:28:32 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2018-07-07 23:24:34 +00:00
|
|
|
$tpl->addPath('mio', __DIR__ . '/views/mio');
|
2018-05-16 02:58:21 +00:00
|
|
|
|
2018-03-31 22:28:32 +00:00
|
|
|
if (isset($_COOKIE['msz_uid'], $_COOKIE['msz_sid'])) {
|
|
|
|
$app->startSession((int)$_COOKIE['msz_uid'], $_COOKIE['msz_sid']);
|
2018-04-17 21:01:49 +00:00
|
|
|
|
2018-05-16 02:58:21 +00:00
|
|
|
if ($app->hasActiveSession()) {
|
|
|
|
$db = Database::connection();
|
|
|
|
|
|
|
|
$bumpUserLast = $db->prepare('
|
|
|
|
UPDATE `msz_users` SET
|
|
|
|
`last_seen` = NOW(),
|
|
|
|
`last_ip` = INET6_ATON(:last_ip)
|
|
|
|
WHERE `user_id` = :user_id
|
|
|
|
');
|
|
|
|
$bumpUserLast->bindValue('last_ip', Net\IPAddress::remote()->getString());
|
|
|
|
$bumpUserLast->bindValue('user_id', $app->getUserId());
|
|
|
|
$bumpUserLast->execute();
|
|
|
|
|
|
|
|
$getUserDisplayInfo = $db->prepare('
|
|
|
|
SELECT
|
|
|
|
u.`user_id`, u.`username`,
|
|
|
|
COALESCE(r.`role_colour`, CAST(0x40000000 AS UNSIGNED)) as `colour`
|
|
|
|
FROM `msz_users` as u
|
|
|
|
LEFT JOIN `msz_roles` as r
|
|
|
|
ON u.`display_role` = r.`role_id`
|
|
|
|
WHERE `user_id` = :user_id
|
|
|
|
');
|
|
|
|
$getUserDisplayInfo->bindValue('user_id', $app->getUserId());
|
|
|
|
$userDisplayInfo = $getUserDisplayInfo->execute() ? $getUserDisplayInfo->fetch() : [];
|
2018-07-07 23:24:34 +00:00
|
|
|
$tpl->var('current_user', $userDisplayInfo);
|
2018-04-17 21:01:49 +00:00
|
|
|
}
|
2018-03-31 22:28:32 +00:00
|
|
|
}
|
|
|
|
|
2018-07-07 23:24:34 +00:00
|
|
|
$inManageMode = starts_with($_SERVER['REQUEST_URI'], '/manage');
|
2018-07-10 21:24:00 +00:00
|
|
|
$hasManageAccess = perms_check(perms_get_user(MSZ_PERMS_GENERAL, $app->getUserId()), MSZ_GENERAL_PERM_CAN_MANAGE);
|
2018-07-07 23:24:34 +00:00
|
|
|
$tpl->var('has_manage_access', $hasManageAccess);
|
2018-03-28 00:35:37 +00:00
|
|
|
|
2018-07-07 23:24:34 +00:00
|
|
|
if ($inManageMode) {
|
|
|
|
if (!$hasManageAccess) {
|
2018-05-26 20:33:05 +00:00
|
|
|
echo render_error(403);
|
2018-03-28 00:35:37 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2018-07-07 23:24:34 +00:00
|
|
|
$tpl = $app->getTemplating();
|
|
|
|
$tpl->var('manage_menu', manage_get_menu($app->getUserId()));
|
|
|
|
$tpl->addPath('manage', __DIR__ . '/views/manage');
|
2018-03-28 00:35:37 +00:00
|
|
|
}
|
2018-03-14 01:39:02 +00:00
|
|
|
}
|