-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathindex.php
57 lines (50 loc) · 1.7 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
<?php
function __autoload($class)
{
$path = '../';
if (preg_match('/^(.*)_Controller$/', $class, $matches)) {
$class = $matches[1];
$dir = 'controllers';
} elseif (preg_match('/^(.*)_Model$/', $class, $matches)) {
$class = $matches[1];
$dir = 'models';
} elseif (preg_match('/^(.*)_Helper$/', $class, $matches)) {
$class = $matches[1];
$dir = 'helpers';
} else {
$dir = 'libraries';
}
include_once($path.$dir.'/'.(strtolower($class)).'.php');
}
if (isset(App::instance()->config['timezone'])) {
date_default_timezone_set(App::instance()->config['timezone']);
}
$authenticated = true;
if (PHP_SAPI !== 'cli' && isset(App::instance()->config['auth'])) {
$username = null;
$password = null;
$auth = App::instance()->config['auth'];
if(isset($auth['username']) && isset($auth['password']))
{
// mod_php
if (isset($_SERVER['PHP_AUTH_USER'])) {
$username = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
// most other servers
} elseif (isset($_SERVER['HTTP_AUTHORIZATION']) && strpos(strtolower($_SERVER['HTTP_AUTHORIZATION']), 'basic') === 0) {
list($username, $password) = explode(':', base64_decode(substr($_SERVER['HTTP_AUTHORIZATION'], 6)));
}
if ($username != $auth['username'] || !password_verify($password, $auth['password'])) {
$authenticated = false;
}
}
}
if ($authenticated) {
$error = new Error();
Router::instance()->route();
} else {
header('WWW-Authenticate: Basic realm="PHPRedis Administrator"');
header('HTTP/1.0 401 Unauthorized');
echo 'Not Authorized';
die();
}