<?php
if(!$_REQUEST['url']) exit(0);
$url = trim($_REQUEST['url']);
$filename = 'tor.torrent'; //default name
if(preg_match("/http:\/\/[\w\.]*torrents.ru/",$url,$mass)){
// torrents.ru!!!!
if(preg_match("/^http.*\?t=([0-9]*)$/",$url,$mass))
{
$filename = "[torrents.ru].t".$mass[1].".torrent";
}
$login = '';
$pass = '';
$cmd_login = "wget -nv --post-data 'login_username=".$login."&login_password=".$pass."&ses_short=1&login=' --save-cookies=tor-cookie login.torrents.ru/forum/login.php --referer=http://torrents.ru/forum/index.php -O ./logintest.html";
$cmd_download = "wget --keep-session-cookies --load-cookies=tor-cookie --save-cookies=tor-cookie ".$url." -O ".$filename;
$mime_good = "BitTorrent file";
$cmd_mime = "file -b ";
//Try download use old cookies
$ret = shell_exec($cmd_download);
//Check torrent file
if($mime_good != trim(shell_exec($cmd_mime.$filename))){
// download fail, must login
$ret = shell_exec($cmd_login);
sleep(1);
$ret = shell_exec($cmd_download);
if($mime_good != trim(shell_exec($cmd_mime.$filename))){
echo "ERROR!!!";
exit(0);
}
}
// torrent file loaded, now we can upload it
header( "Content-Type: application/x-bittorrent;" );
header( "Content-Disposition: inline; filename=\"".$filename."\"" );
readfile($filename);
unlink($filename);
}// if torrents.ru
else
{
// NO torrents.ru
$filename = basename($url);
header( "Content-Type: application/x-bittorrent;" );
header( "Content-Disposition: inline; filename=\"".$filename."\"" );
readfile($url);
}
?>
addTorrent: function(torrentURL, callback) {
autotrans.log(autotrans.strings.getString("extensions.autotrans.adding_url") + ": " + torrentURL);
var transURL = autotrans.prefService.getCharPref("extensions.autotrans.url");
torrentURL = torrentURL.replace(/&/g,"%26");
torrentURL = torrentURL.replace(/:\/\//g,"%3A%2F%2F");
torrentURL = torrentURL.replace(/\?/g,"%3F");
torrentURL = torrentURL.replace(/=/g,"%3D");
torrentURL = "http://localhost/torrent.php?url=".concat(torrentURL);
autotrans.ajaxToUrl(transURL, autotrans.jsonService.encode({ method: "torrent-add", arguments: { filename: torrentURL } }), callback);
},
contextMenuVisible: function() {
if (autotrans.prefService.getBoolPref("extensions.autotrans.extfilter")) {
// Only show context menu item if selected file has torrent extension or mime-type
var visible = false;
if (gContextMenu.onLink) {
/*try {
var request = new XMLHttpRequest();
request.open("HEAD", gContextMenu.linkURL, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var mime = request.getResponseHeader("Content-Type");
autotrans.showContextMenu(mime == "application/x-bittorrent");
}
}
request.send(null);
} catch (e) {
autotrans.log(autotrans.strings.getString("extensions.autotrans.error") + ": " + e);
}*/
visible = /\.torrent$/.test(gContextMenu.linkURL);
if(!visible ) visible = /\.torrent$/.test(gContextMenu.linkText());
}
return visible;
} else {
return true;
}
},
Source: https://habr.com/ru/post/79190/
All Articles