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