-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.php
More file actions
77 lines (64 loc) · 1.96 KB
/
Copy pathindex.php
File metadata and controls
77 lines (64 loc) · 1.96 KB
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
<?php
require( __DIR__ . "/private/cfg.php");
require(__DIR__ . '/vendor/autoload.php');
function str_contains_any(string $haystack, array $needles): bool
{
return array_reduce($needles, fn($a, $n) => $a || str_contains($haystack, $n), false);
}
function generateUUID(): string
{
return sprintf(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff),
mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000,
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
);
}
register_shutdown_function(function() {
$error = error_get_last();
if ($error && in_array($error['type'], [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR])) {
http_response_code(500);
if (is_file(__DIR__ . '/500.php')) {
include __DIR__ . '/500.php';
} else {
echo "Internal Server Error";
}
exit();
}
});
use parabase\Sessions;
use parabase\Session;
try {
$conn = new \PDO(
"mysql:host=" . CONFIG['database']['host'] . ";
dbname=" . CONFIG['database']['name'], CONFIG['database']['username'], CONFIG['database']['password']
);
$conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$conn->setAttribute(\PDO::ATTR_PERSISTENT, true);
} catch(Exception $e) {
exit("Internal Server Error");
}
function undefineSESSION($cookie) {
setcookie($cookie, "", 1, "/");
define('SESSION', (object)array());
}
foreach(CONFIG["auth"]["cookies"] as $cookie){
$val = str_replace(".", "_", $cookie);
if(isset($_COOKIE[$val])){
$validated = Sessions::Validate($_COOKIE[$val]);
if(!$validated) {
undefineSESSION($cookie);
continue;
}
// auth your user based on $validated->user_id or whatever you wish
if(!defined('SESSION')) {
define('SESSION', new Session($validated->session_key, $user, $validated->csrf));
break;
}
}
}
if(!defined('SESSION')){
define('SESSION', false);
}
require_once(__DIR__ . "/router.php");
exit();