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