-
Notifications
You must be signed in to change notification settings - Fork 114
/
header.php
executable file
·292 lines (235 loc) · 8.68 KB
/
header.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
<?php
/*
Copyright (C) 2004-2010 Kestas J. Kuliukas
This file is part of webDiplomacy.
webDiplomacy is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
webDiplomacy 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 Affero General Public License
along with webDiplomacy. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* The header file; sanitize, initialize, get everything set up quickly
*
* @package Base
*/
//$_SERVER['HTTP_CACHE_CONTROL'] = 'max-age=10000';
/*
function setExpires($expires) {
header('Expires: '.gmdate('D, d M Y H:i:s', time()+$expires).'GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s', time()-$expires).'GMT');
}
setExpires(600);
echo ( 'This page will self destruct in 10 seconds<br />' );
echo ( 'The GMT is now '.gmdate('H:i:s').'<br />' );
echo ( 'The GMT is now '.gmdate('H:i:s',time()).'<br />' );
echo ( '<a href="'.$_SERVER['PHP_SELF'].'">View Again</a><br />' );
die();*/
if( strpos($_SERVER['PHP_SELF'], 'header.php') )
{
die("You can't view this document by itself.");
}
if( !defined('IN_CODE') )
define('IN_CODE', 1); // A flag to tell scripts they aren't being executed by themselves
require_once('config.php');
require_once('global/definitions.php');
if( strlen(Config::$serverMessages['ServerOffline']) )
die('<html><head><title>Server offline</title></head>'.
'<body>'.Config::$serverMessages['ServerOffline'].'</body></html>');
require_once('objects/memcached.php');
if( ini_get('request_order') !== false ) {
// There is a request_order php.ini variable; this must be PHP 5.3.0+
/*
* This variable determines whether $_COOKIE is included in $_REQUEST;
* if request_order contains no 'c' then $_COOKIE is not included.
*
* $_COOKIE shouldn't be included in $_REQUEST, however since webDip
* has historically relied on it being there this code is here
* temporarily, while the improper $_REQUEST references are found and
* switched to $_COOKIE.
*/
if( substr_count(strtolower(ini_get('request_order')), 'c') == 0 ) {
/*
* No 'c' in request_order, so no $_COOKIE variables in $_REQUEST;
* $_COOKIE will need to be merged into $_REQUEST manually.
*
* The default config used to be GPC ($_GET, $_POST, $_COOKIE), so
* to get the standard behaviour $_COOKIE overwrites variables
* already in $_REQUEST.
*/
foreach($_COOKIE as $key=>$value)
{
$_REQUEST[$key] = $value;
// array_merge could be used here, but creating a new array
// for use as a super-global can have weird results.
}
}
}
/*
* If register_globals in enabled remove globals.
*/
if (ini_get('register_globals'))
{
function stripslashes_deep(&$value)
{
if ( is_array($value) )
return array_map('stripslashes_deep', $value);
else
return stripslashes($value);
}
$defined_vars = get_defined_vars();
while( list($var_name, $var_value) = each($defined_vars) )
{
switch( $var_name )
{
case "_COOKIE":
case "_POST":
case "_GET":
case "_REQUEST":
if (get_magic_quotes_gpc())
{
// Strip slashes if magic quotes added slashes
${$var_name} = stripslashes_deep(${$var_name});
}
break;
case "_SERVER":
break; // Don't strip slashes on _SERVER variables, slashes aren't added to these
case "_FILES":
break; // Don't strip slashes on _FILES (file uploads, currently only used for locale text lookup changes)
default:
unset( ${$var_name} ); // Remove register_globals variables
break;
}
}
unset($defined_vars);
}
// Support the legacy request variables
if ( isset($_REQUEST['gid']) ) $_REQUEST['gameID'] = $_REQUEST['gid'];
if ( isset($_REQUEST['uid']) ) $_REQUEST['userID'] = $_REQUEST['uid'];
// Reset globals
// FIXME: Resetting this means $GLOBALS['asdf'] is no longer kept in sync with global $asdf. This causes problems during construction
$GLOBALS = array();
$GLOBALS['scriptStartTime'] = microtime(true);
ini_set('memory_limit',"8M"); // 8M is the default
ini_set('max_execution_time','4');
//ini_set('session.cache_limiter','public');
ignore_user_abort(TRUE); // Carry on if the user exits before the script gets printed.
// This shouldn't be necessary for data integrity, but either way it may save reprocess time
ob_start(); // Buffer output. libHTML::footer() flushes.
// All the standard includes.
require_once('lib/cache.php');
require_once('lib/time.php');
require_once('lib/group.php');
require_once('lib/html.php');
require_once('locales/layer.php');
global $Locale;
require_once('locales/'.Config::$locale.'/layer.php'); // This will set $Locale
$Locale->initialize();
require_once(l_r('objects/silence.php'));
require_once(l_r('objects/user.php'));
require_once(l_r('objects/game.php'));
require_once(l_r('global/error.php'));
// Set up the error handler
date_default_timezone_set('UTC');
// Create database object
require_once(l_r('objects/database.php'));
$DB = new Database();
// Set up the misc values object
require_once(l_r('objects/misc.php'));
global $Misc;
$Misc = new Misc();
if ( $Misc->Version != VERSION )
{
require_once(l_r('install/install.php'));
}
// Taken from the php manual to disable cacheing.
header("Last-Modified: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("X-Frame-Options: SAMEORIGIN"); //@ibarrionuevo
if( defined('FACEBOOKSCRIPT') ) {
require_once(l_r('facebook/facebook-platform/php/facebook.php'));
$facebook=new Facebook(Config::$facebookAPIKey,Config::$facebookSecret);
$facebook->require_frame();
$fb_user=$facebook->get_loggedin_user();
if( !$fb_user ) {
if( !isset($_REQUEST['wD_FB_AuthNow'])) {
libHTML::notice(l_t('Not authorized'),l_t('To play in webDiplomacy games you need to authorize this application, so that '.
'it can send you notifications informing you when a game you\'re playing in needs your attention. '.
'Please <a href="index.php?wD_FB_AuthNow=on">authorize this application</a> to continue.'));
} else {
$fb_user=$facebook->require_login();
}
}
}
require_once(l_r('lib/auth.php'));
if( !defined('AJAX') )
{
if( isset($_REQUEST['logoff']) )
{
$success=libAuth::keyWipe();
$User = new User(GUESTID); // Give him a guest $User
header('refresh: 4; url=logon.php?noRefresh=on');
libHTML::notice(l_t("Logged out"),l_t("You have been logged out, and are being redirected to the logon page."));
}
global $User;
$User = libAuth::auth();
if ( $User->type['Admin'] )
{
Config::$debug=true;
if ( isset($_REQUEST['auid_cookie']) )
{
libAuth::keyWipe();
libAuth::keySet($_REQUEST['auid_cookie'], true);
die("Your cookie has been swapped for user ID " . $_REQUEST['auid_cookie'] . " <a href='.'>Refresh page as new user</a>");
}
if ( isset($_REQUEST['auid']) || isset($_SESSION['auid']) )
$User = libAuth::adminUserSwitch($User);
else
define('AdminUserSwitch',$User->id);
}
elseif ( $Misc->Maintenance )
{
list($contents) = $DB->sql_row("SELECT message FROM wD_Config WHERE name = 'Maintenance'");
unset($DB); // This lets libHTML know there's a problem
libHTML::error($contents);
}
}
if( Config::isOnPlayNowDomain() && !defined('PLAYNOW') )
{
// This is a play-now request, but we are not on a play-now page. Show the play-now
// intro page which gives a quick intro, lists any games the viewer is already in if
// they are logged on, and gives a link to allow the user to start up a game.
define('PLAYNOW',true);
libHTML::starthtml();
require_once(l_r('locales/English/playnowintro.php'));
print '</div>';
libHTML::footer();
}
if( isset($User) && $User->type['User'] )
{
// If we aren't currently looking at the group page check whether we need to redirect to a group panel:
if( false === strstr(strtolower($_SERVER['PHP_SELF']),'group') )
libGroup::redirectToGroup();
}
// This gets called by libHTML::footer
function close()
{
global $DB, $Misc;
// This isn't put into the database destructor in case of dieing due to an error
if ( is_object($DB) )
{
$Misc->write();
if( !defined('ERROR'))
$DB->sql_put("COMMIT");
unset($DB);
}
ob_end_flush();
die();
}
?>