Strict Standards: Resource ID#25 used as offset, casting to integer (25) in /home/tvoyweb/domains/tvoyweb.ru/public_html/forums/include/fm.class.php on line 401

Strict Standards: Resource ID#27 used as offset, casting to integer (27) in /home/tvoyweb/domains/tvoyweb.ru/public_html/forums/include/fm.class.php on line 401

Strict Standards: Resource ID#28 used as offset, casting to integer (28) in /home/tvoyweb/domains/tvoyweb.ru/public_html/forums/include/fm.class.php on line 401
ТвойWeb :: Версия для печати :: Тестирование скрипта
ТвойWeb » WebMaster класс » PHP/Perl » Тестирование скрипта

Страниц (1): [1]
 

1. ETC - 11 Декабря, 2004 - 10:28:13 - перейти к сообщению
Собственно, хочу узнать, безопасен-ли мой скрипт. Вроде писал, шоб никаких лазеек.
PHP:

<?php
include("./files.inc.php");

function get_statfile() {
$fp = fopen("./count.dat", "r");
$fr = fread($fp, filesize("./count.dat"));
$out = explode("\n", $fr);
$nout = array();
while (list($k, $v) = each($out)) {
if(strlen($v)>1) {
$tmp = explode(":", $v);
$nout[$tmp[0]] = $tmp[1];
}
}
fclose($fp);
return $nout;
}

function write_statfile($stat) {
$str = "";
while (list($k, $v) = each($stat)) {
$str .= $k.":".$v."\n";
}
$fp = fopen("./count.dat", "w");
fwrite($fp, $str);
fclose($fp);
}

if (!is_file("./count.dat")) {
$str = "";
$fp = fopen("./count.dat", "w");
while (list($k, $v) = each($files)) {
$str .= $k.":0\n";
}
fwrite($fp, $str);
fclose($fp);
} else {
$stat = get_statfile();
$nstat = array();
while (list($k, $v) = each($files)) {
if (!in_array($k, array_keys($stat))) {
$nstat[$k] = "0";
}
}
if (count($nstat)>0) {
$newstat = array_merge($stat, $nstat);
write_statfile($newstat);
}
$nstat = array();
while (list($k, $v) = each($stat)) {
if (in_array($k, array_keys($files))) {
$nstat[$k] = $v;
}
}
if (count($stat) != count($nstat)) {
write_statfile($nstat);
}
unset($stat);
}

$get = isset($HTTP_GET_VARS["get"]) ? $HTTP_GET_VARS["get"] : "none";
$get = (is_string($get) && strlen($get) > 0) ? $get : "none";
if ($get=="none") {
header("HTTP/1.0 403 Forbidden");
exit;
} else if ($get=="jstat" || $get=="xstat" || $get=="jsstat" || $get=="xsstat") {
$file = isset($HTTP_GET_VARS["file"]) ? $HTTP_GET_VARS["file"] : "none";
$file = (is_string($file) && strlen($file)>0) ? $file : "none";
if ($file=="none") {
header("HTTP/1.0 403 Forbidden");
exit;
} else {
if (in_array($file, array_keys($files))) {
$stat = get_statfile();
$count = "0";
while (list($k, $v) = each($stat)) {
if ($k == $file) {
$count = $v;
break;
}
}
if ($get == "jstat"&&is_file($files[$file])) {
header("Cache-Control: no-cache");
header("Pragma: no-cache");
echo "document.write(".$count.");";
} else if ($get=="xstat"&&is_file($files[$file])) {
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Content-Type: text/xml");
echo "<"."?xml version=\"1.0\"?".">";
echo "\n<stat value=\"".$count."\"/>";
exit;
} else if ($get=="jsstat"&&is_file($files[$file])) {
header("Cache-Control: no-cache");
header("Pragma: no-cache");
echo "document.write(".round(filesize($files[$file])/1024).");";
} else if ($get=="xsstat"&&is_file($files[$file])) {
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Content-Type: text/xml");
echo "<"."?xml version=\"1.0\"?".">";
echo "\n<stat value=\"".round(filesize($files[$file])/1024)."\"/>";
exit;
} else {
header("HTTP/1.0 403 Forbidden");
exit;
}
} else {
header("HTTP/1.0 403 Forbidden");
exit;
}
}
} else {
if (in_array($get, array_keys($files))) {
if (is_file($files[$get])) {
$stat = get_statfile();
$stat[$get]++;
write_statfile($stat);
//header("Content-Type: application/force-download");
//header("Content-Transfer-Encoding: Binary");
//header("Content-Length: ".filesize($files[$get]));
//header("Content-Disposition: attachment; filename=\"".basename($files[$get])."\"");
//@readfile($files[$get]);
header("Location: ".$files[$get]);
} else {
header("HTTP/1.0 403 Forbidden");
exit;
}
} else {
header("HTTP/1.0 403 Forbidden");
exit;
}
}
?>


Если раскоменнтить строки header-ов и убрать Location, то файл будет выдаваться потоком, но тогда невозможно будет докачать файл или качать в несколько потоков...

скрипт работает через параметры get и file. Если задан get равный xstat,jstat,xsstat,jsstat, и параметр file, указывающий на индекс в массиве и файл из массива существует, то выдаётся статистика файла в XML, JS, размер файла в XML, JS виде соответсвенно...

в файле files.inc.php вбит ассоциативный массив
PHP:

<?php
$files = array("test"=>"./files/test.exe","test1"=>"./files/test1.exe");
?>


Ссылка выглядит как get.php?get=test
2. TvoyWeb - 11 Декабря, 2004 - 16:54:10 - перейти к сообщению
ETC
Я чуть позже гляну....

Форум на AlfaSpace.NET


Powered by ExBB
ExBB FM 1.0 RC1 by TvoyWeb.ru
InvisionExBB Style converted by Markus®

[Script Execution time: 0.0343]     [ Gzipped ]