-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.inc.php
136 lines (100 loc) · 3.2 KB
/
common.inc.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
<?php
// Wenn RelativePath nicht definiert wurde, funktioniert das Projekt nicht richtig.
if(!defined('RelativePath'))
{
trigger_error('Notwendige PHP-Konstante "RelativePath" wurde nicht definiert.', E_USER_ERROR);
exit;
}
// Prüfen ob Konfiguration erstellt wurde
if(!file_exists(RelativePath . '/cfg/config.inc.php'))
{
trigger_error('Die notwendige Konfigurationsdatei /cfg/config.inc.php wurde noch nicht angelegt.', E_USER_ERROR);
exit;
}
// Notwendige Initial-Includes
require_once(RelativePath.'/cfg/config.inc.php');
require_once(RelativePath.'/lib/utils.php');
// Ausgabe komprimieren - Deaktivieren wenn Apache mod_deflate verwendet wird
if(!defined('USE_GZHANDLER') || USE_GZHANDLER == false)
ob_start();
else
ob_start('ob_gzhandler');
// Wartungsmodus aktiv?
if(defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == true)
{
http_response_code(503); // Service Unavailable
header('Content-Type: application/json');
echo json_encode(array(
'success' => false,
'rows' => false,
'total' => 0,
'error' => array(
'error_message' => 'Diese Seite befindet sich aktuell im Wartungsmodus. Bitte versuchen Sie es später erneut',
'error_code' => -1040
)
));
exit(0);
}
// dynamische Konstanten aus Konfiguration ableiten
// Datei-Berechtigungen beim Schreiben automatisch beschränken?!
umask(000);
// richtige Zeitzone und Sprache des Systems setzen
date_default_timezone_set('UTC');
// Stringvergleiche und Numerische Werte auf standard/ englisch setzen um Seiteneffekte zu vermeiden
setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
// Session starten
if(defined('SESSION_LIVETIME'))
ini_set("session.cookie_lifetime", SESSION_LIVETIME);
session_start();
// Errorhandling
if(defined('ERROR_REPORTING'))
error_reporting(ERROR_REPORTING);
// Errorhandler setzen
if(defined('USE_ERROR_HANDLER') && USE_ERROR_HANDLER == true)
{
// @todo
//require_once(RelativePath . '/scripts/includes/error_handler.inc.php');
//set_error_handler('');
}
// Zeichensatz
define('CHARSET', 'UTF-8');
ini_set('default_charset', CHARSET);
// Wenn max_input_vars ausgeschöpft wird, dann Fehlermeldung erzeugen, da es sich sonst nur um ein Warning handelt
$max_input_vars = ini_get('max_input_vars');
if($max_input_vars > 0 && count($_POST) >= $max_input_vars)
{
trigger_error('Zulässige Anzahl an Formularparametern überschritten - max_input_vars: '.$max_input_vars, E_USER_ERROR);
}
// Versionsnummer
define('VERSION', '0.0.1');
// Weitere Includes tätigen
require_once(RelativePath.'/lib/DB.class.php');
require_once(RelativePath.'/lib/Cache.class.php');
require_once(RelativePath.'/lib/Member.class.php');
// Datenbank und andere Objekte initialisieren
DB::init();
if(defined('MBU_VTOOL_USE_CACHE') && MBU_VTOOL_USE_CACHE)
Cache::enable();
else
Cache::disable();
// Zugriffsberechtigung erfragen
if(file_exists(__DIR__.'/auth.inc.php'))
{
$allowed = include 'auth.inc.php';
if (!$allowed)
{
http_response_code(401); // Authentication required
header('Content-Type: application/json');
echo json_encode(array(
'success' => false,
'rows' => false,
'total' => 0,
'error' => array(
'error_message' => 'Authentication required',
'error_code' => -1050
)
));
exit(0);
}
}
?>