OSDN Git Service

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