OSDN Git Service

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