-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
341 lines (287 loc) · 10.3 KB
/
index.php
File metadata and controls
341 lines (287 loc) · 10.3 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
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<?php
/*******************************************************************************
WISY
********************************************************************************
Portals Main Entry Point
@author Bjoern Petersen
*******************************************************************************/
define('IN_WISY', true);
/*******************************************************************************
Set any cookie, used to enable special features
*******************************************************************************/
// with &setcookie=name,val you can set a cookie to the given value
// with &setcookie=name you can remove a cookie
// an serverless alternative would be:
// javascript:d=new%20Date();d.setTime(d.getTime()+10*24*60*60*1000);document.cookie="cookiename=val;expires="+d.toGMTString();
if( isset($_GET['setcookie']) )
{
$temp = explode(',', $_GET['setcookie']);
if( sizeof($temp)>1 )
{
setcookie($temp[0], $temp[1], time()+864000); // expires in 10 days
$_COOKIE[ $temp[0] ] = $temp[1];
}
else
{
setcookie($temp[0]);
unset($_COOKIE[ $temp[0] ]);
}
}
/*******************************************************************************
Connect to the database
*******************************************************************************/
require_once("admin/sql_curr.inc.php");
require_once("admin/config/config.inc.php");
$db = new DB_Admin;
/*******************************************************************************
Tools
*******************************************************************************/
// wrappers for PHP >= 5.4 with changed defaults for some functions
function isohtmlspecialchars($a, $f=ENT_COMPAT) { return htmlspecialchars($a, $f, 'ISO-8859-1'); }
function isohtmlentities ($a, $f=ENT_COMPAT) { return htmlentities ($a, $f, 'ISO-8859-1'); }
// temporary functions for switching between html5/html3.2 rendering
function html5($h) { return $GLOBALS['wisyPortalEinstellungen']['html5']? $h : ''; }
function html3($h) { return $GLOBALS['wisyPortalEinstellungen']['html5']? '' : $h; }
function explodeSettings__($in, &$out, $follow_includes)
{
$in = strtr($in, "\r\t", "\n ");
$in = explode("\n", $in);
for( $i = 0; $i < sizeof($in); $i++ )
{
$equalPos = strpos($in[$i], '=');
if( $equalPos )
{
$regKey = trim(substr($in[$i], 0, $equalPos));
if( $regKey != '' )
{
$regValue = trim(substr($in[$i], $equalPos+1));
if( $regKey == 'include' )
{
if( !$follow_includes ) {
echo 'ERROR: includes inside includes are not allowed!'; // a die() would be too harsh ...
}
else if( !@file_exists($regValue) ) {
echo "ERROR: the following include-file does not exists: $regValue"; // a die() would be too harsh ...
}
else {
$infile = file_get_contents($regValue);
explodeSettings__($infile, $out, false);
}
}
else
{
$out[$regKey] = $regValue; // the key may be set with an empty value!
}
}
}
}
}
function explodeSettings($in)
{
$out = array();
explodeSettings__($in, $out, true);
return $out;
}
function headerDoCache($seconds = 43200 /*12 hours*/)
{
if( $seconds <= 0 )
{
// add header entries that make sure, the file is NOT cached
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Pragma: no-cache"); // HTTP/1.0
}
else
{
// add header entries that make sure, the file IS CACHED
header("Cache-Control: public");
header('Expires: ' . gmdate("D, d M Y H:i:s", time()+intval($seconds)) . ' GMT');
}
}
function fwd301($fwdTo)
{
// wenn man nur "Location:" verwendet, wird von PHP der Code 302 versandt
header("HTTP/1.1 301 Moved Permanently");
header("Location: $fwdTo");
header("Connection: close");
exit();
}
function error404()
{
global $wisyCore;
header("HTTP/1.1 404 Not Found");
echo '<html>
<head>
<title>Fehler 404 - Seite nicht gefunden</title>
</head>
<body>
<h1>Fehler 404 - Seite nicht gefunden</h1>
<p>Entschuldigung, aber die von Ihnen gewünschte Seite (<i>'.isohtmlspecialchars($_SERVER['REQUEST_URI']).'</i> in <i>/'.isohtmlspecialchars($wisyCore).'</i> auf <i>' .$_SERVER['HTTP_HOST']. '</i>) konnte leider nicht gefunden werden. Sie können jedoch ...
<ul>
<li><a href="http://'.$_SERVER['HTTP_HOST'].'">Die Startseite von '.$_SERVER['HTTP_HOST'].' aufrufen ...</a></li>
<li><a href="javascript:history.back();">Zurück zur zuletzt besuchten Seite wechseln ...</a></li>
</ul>
</body>
</html>';
exit();
}
/*******************************************************************************
Find out the portal to use, load some basic settings
*******************************************************************************/
function selectPortalOrFwd301()
{
global $db;
$ist_domain = strtolower($_SERVER['HTTP_HOST']);
// do forward by default - however, we skip forwarding on special domains
$do_fwd = true;
// some special domain handling
if( substr($ist_domain, 0, 7)=='sandbox' ) // remove sandbox prefix
{
if( substr($ist_domain, 0, 8)=='sandbox1' || substr($ist_domain, 0, 8)=='sandbox2' || substr($ist_domain, 0, 8)=='sandbox3' )
$ist_domain = substr($ist_domain, 8 + 1 /*dot or minus*/ );
else
$ist_domain = substr($ist_domain, 7 + 1 /*dot or minus*/ );
$do_fwd = false;
}
else if( substr($ist_domain, -6)=='.local' ) // ... special domain needed for development
{
$ist_domain = str_replace('.local', '.info', $ist_domain);
$do_fwd = false;
}
else if( substr($_SERVER['REQUEST_URI'], 0, 5)=='/sync' ) // ... do not forward on sync as we may use special domains with more CPU-Time (as kursportal.domainfactory-kunde.de with 9 additional minutes CPU time)
{
$do_fwd = false;
}
// find all matching domains
$sql = "SELECT * FROM portale WHERE domains LIKE '%" . addslashes(str_replace('www.', '', $ist_domain)) . "%';";
$db->query($sql);
while( $db->next_record() )
{
// as the LIKE above may give us by far too many results, we have to inspect the result carefully
$domains = strtr($db->fs('domains'), ';,/*', ' '); // allow `:` for ports in domain names
$domains = explode(' ', $domains);
$first_domain = '';
for( $i = 0; $i < sizeof($domains); $i++ )
{
$domain = strtolower($domains[$i]);
if( $domain != '' )
{
if( $first_domain == '' )
{
$first_domain = $domain;
}
if( $domain==$first_domain && $domain==$ist_domain )
{
return; // success - $db contains a pointer to the current portal now
}
else if( str_replace('www.', '', $domain)==str_replace('www.', '', $ist_domain) )
{
if( $do_fwd )
fwd301("http://" . $first_domain . $_SERVER["REQUEST_URI"]);
else
return; // success - $db contains a pointer to the current portal now
}
}
}
}
// nothing found at all - go to fallback (domain containing an "*") or show an error
$sql = "SELECT * FROM portale WHERE domains LIKE '%*%';";
$db->query($sql);
if( $db->next_record() )
{
$domains = strtr($db->fs('domains'), ';,/*', ' '); // allow `:` for ports in domain names
$domains = explode(' ', $domains);
for( $i = 0; $i < sizeof($domains); $i++ )
{
$domain = strtolower($domains[$i]);
if( $domain != '' )
{
if( $do_fwd )
fwd301("http://" . $domain . $_SERVER["REQUEST_URI"]);
else
return; // success - $db contains a pointer to the current portal now
}
}
}
error404();
}
selectPortalOrFwd301();
$wisyPortalId = intval($db->f('id'));
$wisyPortalModified = $db->fs('date_modified');
$wisyPortalName = $db->fs('name');
$wisyPortalKurzname = $db->fs('kurzname');
$wisyPortalCSS = trim($db->fs('css'))==''? 0 : 1;
$wisyPortalBodyStart = stripslashes($db->f('bodystart'));
$wisyPortalEinstellungen = explodeSettings($db->fs('einstellungen'));
$wisyPortalFilter = explodeSettings($db->fs('filter'));
$wisyPortalEinstcache = explodeSettings($db->fs('einstcache'));
define('DEF_STICHWORT_BILDUNGSURLAUB', 1);
define('DEF_STICHWORTTYP_QZERTIFIKAT', 4);
/*******************************************************************************
Get the requested file
*******************************************************************************/
$wisyRequestedFile = 'index.php';
if( preg_match('#/([^/\?]+)#', $_SERVER['REQUEST_URI'], $temp) )
{
$wisyRequestedFile = $temp[1];
}
$wisyRequestedExt = '';
if( ($temp=strrpos($wisyRequestedFile, '.')) !== false )
{
$wisyRequestedExt = substr($wisyRequestedFile, $temp+1);
}
/*******************************************************************************
Find out the core to use
*******************************************************************************/
$wisyCore = 'core20';
if( strval($_GET['filecore']) != '' )
{
$wisyCore = 'core' . strval($_GET['filecore']);
}
else if( strval($_COOKIE['core']) != '' )
{
$wisyCore = 'core' . strval($_COOKIE['core']);
}
else if( strval($wisyPortalEinstellungen['core']) != '' )
{
$wisyCore = 'core' . strval($wisyPortalEinstellungen['core']);
}
/*******************************************************************************
Forward to the requested file
*******************************************************************************/
$wisyMiniMime = array(
'css' => 'text/css',
'gif' => 'image/gif',
'html' => 'text/html',
'ico' => 'image/x-icon',
'jpg' => 'image/jpeg',
'js' => 'application/javascript',
'php' => 'require_once',
'png' => 'image/png',
'txt' => 'text/plain',
);
if( @file_exists("$wisyCore/$wisyRequestedFile") )
{
$temp = $wisyMiniMime[$wisyRequestedExt];
if( $temp == 'require_once' )
{
require_once("$wisyCore/$wisyRequestedFile");
exit();
}
else if( $temp != '' )
{
header("Content-type: $temp");
header("Content-length: " . @filesize("$wisyCore/$wisyRequestedFile"));
headerDoCache();
readfile("$wisyCore/$wisyRequestedFile");
exit();
}
}
else if( @file_exists("$wisyCore/main.inc.php") )
{
require_once("$wisyCore/main.inc.php");
exit();
}
/*******************************************************************************
If we reach this part, we cannot handle the request -> 404
*******************************************************************************/
error404();