fuxu
[specialops2.git] / con.php
blob2ff478da64c1b3a60b972c399758a72aa2ad66cf
1 <?php
2 // $Id$
4 if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false )
5 exit ('Error: Your browser is too outdated to view this site correctly. <a href="http://getfirefox.com">Upgrade your browser.</a>');
7 define('CLOCK', microtime(1));
8 define('SO2VER', '$Rev$');
9 define('DEFAULT_LANGUAGE', 'en_GB, en_GB.UTF-8');
12 // Empty exception types
13 class invalidInputException extends Exception { }
14 class databaseException extends Exception { }
15 class rateLimitException extends Exception { }
18 // These are useless
19 define('LVL_RESTRICTED', 0);
20 define('LVL_NEW', 10);
21 define('LVL_USER', 20);
22 define('LVL_VETERAN', 30);
23 define('LVL_VIP', 40);
24 define('LVL_MOD', 50);
25 define('LVL_ADMIN', 60);
26 define('LVL_DEV', 70);
29 // Some compatibility
30 if ( !function_exists('gettext') ) {
31 function _($message)
33 return $message;
35 function ngettext($msgid1, $msgid2, $n)
37 return 1 == $n ? $msgid1 : $msgid2;
39 define('NO_GETTEXT', 1);
40 } else {
41 bindtextdomain('so', './lang/locale');
42 textdomain('so');
46 //Class loader
47 function __autoload($classname)
49 require 'lib/class.'.$classname.'.php';
53 //Debug settings
54 if ( !isset($_SERVER['REMOTE_ADDR']) || $_SERVER['REMOTE_ADDR'] === $_SERVER['SERVER_ADDR'] || $_SERVER['REMOTE_ADDR'] === '84.24.205.182' )
55 define('DEVELOPER', 1);
58 //Exception handler
59 if ( defined('DEVELOPER') ) {
60 function e_handler($exception)
62 header('Content-Type: text/html; charset=UTF-8');
63 echo '<pre class="error">',$exception->__toString(),'</pre>';
64 exit;
66 } else {
67 function e_handler($exception)
69 restore_error_handler();
70 ini_set('display_errors', 0);
71 header('Content-Type: text/html; charset=UTF-8');
72 echo '<div class="error">',_('An unrecoverable error has been detected and page execution has been halted.'),"</div>\n",
73 '<div class="error">',_('Try reloading the page, or contact the site owner if this happens again.'),'</div>';
74 trigger_error($exception->getMessage(), E_USER_ERROR);
75 exit;
78 set_exception_handler('e_handler');
81 // Database Auth+object
82 require 'mysql_ident.php';
84 if ( defined('DEVELOPER') )
85 $DB = new debugmysqli($DB['host'], $DB['user'], $DB['pass'], $DB['db']);
86 else
87 $DB = new mysqli($DB['host'], $DB['user'], $DB['pass'], $DB['db']);
89 if ( mysqli_connect_errno() )
90 die('FUX');
93 // Login cookie setting hack
94 if ( isset($_POST['login'], $_POST['u'], $_POST['p']) ) {
95 list($_COOKIE['u'], $_COOKIE['p']) = array($_POST['u'], $_POST['p']);
99 // User Auth+object
100 if ( isset($_POST['logout']) ) {
102 setcookie('u', null, 1);
103 setcookie('p', null, 1);
104 unset($_COOKIE);
105 $user = new anonuser($DB);
107 } elseif ( isset($_COOKIE['u'], $_COOKIE['p']) ) {
109 $q = $DB->query('SELECT `userid` FROM `users`
110 WHERE `u_name` = \''.$DB->escape_string($_COOKIE['u']).'\'
111 AND `u_passwd` = AES_ENCRYPT(\''.$DB->escape_string($_COOKIE['p']).'\', `u_regip`)');
113 if ( 1 === $q->num_rows ) {
114 setcookie('u', $_COOKIE['u'], time()+86400*7);
115 setcookie('p', $_COOKIE['p'], time()+86400*7);
117 if ( isset($_POST['login']) )
118 $DB->query('UPDATE `users`
119 SET `u_lastloginip` = INET_ATON(\''.$_SERVER['REMOTE_ADDR'].'\')
120 WHERE `u_name` = \''.$DB->escape_string($_COOKIE['u']).'\'');
122 if ( empty($prefetch) )
123 $prefetch = array();
125 $user = new authuser($DB, $q->fetch_object()->userid, $prefetch);
126 } else {
127 setcookie('u', null, 1);
128 setcookie('p', null, 1);
129 $user = new anonuser($DB);
132 } else {
133 $user = new anonuser($DB);
137 // Page object
138 if ( defined('DEVELOPER') )
139 $page = new debugpage();
140 else
141 $page = new page();