]> scripts.mit.edu Git - autoinstalls/phpBB.git/blob - common.php
phpBB 2.0.19-scripts
[autoinstalls/phpBB.git] / common.php
1 <?php
2 /***************************************************************************
3  *                                common.php
4  *                            -------------------
5  *   begin                : Saturday, Feb 23, 2001
6  *   copyright            : (C) 2001 The phpBB Group
7  *   email                : support@phpbb.com
8  *
9  *   $Id: common.php,v 1.74.2.22 2005/12/30 09:51:01 acydburn Exp $
10  *
11  ***************************************************************************/
12
13 /***************************************************************************
14  *
15  *   This program is free software; you can redistribute it and/or modify
16  *   it under the terms of the GNU General Public License as published by
17  *   the Free Software Foundation; either version 2 of the License, or
18  *   (at your option) any later version.
19  *
20  ***************************************************************************/
21
22 if ( !defined('IN_PHPBB') )
23 {
24         die("Hacking attempt");
25 }
26
27 //
28 error_reporting  (E_ERROR | E_WARNING | E_PARSE); // This will NOT report uninitialized variables
29 set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
30
31 // The following code (unsetting globals)
32 // Thanks to Matt Kavanagh and Stefan Esser for providing feedback as well as patch files
33
34 // PHP5 with register_long_arrays off?
35 if (@phpversion() >= '5.0.0' && (!@ini_get('register_long_arrays') || @ini_get('register_long_arrays') == '0' || strtolower(@ini_get('register_long_arrays')) == 'off'))
36 {
37         $HTTP_POST_VARS = $_POST;
38         $HTTP_GET_VARS = $_GET;
39         $HTTP_SERVER_VARS = $_SERVER;
40         $HTTP_COOKIE_VARS = $_COOKIE;
41         $HTTP_ENV_VARS = $_ENV;
42         $HTTP_POST_FILES = $_FILES;
43
44         // _SESSION is the only superglobal which is conditionally set
45         if (isset($_SESSION))
46         {
47                 $HTTP_SESSION_VARS = $_SESSION;
48         }
49 }
50
51 // Protect against GLOBALS tricks
52 if (isset($HTTP_POST_VARS['GLOBALS']) || isset($HTTP_POST_FILES['GLOBALS']) || isset($HTTP_GET_VARS['GLOBALS']) || isset($HTTP_COOKIE_VARS['GLOBALS']))
53 {
54         die("Hacking attempt");
55 }
56
57 // Protect against HTTP_SESSION_VARS tricks
58 if (isset($HTTP_SESSION_VARS) && !is_array($HTTP_SESSION_VARS))
59 {
60         die("Hacking attempt");
61 }
62
63 if (@ini_get('register_globals') == '1' || strtolower(@ini_get('register_globals')) == 'on')
64 {
65         // PHP4+ path
66         $not_unset = array('HTTP_GET_VARS', 'HTTP_POST_VARS', 'HTTP_COOKIE_VARS', 'HTTP_SERVER_VARS', 'HTTP_SESSION_VARS', 'HTTP_ENV_VARS', 'HTTP_POST_FILES', 'phpEx', 'phpbb_root_path');
67
68         // Not only will array_merge give a warning if a parameter
69         // is not an array, it will actually fail. So we check if
70         // HTTP_SESSION_VARS has been initialised.
71         if (!isset($HTTP_SESSION_VARS) || !is_array($HTTP_SESSION_VARS))
72         {
73                 $HTTP_SESSION_VARS = array();
74         }
75
76         // Merge all into one extremely huge array; unset
77         // this later
78         $input = array_merge($HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS, $HTTP_SERVER_VARS, $HTTP_SESSION_VARS, $HTTP_ENV_VARS, $HTTP_POST_FILES);
79
80         unset($input['input']);
81         unset($input['not_unset']);
82
83         while (list($var,) = @each($input))
84         {
85                 if (!in_array($var, $not_unset))
86                 {
87                         unset($$var);
88                 }
89         }
90
91         unset($input);
92 }
93
94 //
95 // addslashes to vars if magic_quotes_gpc is off
96 // this is a security precaution to prevent someone
97 // trying to break out of a SQL statement.
98 //
99 if( !get_magic_quotes_gpc() )
100 {
101         if( is_array($HTTP_GET_VARS) )
102         {
103                 while( list($k, $v) = each($HTTP_GET_VARS) )
104                 {
105                         if( is_array($HTTP_GET_VARS[$k]) )
106                         {
107                                 while( list($k2, $v2) = each($HTTP_GET_VARS[$k]) )
108                                 {
109                                         $HTTP_GET_VARS[$k][$k2] = addslashes($v2);
110                                 }
111                                 @reset($HTTP_GET_VARS[$k]);
112                         }
113                         else
114                         {
115                                 $HTTP_GET_VARS[$k] = addslashes($v);
116                         }
117                 }
118                 @reset($HTTP_GET_VARS);
119         }
120
121         if( is_array($HTTP_POST_VARS) )
122         {
123                 while( list($k, $v) = each($HTTP_POST_VARS) )
124                 {
125                         if( is_array($HTTP_POST_VARS[$k]) )
126                         {
127                                 while( list($k2, $v2) = each($HTTP_POST_VARS[$k]) )
128                                 {
129                                         $HTTP_POST_VARS[$k][$k2] = addslashes($v2);
130                                 }
131                                 @reset($HTTP_POST_VARS[$k]);
132                         }
133                         else
134                         {
135                                 $HTTP_POST_VARS[$k] = addslashes($v);
136                         }
137                 }
138                 @reset($HTTP_POST_VARS);
139         }
140
141         if( is_array($HTTP_COOKIE_VARS) )
142         {
143                 while( list($k, $v) = each($HTTP_COOKIE_VARS) )
144                 {
145                         if( is_array($HTTP_COOKIE_VARS[$k]) )
146                         {
147                                 while( list($k2, $v2) = each($HTTP_COOKIE_VARS[$k]) )
148                                 {
149                                         $HTTP_COOKIE_VARS[$k][$k2] = addslashes($v2);
150                                 }
151                                 @reset($HTTP_COOKIE_VARS[$k]);
152                         }
153                         else
154                         {
155                                 $HTTP_COOKIE_VARS[$k] = addslashes($v);
156                         }
157                 }
158                 @reset($HTTP_COOKIE_VARS);
159         }
160 }
161
162 //
163 // Define some basic configuration arrays this also prevents
164 // malicious rewriting of language and otherarray values via
165 // URI params
166 //
167 $board_config = array();
168 $userdata = array();
169 $theme = array();
170 $images = array();
171 $lang = array();
172 $nav_links = array();
173 $gen_simple_header = FALSE;
174
175 include($phpbb_root_path . 'config.'.$phpEx);
176
177 if( !defined("PHPBB_INSTALLED") )
178 {
179         header('Location: ' . $phpbb_root_path . 'install/install.' . $phpEx);
180         exit;
181 }
182
183 include($phpbb_root_path . 'includes/constants.'.$phpEx);
184 include($phpbb_root_path . 'includes/template.'.$phpEx);
185 include($phpbb_root_path . 'includes/sessions.'.$phpEx);
186 include($phpbb_root_path . 'includes/auth.'.$phpEx);
187 include($phpbb_root_path . 'includes/functions.'.$phpEx);
188 include($phpbb_root_path . 'includes/db.'.$phpEx);
189
190 // We do not need this any longer, unset for safety purposes
191 unset($dbpasswd);
192
193 //
194 // Obtain and encode users IP
195 //
196 // I'm removing HTTP_X_FORWARDED_FOR ... this may well cause other problems such as
197 // private range IP's appearing instead of the guilty routable IP, tough, don't
198 // even bother complaining ... go scream and shout at the idiots out there who feel
199 // "clever" is doing harm rather than good ... karma is a great thing ... :)
200 //
201 $client_ip = ( !empty($HTTP_SERVER_VARS['REMOTE_ADDR']) ) ? $HTTP_SERVER_VARS['REMOTE_ADDR'] : ( ( !empty($HTTP_ENV_VARS['REMOTE_ADDR']) ) ? $HTTP_ENV_VARS['REMOTE_ADDR'] : getenv('REMOTE_ADDR') );
202 $user_ip = encode_ip($client_ip);
203
204 //
205 // Setup forum wide options, if this fails
206 // then we output a CRITICAL_ERROR since
207 // basic forum information is not available
208 //
209 $sql = "SELECT *
210         FROM " . CONFIG_TABLE;
211 if( !($result = $db->sql_query($sql)) )
212 {
213         message_die(CRITICAL_ERROR, "Could not query config information", "", __LINE__, __FILE__, $sql);
214 }
215
216 while ( $row = $db->sql_fetchrow($result) )
217 {
218         $board_config[$row['config_name']] = $row['config_value'];
219 }
220
221 if (file_exists('install') || file_exists('contrib'))
222 {
223         message_die(GENERAL_MESSAGE, 'Please_remove_install_contrib');
224 }
225
226 //
227 // Show 'Board is disabled' message if needed.
228 //
229 if( $board_config['board_disable'] && !defined("IN_ADMIN") && !defined("IN_LOGIN") )
230 {
231         message_die(GENERAL_MESSAGE, 'Board_disable', 'Information');
232 }
233
234 ?>