From e22da621646c2f4edb3b5e99b7605f51380a9718 Mon Sep 17 00:00:00 2001 From: "Janus B. Kristensen" Date: Thu, 21 Jun 2007 05:57:08 +0000 Subject: [PATCH] Scraping mechanism for Bittorrent svn path=/trunk/boinc/; revision=12976 --- html/bt/scrape.php | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 html/bt/scrape.php diff --git a/html/bt/scrape.php b/html/bt/scrape.php new file mode 100755 index 0000000000..591f929485 --- /dev/null +++ b/html/bt/scrape.php @@ -0,0 +1,47 @@ +$error)); + exit; +} + +$info_hash = rawurldecode($_GET["info_hash"]); +if (strlen($info_hash)<20) throw new IllegalArgumentException("Malformed infohash key (length ".strlen($info_hash).")"); + +if (!$ip){ + $ip = $_SERVER["REMOTE_ADDR"]; +} + +// Is the IP banned? +db_init(); +if (isIPBanned($ip)){ + trackerError("Banned IP: ".$ip); +} + +// Check that the info_hash is one that we allow: +$queryHandle = mysql_query("SELECT * from bittorrent_files where info_hash=\"".process_user_text($info_hash)."\""); echo mysql_error(); +if (!mysql_num_rows($queryHandle)){ + trackerError("The tracker does not allow tracking of this file:".$info_hash); +} +$infoHashObject = mysql_fetch_object($queryHandle); + +// Get some statistical counts +$queryHandle = mysql_query("SELECT count(fileid) as complete from bittorrent_peers where fileid = '".$infoHashObject->id."' and status='completed'"); +$data = mysql_fetch_object($queryHandle); +$complete = intval($data->complete); +$queryHandle = mysql_query("SELECT count(fileid) as incomplete from bittorrent_peers where fileid = '".$infoHashObject->id."' and status!='completed'"); +$data = mysql_fetch_object($queryHandle); +$incomplete = intval($data->incomplete); + +$out = BDictionary::toEncoded(array("interval"=>DEFAULT_CONNECTION_INTERVAL, "downloaded"=>$complete, "complete"=>$complete, "incomplete"=>$incomplete)); + +?> \ No newline at end of file