punbb/include/common.php
author Dan
Thu, 12 Jul 2007 01:04:01 -0400
changeset 2 a8a21e1c7afa
parent 0 f9ffdbd96607
child 3 c0c445d4a13e
permissions -rw-r--r--
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     1
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     2
/***********************************************************************
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     3
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     4
  Copyright (C) 2002-2005  Rickard Andersson (rickard@punbb.org)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     5
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     6
  This file is part of PunBB.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     7
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     8
  PunBB is free software; you can redistribute it and/or modify it
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     9
  under the terms of the GNU General Public License as published
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    10
  by the Free Software Foundation; either version 2 of the License,
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    11
  or (at your option) any later version.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    12
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    13
  PunBB is distributed in the hope that it will be useful, but
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    14
  WITHOUT ANY WARRANTY; without even the implied warranty of
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    15
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    16
  GNU General Public License for more details.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    17
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    18
  You should have received a copy of the GNU General Public License
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    19
  along with this program; if not, write to the Free Software
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    20
  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    21
  MA  02111-1307  USA
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    22
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    23
************************************************************************/
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    24
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    25
// Enable DEBUG mode by removing // from the following line
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    26
//define('PUN_DEBUG', 1);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    27
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    28
// This displays all executed queries in the page footer.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    29
// DO NOT enable this in a production environment!
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    30
//define('PUN_SHOW_QUERIES', 1);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    31
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    32
if (!defined('PUN_ROOT'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    33
	exit('The constant PUN_ROOT must be defined and point to a valid PunBB installation root directory.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    34
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    35
// Load the functions script
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    36
require PUN_ROOT.'include/functions.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    37
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    38
// Load the compatibility layer between Pun's DBAL and Enano's DBAL
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    39
require PUN_ROOT.'include/enano_dbal.php';
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    40
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    41
// Reverse the effect of register_globals
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    42
// unregister_globals(); // DISABLED for Enano
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    43
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    44
// If PUN isn't defined, config.php is missing or corrupt
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    45
if (!defined('PUN'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    46
	exit('The file \'config.php\' doesn\'t exist or is corrupt. Please run <a href="install.php">install.php</a> to install PunBB first.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    47
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    48
// Record the start time (will be used to calculate the generation time for the page)
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    49
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    50
function get_microtime()
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    51
{
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    52
  list($usec, $sec) = explode(' ', microtime());
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    53
  return ((float)$usec + (float)$sec);
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    54
}
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    55
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    56
$pun_start = get_microtime();
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    57
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    58
// Make sure PHP reports all errors except E_NOTICE. PunBB supports E_ALL, but a lot of scripts it may interact with, do not.
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    59
error_reporting(E_ALL);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    60
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    61
// Turn off magic_quotes_runtime
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    62
set_magic_quotes_runtime(0);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    63
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    64
/*
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    65
Disabled for Enano - this is already done by Enano's API
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    66
// Strip slashes from GET/POST/COOKIE (if magic_quotes_gpc is enabled)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    67
if (get_magic_quotes_gpc())
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    68
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    69
	function stripslashes_array($array)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    70
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    71
		return is_array($array) ? array_map('stripslashes_array', $array) : stripslashes($array);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    72
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    73
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    74
	$_GET = stripslashes_array($_GET);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    75
	$_POST = stripslashes_array($_POST);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    76
	$_COOKIE = stripslashes_array($_COOKIE);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    77
}
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    78
*/
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    79
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    80
// Seed the random number generator
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    81
mt_srand((double)microtime()*1000000);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    82
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    83
// If a cookie name is not specified in config.php, we use the default (punbb_cookie)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    84
if (empty($cookie_name))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    85
	$cookie_name = 'punbb_cookie';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    86
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    87
// Define a few commonly used constants
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    88
define('PUN_UNVERIFIED', 32000);
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    89
define('PUN_ADMIN', USER_LEVEL_ADMIN);
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    90
define('PUN_MOD', USER_LEVEL_MOD);
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    91
define('PUN_GUEST', USER_LEVEL_GUEST);
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    92
define('PUN_MEMBER', USER_LEVEL_MEMBER);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    93
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    94
/*
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    95
Skip this - Enano's API will handle it
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    96
// Load DB abstraction layer and connect
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    97
require PUN_ROOT.'include/dblayer/common_db.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    98
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    99
// Start a transaction
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   100
$pun_db->start_transaction();
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   101
*/
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   102
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   103
$GLOBALS['pun_db'] = new PunBB_DBAL_Enano();
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   104
$GLOBALS['pun_config'] = array();
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   105
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   106
$pun_config =& $GLOBALS['pun_config'];
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   107
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   108
// Load cached config
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   109
@include PUN_ROOT.'cache/cache_config.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   110
if (!defined('PUN_CONFIG_LOADED'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   111
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   112
	require PUN_ROOT.'include/cache.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   113
	generate_config_cache();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   114
	require PUN_ROOT.'cache/cache_config.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   115
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   116
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   117
// Enable output buffering
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   118
if (!defined('PUN_DISABLE_BUFFERING'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   119
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   120
	// For some very odd reason, "Norton Internet Security" unsets this
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   121
	$_SERVER['HTTP_ACCEPT_ENCODING'] = isset($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : '';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   122
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   123
	// Should we use gzip output compression?
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   124
	if ($pun_config['o_gzip'] && extension_loaded('zlib') && (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false || strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') !== false))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   125
		ob_start('ob_gzhandler');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   126
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   127
		ob_start();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   128
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   129
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   130
// Check/update/set cookie and fetch user info
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   131
$GLOBALS['pun_user'] = array();
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   132
$pun_user =& $GLOBALS['pun_user'];
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   133
check_cookie($pun_user);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   134
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   135
// Attempt to load the common language file
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   136
@include PUN_ROOT.'lang/'.$pun_user['language'].'/common.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   137
if (!isset($lang_common))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   138
	exit('There is no valid language pack \''.pun_htmlspecialchars($pun_user['language']).'\' installed. Please reinstall a language of that name.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   139
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   140
// Check if we are to display a maintenance message
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   141
if ($pun_config['o_maintenance'] && $pun_user['g_id'] < PUN_ADMIN && !defined('PUN_TURN_OFF_MAINT'))
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   142
	maintenance_message();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   143
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   144
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   145
// Load cached bans
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   146
/*
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   147
// // DISABLED IN ENANO // //
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   148
// Enano has its own ban list //
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   149
@include PUN_ROOT.'cache/cache_bans.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   150
if (!defined('PUN_BANS_LOADED'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   151
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   152
	require_once PUN_ROOT.'include/cache.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   153
	generate_bans_cache();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   154
	require PUN_ROOT.'cache/cache_bans.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   155
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   156
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   157
// Check if current user is banned
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   158
check_bans();
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   159
*/
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   160
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   161
// Update online list
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   162
update_users_online();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   163