forked from sandboxgangster/Part-DB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_session.php
301 lines (250 loc) · 13.4 KB
/
start_session.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<?php
/*
part-db version 0.1
Copyright (C) 2005 Christoph Lechner
http://www.cl-projects.de/
part-db version 0.2+
Copyright (C) 2009 K. Jacobs and others (see authors.php)
http://code.google.com/p/part-db/
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
$Id$
Changelog (sorted by date):
[DATE] [NICKNAME] [CHANGES]
2012-09-03 kami89 - created
2013-05-05 kami89 - added config.php updates
- added workaround for STRATO servers
*/
/**
* @file start_session.php
*
* @brief This file must be included in every PHP file which produces HTML output!
*/
// set HTTP charset to UTF-8
header('Content-type: text/html; charset=utf-8');
$BASE_tmp = str_replace('\\', '/', dirname(__FILE__)); // temporary base path of Part-DB, without slash at the end
include_once($BASE_tmp.'/lib/lib.start_session.php');
/********************************************************************************
*
* define an exception handler for uncaught exceptions
*
*********************************************************************************/
function exception_handler($e)
{
print_messages_without_template( 'Part-DB: Schwerwiegender Fehler!', NULL,
'<font color="red"><strong>Es ist ein schwerwiegender Fehler aufgetreten:'.
'<br><br>'.nl2br($e->getMessage()).'</strong><br><br>'.
'(Exception wurde geworfen in '.$e->getFile().', Zeile '.$e->getLine().')</font>');
exit;
}
set_exception_handler('exception_handler');
/********************************************************************************
*
* For the Update from Part-DB 0.2.2 to 0.3.0:
* Move the file "config.php" and the folders "backup", "media" and "log" to "data/..."
*
*********************************************************************************/
$old_config_exists = file_exists($BASE_tmp.'/config.php');
$old_backup_exists = file_exists($BASE_tmp.'/backup');
$old_media_exists = file_exists($BASE_tmp.'/media');
$old_log_exists = file_exists($BASE_tmp.'/log');
if (($old_config_exists) || ($old_backup_exists) || ($old_media_exists) || ($old_log_exists))
{
$messages = '<strong>Bitte verschieben Sie die folgenden Dateien und Ordner ins Verzeichnis "data": <br><br>';
if ($old_config_exists) {$messages .= '"config.php" --> "data/config.php"<br>';}
if ($old_backup_exists) {$messages .= '"backup/" --> "data/backup/"<br>';}
if ($old_media_exists) {$messages .= '"media/" --> "data/media/"<br>';}
if ($old_log_exists) {$messages .= '"log/" --> "data/log/"<br>';}
$messages .= '<br><font color="red">WICHTIG:<br>Kopieren Sie jeweils nur den Inhalt der genannten Ordner, nicht den ganzen Ordner an sich!<br>'.
'Die Zielordner enthalten bereits (teilweise versteckte) Dateien, die auf keinen Fall überschrieben werden dürfen!<br>'.
'Kopieren Sie also nur den Inhalt dieser Ordner und löschen Sie danach die alten, leeren Ordner im Hauptverzeichnis.</font></strong>';
print_messages_without_template('Part-DB', 'Update von Part-DB: Manuelle Eingriffe notwendig', $messages);
exit;
}
/********************************************************************************
*
* include config files
*
*********************************************************************************/
include_once($BASE_tmp.'/config_defaults.php'); // first, we load all default values of the $config array...
if (file_exists($BASE_tmp.'/data/config.php') && is_readable($BASE_tmp.'/data/config.php'))
include_once($BASE_tmp.'/data/config.php'); // ...and then we overwrite them with the user settings, if they exist
if (count($manual_config) > 0) // $manual_config is defined in "config_defaults.php" and can be filled in "config.php"
$config = array_merge($config, $manual_config); // if there are manual configs, add them to $config
/********************************************************************************
*
* define directory constants of the part-db installation
*
* please note: we always use slashes, even if the script runs on Windows!
*
* If the paths BASE, DOCUMENT_ROOT or BASE_RELATIVE are not correct,
* the user can set them manually in his config.php.
* Example how to define it in the config.php: $manual_config['BASE'] = '/my/base';
*
*********************************************************************************/
// directory to the part-db installation, without slash at the end
// Example (UNIX/Linux): "/var/www/part-db"
// Example (Windows): "C:/wamp/www/part-db"
if (isset($config['BASE']))
define('BASE', $config['BASE']);
else
define('BASE', $BASE_tmp);
// server-directory without slash at the end
// Example (UNIX/Linux): "/var/www"
// Example (Windows): "C:/wamp/www"
if (isset($config['DOCUMENT_ROOT']))
define('DOCUMENT_ROOT', $config['DOCUMENT_ROOT']);
elseif (isset($_SERVER['DOCUMENT_ROOT']))
define('DOCUMENT_ROOT', rtrim(str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']), '/'));
elseif (isset($_SERVER['SCRIPT_FILENAME']) && isset($_SERVER['PHP_SELF']))
define('DOCUMENT_ROOT', rtrim(str_replace('\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF'])))));
elseif (isset($_SERVER['PATH_TRANSLATED']) && isset($_SERVER['PHP_SELF']))
define('DOCUMENT_ROOT', rtrim(str_replace('\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF'])))));
else
{
$messages = 'Die Konstante "DOCUMENT_ROOT" konnte auf Ihrem Server nicht ermittelt werden.<br>'.
'Bitte definieren Sie diese Konstante manuell in Ihrer Konfigurationsdatei "data/config.php".';
print_messages_without_template('Part-DB', 'DOCUMENT_ROOT kann nicht ermittelt werden', $messages);
exit;
}
// the part-db installation directory without document root, without slash at the end
// Example (UNIX/Linux): "/part-db"
// Example (Windows): "/part-db"
if (isset($config['BASE_RELATIVE']))
define('BASE_RELATIVE', $config['BASE_RELATIVE']);
elseif (mb_strpos(BASE, DOCUMENT_ROOT) === false) // workaround for STRATO servers, see german post on uC.net:
define('BASE_RELATIVE', '.'); // http://www.mikrocontroller.net/topic/269289#3152928
else
define('BASE_RELATIVE', str_replace(DOCUMENT_ROOT, '', BASE));
// for debugging uncomment these lines:
//print 'BASE = "'.BASE.'"<br>';
//print 'DOCUMENT_ROOT = "'.DOCUMENT_ROOT.'"<br>';
//print 'BASE_RELATIVE = "'.BASE_RELATIVE.'"<br>';
//print 'DIRECTORY_SEPARATOR = "'.DIRECTORY_SEPARATOR.'"<br>';
//exit;
/********************************************************************************
*
* make some checks
*
*********************************************************************************/
$messages = check_requirements();
if (count($messages) > 0)
{
print_messages_without_template('Part-DB', 'Mindestanforderungen von Part-DB nicht erfüllt!',
'<font color="red"><strong>•'.implode('<br>•', $messages).'</strong></font><br><br>'.
'Nähere Informationen gibt es in der <a target="_blank" href="'.BASE_RELATIVE.
'/documentation/dokuwiki/doku.php?id=anforderungen">Dokumentation</a>.');
exit;
}
$messages = check_file_permissions();
if (count($messages) > 0)
{
$message = '<strong><font color="red">';
foreach ($messages as $msg)
$message .= '•'.$msg.'<br>';
$message .= '</font></strong><br><br>';
$message .= 'Nähere Informationen zu den Dateirechten gibt es in der <a target="_blank" href="'.BASE_RELATIVE.
'/documentation/dokuwiki/doku.php?id=installation">Dokumentation</a>.<br><br>';
$message .= '<form action="" method="post"><input type="submit" value="Seite neu laden"></form>';
print_messages_without_template('Part-DB', 'Anpassung der Rechte von Verzeichnissen und Dateien', $message);
exit;
// please note: the messages and the "exit;" here are very important, we mustn't continue the script!
// the reasen is: if the config.php is not readable, the array $config is now not loaded successfully.
}
$message = check_if_config_is_valid();
if (is_string($message))
{
print_messages_without_template('Part-DB', 'Ihre config.php ist fehlerhaft!',
'<font color="red"><strong>'.$message.'</strong></font><br><br>'.
'Nähere Informationen gibt es in der <a target="_blank" href="'.BASE_RELATIVE.
'/documentation/dokuwiki/doku.php?id=installation">Dokumentation</a>.<br><br>'.
'<form action="" method="post"><input type="submit" value="Seite neu laden"></form>');
exit;
}
/********************************************************************************
*
* update the config.php if the system is newer than the user's config.php
*
*********************************************************************************/
if (($config['system']['current_config_version'] < $config['system']['latest_config_version'])
&& (file_exists(BASE.'/data/config.php')) && (is_readable(BASE.'/data/config.php'))
&& (filesize(BASE.'/data/config.php') > 0))
{
include_once(BASE.'/updates/config_update_steps.php');
try
{
$update_messages = update_users_config_php();
$message = '<strong><font color="darkgreen">Ihre config.php wurde erfolgreich aktualisiert!</font></strong><br><br>'.
'Es kann sein, dass jetzt der Installationsassistent startet, '.
'um noch einige neue Einstellungen zu tätigen.<br><br>';
if (count($update_messages) > 0)
{
$message .= '<strong><font color="red">';
foreach ($update_messages as $text)
$message .= '•'.$text.'<br>';
$message .= '</font></strong><br>';
}
}
catch (Exception $e)
{
$message = '<strong><font color="red">Es gab ein Fehler bei der Aktualisierung ihrer config.php:<br><br>'.
nl2br($e->getMessage()).'</font></strong><br><br>';
}
$message .= '<form action="" method="post"><input type="submit" value="Seite neu laden"></form>';
print_messages_without_template('Part-DB', 'Aktualisierung ihrer config.php', $message);
exit;
}
$config['html']['http_charset'] = 'utf-8'; ///< @todo remove this later; see config_defaults.php
/********************************************************************************
*
* set internal encoding / timezone / locale / error reporting
*
*********************************************************************************/
if (($config['debug']['enable']) && ( ! $config['debug']['template_debugging_enable'])) // template debugging produces a lot of warnings!
{
error_reporting(E_ALL & ~E_STRICT);
@ini_set("display_errors", 1);
}
else
@ini_set("display_errors", 0);
mb_internal_encoding(/*$config['html']['http_charset']*/ 'UTF-8');
mb_regex_encoding('UTF-8');
date_default_timezone_set($config['timezone']);
own_setlocale(LC_ALL, $config['language']);
/********************************************************************************
*
* start session
*
*********************************************************************************/
session_name('Part-DB');
session_start();
/********************************************************************************
*
* autoload function for classes
*
*********************************************************************************/
function __autoload($classname)
{
if (strpos($classname, 'vlib') === 0)
include_once(BASE.'/lib/vlib/'.$classname.'.php');
else
include_once(BASE.'/lib/class.'.$classname.'.php');
}
/********************************************************************************
*
* include libraries
*
*********************************************************************************/
include_once(BASE.'/lib/lib.functions.php');
include_once(BASE.'/lib/lib.debug.php');
include_once(BASE.'/lib/lib.php');
?>