DEFINE("CACHE_PATH", "/tmp");
DEFINE("COOKIE_FILE_NAME", CACHE_PATH . "/torcookie.txt");
$post=array();
$torrentid = gg('TorrentID');
if ($params == "rutracker") {
$loginurl = "http://login.rutracker.org/forum/login.php";
$post['login_username'] = "galakart";
$post['login_password'] = gg("ThisComputer.rutrackerpas");
$post['login'] = "%C2%F5%EE%E4";
$dlurl = "http://dl.rutracker.org/forum/dl.php?t=".$torrentid;
$refurl = "http://rutracker.org/forum/viewtopic.php?t=".$torrentid;
$out = curl_post($loginurl, "http://rutracker.org", $post);
$post=array();
$post['t']=$torrentid;
$options = array ('Content-Type: application/x-www-form-urlencoded');
$out = curl_post($dlurl, $refurl, $post, $options);
$fp = fopen("/mnt/usbhdd_share/torrent/torrentfiles/".$torrentid.".torrent", 'w');
fwrite($fp, $out);
fclose($fp);
};
function curl_post($url, $ref, array $post = NULL, array $options = array())
{
$headers = array (
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*;q=0.8',
'Accept-Language: ru,en-us;q=0.7,en;q=0.3',
'Accept-Encoding: deflate',
'Accept-Charset: windows-1251;q=0.7,*;q=0.7',
'Connection: close'
);
$defaults = array(
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 120,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_VERBOSE => 0,
CURLOPT_REFERER => $ref,
CURLOPT_COOKIEFILE => COOKIE_FILE_NAME,
CURLOPT_COOKIEJAR => COOKIE_FILE_NAME,
CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1",
CURLOPT_POSTFIELDS => http_build_query($post)
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
curl_setopt ($ch,CURLOPT_HTTPHEADER,$headers);
if( ! $result = curl_exec($ch))
{
return "";
}
curl_close($ch);
return $result;
}
say("Началась закачка торрента");