forked from PeeHaa/OpCacheGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
123 lines (107 loc) · 2.89 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
/**
* Bootstrap the project
*
* PHP version 5.5
*
* @author Pieter Hordijk <[email protected]>
* @copyright Copyright (c) 2013 Pieter Hordijk <https://github.com/PeeHaa>
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 1.0.0
*/
use OpCacheGUI\Format\Byte as ByteFormatter;
use OpCacheGUI\Storage\Session;
use OpCacheGUI\Auth\Ip;
use OpCacheGUI\Security\Generator\Factory;
use OpCacheGUI\Security\CsrfToken;
use OpCacheGUI\Auth\User;
use OpCacheGUI\Network\Request;
use OpCacheGUI\Presentation\Url;
use OpCacheGUI\Presentation\Html;
use OpCacheGUI\Presentation\Json;
use OpCacheGUI\Network\Router;
use OpCacheGUI\Network\RouteFactory;
/**
* Bootstrap the library
*/
require_once __DIR__ . '/src/OpCacheGUI/bootstrap.php';
/**
* Setup the environment
*/
require_once __DIR__ . '/init.deployment.php';
/**
* Start the session
*/
session_start();
/**
* Setup formatters
*/
$byteFormatter = new ByteFormatter;
/**
* Setup CSRF token
*/
$sessionStorage = new Session();
$csrfToken = new CsrfToken($sessionStorage, new Factory());
/**
* Setup the IP whitelist
*/
$whitelist = new Ip([
new \OpCacheGUI\Network\Ip\Any(),
new \OpCacheGUI\Network\Ip\Localhost(),
new \OpCacheGUI\Network\Ip\Single(),
new \OpCacheGUI\Network\Ip\Wildcard(),
new \OpCacheGUI\Network\Ip\Range(),
new \OpCacheGUI\Network\Ip\Cidr(),
]);
$whitelist->buildWhitelist($login['whitelist']);
/**
* Setup the authentication object
*/
$user = new User($sessionStorage, $login['username'], $login['password'], $whitelist);
/**
* Setup URL renderer
*/
$urlRenderer = new Url($uriScheme);
/**
* Setup the HTML template renderer
*/
$htmlTemplate = new Html(__DIR__ . '/template', 'page.phtml', $translator, $urlRenderer);
/**
* Setup the JSON template renderer
*/
$jsonTemplate = new Json(__DIR__ . '/template', $translator);
/**
* Setup the request object
*/
$request = new Request($_GET, $_POST, $_SERVER);
/**
* Setup the router
*/
$routeFactory = new RouteFactory();
$router = new Router($request, $routeFactory, $uriScheme);
/**
* Load public routes
*/
require_once __DIR__ . '/public-routes.php';
/**
* Load the routes
*/
if (!extension_loaded('Zend OPcache') || opcache_get_status() === false) {
if (!in_array($router->getIdentifier(), ['error', 'mainjs', 'maincss', 'fontawesome-webfont_eot', 'fontawesome-webfont_woff', 'fontawesome-webfont_ttf', 'fontawesome-webfont_svg'], true)) {
header('Location: ' . $urlRenderer->get('error'));
exit;
}
$router->get('error', function() use ($htmlTemplate) {
return $htmlTemplate->render('error.phtml', [
'login' => true,
'title' => 'Error',
'type' => !extension_loaded('Zend OPcache') ? 'installed' : 'enabled',
]);
});
} else {
require_once __DIR__ . '/routes.php';
}
/**
* Dispatch the request
*/
echo $router->run();