Small update to user online list.
[iDB.git] / sql.php
blob33d1999f4d240e835182524e729b75ac1ef04f8d
1 <?php
2 /*
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the Revised BSD License.
6 This program is distributed in the hope that it will be useful,
7 but WITHOUT ANY WARRANTY; without even the implied warranty of
8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 Revised BSD License for more details.
11 Copyright 2004-2011 iDB Support - http://idb.berlios.de/
12 Copyright 2004-2011 Game Maker 2k - http://gamemaker2k.org/
14 $FileInfo: sql.php - Last Update: 06/18/2011 SVN 677 - Author: cooldude2k $
16 /* Some ini setting changes uncomment if you need them.
17 Display PHP Errors */
18 $disfunc = @ini_get("disable_functions");
19 if($disfunc!="ini_set") { $disfunc = explode(",",$disfunc); }
20 if($disfunc=="ini_set") { $disfunc = array("ini_set"); }
21 if(!in_array("ini_set", $disfunc)) {
22 // Uncomment next few lines to show errors
23 /*@ini_set("track_errors", true);
24 @ini_set("display_errors", true);
25 @ini_set("display_startup_errors", true); */ }
26 @error_reporting(E_ALL ^ E_NOTICE);
27 /* Get rid of session id in urls */
28 if(!in_array("ini_set", $disfunc)) {
29 @ini_set("session.use_trans_sid", false);
30 @ini_set("session.use_cookies", true);
31 @ini_set("session.use_only_cookies", true);
32 @ini_set("url_rewriter.tags","");
33 ini_set('zend.ze1_compatibility_mode', 0);
34 @ini_set("ignore_user_abort", 1); }
35 @set_time_limit(30); @ignore_user_abort(true);
36 /* Change session garbage collection settings */
37 if(!in_array("ini_set", $disfunc)) {
38 @ini_set("session.gc_probability", 1);
39 @ini_set("session.gc_divisor", 100);
40 @ini_set("session.gc_maxlifetime", 1440);
41 /* Change session hash type here */
42 @ini_set("session.hash_function", 1);
43 @ini_set("session.hash_bits_per_character", 6); }
44 /* Do not change anything below this line unless you know what you are doing */
45 $File3Name = basename($_SERVER['SCRIPT_NAME']);
46 if ($File3Name=="sql.php"||$File3Name=="/sql.php") {
47 header('Location: index.php');
48 exit(); }
49 if(file_exists('settings.php')) {
50 require_once('settings.php');
51 if(!in_array("ini_set", $disfunc)&&$Settings['qstr']!="/"&&$Settings['qstr']!="&") {
52 ini_set("arg_separator.output",htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']));
53 ini_set("arg_separator.input",$Settings['qstr']); } }
54 if(!isset($Settings['idburl'])) { $Settings['idburl'] = null; }
55 if(!isset($Settings['fixbasedir'])) { $Settings['fixbasedir'] = null; }
56 if(!isset($Settings['fixpathinfo'])) { $Settings['fixpathinfo'] = null; }
57 if(!isset($Settings['fixcookiedir'])) { $Settings['fixcookiedir'] = null; }
58 if(!isset($Settings['fixredirectdir'])) { $Settings['fixcookiedir'] = null; }
59 $Settings['bid'] = base64_encode(urlencode($Settings['idburl']));
60 if(!isset($Settings['showverinfo'])) {
61 $Settings['showverinfo'] = "on"; }
62 if($Settings['fixpathinfo']=="off") {
63 $Settings['fixpathinfo'] = null; }
64 if($Settings['fixbasedir']=="off") {
65 $Settings['fixbasedir'] = null; }
66 if($Settings['fixcookiedir']=="off") {
67 $Settings['fixcookiedir'] = null; }
68 if($Settings['fixredirectdir']=="off") {
69 $Settings['fixredirectdir'] = null; }
70 $OldSettings['fixpathinfo'] = $Settings['fixpathinfo'];
71 $OldSettings['fixbasedir'] = $Settings['fixbasedir'];
72 $OldSettings['fixcookiedir'] = $Settings['fixcookiedir'];
73 $OldSettings['fixredirectdir'] = $Settings['fixredirectdir'];
74 if($Settings['idburl']=="localhost") {
75 header("Content-Type: text/plain; charset=UTF-8");
76 echo "500 Error: URL is malformed. Try reinstalling iDB."; die(); }
77 if($Settings['fixbasedir']=="on") {
78 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
79 $PathsTest = parse_url($Settings['idburl']);
80 $Settings['fixbasedir'] = $PathsTest['path']."/";
81 $Settings['fixbasedir'] = str_replace("//", "/", $Settings['fixbasedir']); } }
82 if($Settings['fixcookiedir']=="on") {
83 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
84 $PathsTest = parse_url($Settings['idburl']);
85 $Settings['fixcookiedir'] = $PathsTest['path']."/";
86 $Settings['fixcookiedir'] = str_replace("//", "/", $Settings['fixcookiedir']); } }
87 if($Settings['fixredirectdir']=="on") {
88 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
89 $PathsTest = parse_url($Settings['idburl']);
90 $Settings['fixredirectdir'] = $PathsTest['path']."/";
91 $Settings['fixredirectdir'] = str_replace("//", "/", $Settings['fixredirectdir']); } }
92 if(!isset($Settings['charset'])) {
93 $Settings['charset'] = "ISO-8859-15"; }
94 if(isset($Settings['charset'])) {
95 if($Settings['charset']!="ISO-8859-15"&&$Settings['charset']!="ISO-8859-1"&&
96 $Settings['charset']!="UTF-8"&&$Settings['charset']!="CP866"&&
97 $Settings['charset']!="Windows-1251"&&$Settings['charset']!="Windows-1252"&&
98 $Settings['charset']!="KOI8-R"&&$Settings['charset']!="BIG5"&&
99 $Settings['charset']!="GB2312"&&$Settings['charset']!="BIG5-HKSCS"&&
100 $Settings['charset']!="Shift_JIS"&&$Settings['charset']!="EUC-JP") {
101 $Settings['charset'] = "ISO-8859-15"; } }
102 $chkcharset = $Settings['charset'];
103 @ini_set('default_charset', $Settings['charset']);
104 //session_save_path($SettDir['inc']."temp/");
105 if(!isset($Settings['sqldb'])) {
106 if(file_exists("install.php")) { header('Location: install.php'); die(); }
107 if(!file_exists("install.php")) { header("Content-Type: text/plain; charset=UTF-8");
108 echo "403 Error: Sorry could not find install.php\nTry uploading files again and if that dose not work try download iDB again."; die(); } }
109 if(isset($Settings['sqldb'])&&
110 function_exists("date_default_timezone_set")) {
111 @date_default_timezone_set("UTC"); }
112 if(!isset($Settings['sqlhost'])) { $Settings['sqlhost'] = "localhost"; }
113 if($Settings['fixpathinfo']=="on") {
114 $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
115 putenv("PATH_INFO=".$_SERVER['ORIG_PATH_INFO']); }
116 // Check to see if variables are set
117 if(!isset($SettDir['inc'])) { $SettDir['inc'] = "inc/"; }
118 if(!isset($SettDir['archive'])) { $SettDir['archive'] = "archive/"; }
119 if(!isset($SettDir['misc'])) { $SettDir['misc'] = "inc/misc/"; }
120 if(!isset($SettDir['sql'])) { $SettDir['sql'] = "inc/misc/sql/"; }
121 if(!isset($SettDir['admin'])) { $SettDir['admin'] = "inc/admin/"; }
122 if(!isset($SettDir['sqldumper'])) { $SettDir['sqldumper'] = "inc/admin/sqldumper/"; }
123 if(!isset($SettDir['mod'])) { $SettDir['mod'] = "inc/mod/"; }
124 if(!isset($SettDir['themes'])) { $SettDir['themes'] = "themes/"; }
125 if(!isset($Settings['use_iniset'])) { $Settings['use_iniset'] = null; }
126 if(!isset($Settings['clean_ob'])) { $Settings['clean_ob'] = "off"; }
127 if(!isset($_SERVER['PATH_INFO'])) { $_SERVER['PATH_INFO'] = null; }
128 if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
129 $_SERVER['HTTP_ACCEPT_ENCODING'] = null; }
130 if(!isset($_SERVER["HTTP_ACCEPT"])) { $_SERVER["HTTP_ACCEPT"] = null; }
131 if(!isset($_SERVER['HTTP_REFERER'])) { $_SERVER['HTTP_REFERER'] = null; }
132 if(!isset($_GET['page'])) { $_GET['page'] = null; }
133 if(!isset($_GET['act'])) { $_GET['act'] = null; }
134 if(!isset($_POST['act'])) { $_POST['act'] = null; }
135 if(!isset($_GET['modact'])) { $_GET['modact'] = null; }
136 if(!isset($_POST['modact'])) { $_POST['modact'] = null; }
137 if(!isset($_GET['id'])) { $_GET['id'] = null; }
138 if(!isset($_GET['debug'])) { $_GET['debug'] = "off"; }
139 if(!isset($_GET['post'])) { $_GET['post'] = null; }
140 if(!isset($_POST['License'])) { $_POST['License'] = null; }
141 if(!isset($_SERVER['HTTPS'])) { $_SERVER['HTTPS'] = "off"; }
142 if(!isset($Settings['SQLThemes'])) { $Settings['SQLThemes'] = "off"; }
143 if($Settings['SQLThemes']!="on"&&$Settings['SQLThemes']!="off") {
144 $Settings['SQLThemes'] = "off"; }
145 require_once($SettDir['misc'].'utf8.php');
146 require_once($SettDir['inc'].'filename.php');
147 if(!isset($Settings['use_hashtype'])) {
148 $Settings['use_hashtype'] = "sha1"; }
149 if(!function_exists('hash')||!function_exists('hash_algos')) {
150 if($Settings['use_hashtype']!="md5"&&
151 $Settings['use_hashtype']!="sha1") {
152 $Settings['use_hashtype'] = "sha1"; } }
153 if(function_exists('hash')&&function_exists('hash_algos')) {
154 if(!in_array($Settings['use_hashtype'],hash_algos())) {
155 $Settings['use_hashtype'] = "sha1"; }
156 if($Settings['use_hashtype']!="md2"&&
157 $Settings['use_hashtype']!="md4"&&
158 $Settings['use_hashtype']!="md5"&&
159 $Settings['use_hashtype']!="sha1"&&
160 $Settings['use_hashtype']!="sha224"&&
161 $Settings['use_hashtype']!="sha256"&&
162 $Settings['use_hashtype']!="sha384"&&
163 $Settings['use_hashtype']!="sha512"&&
164 $Settings['use_hashtype']!="ripemd128"&&
165 $Settings['use_hashtype']!="ripemd160"&&
166 $Settings['use_hashtype']!="ripemd256"&&
167 $Settings['use_hashtype']!="ripemd320"&&
168 $Settings['use_hashtype']!="salsa10"&&
169 $Settings['use_hashtype']!="salsa20"&&
170 $Settings['use_hashtype']!="snefru"&&
171 $Settings['use_hashtype']!="snefru256"&&
172 $Settings['use_hashtype']!="gost") {
173 $Settings['use_hashtype'] = "sha1"; } }
174 // Check to see if variables are set
175 require_once($SettDir['misc'].'setcheck.php');
176 $dayconv = array('second' => 1, 'minute' => 60, 'hour' => 3600, 'day' => 86400, 'week' => 604800, 'month' => 2630880, 'year' => 31570560, 'decade' => 315705600);
177 require_once($SettDir['inc'].'function.php');
178 $iDBVerName = "iDB|".$VER2[1]."|".$VER1[0].".".$VER1[1].".".$VER1[2]."|".$VER2[2]."|".$SubVerN;
180 This way checks iDB version by sending the iDBVerName to the iDB Version Checker.
181 $Settings['vercheck'] = 1;
182 This way checks iDB version by sending the board url to the iDB Version Checker.
183 $Settings['vercheck'] = 2;
185 if(!isset($Settings['vercheck'])) {
186 $Settings['vercheck'] = 2; }
187 if($Settings['vercheck']!=1&&
188 $Settings['vercheck']!=2) {
189 $Settings['vercheck'] = 2; }
190 if($Settings['vercheck']===2) {
191 if($_GET['act']=="vercheckxsl") {
192 if(stristr($_SERVER["HTTP_ACCEPT"],"application/xml") ) {
193 header("Content-Type: application/xml; charset=".$Settings['charset']); }
194 else { header("Content-Type: text/xml; charset=".$Settings['charset']); }
195 xml_doc_start("1.0",$Settings['charset']);
196 echo "\n"; ?>
197 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
199 <xsl:template match="/">
200 <html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
201 <body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
202 <xsl:for-each select="versioninfo/version">
203 <div style="background-color:teal;color:white;padding:4px">
204 <span style="font-weight:bold"><xsl:value-of select="vname"/></span>
205 </div>
206 <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
207 <span style="font-style:italic">
208 Board Name: <a href="<?php echo url_maker($exfile['index'],$Settings['file_ext'],"act=view",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index']); ?>"><xsl:value-of select="title"/></a></span>
209 </div>
210 </xsl:for-each>
211 </body>
212 </html>
213 </xsl:template>
215 </xsl:stylesheet>
216 <?php gzip_page("off",$GZipEncode['Type']); session_write_close(); die(); }
217 if($_GET['act']=="versioninfo") {
218 if(stristr($_SERVER["HTTP_ACCEPT"],"application/xml") ) {
219 header("Content-Type: application/xml; charset=".$Settings['charset']); }
220 else { header("Content-Type: text/xml; charset=".$Settings['charset']); }
221 xml_doc_start("1.0",$Settings['charset']);
222 echo '<?xml-stylesheet type="text/xsl" href="'.url_maker($exfile['index'],$Settings['file_ext'],"act=vercheckxsl",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index']).'"?>'."\n"; ?>
224 <!DOCTYPE versioninfo [
225 <!ELEMENT versioninfo (version*)>
226 <!ELEMENT version (charset,title,name,vname)>
227 <!ELEMENT charset (#PCDATA)>
228 <!ELEMENT title (#PCDATA)>
229 <!ELEMENT name (#PCDATA)>
230 <!ELEMENT vname (#PCDATA)>
233 <versioninfo>
235 <version>
236 <charset><?php echo $Settings['charset']; ?></charset>
237 <title><?php echo $Settings['board_name']; ?></title>
238 <?php echo "<name>".$iDBVerName."</name>\n"; ?>
239 <vname>iDB Version Checker</vname>
240 </version>
242 </versioninfo>
243 <?php gzip_page("off",$GZipEncode['Type']); session_write_close(); die(); } }
244 if($Settings['vercheck']===1) {
245 if($_GET['act']=="versioninfo") { header("Content-Type: text/plain; charset=UTF-8");
246 header("Location: ".$VerCheckURL."&name=".urlencode($iDBVerName)); $urlstatus = 302;
247 gzip_page("off",$GZipEncode['Type']); session_write_close(); die(); } }
248 if($_GET['act']=="homepage") { header("Content-Type: text/plain; charset=UTF-8");
249 header("Location: ".$Settings['weburl']); $urlstatus = 302;
250 gzip_page("off",$GZipEncode['Type']); session_write_close(); die(); }
251 if($Settings['enable_pathinfo']=="on") {
252 mrstring(); /* Change Path info to Get Vars :P */ }
253 // Check to see if variables are set
254 $qstrhtml = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
255 if($Settings['enable_https']=="on"&&$_SERVER['HTTPS']=="on") {
256 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
257 $HTTPsTest = parse_url($Settings['idburl']); if($HTTPsTest['scheme']=="http") {
258 $Settings['idburl'] = preg_replace("/http\:\/\//i", "https://", $Settings['idburl']); } } }
259 $cookieDomain = null; $cookieSecure = false;
260 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
261 $URLsTest = parse_url($Settings['idburl']);
262 $cookieDomain = $URLsTest['host'];
263 if($cookieDomain=="localhost") { $cookieDomain = false; }
264 if($Settings['enable_https']=="on") {
265 if($URLsTest['scheme']=="https") { $cookieSecure = true; }
266 if($URLsTest['scheme']!="https") { $cookieSecure = false; } } }
267 @ini_set("default_charset",$Settings['charset']);
268 $File1Name = dirname($_SERVER['SCRIPT_NAME'])."/";
269 $File2Name = $_SERVER['SCRIPT_NAME'];
270 $File3Name=str_replace($File1Name, null, $File2Name);
271 if ($File3Name=="sql.php"||$File3Name=="/sql.php") {
272 header('Location: index.php');
273 exit(); }
274 //error_reporting(E_ERROR);
275 // Check if gzip is on and if user's browser can accept gzip pages
276 if($_GET['act']=="MkCaptcha"||$_GET['act']=="Captcha") {
277 $Settings['use_gzip'] = 'off'; }
278 if($Settings['use_gzip']=="on") {
279 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "gzip")) {
280 $GZipEncode['Type'] = "gzip"; } else {
281 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "deflate")) {
282 $GZipEncode['Type'] = "deflate"; } else {
283 $Settings['use_gzip'] = "off"; $GZipEncode['Type'] = "none"; } } }
284 if($Settings['use_gzip']=="gzip") {
285 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "gzip")) { $Settings['use_gzip'] = "on";
286 $GZipEncode['Type'] = "gzip"; } else { $Settings['use_gzip'] = "off"; } }
287 if($Settings['use_gzip']=="deflate") {
288 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "deflate")) { $Settings['use_gzip'] = "on";
289 $GZipEncode['Type'] = "deflate"; } else { $Settings['use_gzip'] = "off"; } }
290 if($Settings['clean_ob']=="on") {
291 /* Check for other output handlers/buffers are open
292 and close and get the contents in an array */
293 $numob = count(ob_list_handlers()); $iob = 0;
294 while ($iob < $numob) {
295 $old_ob_var[$iob] = ob_get_clean();
296 ++$iob; } } ob_start();
297 if($Settings['use_gzip']=="on") {
298 if($GZipEncode['Type']!="gzip") { if($GZipEncode['Type']!="deflate") { $GZipEncode['Type'] = "gzip"; } }
299 if($GZipEncode['Type']=="gzip") {
300 header("Content-Encoding: gzip"); }
301 if($GZipEncode['Type']=="deflate") {
302 header("Content-Encoding: deflate"); } }
303 /* if(eregi("msie",$browser) && !eregi("opera",$browser)){
304 header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"'); } */
305 // Some http stuff
306 $SQLStat = sql_connect_db($Settings['sqlhost'],$Settings['sqluser'],$Settings['sqlpass'],$Settings['sqldb']);
307 if(isset($Settings['sql_collate'])&&!isset($Settings['sql_charset'])) {
308 if($Settings['sql_collate']=="ascii_bin"||
309 $Settings['sql_collate']=="ascii_generel_ci") {
310 $Settings['sql_charset'] = "ascii"; }
311 if($Settings['sql_collate']=="latin1_bin"||
312 $Settings['sql_collate']=="latin1_general_ci"||
313 $Settings['sql_collate']=="latin1_general_cs") {
314 $Settings['sql_charset'] = "latin1"; }
315 if($Settings['sql_collate']=="utf8_bin"||
316 $Settings['sql_collate']=="utf8_general_ci"||
317 $Settings['sql_collate']=="utf8_unicode_ci") {
318 $Settings['sql_charset'] = "utf8"; } }
319 if(isset($Settings['sql_collate'])&&isset($Settings['sql_charset'])) {
320 if($Settings['sql_charset']=="ascii") {
321 if($Settings['sql_collate']!="ascii_bin"&&
322 $Settings['sql_collate']!="ascii_generel_ci") {
323 $Settings['sql_collate'] = "ascii_generel_ci"; } }
324 if($Settings['sql_charset']=="latin1") {
325 if($Settings['sql_collate']!="latin1_bin"&&
326 $Settings['sql_collate']!="latin1_general_ci"&&
327 $Settings['sql_collate']!="latin1_general_cs") {
328 $Settings['sql_collate'] = "latin1_general_ci"; } }
329 if($Settings['sql_charset']=="utf8") {
330 if($Settings['sql_collate']!="utf8_bin"&&
331 $Settings['sql_collate']!="utf8_general_ci"&&
332 $Settings['sql_collate']!="utf8_unicode_ci") {
333 $Settings['sql_collate'] = "utf8_unicode_ci"; } }
334 $SQLCollate = $Settings['sql_collate'];
335 $SQLCharset = $Settings['sql_charset']; }
336 if(!isset($Settings['sql_collate'])||!isset($Settings['sql_charset'])) {
337 $SQLCollate = "latin1_general_ci";
338 $SQLCharset = "latin1";
339 if($Settings['charset']=="ISO-8859-1") {
340 $SQLCollate = "latin1_general_ci";
341 $SQLCharset = "latin1"; }
342 if($Settings['charset']=="ISO-8859-15") {
343 $SQLCollate = "latin1_general_ci";
344 $SQLCharset = "latin1"; }
345 if($Settings['charset']=="UTF-8") {
346 $SQLCollate = "utf8_unicode_ci";
347 $SQLCharset = "utf8"; }
348 $Settings['sql_collate'] = $SQLCollate;
349 $Settings['sql_charset'] = $SQLCharset; }
350 sql_set_charset($SQLCharset,$SQLStat);
351 if($SQLStat===false) {
352 header("Content-Type: text/plain; charset=".$Settings['charset']); sql_free_result($peresult);
353 ob_clean(); echo "Sorry could not connect to mysql database.\nContact the board admin about error. Error log below.";
354 echo "\n".sql_errorno($SQLStat); $urlstatus = 503;
355 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
356 $sqltable = $Settings['sqltable'];
357 $temp_user_ip = $_SERVER['REMOTE_ADDR'];
358 if(!isset($_SERVER['HTTP_USER_AGENT'])) {
359 $_SERVER['HTTP_USER_AGENT'] = ""; }
360 if(strpos($_SERVER['HTTP_USER_AGENT'], "msie") &&
361 !strpos($_SERVER['HTTP_USER_AGENT'], "opera")){
362 header("X-UA-Compatible: IE=Edge"); }
363 if(strpos($_SERVER['HTTP_USER_AGENT'], "chromeframe")) {
364 header("X-UA-Compatible: IE=Edge,chrome=1"); }
365 $temp_user_agent = $_SERVER['HTTP_USER_AGENT'];
366 if($Settings['file_ext']!="no+ext"&&$Settings['file_ext']!="no ext") {
367 $MkIndexFile = $exfile['index'].$Settings['file_ext']; }
368 if($Settings['file_ext']=="no+ext"||$Settings['file_ext']=="no ext") {
369 $MkIndexFile = $exfile['index']; }
370 $temp_session_data = "ViewingPage|s:9:\"?act=view\";ViewingFile|s:".strlen($MkIndexFile).":\"".$MkIndexFile."\";PreViewingTitle|s:7:\"Viewing\";ViewingTitle|s:11:\"Board index\";UserID|s:1:\"0\";UserIP|s:".strlen($_SERVER['REMOTE_ADDR']).":\"".$_SERVER['REMOTE_ADDR']."\";UserGroup|s:".strlen($Settings['GuestGroup']).":\"".$Settings['GuestGroup']."\";UserGroupID|s:1:\"4\";UserTimeZone|s:".strlen($Settings['DefaultTimeZone']).":\"".$Settings['DefaultTimeZone']."\";UserDST|s:".strlen($Settings['DefaultDST']).":\"".$Settings['DefaultDST']."\";";
371 $SQLSType = $Settings['sqltype'];
372 //Session Open Function
373 function sql_session_open($save_path, $session_name ) {
374 global $sess_save_path;
375 $sess_save_path = $save_path;
376 return true; }
377 //Session Close Function
378 function sql_session_close() {
379 return true; }
380 //Session Read Function
381 function sql_session_read($id) {
382 global $sqltable,$SQLStat,$SQLSType,$temp_user_ip,$temp_user_agent,$temp_session_data;
383 $result = sql_query(sql_pre_query("SELECT * FROM \"".$sqltable."sessions\" WHERE \"session_id\" = '%s'", array($id)),$SQLStat);
384 if (!sql_num_rows($result)) {
385 sql_query(sql_pre_query("DELETE FROM \"".$sqltable."sessions\" WHERE \"session_id\"<>'%s' AND \"ip_address\"='%s'", array($id,$temp_user_ip)),$SQLStat);
386 $time = GMTimeStamp();
387 sql_query(sql_pre_query("INSERT INTO \"".$sqltable."sessions\" (\"session_id\", \"session_data\", \"user_agent\", \"ip_address\", \"expires\") VALUES\n".
388 "('%s', '%s', '%s', '%s', %i)", array($id,$temp_session_data,$temp_user_agent,$temp_user_ip,$time)),$SQLStat);
389 return '';
390 } else {
391 $time = GMTimeStamp();
392 $predata = sql_num_rows($result);
393 $data = "";
394 if($predata > 0) {
395 $row = sql_fetch_assoc($result);
396 $data = $row['session_data']; }
397 /*sql_query(sql_pre_query("UPDATE \"".$sqltable."sessions\" SET \"session_data\"='%s',\"expires\"=%i WHERE \"session_id\"='%s'", array($data,$time,$id)),$SQLStat);*/
398 return $data; } }
399 //Session Write Function
400 function sql_session_write($id,$data) {
401 global $sqltable,$SQLStat,$SQLSType,$temp_user_ip,$temp_user_agent;
402 $time = GMTimeStamp();
403 $rs = sql_query(sql_pre_query("UPDATE \"".$sqltable."sessions\" SET \"session_data\"='%s',\"user_agent\"='%s',\"ip_address\"='%s',\"expires\"=%i WHERE \"session_id\"='%s'", array($data,$temp_user_agent,$temp_user_ip,$time,$id)),$SQLStat);
404 return true; }
405 //Session Destroy Function
406 function sql_session_destroy($id) {
407 global $sqltable,$SQLStat;
408 sql_query(sql_pre_query("DELETE FROM \"".$sqltable."sessions\" WHERE \"session_id\" = '$id'", array($id)),$SQLStat);
409 return true; }
410 //Session Garbage Collection Function
411 function sql_session_gc($maxlifetime) {
412 global $sqltable,$SQLStat;
413 $time = GMTimeStamp() - $maxlifetime;
414 //sql_query(sql_pre_query('DELETE FROM \"'.$sqltable.'sessions\" WHERE \"expires\" < UNIX_TIMESTAMP();', array(null)),$SQLStat);
415 sql_query(sql_pre_query("DELETE FROM \"".$sqltable."sessions\" WHERE \"expires\" < %i", array($time)),$SQLStat);
416 return true; }
417 session_set_save_handler("sql_session_open", "sql_session_close", "sql_session_read", "sql_session_write", "sql_session_destroy", "sql_session_gc");
418 if($cookieDomain==null) {
419 session_set_cookie_params(0, $cbasedir); }
420 if($cookieDomain!=null) {
421 if($cookieSecure===true) {
422 session_set_cookie_params(0, $cbasedir, $cookieDomain, 1); }
423 if($cookieSecure===false) {
424 session_set_cookie_params(0, $cbasedir, $cookieDomain); } }
425 session_cache_limiter("private, no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0");
426 header("Cache-Control: private, no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0");
427 header("Pragma: private, no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0");
428 header("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");
429 header("Date: ".gmdate("D, d M Y H:i:s")." GMT");
430 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
431 header("Expires: ".gmdate("D, d M Y H:i:s")." GMT");
432 if(!isset($_COOKIE[$Settings['sqltable']."sess"])) {
433 $exptime = GMTimeStamp() - ini_get("session.gc_maxlifetime");
434 sql_query(sql_pre_query("DELETE FROM \"".$Settings['sqltable']."sessions\" WHERE \"expires\" < %i OR \"ip_address\"='%s'", array($exptime,$temp_user_ip)),$SQLStat); }
435 session_name($Settings['sqltable']."sess");
436 session_start();
437 //header("Set-Cookie: PHPSESSID=" . session_id() . "; path=".$cbasedir);
438 output_reset_rewrite_vars();
439 if($_GET['act']=="bsdl"||$_GET['act']=="BSDL"||$_GET['act']=="license"||
440 $_GET['act']=="LICENSE"||$_GET['act']=="License") { $_GET['act']="bsd"; }
441 if($_GET['act']=="bsd") {
442 header("Content-Type: text/plain; charset=".$Settings['charset']);
443 require("LICENSE"); gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
444 if($_GET['act']=="README"||$_GET['act']=="ReadME") { $_GET['act']="readme"; }
445 if($_GET['act']=="readme"||$_GET['act']=="ReadMe") {
446 header("Content-Type: text/plain; charset=".$Settings['charset']);
447 require("README"); gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
448 if($_GET['act']=="js"||$_GET['act']=="javascript") {
449 header("Content-Script-Type: text/javascript");
450 if(stristr($_SERVER["HTTP_ACCEPT"],"application/x-javascript") ) {
451 header("Content-Type: application/x-javascript; charset=".$Settings['charset']); } else {
452 if(stristr($_SERVER["HTTP_ACCEPT"],"application/javascript") ) {
453 header("Content-Type: application/javascript; charset=".$Settings['charset']); } else {
454 header("Content-Type: text/javascript; charset=".$Settings['charset']); } }
455 require($SettDir['inc'].'javascript.php');
456 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
457 if($Settings['use_captcha']=="on") {
458 if($_GET['act']=="MkCaptcha"||$_GET['act']=="Captcha") {
459 if($Settings['captcha_clean']=="on") { ob_clean(); }
460 require($SettDir['inc']."captcha.php");
461 $aFonts = array('inc/fonts/VeraBd.ttf', 'inc/fonts/VeraBI.ttf', 'inc/fonts/VeraIt.ttf', 'inc/fonts/Vera.ttf');
462 $oPhpCaptcha = new PhpCaptcha($aFonts, 200, 60);
463 $RNumSize = rand(7,17); $i=0; $RandNum = null;
464 while ($i <= $RNumSize) {
465 $RandNum=$RandNum.dechex(rand(1,15)); ++$i; }
466 $RandNum=strtoupper($RandNum);
467 $oPhpCaptcha->SetOwnerText("Fake Code: ".$RandNum);
468 $oPhpCaptcha->UseColour(true);
469 $oPhpCaptcha->Create(); session_write_close(); die(); } }
470 if(!isset($_SESSION['CheckCookie'])) {
471 if(isset($_COOKIE['SessPass'])&&isset($_COOKIE['MemberName'])) {
472 require($SettDir['inc'].'prelogin.php'); } }
473 require($SettDir['inc'].'groupsetup.php');
474 if($Settings['board_offline']=="on"&&$GroupInfo['CanViewOffLine']!="yes") {
475 header("Content-Type: text/plain; charset=".$Settings['charset']); sql_free_result($peresult);
476 ob_clean(); if(!isset($Settings['offline_text'])) {
477 echo "Sorry the board is off line.\nIf you are a admin you can login by the admin cp."; }
478 if(isset($Settings['offline_text'])) { echo $Settings['offline_text']; } $urlstatus = 503;
479 //echo "\n".sql_errorno($SQLStat);
480 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
481 //Time Zone Set
482 if(!isset($_SESSION['UserTimeZone'])) {
483 if(isset($Settings['DefaultTimeZone'])) {
484 $_SESSION['UserTimeZone'] = $Settings['DefaultTimeZone'];
485 if(!isset($Settings['DefaultTimeZone'])) {
486 $_SESSION['UserTimeZone'] = SeverOffSet().":00"; } } }
487 $checktime = explode(":",$_SESSION['UserTimeZone']);
488 if(count($checktime)!=2) {
489 if(!isset($checktime[0])) { $checktime[0] = "0"; }
490 if(!isset($checktime[1])) { $checktime[1] = "00"; }
491 $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
492 if(!is_numeric($checktime[0])) { $checktime[0] = "0"; }
493 if(!is_numeric($checktime[1])) { $checktime[1] = "00"; }
494 if($checktime[1]<0) { $checktime[1] = "00"; $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
495 $checktimea = array("offset" => $_SESSION['UserTimeZone'], "hour" => $checktime[0], "minute" => $checktime[1]);
496 if(!isset($_SESSION['UserDST'])) { $_SESSION['UserDST'] = null; }
497 if($_SESSION['UserDST']==null) {
498 if($Settings['DefaultDST']=="off") {
499 $_SESSION['UserDST'] = "off"; }
500 if($Settings['DefaultDST']=="on") {
501 $_SESSION['UserDST'] = "on"; } }
502 // Guest Stuff
503 if(isset($_SESSION['MemberName'])||
504 isset($_COOKIE['MemberName'])) {
505 $_SESSION['GuestName'] = null;
506 $_COOKIE['GuestName'] = null; }
507 if(!isset($_SESSION['MemberName'])&&!isset($_COOKIE['MemberName'])) {
508 if(!isset($_SESSION['GuestName'])&&isset($_COOKIE['GuestName'])) {
509 $_SESSION['GuestName'] = $_COOKIE['GuestName']; } }
510 if(!isset($_SESSION['LastPostTime'])) { $_SESSION['LastPostTime'] = "0"; }
511 // Skin Stuff
512 if(!isset($_SESSION['Theme'])) { $_SESSION['Theme'] = null; }
513 if(!isset($_GET['theme'])) { $_GET['theme'] = null; }
514 if(!isset($_POST['theme'])) { $_POST['theme'] = null; }
515 if(!isset($_GET['skin'])) { $_GET['skin'] = null; }
516 if(!isset($_POST['skin'])) { $_POST['skin'] = null; }
517 if(!isset($_GET['style'])) { $_GET['style'] = null; }
518 if(!isset($_POST['style'])) { $_POST['style'] = null; }
519 if(!isset($_GET['css'])) { $_GET['css'] = null; }
520 if(!isset($_POST['css'])) { $_POST['css'] = null; }
521 if($_GET['theme']==null) {
522 if($_POST['theme']!=null) {
523 $_GET['theme'] = $_POST['theme']; }
524 if($_POST['skin']!=null) {
525 $_GET['theme'] = $_POST['skin']; }
526 if($_POST['style']!=null) {
527 $_GET['theme'] = $_POST['style']; }
528 if($_POST['css']!=null) {
529 $_GET['theme'] = $_POST['css']; }
530 if($_GET['skin']!=null) {
531 $_GET['theme'] = $_GET['skin']; }
532 if($_GET['style']!=null) {
533 $_GET['theme'] = $_GET['style']; }
534 if($_GET['css']!=null) {
535 $_GET['theme'] = $_GET['css']; } }
536 if($Settings['SQLThemes']=="off") {
537 if($_GET['theme']!=null) {
538 $_GET['theme'] = chack_themes($_GET['theme']);
539 if($_GET['theme']=="../"||$_GET['theme']=="./") {
540 $_GET['theme']="iDB"; $_SESSION['Theme']="iDB"; }
541 if (file_exists($SettDir['themes'].$_GET['theme']."/settings.php")) {
542 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
543 $NewDay=GMTimeStamp();
544 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_GET['theme'],$NewDay,$_SESSION['UserID']));
545 sql_query($qnewskin,$SQLStat); }
546 /* The file Theme Exists */ }
547 else { $_GET['theme'] = $Settings['DefaultTheme'];
548 $_SESSION['Theme'] = $Settings['DefaultTheme'];
549 /* The file Theme Dose Not Exists */ } }
550 if($_GET['theme']==null) {
551 if($_SESSION['Theme']!=null) {
552 $OldTheme = $_SESSION['Theme'];
553 $_SESSION['Theme'] = chack_themes($_SESSION['Theme']);
554 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
555 if($OldTheme!=$_SESSION['Theme']) {
556 $NewDay=GMTimeStamp();
557 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_SESSION['Theme'],$NewDay,$_SESSION['UserID']));
558 sql_query($qnewskin,$SQLStat); } }
559 $_GET['theme']=$_SESSION['Theme']; }
560 if($_SESSION['Theme']==null) {
561 $_SESSION['Theme']=$Settings['DefaultTheme'];
562 $_GET['theme']=$Settings['DefaultTheme']; } }
563 $PreSkin['skindir1'] = $_SESSION['Theme'];
564 $PreSkin['skindir2'] = $SettDir['themes'].$_SESSION['Theme'];
565 require($SettDir['themes'].$_GET['theme']."/settings.php"); }
566 if($Settings['SQLThemes']=="on") {
567 if($_GET['theme']==null&&$_SESSION['Theme']==null) {
568 $_GET['theme'] = $Settings['DefaultTheme'];
569 $_SESSION['Theme'] = $Settings['DefaultTheme']; }
570 if($_GET['theme']!=null) {
571 $themequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_GET['theme'])); }
572 if($_GET['theme']==null) {
573 if($_SESSION['Theme']!=null) {
574 $themequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_SESSION['Theme'])); } }
575 $themeresult=sql_query($themequery,$SQLStat);
576 $themenum=sql_num_rows($themeresult);
577 if($themenum<=0) {
578 $_GET['theme'] = $Settings['DefaultTheme'];
579 $_SESSION['Theme'] = $Settings['DefaultTheme'];
580 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
581 $NewDay=GMTimeStamp();
582 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_SESSION['Theme'],$NewDay,$_SESSION['UserID']));
583 sql_query($qnewskin,$SQLStat); }
584 $themequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_GET['theme']));
585 $themeresult=sql_query($themequery,$SQLStat);
586 $themenum=sql_num_rows($themeresult); }
587 else {
588 if($_GET['theme']==null) {
589 if($_SESSION['Theme']!=null) {
590 $_GET['theme'] = $_SESSION['Theme']; } }
591 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
592 $NewDay=GMTimeStamp();
593 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_GET['theme'],$NewDay,$_SESSION['UserID']));
594 sql_query($qnewskin,$SQLStat); } }
595 require($SettDir['inc'].'sqlthemes.php');
596 sql_free_result($themeresult); }
597 $_SESSION['Theme'] = $_GET['theme'];
598 if(!isset($ThemeSet['TableStyle'])) {
599 $ThemeSet['TableStyle'] = "table"; }
600 if(isset($ThemeSet['TableStyle'])) {
601 if($ThemeSet['TableStyle']!="div"&&
602 $ThemeSet['TableStyle']!="table") {
603 $ThemeSet['TableStyle'] = "table"; } }
604 if(!isset($_SESSION['DBName'])) { $_SESSION['DBName'] = null; }
605 if($_SESSION['DBName']==null) {
606 $_SESSION['DBName'] = $Settings['sqldb']; }
607 if($_SESSION['DBName']!=null) {
608 if($_SESSION['DBName']!=$Settings['sqldb']) {
609 redirect("location",$rbasedir.url_maker($exfile['member'],$Settings['file_ext'],"act=logout",$Settings['qstr'],$Settings['qsep'],$prexqstr['member'],$exqstr['member'],false)); } }