访客也可以从TorrentTrade v3下载Torrent

时间:2019-04-08 22:29:00

标签: php

我也想从下载页面以Guest身份下载torrent文件。 我正在使用TorrentTrade脚本,该脚本设置为Memberonly模式,当用户登录时,他们可以下载.torrent文件,该文件也为他们分配了密码,我想知道我应该由来宾添加或从download.php文件中修改什么代码也要下载具有密码的.torrent文件。

<?php
require_once("backend/functions.php");
dbconn();

if ($_GET["passkey"]) {
    $CURUSER = mysqli_fetch_assoc(SQL_Query_exec("SELECT * FROM users INNER JOIN groups ON users.class=groups.group_id WHERE passkey=".sqlesc($_GET["passkey"])." AND enabled='yes' AND status='confirmed'"));
}

//check permissions
if ($site_config["MEMBERSONLY"]){
    loggedinonly();

    if($CURUSER["can_download"]=="no")
        show_error_msg(T_("ERROR"), T_("NO_PERMISSION_TO_DOWNLOAD"), 1);
}

$id = (int)$_GET["id"];

if (!$id)
    show_error_msg(T_("ID_NOT_FOUND"), T_("ID_NOT_FOUND_MSG_DL"), 1);

$res = SQL_Query_exec("SELECT filename, banned, external, announce FROM torrents WHERE id =".intval($id));
$row = mysqli_fetch_assoc($res);

$torrent_dir = $site_config["torrent_dir"];

$fn = "$torrent_dir/$id.torrent";

if (!$row)
    show_error_msg(T_("FILE_NOT_FOUND"), T_("ID_NOT_FOUND"),1);
if ($row["banned"] == "yes")
    show_error_msg(T_("ERROR"), T_("BANNED_TORRENT"), 1);
if (!is_file($fn))
    show_error_msg(T_("FILE_NOT_FOUND"), T_("FILE_NOT_FILE"), 1);
if (!is_readable($fn))
    show_error_msg(T_("FILE_NOT_FOUND"), T_("FILE_UNREADABLE"), 1);

$name = $row['filename'];
$friendlyurl = str_replace("http://","",$site_config["SITEURL"]);
$friendlyname = str_replace(".torrent","",$name);
$friendlyext = ".torrent";
$name = $friendlyname ."[". $friendlyurl ."]". $friendlyext;

SQL_Query_exec("UPDATE torrents SET hits = hits + 1 WHERE id = $id");

require_once("backend/BEncode.php");
require_once("backend/BDecode.php");

//if user dont have a passkey generate one, only if tracker is set to members only
if ($site_config["MEMBERSONLY"]){
    if (strlen($CURUSER['passkey']) != 32) {
        $rand = array_sum(explode(" ", microtime()));
        $CURUSER['passkey'] = md5($CURUSER['username'].$rand.$CURUSER['secret'].($rand*mt_rand()));
        SQL_Query_exec("UPDATE users SET passkey='$CURUSER[passkey]' WHERE id=$CURUSER[id]");
    }
}

if ($row["external"]!='yes' && $site_config["MEMBERSONLY"]){// local torrent so add passkey
    $dict = BDecode(file_get_contents($fn));
    $dict['announce'] = sprintf($site_config["PASSKEYURL"], $CURUSER["passkey"]);
    unset($dict['announce-list']);

    $data = BEncode($dict);

    header('Content-Disposition: attachment; filename="'.$name.'"');

    //header('Content-Length: ' . strlen($data)); 

    header("Content-Type: application/x-bittorrent");

    print $data; 

}else{// external torrent so no passkey needed

    header('Content-Disposition: attachment; filename="'.$name.'"');

    header('Content-Length: ' . filesize($fn));  

    header("Content-Type: application/x-bittorrent");

    readfile($fn); 
}

mysqli_close($GLOBALS["DBconnector"]);
?>

这是我的download.php文件,请同时进行指导以进行更改以获取作为Guest的下载文件,以及会员,成员和来宾都应获取下载的.torrent文件。

0 个答案:

没有答案