Ejemplo n.º 1
0
function benc($str)
{
    if (is_string($str)) {
        //string
        return strlen($str) . ':' . $str;
    }
    if (is_numeric($str)) {
        //integer
        return 'i' . $str . 'e';
    }
    if (is_array($str)) {
        $ret_str = '';
        //the return string
        $k = key($str);
        //we check the 1st key, if the key is 0 then is a list if not a dictionary
        foreach ($str as $var => $val) {
            if ($k) {
                //is dictionary
                $ret_str .= benc($var);
                //bencode the var
            }
            $ret_str .= benc($val);
            //we recursivly bencode the contents
        }
        if ($k) {
            //is dictionary
            return 'd' . $ret_str . 'e';
        }
        return 'l' . $ret_str . 'e';
    }
}
Ejemplo n.º 2
0
Archivo: benc.php Proyecto: latik/xbt
function benc_list($a)
{
    $s = 'l';
    foreach ($a as $e) {
        $s .= benc($e);
    }
    $s .= 'e';
    return $s;
}
Ejemplo n.º 3
0
function benc_dict($d)
{
    $s = "d";
    $keys = array_keys($d);
    sort($keys);
    foreach ($keys as $k) {
        $v = $d[$k];
        $s .= benc_str($k);
        $s .= benc($v);
    }
    $s .= "e";
    return $s;
}
Ejemplo n.º 4
0
    // ///////////////////////////END///////////////////////////////////
    if (!$ret) {
        if (mysql_errno() == 1062) {
            bark("#{$i} torrent was already uploaded!");
        }
        bark("mysql puked: " . mysql_error());
    }
    $id = mysql_insert_id();
    $ids[] = $id;
    @mysql_query("DELETE FROM files WHERE torrent = {$id}");
    foreach ($filelist as $file) {
        @mysql_query("INSERT INTO files (torrent, filename, size) VALUES ({$id}, " . sqlesc($file[0]) . "," . $file[1] . ")");
    }
    $fp = fopen("{$torrent_dir}/{$id}.torrent", "w");
    if ($fp) {
        @fwrite($fp, benc($dict[$i]), strlen(benc($dict[$i])));
        fclose($fp);
    }
    // ===add karma
    mysql_query("UPDATE users SET seedbonus = seedbonus+75.0 WHERE id = {$CURUSER['id']}") or sqlerr(__FILE__, __LINE__);
    // ===end
    // //////new torrent upload detail sent to shoutbox//////////
    autoshout($message);
    // ///////////////////////////end///////////////////////////////////
    $i++;
}
function dict_check($d, $s)
{
    // echo $d["type"];
    // print_r($d);
    if ($d["type"] != "dictionary") {
Ejemplo n.º 5
0
if (!$ret) {
    if (mysql_errno() == 1062) {
        bark($lang_takeupload['std_torrent_existed']);
    }
    bark("mysql puked: " . mysql_error());
    //bark("mysql puked: ".preg_replace_callback('/./s', "hex_esc2", mysql_error()));
}
$id = mysql_insert_id();
@sql_query("DELETE FROM files WHERE torrent = {$id}");
foreach ($filelist as $file) {
    @sql_query("INSERT INTO files (torrent, filename, size) VALUES ({$id}, " . sqlesc($file[0]) . "," . $file[1] . ")");
}
//move_uploaded_file($tmpname, "$torrent_dir/$id.torrent");
$fp = fopen("{$torrent_dir}/{$id}.torrent", "w");
if ($fp) {
    @fwrite($fp, benc($dict), strlen(benc($dict)));
    fclose($fp);
}
//===add karma
KPS("+", $uploadtorrent_bonus, $CURUSER["id"]);
//===end
write_log("Torrent {$id} ({$torrent}) was uploaded by {$anon}");
//===notify people who voted on offer thanks CoLdFuSiOn :)
if ($is_offer) {
    $res = sql_query("SELECT `userid` FROM `offervotes` WHERE `userid` != " . $CURUSER["id"] . " AND `offerid` = " . sqlesc($offerid) . " AND `vote` = 'yeah'") or sqlerr(__FILE__, __LINE__);
    while ($row = mysql_fetch_assoc($res)) {
        $pn_msg = $lang_takeupload_target[get_user_lang($row["userid"])]['msg_offer_you_voted'] . $torrent . $lang_takeupload_target[get_user_lang($row["userid"])]['msg_was_uploaded_by'] . $CURUSER["username"] . $lang_takeupload_target[get_user_lang($row["userid"])]['msg_you_can_download'] . "[url=" . get_protocol_prefix() . "{$BASEURL}/details.php?id={$id}&hit=1]" . $lang_takeupload_target[get_user_lang($row["userid"])]['msg_here'] . "[/url]";
        //=== use this if you DO have subject in your PMs
        $subject = $lang_takeupload_target[get_user_lang($row["userid"])]['msg_offer'] . $torrent . $lang_takeupload_target[get_user_lang($row["userid"])]['msg_was_just_uploaded'];
        //=== use this if you DO NOT have subject in your PMs
        //$some_variable .= "(0, $row[userid], '" . date("Y-m-d H:i:s") . "', " . sqlesc($pn_msg) . ")";
function benc_resp($d)
{
    benc_resp_raw(benc(array(type => "dictionary", value => $d)));
}
Ejemplo n.º 7
0
    bark("mysql puked: " . mysql_error());
}
$id = mysql_insert_id();
@mysql_query("DELETE FROM files WHERE torrent = {$id}");
function file_list($arr, $id)
{
    foreach ($arr as $v) {
        $new[] = "({$id}," . sqlesc($v[0]) . "," . $v[1] . ")";
    }
    return join(",", $new);
}
mysql_query("INSERT INTO files (torrent, filename, size) VALUES " . file_list($filelist, $id));
//#Morgan: Instead of moving the uploaded torrent just create a new one with the simpler announce url
#move_uploaded_file($tmpname, "$torrent_dir/$id.torrent");
$morgan_fh = fopen("{$torrent_dir}/{$id}.torrent", 'w');
fwrite($morgan_fh, benc($my_dict));
fclose($morgan_fh);
write_log("Torrent {$id} ({$torrent}) was uploaded by " . $CURUSER["username"]);
/* RSS feeds */
require_once "rss_old.php";
/* Email notifs */
/*******************

$res = mysql_query("SELECT name FROM categories WHERE id=$catid") or sqlerr();
$arr = mysql_fetch_assoc($res);
$cat = $arr["name"];
$res = mysql_query("SELECT email FROM users WHERE enabled='yes' AND notifs LIKE '%[cat$catid]%'") or sqlerr();
$uploader = $CURUSER['username'];

$size = mksize($totallen);
$description = ($html ? strip_tags($descr) : $descr);
Ejemplo n.º 8
0
     happyLog($CURUSER["id"], $id, $multiplier);
     mysql_query("INSERT INTO happyhour (userid, torrentid, multiplier ) VALUES (" . sqlesc($CURUSER["id"]) . " , " . sqlesc($id) . ", " . sqlesc($multiplier) . " )") or sqlerr(__FILE__, __LINE__);
 }
 // Passkey Mod
 require_once "include/benc.php";
 if ($row["vip"] == 'yes' && get_user_class() < UC_VIP) {
     stdmsg("Sorry...", "You are not allowed to download this torrent");
     exit;
 }
 $dict = bdec_file($fn, 1024 * 1024);
 $dict['value']['announce']['value'] = "{$BASEURL}/announce.php?passkey={$CURUSER['passkey']}";
 $dict['value']['announce']['string'] = strlen($dict['value']['announce']['value']) . ":" . $dict['value']['announce']['value'];
 $dict['value']['announce']['strlen'] = strlen($dict['value']['announce']['string']);
 // download as zip file by putyn tbdev
 $name = str_replace(array(" ", ".", "-"), "_", $row["name"]);
 $new = benc($dict);
 $f = $torrent_dir . '/' . $name . '.torrent';
 $newFile = fopen($f, "w");
 fwrite($newFile, $new);
 fclose($newFile);
 $file = array();
 $zip = new PHPZip();
 $file[] = "{$f}";
 $fName = "{$torrent_dir}/{$name}.zip";
 $zip->Zip($file, $fName);
 $zip->forceDownload($fName);
 unlink($torrent_dir . '/' . $name . '.torrent');
 unlink($torrent_dir . '/' . $name . '.zip');
 /**
  * ********************************** uploadpos people only ***************************************
  */
function benc_resp($d)
{
    benc_resp_raw(benc(array('type' => 'dictionary', 'value' => $d)));
}
Ejemplo n.º 10
0
    $torrent_id = $_GET['torrent'];
    $torrent = new DB("torrents");
    $torrent->setColPrefix("torrent_");
    $torrent->select("torrent_id = '" . $torrent_id . "'");
    if (!$torrent->numRows()) {
        throw new Exception("File not found");
    }
    $torrent->nextRecord();
    if (!isset($_GET['passkey'])) {
        $acl = new Acl(USER_ID);
    } else {
        $db = new DB("users");
        $db->setColPrefix("user_");
        $db->select("user_passkey = '" . $db->escape($_GET['passkey']) . "'");
        if (!$db->numRows()) {
            throw new Exception("user not found");
        }
        $db->nextRecord();
        $acl = new Acl($db->id);
    }
    $fn = PATH_TORRENTS . $torrent->id . ".torrent";
    $dict = bdec_file($fn, filesize($fn));
    $dict['value']['announce']['value'] = CMS_URL . "announce.php?passkey=" . $acl->passkey;
    $dict['value']['announce']['string'] = strlen($dict['value']['announce']['value']) . ":" . $dict['value']['announce']['value'];
    $dict['value']['announce']['strlen'] = strlen($dict['value']['announce']['string']);
    header('Content-Disposition: attachment; filename="' . $torrent->filename . '"');
    header("Content-Type: application/x-bittorrent");
    die(benc($dict));
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
Ejemplo n.º 11
0
 public function download($id)
 {
     $torrent = $this->get($id);
     include 'benc.php';
     $filepath = $this->torrentDir . $torrent["id"] . ".torrent";
     if (!file_exists($filepath)) {
         throw new Exception('Torrentfilen saknas.');
     }
     if ($this->user->getHttps()) {
         $announce = Helper::$trackerUrlSsl . "/tracker.php/" . $this->user->getPasskey() . "/announce";
     } else {
         $announce = Helper::$trackerUrl . "/tracker.php/" . $this->user->getPasskey() . "/announce";
     }
     $dict = bdec_file($filepath, filesize($filepath));
     $dict['value']['announce']['value'] = $announce;
     $dict['value']['announce']['string'] = strlen($dict['value']['announce']['value']) . ":" . $dict['value']['announce']['value'];
     $dict['value']['announce']['strlen'] = strlen($dict['value']['announce']['string']);
     $dict["value"]["comment"]["type"] = "string";
     $dict["value"]["comment"]["value"] = Helper::$siteName;
     $dict["value"]["comment"]["strlen"] = strlen(strlen(Helper::$siteName) . ":" . Helper::$siteName);
     $dict["value"]["comment"]["string"] = strlen(Helper::$siteName) . ":" . Helper::$siteName;
     unset($dict['value']['announce-list']);
     header('Content-Disposition: attachment;filename="' . $torrent['filename'] . '"');
     header("Content-Type: application/x-bittorrent");
     print benc($dict);
     exit;
 }
Ejemplo n.º 12
0
 public function download($id, $passkey = null)
 {
     $useHttps = null;
     if ($passkey) {
         $sth = $this->db->prepare("SELECT https FROM users WHERE passkey = ? AND enabled = 'yes'");
         $sth->bindParam(1, $passkey, PDO::PARAM_STR);
         $sth->execute();
         $user = $sth->fetch(PDO::FETCH_ASSOC);
         if (!$user) {
             throw new Exception(L::get("USER_NOT_EXIST"), 404);
         }
         $useHttps = $user["https"] == 1;
     } else {
         $useHttps = $this->user->getHttps();
         $passkey = $this->user->getPasskey();
     }
     $torrent = $this->get($id);
     include 'benc.php';
     $filepath = $this->torrentDir . $torrent["id"] . ".torrent";
     if (!file_exists($filepath)) {
         throw new Exception(L::get("TORRENT_NOT_FOUND"), 404);
     }
     if ($useHttps) {
         $announce = Config::TRACKER_URL_SSL . "/tracker.php/" . $passkey . "/announce";
     } else {
         $announce = Config::TRACKER_URL . "/tracker.php/" . $passkey . "/announce";
     }
     $dict = bdec_file($filepath, filesize($filepath));
     $dict['value']['announce']['value'] = $announce;
     $dict['value']['announce']['string'] = strlen($dict['value']['announce']['value']) . ":" . $dict['value']['announce']['value'];
     $dict['value']['announce']['strlen'] = strlen($dict['value']['announce']['string']);
     $dict["value"]["comment"]["type"] = "string";
     $dict["value"]["comment"]["value"] = Config::SITE_NAME;
     $dict["value"]["comment"]["strlen"] = strlen(strlen(Config::SITE_NAME) . ":" . Config::SITE_NAME);
     $dict["value"]["comment"]["string"] = strlen(Config::SITE_NAME) . ":" . Config::SITE_NAME;
     unset($dict['value']['announce-list']);
     header('Content-Disposition: attachment;filename="' . $torrent['filename'] . '"');
     header("Content-Type: application/x-bittorrent");
     print benc($dict);
     exit;
 }
Ejemplo n.º 13
0
if (!$row || !is_file($fn) || !is_readable($fn))
	httperr();


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

if (strlen($CURUSER['passkey']) != 32) {

$CURUSER['passkey'] = md5($CURUSER['username'].get_date_time().$CURUSER['passhash']);

mysql_query("UPDATE users SET passkey='$CURUSER[passkey]' WHERE id=$CURUSER[id]");

}



$dict = bdec_file($fn, filesize($fn));

$dict['value']['announce']['value'] = "$BASEURL/announce.php?passkey=$CURUSER[passkey]";

$dict['value']['announce']['string'] = strlen($dict['value']['announce']['value']).":".$dict['value']['announce']['value'];

$dict['value']['announce']['strlen'] = strlen($dict['value']['announce']['string']);

header('Content-Disposition: attachment; filename="'.$row['filename'].'"');

header('Content-Type: application/x-bittorrent');
print(benc($dict)); 

?>
Ejemplo n.º 14
0
 function doubleUp()
 {
     $this->_dict = bdec(benc($this->_dict));
 }
Ejemplo n.º 15
0
header ("Last-Modified: ".date("D, d M Y H:i:s"));
header ("Cache-Control: no-store, no-cache, must-revalidate");
header ("Cache-Control: post-check=0, pre-check=0", false);
header ("Pragma: no-cache");
header ("X-Powered-By: ".VERSION." (c) ".date("Y")." ".$SITENAME."");
header ("Accept-Ranges: bytes");
header ("Connection: close");
header ("Content-Transfer-Encoding: binary");
*/
header("Content-Type: application/x-bittorrent");
if (str_replace("Gecko", "", $_SERVER['HTTP_USER_AGENT']) != $_SERVER['HTTP_USER_AGENT']) {
    header("Content-Disposition: attachment; filename=\"{$torrentnameprefix}." . $row["save_as"] . ".torrent\" ; charset=utf-8");
} else {
    if (str_replace("Firefox", "", $_SERVER['HTTP_USER_AGENT']) != $_SERVER['HTTP_USER_AGENT']) {
        header("Content-Disposition: attachment; filename=\"{$torrentnameprefix}." . $row["save_as"] . ".torrent\" ; charset=utf-8");
    } else {
        if (str_replace("Opera", "", $_SERVER['HTTP_USER_AGENT']) != $_SERVER['HTTP_USER_AGENT']) {
            header("Content-Disposition: attachment; filename=\"{$torrentnameprefix}." . $row["save_as"] . ".torrent\" ; charset=utf-8");
        } else {
            if (str_replace("IE", "", $_SERVER['HTTP_USER_AGENT']) != $_SERVER['HTTP_USER_AGENT']) {
                header("Content-Disposition: attachment; filename=" . str_replace("+", "%20", rawurlencode("{$torrentnameprefix}." . $row["save_as"] . ".torrent")));
            } else {
                header("Content-Disposition: attachment; filename=" . str_replace("+", "%20", rawurlencode("{$torrentnameprefix}." . $row["save_as"] . ".torrent")));
            }
        }
    }
}
//header ("Content-Disposition: attachment; filename=".$row["filename"]."");
//ob_implicit_flush(true);
print benc($dict);
 function move($destfile)
 {
     move_uploaded_file($this->_tmpname, $destfile);
     $fp = fopen($destfile, "w");
     if ($fp) {
         @fwrite($fp, benc($this->dict->_dict), strlen(benc($this->dict->_dict)));
         fclose($fp);
     }
 }
 function download($id)
 {
     $this->autoRender = false;
     $this->autoLayout = false;
     Configure::write('debug', '0');
     app::import('vendor', 'ztracker/dict');
     app::import('vendor', 'ztracker/global');
     $tfile = "../torrents/{$id}.torrent";
     $torrent = $this->Torrent->find(array('id' => $id));
     $user = $this->User->find(array('username' => $this->ZTAuth->user('username')));
     if (strlen($user['User']['passkey']) != 40) {
         $user['User']['passkey'] = sha1($user['User']['username'] . get_date_time() . $user['User']['username']);
         $this->User->save($user['User']);
     }
     $passkey = $user['User']['passkey'];
     $dict = bdec_file($tfile, 1024 * 1024);
     $dict['value']['announce']['value'] = $this->webroot . "announce.php?passkey={$passkey}";
     $dict['value']['announce']['string'] = strlen($dict['value']['announce']['value']) . ":" . $dict['value']['announce']['value'];
     $dict['value']['announce']['strlen'] = strlen($dict['value']['announce']['string']);
     header("Expires: Tue, 1 Jan 2000 00:00:00 GMT");
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     header("Cache-Control: no-store, no-cache, must-revalidate");
     header("Cache-Control: post-check=0, pre-check=0", false);
     header("Pragma: no-cache");
     header("X-Powered-by: ZTracker (c) ZTSoft Research Lab - http://bymep.com");
     header("Accept-Ranges: bytes");
     header("Connection: close");
     header("Content-Transfer-Encoding: binary");
     header("Content-Type: application/x-bittorrent");
     header("Content-Disposition: attachment; filename=\"" . $torrent['Torrent']['filename'] . "\"");
     print benc($dict);
     exit;
 }