56 lines
1.2 KiB
PHP
56 lines
1.2 KiB
PHP
<?php
|
|
|
|
use App\auth\Authenticator;
|
|
use App\download\DownloadHandler;
|
|
use App\login\LoginHandler;
|
|
use Whoops\Handler\PrettyPageHandler;
|
|
use Whoops\Run;
|
|
|
|
require __DIR__.'/../vendor/autoload.php';
|
|
require __DIR__.'/../src/base.php';
|
|
require_once __DIR__.'/../config/config.php';
|
|
|
|
$environment = 'prod';
|
|
|
|
$whoops = new Run;
|
|
if ($environment === 'dev') {
|
|
$whoops->pushHandler(new PrettyPageHandler);
|
|
} else {
|
|
$whoops->pushHandler(function($e) {
|
|
handle_error($e);
|
|
die();
|
|
});
|
|
}
|
|
$whoops->register();
|
|
|
|
session_start();
|
|
|
|
// parse request uri
|
|
$uri = substr($_SERVER['REQUEST_URI'], strlen(BASE));
|
|
$split_uri = explode('/', explode('?', $uri)[0]);
|
|
array_splice($split_uri, 0, 1);
|
|
|
|
$authenticator = new Authenticator();
|
|
|
|
if (empty($split_uri[0])) {
|
|
\App\template\Error::printError(403);
|
|
die();
|
|
}
|
|
|
|
if (!$authenticator->isLoggedIn() && !($split_uri[0] === 'login')) {
|
|
$_SESSION['return_uri'] = ($uri !== '/favicon.ico') ? $uri : '/';
|
|
redirect('/login');
|
|
die();
|
|
}
|
|
|
|
if ($split_uri[0] === 'login') {
|
|
if ($authenticator->isLoggedIn()) {
|
|
redirect($_SESSION['return_uri']);
|
|
die();
|
|
}
|
|
$handler = new LoginHandler();
|
|
} else {
|
|
$handler = new DownloadHandler($split_uri[0]);
|
|
}
|
|
|
|
$handler->handle(); |