OSDN Git Service

Added iWrapper (Like IPB Board Wrappers). :P
[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/30/2011 SVN 729 - 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 $iWrappers = array(null);
347 function idb_output_handler($buffer) { return $buffer; }
348 function idb_suboutput_handler($buffer) { return $buffer; }
349 if($Settings['clean_ob']=="on") {
350 /* Check for other output handlers/buffers are open
351    and close and get the contents in an array */
352 $numob = count(ob_list_handlers()); $iob = 0; 
353 while ($iob < $numob) { 
354         $old_ob_var[$iob] = ob_get_clean(); 
355         ++$iob; } } ob_start("idb_output_handler");
356 if($Settings['use_gzip']=="on") { 
357 if($GZipEncode['Type']!="gzip") { if($GZipEncode['Type']!="deflate") { $GZipEncode['Type'] = "gzip"; } }
358         if($GZipEncode['Type']=="gzip") {
359         header("Content-Encoding: gzip"); }
360         if($GZipEncode['Type']=="deflate") {
361         header("Content-Encoding: deflate"); } }
362 /* if(eregi("msie",$browser) && !eregi("opera",$browser)){
363 header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"'); } */
364 // Some http stuff
365 $SQLStat = sql_connect_db($Settings['sqlhost'],$Settings['sqluser'],$Settings['sqlpass'],$Settings['sqldb']);
366 if(isset($Settings['sql_collate'])&&!isset($Settings['sql_charset'])) {
367         if($Settings['sql_collate']=="ascii_bin"||
368                 $Settings['sql_collate']=="ascii_generel_ci") {
369                 $Settings['sql_charset'] = "ascii"; }
370         if($Settings['sql_collate']=="latin1_bin"||
371                 $Settings['sql_collate']=="latin1_general_ci"||
372                 $Settings['sql_collate']=="latin1_general_cs") {
373                 $Settings['sql_charset'] = "latin1"; }
374         if($Settings['sql_collate']=="utf8_bin"||
375                 $Settings['sql_collate']=="utf8_general_ci"||
376                 $Settings['sql_collate']=="utf8_unicode_ci") {
377                 $Settings['sql_charset'] = "utf8"; } }
378 if(isset($Settings['sql_collate'])&&isset($Settings['sql_charset'])) {
379         if($Settings['sql_charset']=="ascii") {
380         if($Settings['sql_collate']!="ascii_bin"&&
381                 $Settings['sql_collate']!="ascii_generel_ci") {
382                 $Settings['sql_collate'] = "ascii_generel_ci"; } }
383         if($Settings['sql_charset']=="latin1") {
384         if($Settings['sql_collate']!="latin1_bin"&&
385                 $Settings['sql_collate']!="latin1_general_ci"&&
386                 $Settings['sql_collate']!="latin1_general_cs") {
387                 $Settings['sql_collate'] = "latin1_general_ci"; } }
388         if($Settings['sql_charset']=="utf8") {
389         if($Settings['sql_collate']!="utf8_bin"&&
390                 $Settings['sql_collate']!="utf8_general_ci"&&
391                 $Settings['sql_collate']!="utf8_unicode_ci") {
392                 $Settings['sql_collate'] = "utf8_unicode_ci"; } }
393         $SQLCollate = $Settings['sql_collate'];
394         $SQLCharset = $Settings['sql_charset']; }
395 if(!isset($Settings['sql_collate'])||!isset($Settings['sql_charset'])) {
396 $SQLCollate = "latin1_general_ci";
397 $SQLCharset = "latin1"; 
398 if($Settings['charset']=="ISO-8859-1") {
399         $SQLCollate = "latin1_general_ci";
400         $SQLCharset = "latin1"; }
401 if($Settings['charset']=="ISO-8859-15") {
402         $SQLCollate = "latin1_general_ci";
403         $SQLCharset = "latin1"; }
404 if($Settings['charset']=="UTF-8") {
405         $SQLCollate = "utf8_unicode_ci";
406         $SQLCharset = "utf8"; } 
407 $Settings['sql_collate'] = $SQLCollate;
408 $Settings['sql_charset'] = $SQLCharset; }
409 sql_set_charset($SQLCharset,$SQLStat);
410 if($SQLStat===false) {
411 header("Content-Type: text/plain; charset=".$Settings['charset']); sql_free_result($peresult);
412 ob_clean(); echo "Sorry could not connect to sql database.\nContact the board admin about error. Error log below.";
413 echo "\n".sql_errorno($SQLStat); $urlstatus = 503;
414 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
415 $sqltable = $Settings['sqltable'];
416 $temp_user_ip = $_SERVER['REMOTE_ADDR'];
417 if(!isset($_SERVER['HTTP_USER_AGENT'])) {
418         $_SERVER['HTTP_USER_AGENT'] = ""; }
419 if(strpos($_SERVER['HTTP_USER_AGENT'], "msie") && 
420         !strpos($_SERVER['HTTP_USER_AGENT'], "opera")){
421         header("X-UA-Compatible: IE=Edge"); }
422 if(strpos($_SERVER['HTTP_USER_AGENT'], "chromeframe")) {
423         header("X-UA-Compatible: IE=Edge,chrome=1"); }
424 $temp_user_agent = $_SERVER['HTTP_USER_AGENT'];
425 if($Settings['file_ext']!="no+ext"&&$Settings['file_ext']!="no ext") {
426 $MkIndexFile = $exfile['index'].$Settings['file_ext']; }
427 if($Settings['file_ext']=="no+ext"||$Settings['file_ext']=="no ext") {
428 $MkIndexFile = $exfile['index']; }
429 $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']."\";";
430 $SQLSType = $Settings['sqltype'];
431 //Session Open Function
432 function sql_session_open($save_path, $session_name ) {
433 global $sess_save_path;
434 $sess_save_path = $save_path;
435 return true; }
436 //Session Close Function
437 $iDBSessCloseDB = true;
438 function sql_session_close() {
439 global $SQLStat,$iDBSessCloseDB;
440 if($iDBSessCloseDB===true) {
441 sql_disconnect_db($SQLStat); }
442 return true; }
443 //Session Read Function
444 function sql_session_read($id) {
445 global $sqltable,$SQLStat,$SQLSType,$temp_user_ip,$temp_user_agent,$temp_session_data;
446 $result = sql_query(sql_pre_query("SELECT * FROM \"".$sqltable."sessions\" WHERE \"session_id\" = '%s'", array($id)),$SQLStat);
447 if (!sql_num_rows($result)) {
448 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);
449 $time = GMTimeStamp();
450 sql_query(sql_pre_query("INSERT INTO \"".$sqltable."sessions\" (\"session_id\", \"session_data\", \"user_agent\", \"ip_address\", \"expires\") VALUES\n".
451 "('%s', '%s', '%s', '%s', %i)", array($id,$temp_session_data,$temp_user_agent,$temp_user_ip,$time)),$SQLStat);
452 return '';
453 } else {
454 $time = GMTimeStamp();
455 $predata = sql_num_rows($result);
456 $data = "";
457 if($predata > 0) {
458 $row = sql_fetch_assoc($result);
459 $data = $row['session_data']; }
460 /*sql_query(sql_pre_query("UPDATE \"".$sqltable."sessions\" SET \"session_data\"='%s',\"expires\"=%i WHERE \"session_id\"='%s'", array($data,$time,$id)),$SQLStat);*/
461 return $data; } }
462 //Session Write Function
463 function sql_session_write($id,$data) {
464 global $sqltable,$SQLStat,$SQLSType,$temp_user_ip,$temp_user_agent;
465 $time = GMTimeStamp();
466 $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);
467 return true; }
468 //Session Destroy Function
469 function sql_session_destroy($id) {
470 global $sqltable,$SQLStat;
471 sql_query(sql_pre_query("DELETE FROM \"".$sqltable."sessions\" WHERE \"session_id\" = '$id'", array($id)),$SQLStat);
472 return true; }
473 //Session Garbage Collection Function
474 function sql_session_gc($maxlifetime) {
475 global $sqltable,$SQLStat;
476 $time = GMTimeStamp() - $maxlifetime;
477 //sql_query(sql_pre_query('DELETE FROM \"'.$sqltable.'sessions\" WHERE \"expires\" < UNIX_TIMESTAMP();', array(null)),$SQLStat);
478 sql_query(sql_pre_query("DELETE FROM \"".$sqltable."sessions\" WHERE \"expires\" < %i", array($time)),$SQLStat);
479 return true; }
480 if (session_id()) { session_destroy(); }
481 session_set_save_handler("sql_session_open", "sql_session_close", "sql_session_read", "sql_session_write", "sql_session_destroy", "sql_session_gc");
482 if($cookieDomain==null) {
483 session_set_cookie_params(0, $cbasedir); }
484 if($cookieDomain!=null) {
485 if($cookieSecure===true) {
486 session_set_cookie_params(0, $cbasedir, $cookieDomain, 1); }
487 if($cookieSecure===false) {
488 session_set_cookie_params(0, $cbasedir, $cookieDomain); } }
489 session_cache_limiter("private, no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0");
490 header("Cache-Control: private, no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0");
491 header("Pragma: private, no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0");
492 header("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");
493 header("Date: ".gmdate("D, d M Y H:i:s")." GMT");
494 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
495 header("Expires: ".gmdate("D, d M Y H:i:s")." GMT");
496 if(!isset($_COOKIE[$Settings['sqltable']."sess"])) {
497 $exptime = GMTimeStamp() - ini_get("session.gc_maxlifetime");
498 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); }
499 if(!isset($_SESSION['CheckCookie'])) {
500 if(isset($_COOKIE['SessPass'])&&isset($_COOKIE['MemberName'])) {
501 session_set_save_handler("sql_session_open", "sql_session_close", "sql_session_read", "sql_session_write", "sql_session_destroy", "sql_session_gc");
502 session_name($Settings['sqltable']."sess");
503 session_start();
504 $iDBSessCloseDB = false;
505 $_SESSION['ShowActHidden'] = "no";
506 output_reset_rewrite_vars();
507 require($SettDir['inc'].'prelogin.php'); 
508 session_write_close(); } }
509 session_set_save_handler("sql_session_open", "sql_session_close", "sql_session_read", "sql_session_write", "sql_session_destroy", "sql_session_gc");
510 session_name($Settings['sqltable']."sess");
511 session_start();
512 $iDBSessCloseDB = true;
513 output_reset_rewrite_vars();
514 //@register_shutdown_function("session_write_close");
515 //header("Set-Cookie: PHPSESSID=" . session_id() . "; path=".$cbasedir);
516 output_reset_rewrite_vars();
517 if($_GET['act']=="bsdl"||$_GET['act']=="BSDL"||$_GET['act']=="license"||
518         $_GET['act']=="LICENSE"||$_GET['act']=="License") { $_GET['act']="bsd"; }
519 if($_GET['act']=="bsd") {
520 header("Content-Type: text/plain; charset=".$Settings['charset']);
521 require("LICENSE"); gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
522 if($_GET['act']=="README"||$_GET['act']=="ReadME") { $_GET['act']="readme"; }
523 if($_GET['act']=="readme"||$_GET['act']=="ReadMe") {
524 header("Content-Type: text/plain; charset=".$Settings['charset']);
525 require("README"); gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
526 if($_GET['act']=="js"||$_GET['act']=="javascript") {
527 header("Content-Script-Type: text/javascript");
528 if(stristr($_SERVER["HTTP_ACCEPT"],"application/x-javascript") ) {
529 header("Content-Type: application/x-javascript; charset=".$Settings['charset']); } else {
530 if(stristr($_SERVER["HTTP_ACCEPT"],"application/javascript") ) {
531 header("Content-Type: application/javascript; charset=".$Settings['charset']); } else {
532 header("Content-Type: text/javascript; charset=".$Settings['charset']); } }
533 require($SettDir['inc'].'javascript.php');
534 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
535 if($Settings['use_captcha']=="on") {
536 if($_GET['act']=="MkCaptcha"||$_GET['act']=="Captcha") {
537         if($Settings['captcha_clean']=="on") { ob_clean(); }
538         require($SettDir['inc']."captcha.php");
539         $aFonts = array('inc/fonts/VeraBd.ttf', 'inc/fonts/VeraBI.ttf', 'inc/fonts/VeraIt.ttf', 'inc/fonts/Vera.ttf');
540         $oPhpCaptcha = new PhpCaptcha($aFonts, 200, 60);
541         $RNumSize = rand(7,17); $i=0; $RandNum = null;
542         while ($i <= $RNumSize) {
543         $RandNum=$RandNum.dechex(rand(1,15)); ++$i; }
544         $RandNum=strtoupper($RandNum);
545         $oPhpCaptcha->SetOwnerText("Fake Code: ".$RandNum);
546         $oPhpCaptcha->UseColour(true);
547         $oPhpCaptcha->Create(); session_write_close(); die(); } }
548 require($SettDir['inc'].'groupsetup.php');
549 if($Settings['board_offline']=="on"&&$GroupInfo['CanViewOffLine']!="yes") {
550 header("Content-Type: text/plain; charset=".$Settings['charset']); sql_free_result($peresult);
551 ob_clean(); if(!isset($Settings['offline_text'])) {
552 echo "Sorry the board is off line.\nIf you are a admin you can login by the admin cp."; }
553 if(isset($Settings['offline_text'])) { echo $Settings['offline_text']; } $urlstatus = 503;
554 //echo "\n".sql_errorno($SQLStat);
555 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
556 //Time Zone Set
557 if(!isset($_SESSION['UserTimeZone'])) { 
558         if(isset($Settings['DefaultTimeZone'])) { 
559         $_SESSION['UserTimeZone'] = $Settings['DefaultTimeZone'];
560         if(!isset($Settings['DefaultTimeZone'])) { 
561         $_SESSION['UserTimeZone'] = SeverOffSet().":00"; } } }
562 $checktime = explode(":",$_SESSION['UserTimeZone']);
563 if(count($checktime)!=2) {
564         if(!isset($checktime[0])) { $checktime[0] = "0"; }
565         if(!isset($checktime[1])) { $checktime[1] = "00"; }
566         $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
567 if(!is_numeric($checktime[0])) { $checktime[0] = "0"; }
568 if(!is_numeric($checktime[1])) { $checktime[1] = "00"; }
569 if($checktime[1]<0) { $checktime[1] = "00"; $_SESSION['UserTimeZone'] = $checktime[0].":".$checktime[1]; }
570 $checktimea = array("offset" => $_SESSION['UserTimeZone'], "hour" => $checktime[0], "minute" => $checktime[1]);
571 if(!isset($_SESSION['UserDST'])) { $_SESSION['UserDST'] = null; }
572 if($_SESSION['UserDST']==null) {
573 if($Settings['DefaultDST']=="off") { 
574         $_SESSION['UserDST'] = "off"; }
575 if($Settings['DefaultDST']=="on") { 
576         $_SESSION['UserDST'] = "on"; } }
577 // Guest Stuff
578 if(isset($_SESSION['MemberName'])||
579    isset($_COOKIE['MemberName'])) {
580         $_SESSION['GuestName'] = null;
581         $_COOKIE['GuestName'] = null; }
582 if(!isset($_SESSION['MemberName'])&&!isset($_COOKIE['MemberName'])) {
583 if(!isset($_SESSION['GuestName'])&&isset($_COOKIE['GuestName'])) {
584         $_SESSION['GuestName'] = $_COOKIE['GuestName']; } }
585 if(!isset($_SESSION['LastPostTime'])) { $_SESSION['LastPostTime'] = "0"; }
586 // Skin Stuff
587 if(!isset($_SESSION['Theme'])) { $_SESSION['Theme'] = null; }
588 if(!isset($_GET['theme'])) { $_GET['theme'] = null; }
589 if(!isset($_POST['theme'])) { $_POST['theme'] = null; }
590 if(!isset($_GET['skin'])) { $_GET['skin'] = null; }
591 if(!isset($_POST['skin'])) { $_POST['skin'] = null; }
592 if(!isset($_GET['style'])) { $_GET['style'] = null; }
593 if(!isset($_POST['style'])) { $_POST['style'] = null; }
594 if(!isset($_GET['css'])) { $_GET['css'] = null; }
595 if(!isset($_POST['css'])) { $_POST['css'] = null; }
596 if($_GET['theme']==null) {
597         if($_POST['theme']!=null) {
598                 $_GET['theme'] = $_POST['theme']; }
599         if($_POST['skin']!=null) {
600                 $_GET['theme'] = $_POST['skin']; }
601         if($_POST['style']!=null) {
602                 $_GET['theme'] = $_POST['style']; }
603         if($_POST['css']!=null) {
604                 $_GET['theme'] = $_POST['css']; }
605         if($_GET['skin']!=null) {
606                 $_GET['theme'] = $_GET['skin']; }
607         if($_GET['style']!=null) {
608                 $_GET['theme'] = $_GET['style']; }
609         if($_GET['css']!=null) {
610                 $_GET['theme'] = $_GET['css']; } }
611 if($Settings['SQLThemes']=="off") {
612 if($_GET['theme']!=null) {
613 $_GET['theme'] = chack_themes($_GET['theme']);
614 if($_GET['theme']=="../"||$_GET['theme']=="./") {
615 $_GET['theme']=$Settings['DefaultTheme']; $_SESSION['Theme']=$Settings['DefaultTheme']; }
616 if (file_exists($SettDir['themes'].$_GET['theme']."/settings.php")) {
617 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
618 $NewDay=GMTimeStamp();
619 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_GET['theme'],$NewDay,$_SESSION['UserID']));
620 sql_query($qnewskin,$SQLStat); }
621 /* The file Theme Exists */ }
622 else { $_GET['theme'] = $Settings['DefaultTheme']; 
623 $_SESSION['Theme'] = $Settings['DefaultTheme'];
624 /* The file Theme Dose Not Exists */ } }
625 if($_GET['theme']==null) { 
626 if($_SESSION['Theme']!=null) {
627 $OldTheme = $_SESSION['Theme'];
628 $_SESSION['Theme'] = chack_themes($_SESSION['Theme']);
629 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
630 if($OldTheme!=$_SESSION['Theme']) { 
631 $NewDay=GMTimeStamp();
632 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_SESSION['Theme'],$NewDay,$_SESSION['UserID']));
633 sql_query($qnewskin,$SQLStat); } }
634 $_GET['theme']=$_SESSION['Theme']; }
635 if($_SESSION['Theme']==null) {
636 $_SESSION['Theme']=$Settings['DefaultTheme'];
637 $_GET['theme']=$Settings['DefaultTheme']; } }
638 $PreSkin['skindir1'] = $_SESSION['Theme'];
639 $PreSkin['skindir2'] = $SettDir['themes'].$_SESSION['Theme'];
640 require($SettDir['themes'].$_GET['theme']."/settings.php"); }
641 if($Settings['SQLThemes']=="on") {
642 if($_GET['theme']==null&&$_SESSION['Theme']==null) { 
643         $_GET['theme'] = $Settings['DefaultTheme']; 
644         $_SESSION['Theme'] = $Settings['DefaultTheme']; }
645 if($_GET['theme']!=null) {
646 $themequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_GET['theme'])); }
647 if($_GET['theme']==null) { 
648 if($_SESSION['Theme']!=null) {
649 $themequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_SESSION['Theme'])); } }
650 $themeresult=sql_query($themequery,$SQLStat);
651 $themenum=sql_num_rows($themeresult);
652 if($themenum<=0) {
653 $_GET['theme'] = $Settings['DefaultTheme']; 
654 $_SESSION['Theme'] = $Settings['DefaultTheme']; 
655 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
656 $NewDay=GMTimeStamp();
657 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_SESSION['Theme'],$NewDay,$_SESSION['UserID']));
658 sql_query($qnewskin,$SQLStat); }
659 $themequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_GET['theme']));
660 $themeresult=sql_query($themequery,$SQLStat);
661 $themenum=sql_num_rows($themeresult); } 
662 else {
663 if($_GET['theme']==null) { 
664 if($_SESSION['Theme']!=null) {
665 $_GET['theme'] = $_SESSION['Theme']; } }
666 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
667 $NewDay=GMTimeStamp();
668 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_GET['theme'],$NewDay,$_SESSION['UserID']));
669 sql_query($qnewskin,$SQLStat); } } 
670 require($SettDir['inc'].'sqlthemes.php');
671 sql_free_result($themeresult); }
672 $_SESSION['Theme'] = $_GET['theme'];
673 function get_theme_values($matches) {
674         global $ThemeSet;
675         $return_text = null;
676         if(isset($ThemeSet[$matches[1]])) { $return_text = $ThemeSet[$matches[1]]; }
677         if(!isset($ThemeSet[$matches[1]])) { $return_text = null; }
678         return $return_text; }
679 foreach($ThemeSet AS $key => $value) {
680         $ThemeSet[$key] = preg_replace("/%%/s", "{percent}p", $ThemeSet[$key]);
681         $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}T/s", "get_theme_values", $ThemeSet[$key]);
682         $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}e/s", "get_env_values", $ThemeSet[$key]);
683         $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}i/s", "get_server_values", $ThemeSet[$key]);
684         $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}s/s", "get_setting_values", $ThemeSet[$key]);
685         $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}t/s", "get_time", $ThemeSet[$key]); 
686         $ThemeSet[$key] = preg_replace("/\{percent\}p/s", "%", $ThemeSet[$key]); }
687 if(!isset($ThemeSet['TableStyle'])) {
688         $ThemeSet['TableStyle'] = "table"; }
689 if(isset($ThemeSet['TableStyle'])) {
690 if($ThemeSet['TableStyle']!="div"&&
691         $ThemeSet['TableStyle']!="table") {
692         $ThemeSet['TableStyle'] = "table"; } }
693 if(!isset($_SESSION['DBName'])) { $_SESSION['DBName'] = null; }
694 if($_SESSION['DBName']==null) {
695         $_SESSION['DBName'] = $Settings['sqldb']; }
696 if($_SESSION['DBName']!=null) {
697         if($_SESSION['DBName']!=$Settings['sqldb']) {
698 redirect("location",$rbasedir.url_maker($exfile['member'],$Settings['file_ext'],"act=logout",$Settings['qstr'],$Settings['qsep'],$prexqstr['member'],$exqstr['member'],false)); } }
699 ?>