-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.php
216 lines (185 loc) · 7.6 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
/**
* Core routing file
*
* This file is part of the OSIRIS package.
* Copyright (c) 2024 Julia Koblitz, OSIRIS Solutions GmbH
*
* @package OSIRIS
* @since 1.0.0
*
* @copyright Copyright (c) 2024 Julia Koblitz, OSIRIS Solutions GmbH
* @author Julia Koblitz <[email protected]>
* @license MIT
*/
if (file_exists('CONFIG.php')) {
require_once 'CONFIG.php';
require_once 'CONFIG.fallback.php';
} else {
require_once 'CONFIG.default.php';
}
// error_reporting(E_ERROR);
session_start();
define('BASEPATH', $_SERVER['DOCUMENT_ROOT'] . ROOTPATH);
define('OSIRIS_VERSION', '1.3.6');
// set time constants
$year = date("Y");
$month = date("n");
$quarter = ceil($month / 3);
define('CURRENTQUARTER', intval($quarter));
define('CURRENTMONTH', intval($month));
define('CURRENTYEAR', intval($year));
if (isset($_GET['OSIRIS-SELECT-MAINTENANCE-USER'])) {
// someone tries to switch users
include_once BASEPATH . "/php/init.php";
$realusername = ($_SESSION['realuser'] ?? $_SESSION['username']);
$username = ($_GET['OSIRIS-SELECT-MAINTENANCE-USER']);
// check if the user is allowed to do that
$allowed = $osiris->persons->count(['username' => $username, 'maintenance' => $realusername]);
// change username if user is allowed
if ($allowed == 1 || $realusername == $username) {
$msg = "User switched!";
$_SESSION['realuser'] = $realusername;
$_SESSION['username'] = $username;
header("Location: " . ROOTPATH . "/profile/$username");
}
// do nothing if user is not allowed
}
function lang($en, $de = null)
{
if ($de === null) return $en;
// Standard language = DE
$lang = $_GET['lang'] ?? $_COOKIE['osiris-language'] ?? 'de';
if ($lang == "en") return $en;
if ($lang == "de") return $de;
return $en;
}
include_once BASEPATH . "/php/Route.php";
Route::get('/', function () {
include_once BASEPATH . "/php/init.php";
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] === false) {
include BASEPATH . "/header.php";
include BASEPATH . "/pages/userlogin.php";
include BASEPATH . "/footer.php";
} else {
$path = ROOTPATH . "/profile/" . $_SESSION['username'];
if (!empty($_SERVER['QUERY_STRING'])) $path .= "?" . $_SERVER['QUERY_STRING'];
header("Location: $path");
}
});
if (defined('USER_MANAGEMENT') && strtoupper(USER_MANAGEMENT) == 'AUTH') {
require_once BASEPATH . '/addons/auth/index.php';
}
include_once BASEPATH . "/routes/login.php";
// route for language setting
Route::get('/set-preferences', function () {
// Language settings and cookies
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'GET' && array_key_exists('language', $_GET)) {
$_COOKIE['osiris-language'] = $_GET['language'] === 'en' ? 'en' : 'de';
$domain = ($_SERVER['HTTP_HOST'] != 'testserver') ? $_SERVER['HTTP_HOST'] : false;
setcookie('osiris-language', $_COOKIE['osiris-language'], [
'expires' => time() + 86400,
'path' => ROOTPATH . '/',
'domain' => $domain,
'httponly' => false,
'samesite' => 'Lax',
]);
}
// check if accessibility settings are given
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'GET' && array_key_exists('accessibility', $_GET)) {
// define base parameter
$domain = $_SERVER['HTTP_HOST'];
$cookie_settings = [
'expires' => time() + 86400,
'path' => ROOTPATH . '/',
'domain' => $domain,
'httponly' => false,
'samesite' => 'Lax',
];
// set cookies for current sessions
$_COOKIE['D3-accessibility-contrast'] = $_GET['accessibility']['contrast'] ?? '';
$_COOKIE['D3-accessibility-transitions'] = $_GET['accessibility']['transitions'] ?? '';
$_COOKIE['D3-accessibility-dyslexia'] = $_GET['accessibility']['dyslexia'] ?? '';
// save cookies for persistent use
setcookie('D3-accessibility-dyslexia', $_COOKIE['D3-accessibility-dyslexia'], $cookie_settings);
setcookie('D3-accessibility-contrast', $_COOKIE['D3-accessibility-contrast'], $cookie_settings);
setcookie('D3-accessibility-transitions', $_COOKIE['D3-accessibility-transitions'], $cookie_settings);
}
$redirect = $_GET['redirect'] ?? ROOTPATH . '/';
header("Location: " . $redirect);
});
if (
isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true
&&
isset($_SESSION['username']) && !empty($_SESSION['username'])
) {
include_once BASEPATH . "/routes/components.php";
include_once BASEPATH . "/routes/controlling.php";
include_once BASEPATH . "/routes/database.php";
include_once BASEPATH . "/routes/docs.php";
include_once BASEPATH . "/routes/groups.php";
include_once BASEPATH . "/routes/import.php";
include_once BASEPATH . "/routes/journals.php";
include_once BASEPATH . "/routes/projects.php";
include_once BASEPATH . "/routes/queue.php";
include_once BASEPATH . "/routes/tags.php";
include_once BASEPATH . "/routes/static.php";
include_once BASEPATH . "/routes/teaching.php";
include_once BASEPATH . "/routes/users.php";
include_once BASEPATH . "/routes/visualize.php";
include_once BASEPATH . "/routes/activities.php";
include_once BASEPATH . "/routes/export.php";
include_once BASEPATH . "/routes/reports.php";
include_once BASEPATH . "/routes/concepts.php";
include_once BASEPATH . "/routes/admin.php";
include_once BASEPATH . "/routes/conferences.php";
require_once BASEPATH . '/routes/guests.php';
// include_once BASEPATH . "/routes/adminGeneral.php";
// include_once BASEPATH . "/routes/adminRoles.php";
include_once BASEPATH . "/addons/ida/index.php";
}
include_once BASEPATH . "/routes/migrate.php";
include_once BASEPATH . "/routes/api.php";
include_once BASEPATH . "/routes/rest.php";
// include_once BASEPATH . "/routes/CRUD.php";
/**
* Routes for OSIRIS Portal
*/
include_once BASEPATH . "/addons/portal/index.php";
Route::get('/error/([0-9]*)', function ($error) {
// header("HTTP/1.0 $error");
http_response_code($error);
include BASEPATH . "/header.php";
echo "Error " . $error;
// include BASEPATH . "/pages/error.php";
include BASEPATH . "/footer.php";
});
// Add a 404 not found route
Route::pathNotFound(function ($path) {
// Do not forget to send a status header back to the client
// The router will not send any headers by default
// So you will have the full flexibility to handle this case
// header('HTTP/1.0 404 Not Found');
http_response_code(404);
$error = 404;
// header('HTTP/1.0 404 Not Found');
include BASEPATH . "/header.php";
// $browser = $_SERVER['HTTP_USER_AGENT'];
// var_dump($browser);
include BASEPATH . "/pages/error.php";
// echo "Error 404";
include BASEPATH . "/footer.php";
});
// Add a 405 method not allowed route
Route::methodNotAllowed(function ($path, $method) {
// Do not forget to send a status header back to the client
// The router will not send any headers by default
// So you will have the full flexibility to handle this case
header('HTTP/1.0 405 Method Not Allowed');
$error = 405;
include BASEPATH . "/header.php";
// include BASEPATH . "/pages/error.php";
echo "Error 405";
include BASEPATH . "/footer.php";
});
Route::run(ROOTPATH);