-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
159 lines (132 loc) · 4.29 KB
/
Copy pathbootstrap.php
File metadata and controls
159 lines (132 loc) · 4.29 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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
require_once dirname(__DIR__) . '/shared-ui/bootstrap.php';
function curriculum_request_scheme()
{
if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
$values = explode(',', $_SERVER['HTTP_X_FORWARDED_PROTO']);
return strtolower(trim($values[0])) === 'https' ? 'https' : 'http';
}
if (!empty($_SERVER['HTTP_X_FORWARDED_PROTOCOL'])) {
$values = explode(',', $_SERVER['HTTP_X_FORWARDED_PROTOCOL']);
return strtolower(trim($values[0])) === 'https' ? 'https' : 'http';
}
if (!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && strtolower((string) $_SERVER['HTTP_X_FORWARDED_SSL']) === 'on') {
return 'https';
}
if (!empty($_SERVER['HTTPS']) && strcasecmp((string) $_SERVER['HTTPS'], 'off') !== 0) {
return 'https';
}
$host = strtolower(curriculum_request_host());
if ($host === 'localhost'
|| strpos($host, 'localhost:') === 0
|| strpos($host, '127.0.0.1') === 0
|| strpos($host, '[::1]') === 0
|| $host === '::1') {
return 'http';
}
return 'https';
}
function curriculum_request_host()
{
if (!empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
$hosts = explode(',', $_SERVER['HTTP_X_FORWARDED_HOST']);
$host = trim($hosts[0]);
if ($host !== '') {
return $host;
}
}
if (!empty($_SERVER['HTTP_HOST'])) {
return $_SERVER['HTTP_HOST'];
}
if (!empty($_SERVER['SERVER_NAME'])) {
return $_SERVER['SERVER_NAME'];
}
return 'localhost';
}
function curriculum_request_origin()
{
return curriculum_request_scheme() . '://' . curriculum_request_host();
}
function curriculum_public_origin()
{
$envOrigin = getenv('AR_PUBLIC_ORIGIN');
if ($envOrigin) {
return function_exists('shared_auth_normalize_origin')
? shared_auth_normalize_origin($envOrigin)
: rtrim(trim($envOrigin), '/');
}
return curriculum_request_origin();
}
function curriculum_shared_auth_broker_path()
{
$envPath = getenv('AR_SHARED_AUTH_BROKER_PATH');
if ($envPath && is_file($envPath)) {
return $envPath;
}
$documentRoot = rtrim((string) ($_SERVER['DOCUMENT_ROOT'] ?? ''), '/');
$candidates = array_filter(array(
dirname(__DIR__) . '/sharedAuth/broker.php',
dirname(__DIR__, 2) . '/sharedAuth/broker.php',
$documentRoot !== '' ? $documentRoot . '/Web/sharedAuth/broker.php' : null,
$documentRoot !== '' ? $documentRoot . '/sharedAuth/broker.php' : null,
));
foreach ($candidates as $candidate) {
if (is_file($candidate)) {
return $candidate;
}
}
throw new RuntimeException(
'Unable to locate sharedAuth/broker.php. Set AR_SHARED_AUTH_BROKER_PATH or place the file in a supported location.'
);
}
function curriculum_current_path()
{
return strtok($_SERVER['REQUEST_URI'] ?? '/index.php', '?') ?: '/index.php';
}
function curriculum_remove_auth_params(array $params)
{
unset($params['login'], $params['logout'], $params['ticket'], $params['auth']);
return $params;
}
function curriculum_current_url_without_auth_params()
{
$path = curriculum_current_path();
$params = curriculum_remove_auth_params($_GET);
$query = http_build_query($params);
return curriculum_public_origin() . $path . ($query ? ('?' . $query) : '');
}
function curriculum_clear_session_user()
{
unset($_SESSION['auth_user']);
}
function curriculum_destroy_session()
{
curriculum_clear_session_user();
if (session_status() === PHP_SESSION_ACTIVE) {
$cookieParams = session_get_cookie_params();
$_SESSION = array();
if (!headers_sent()) {
setcookie(
session_name(),
'',
time() - 3600,
$cookieParams['path'] ?? '/',
$cookieParams['domain'] ?? '',
!empty($cookieParams['secure']),
!empty($cookieParams['httponly'])
);
}
session_destroy();
}
}
if (session_status() !== PHP_SESSION_ACTIVE) {
session_set_cookie_params(array(
'lifetime' => 0,
'path' => '/',
'domain' => '',
'secure' => curriculum_request_scheme() === 'https',
'httponly' => true,
'samesite' => 'Lax',
));
session_start();
}