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