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