| 1 |
<?php |
| 2 |
/** |
| 3 |
* File functions: |
| 4 |
* Page source |
| 5 |
* |
| 6 |
* @name : source.php |
| 7 |
* @copyright : (C) 2004-2005 Vallheru Team based on Gamers-Fusion ver 2.5 |
| 8 |
* @author : thindil <thindil@users.sourceforge.net> |
| 9 |
* @version : 1.0 rc1 |
| 10 |
* @since : 27.11.2005 |
| 11 |
* |
| 12 |
*/ |
| 13 |
|
| 14 |
// |
| 15 |
// |
| 16 |
// This program is free software; you can redistribute it and/or modify |
| 17 |
// it under the terms of the GNU General Public License as published by |
| 18 |
// the Free Software Foundation; either version 2 of the License, or |
| 19 |
// (at your option) any later version. |
| 20 |
// |
| 21 |
// This program is distributed in the hope that it will be useful, |
| 22 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 |
// GNU General Public License for more details. |
| 25 |
// |
| 26 |
// You should have received a copy of the GNU General Public License |
| 27 |
// along with this program; if not, write to the Free Software |
| 28 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 29 |
// |
| 30 |
// |
| 31 |
|
| 32 |
/** |
| 33 |
* Some security tests |
| 34 |
*/ |
| 35 |
if ($_GET['file'] == 'includes/config.php' || $_GET['file'] == 'includes/sessions.php') |
| 36 |
{ |
| 37 |
exit; |
| 38 |
} |
| 39 |
|
| 40 |
$arrTest = explode('/', $_GET['file']); |
| 41 |
$intAmount = count($arrTest); |
| 42 |
if ($intAmount > 2) |
| 43 |
{ |
| 44 |
exit; |
| 45 |
} |
| 46 |
elseif ($intAmount == 2) |
| 47 |
{ |
| 48 |
if ($arrTest[0] != 'includes' && $arrTest[0] != 'class') |
| 49 |
{ |
| 50 |
exit; |
| 51 |
} |
| 52 |
} |
| 53 |
$arrTest2 = explode('.', $_GET['file']); |
| 54 |
$intAmount = (count($arrTest2) - 1); |
| 55 |
if ($arrTest2[$intAmount] != 'php') |
| 56 |
{ |
| 57 |
exit; |
| 58 |
} |
| 59 |
|
| 60 |
$do_gzip_compress = FALSE; |
| 61 |
$compress = FALSE; |
| 62 |
$phpver = phpversion(); |
| 63 |
$useragent = (isset($_SERVER["HTTP_USER_AGENT"]) ) ? $_SERVER["HTTP_USER_AGENT"] : $HTTP_USER_AGENT; |
| 64 |
if ( $phpver >= '4.0.4pl1' && ( strstr($useragent,'compatible') || strstr($useragent,'Gecko') ) ) |
| 65 |
{ |
| 66 |
if ( extension_loaded('zlib') ) |
| 67 |
{ |
| 68 |
$compress = TRUE; |
| 69 |
ob_start('ob_gzhandler'); |
| 70 |
} |
| 71 |
} |
| 72 |
elseif ( $phpver > '4.0' ) |
| 73 |
{ |
| 74 |
if ( strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip') ) |
| 75 |
{ |
| 76 |
if ( extension_loaded('zlib') ) |
| 77 |
{ |
| 78 |
$do_gzip_compress = TRUE; |
| 79 |
$compress = TRUE; |
| 80 |
ob_start(); |
| 81 |
ob_implicit_flush(0); |
| 82 |
header('Content-Encoding: gzip'); |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Display source |
| 89 |
*/ |
| 90 |
|
| 91 |
require_once 'libs/Smarty.class.php'; |
| 92 |
$smarty = new Smarty; |
| 93 |
|
| 94 |
$smarty -> compile_check = false; |
| 95 |
$smarty -> caching = true; |
| 96 |
|
| 97 |
|
| 98 |
if ($_GET['file'] == 'includes/head.php') |
| 99 |
{ |
| 100 |
$strSource = show_source('includes/head.php', true); |
| 101 |
} |
| 102 |
elseif ($_GET['file'] == 'includes/foot.php') |
| 103 |
{ |
| 104 |
$strSource = show_source('includes/foot.php', true); |
| 105 |
} |
| 106 |
else |
| 107 |
{ |
| 108 |
$strSource2 = "<a href=\"source.php?file=includes/head.php\" target=\"_blank\">head.php</a><br /><br />"; |
| 109 |
$strSource = show_source($_GET['file'], true); |
| 110 |
$strSource3 = "<br /><a href=\"source.php?file=includes/foot.php\" target=\"_blank\">foot.php</a><br />"; |
| 111 |
$strSource = $strSource2.$strSource.$strSource3; |
| 112 |
} |
| 113 |
|
| 114 |
$strCacheid = $_GET['file']; |
| 115 |
|
| 116 |
$smarty -> assign(array("Source" => $strSource, |
| 117 |
"File" => $_GET['file'])); |
| 118 |
|
| 119 |
$smarty -> display('source.tpl', $strCacheid); |
| 120 |
exit; |
| 121 |
|
| 122 |
if (!isset($do_gzip_compress)) |
| 123 |
{ |
| 124 |
$do_gzip_compress = $compress; |
| 125 |
} |
| 126 |
|
| 127 |
if ( $do_gzip_compress ) |
| 128 |
{ |
| 129 |
// |
| 130 |
// Borrowed from php.net! |
| 131 |
// |
| 132 |
$gzip_contents = ob_get_contents(); |
| 133 |
ob_end_clean(); |
| 134 |
|
| 135 |
$gzip_size = strlen($gzip_contents); |
| 136 |
$gzip_crc = crc32($gzip_contents); |
| 137 |
|
| 138 |
$gzip_contents = gzcompress($gzip_contents, 9); |
| 139 |
$gzip_contents = substr($gzip_contents, 0, strlen($gzip_contents) - 4); |
| 140 |
|
| 141 |
echo "\x1f\x8b\x08\x00\x00\x00\x00\x00"; |
| 142 |
echo $gzip_contents; |
| 143 |
echo pack('V', $gzip_crc); |
| 144 |
echo pack('V', $gzip_size); |
| 145 |
} |
| 146 |
?> |