-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrape.php
94 lines (77 loc) · 2.3 KB
/
scrape.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
//
// TorrentTrader v2.x
// $LastChangedDate: 2011-11-04 15:06:52 +0000 (Fri, 04 Nov 2011) $
// $LastChangedBy: dj-howarth1 $
//
// http://www.torrenttrader.org
//
//
error_reporting(0); //disable error reporting
// check if client can handle gzip
if (stristr($_SERVER["HTTP_ACCEPT_ENCODING"],"gzip") && extension_loaded('zlib') && ini_get("zlib.output_compression") == 0) {
if (ini_get('output_handler')!='ob_gzhandler') {
ob_start("ob_gzhandler");
} else {
ob_start();
}
}else{
ob_start();
}
// end gzip controll
require_once("backend/mysql.php");
require_once("backend/mysql.class.php");
function dbconn() {
global $mysql_host, $mysql_user, $mysql_pass, $mysql_db;
if (!@mysql_connect($mysql_host, $mysql_user, $mysql_pass))
{
die('DATABASE: mysql_connect: ' . mysql_error());
}
mysql_select_db($mysql_db)
or die('DATABASE: mysql_select_db: ' + mysql_error());
unset($mysql_pass); //security
}
function hex2bin($hexdata) {
$bindata = "";
for ($i=0;$i<strlen($hexdata);$i+=2) {
$bindata.=chr(hexdec(substr($hexdata,$i,2)));
}
return $bindata;
}
function sqlesc($x) {
return "'".mysql_real_escape_string($x)."'";
}
dbconn();
$infohash = array();
foreach (explode("&", $_SERVER["QUERY_STRING"]) as $item) {
if (preg_match("#^info_hash=(.+)\$#", $item, $m)) {
$hash = urldecode($m[1]);
if (get_magic_quotes_gpc())
$info_hash = stripslashes($hash);
else
$info_hash = $hash;
if (strlen($info_hash) == 20)
$info_hash = bin2hex($info_hash);
else if (strlen($info_hash) != 40)
continue;
$infohash[] = sqlesc(strtolower($info_hash));
}
}
if (!count($infohash)) die("Invalid infohash.");
$query = SQL_Query_exec("SELECT info_hash, seeders, leechers, times_completed, filename FROM torrents WHERE info_hash IN (".join(",", $infohash).")");
$result="d5:filesd";
while ($row = mysql_fetch_row($query))
{
$hash = hex2bin($row[0]);
$result.="20:".$hash."d";
$result.="8:completei".$row[1]."e";
$result.="10:downloadedi".$row[3]."e";
$result.="10:incompletei".$row[2]."e";
$result.="4:name".strlen($row[4]).":".$row[4]."e";
$result.="e";
}
$result.="ee";
echo $result;
ob_end_flush();
mysql_close();
?>