<?
// be cautious with this !
require_once("bittorrent.inc.php");
require_once("bencode.php");
function url_validate( $link,$id )
{
if ( empty( $url_parts["host"] ) ) return( false );
if ( !
empty( $url_parts["path"] ) ) {
$documentpath = $url_parts["path"];
//if (substr($documentpath, -6)=="scrape") { $documentpath.="/";}
}
else
{
$documentpath = "/";
}
if ( !
empty( $url_parts["query"] ) ) {
$documentpath .= "?" . $url_parts["query"];
}
$host = $url_parts["host"];
$port = $url_parts["port"];
// Now (HTTP-)GET $documentpath at $host";
if (empty( $port ) ) $port =
"80";
$socket = @
fsockopen( $host,
$port,
$errno,
$errstr,
30 );
if (!$socket)
{
return(false);
mysql_query("UPDATE torrents SET reason=\"Tracker seems to be dead,so it was skipped\" WHERE id = $id");
mysql_query("UPDATE torrents SET skip=\"yes\" WHERE id = $id");
}
else
{
// change this value if you want : 1s is enough for fast trackers, else it will slow too much bytestats
fwrite ($socket,
"HEAD ".
$documentpath.
" HTTP/1.0\r\nHost: $host\r\n\r\n");
$http_response =
fgets( $socket,
22 );
// if ( ereg("200", $http_response, $regs ) || ereg("302", $http_response, $regs ) )
//{
mysql_query("UPDATE torrents SET reason=\"This torrent is working fine\" WHERE id = $id");
mysql_query("UPDATE torrents SET skip=\"no\" WHERE id = $id");
return(true);
// } else
//{
//echo "HTTP-Response: $http_response<br>";
// return(false);
//mysql_query("UPDATE torrents SET reason=\"Tracker gave an abnormal answer,so it was skipped\" WHERE id = $id");
//mysql_query("UPDATE torrents SET skip=\"yes\" WHERE id = $id");
// }
}
}
function hex2bin($hex)
{
$result = '';
for ($i =
0;
$i <
strlen($hex);
$i +=
2) return $result;
}
function hexesc($matches) {
}
function docleanup() {
global $torrent_dir,
$signup_timeout,
$max_dead_torrent_time;
do {
$id = $row[0];
$ar[$id] = 1;
}
break;
if (!$dp)
break;
while (($file =
readdir($dp)) !==
false) { continue;
$id = $m[1];
$ar2[$id] = 1;
if (isset($ar[$id]) &&
$ar[$id]) continue;
$ff = $torrent_dir . "/$file";
}
break;
if (isset($ar2[$k]) &&
$ar2[$k]) continue;
$delids[] = $k;
}
mysql_query("DELETE FROM torrents WHERE id IN (" .
join(",",
$delids) .
")");
$res =
mysql_query("SELECT torrent FROM peers GROUP BY torrent");
$id = $row[0];
if (isset($ar[$id]) &&
$ar[$id]) continue;
$delids[] = $id;
}
mysql_query("DELETE FROM peers WHERE torrent IN (" .
join(",",
$delids) .
")");
$res =
mysql_query("SELECT torrent FROM files GROUP BY torrent");
$id = $row[0];
if (@$ar[$id])
continue;
$delids[] = $id;
}
mysql_query("DELETE FROM files WHERE torrent IN (" .
join(",",
$delids) .
")");
} while (0);
$deadtime = deadtime();
mysql_query("DELETE FROM peers WHERE last_action < FROM_UNIXTIME($deadtime)");
$deadtime -= $max_dead_torrent_time;
mysql_query("UPDATE torrents SET visible='no' WHERE visible='yes' AND last_action < FROM_UNIXTIME($deadtime)");
$deadtime =
time() -
$signup_timeout;
mysql_query("DELETE FROM users WHERE status = 'pending' AND added < FROM_UNIXTIME($deadtime) AND last_login < FROM_UNIXTIME($deadtime) AND last_access < FROM_UNIXTIME($deadtime)");
$res =
mysql_query("SELECT torrent, seeder, COUNT(*) AS c FROM peers GROUP BY torrent, seeder");
if ($row["seeder"] == "yes")
$key = "seeders";
else
$key = "leechers";
$torrents[$row["torrent"]][$key] = $row["c"];
}
$res =
mysql_query("SELECT torrent, COUNT(*) AS c FROM comments GROUP BY torrent");
$torrents[$row["torrent"]]["comments"] = $row["c"];
}
// i thing it is here that modifications need to be made !
$fields =
explode(":",
"comments:leechers:seeders");
$res =
mysql_query("SELECT id, seeders, leechers, comments,scrape_url FROM torrents");
$id = $row["id"];
$torr = @$torrents[$id];
foreach ($fields as $field) {
if (!
isset($torr[$field])) $torr[$field] = 0;
}
foreach ($fields as $field) {
if ($torr[$field] != $row[$field])
$update[] = "$field = " . $torr[$field];
}
// temporary fix :(
if ( ereg($tracker_url,
$row["scrape_url"]) ) {
}
}
$sql = 'SELECT id FROM torrents WHERE skip = "no" ';
// on envoie la requete
// on fait une boucle qui va faire un tour pour chaque enregistrements
{
$id = $data["id"];
$row[0] = '?' ;
$row[1] = '?' ;
// on affiche les informations de l'enregistrements en cours
$sql2 = "SELECT info_hash,scrape_url FROM torrents WHERE id = $id";
if ( ereg($tracker_url,
$dat["scrape_url"]) ) {
$max_cache_file_age = '360';
// $scrape = file_get_contents('http://torrentstats.phpsoft.org/bytestats.php?tracker='.$dat["scrape_url"].'&infohash='.$hash);
$bencode = new BEncodeLib();
// some optimisations can be made here : do not get twice or more the same scrape file from the same tracker ...
$tracker_md5 = $infohash;
if(file_exists('temp/'.
$tracker_md5) &&
$cache_age <
$max_cache_file_age) {
mysql_query("UPDATE torrents SET reason=\"This torrent is working fine\" WHERE id = $id");
mysql_query("UPDATE torrents SET visible=\"yes\" WHERE id = $id");
$info = $bencode->bdecode($scrape);
$torrentseeds = $info['files'][hex2bin($infohash)]['complete'];
$torrentpeers = $info['files'][hex2bin($infohash)]['incomplete'];
// debug purposes only echo "<br>".$dat["scrape_url"]." - $infohash - $torrentseeds - $torrentpeers";
mysql_query("UPDATE torrents SET seeders=$torrentseeds WHERE id = $id");
mysql_query("UPDATE torrents SET leechers=$torrentpeers WHERE id = $id");
}
if(file_exists('temp/'.
$tracker_md5) &&
$cache_age >
$max_cache_file_age) { if (url_validate($dat["scrape_url"],$id))
{
$refresh='1';
$save = @
fopen('temp/'.
$tracker_md5,
'w+',
1);
mysql_query("UPDATE torrents SET reason=\"This torrent is working fine\" WHERE id = $id");
mysql_query("UPDATE torrents SET visible=\"yes\" WHERE id = $id");
$info = $bencode->bdecode($scrape);
$torrentseeds = $info['files'][hex2bin($infohash)]['complete'];
$torrentpeers = $info['files'][hex2bin($infohash)]['incomplete'];
// debug purposes only echo "<br>".$dat["scrape_url"]." - $infohash - $torrentseeds - $torrentpeers";
mysql_query("UPDATE torrents SET seeders=$torrentseeds WHERE id = $id");
mysql_query("UPDATE torrents SET leechers=$torrentpeers WHERE id = $id");
}
}
else { mysql_query("UPDATE torrents SET reason=\"Tracker seems to be dead,so it was skipped\" WHERE id = $id");
} }
if (url_validate($dat["scrape_url"],$id))
{
$refresh='1';
$save = @
fopen('temp/'.
$tracker_md5,
'w+');
mysql_query("UPDATE torrents SET reason=\"This torrent is working fine\" WHERE id = $id");
mysql_query("UPDATE torrents SET visible=\"yes\" WHERE id = $id");
$info = $bencode->bdecode($scrape);
$torrentseeds = $info['files'][hex2bin($infohash)]['complete'];
$torrentpeers = $info['files'][hex2bin($infohash)]['incomplete'];
// debug purposes only echo "<br>".$dat["scrape_url"]." - $infohash - $torrentseeds - $torrentpeers";
mysql_query("UPDATE torrents SET seeders=$torrentseeds WHERE id = $id");
mysql_query("UPDATE torrents SET leechers=$torrentpeers WHERE id = $id");
}
else { mysql_query("UPDATE torrents SET reason=\"Tracker seems to be dead,so it was skipped\" WHERE id = $id");
} }
}
}
}
}
?>