OSDN Git Service

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