Exemple #1
0
 function __construct($password = NULL, $host = "127.0.0.1", $port = 11234)
 {
     $this->socket = stream_socket_client("udp://" . $host . ":" . $port, $errorno, $errorstr);
     if (!$this->socket) {
         die("Failed to connect, Error #{$errorno}: {$errorstr}");
     }
     fwrite($this->socket, bencode(array("q" => "ping")));
     // Try to ping it
     $returndata = fread($this->socket, $this->buffersize);
     if ($returndata != "d1:q4:ponge") {
         die("Looks like {$host}:{$port} isn't a cjdns admin port");
     }
     $this->password = $password;
     $page = 0;
     while (True) {
         $request = array("q" => "Admin_availableFunctions", "args" => array("page" => $page));
         fwrite($this->socket, bencode($request));
         $result = bdecode(fread($this->socket, $this->buffersize));
         foreach ($result['availableFunctions'] as $function => $description) {
             $this->functions[$function] = $description;
         }
         if (isset($result['more'])) {
             $page++;
         } else {
             break;
         }
     }
 }
 static function Decode($str)
 {
     $res = bdecode($str);
     if ($res === null) {
         throw new EBEncode(null, 'Cannot decode bencoded data.', 'string: ' . $str);
     } else {
         return $res;
     }
 }
Exemple #3
0
function build_tor_filelist($file_contents)
{
    global $lang;
    if (!($tor = bdecode($file_contents))) {
        return $lang['TORFILE_INVALID'];
    }
    $torrent = new torrent($tor);
    return $torrent->get_filelist();
}
Exemple #4
0
}
if (!preg_match('/^(.+)\\.torrent$/si', $fname, $matches)) {
    bark("Неверное имя файла (не .torrent).");
}
$shortfname = $torrent = $matches[1];
if (!empty($_POST["name"])) {
    $torrent = unesc($_POST["name"]);
}
$tmpname = $f["tmp_name"];
if (!is_uploaded_file($tmpname)) {
    bark("eek");
}
if (!filesize($tmpname)) {
    bark("Пустой файл!");
}
$dict = bdecode(file_get_contents($tmpname));
if (!isset($dict)) {
    bark("Что за хрень ты загружаешь? Это не бинарно-кодированый файл!");
}
if (get_user_class() >= UC_ADMINISTRATOR && in_array($_POST['free'], array('yes', 'silver', 'no'))) {
    $free = $_POST['free'];
}
if ($_POST['not_sticky'] == 'no' and get_user_class() >= UC_ADMINISTRATOR) {
    $not_sticky = "no";
} else {
    $not_sticky = "yes";
}
if ($_POST['multi'] == 'yes') {
    $multi_torrent = 'yes';
} else {
    $multi_torrent = 'no';
Exemple #5
0
            $hashes[] = urldecode(substr($request_var, 10));
        }
    }
    if (count($hashes[0]) == 0) {
        bt_message('Please supply an info_hash', BITTORRENT_MESSAGE_ERROR);
    }
    foreach ($hashes as $info_hash) {
        $info_hash;
        $valid = db_result(db_query("SELECT nid FROM {bt_torrents} WHERE info_hash = %b", $info_hash));
        if ($valid) {
            if (variable_get('bt_tracker_scrape_scope', 0) == 0) {
                $response['files'][$info_hash] = db_fetch_array(db_query("SELECT bt.seeders AS complete, bt.leechers AS incomplete, bt.downloaded FROM {bt_torrents} bt WHERE bt.info_hash = %b", $info_hash));
            } else {
                $response['files'][$info_hash]['complete'] = db_result(db_query("SELECT COUNT(btau.ip) FROM {bt_tracker_active_users} btau WHERE btau.bytes_left = 0 AND btau.info_hash = %b", $info_hash));
                $response['files'][$info_hash]['incomplete'] = db_result(db_query("SELECT COUNT(btau.ip) FROM {bt_tracker_active_users} btau WHERE (NOT btau.bytes_left = 0) AND btau.info_hash = %b", $info_hash));
                $response['files'][$info_hash]['completed'] = db_result(db_query("SELECT bt.downloaded FROM {bt_torrents} bt WHERE bt.info_hash = %b", $info_hash));
            }
            $struct = strip_excess(bdecode(db_result(db_query('SELECT metadata FROM {bt_torrents} WHERE info_hash = %b', $info_hash))));
            $response['files'][$info_hash]['name'] = $struct['info']['name'];
        }
    }
    if (count($response['files']) == 0) {
        bt_message('Invalid info hash(s)', BITTORRENT_MESSAGE_ERROR);
    }
    $response['flags'] = array();
    $response['flags']['min_request_interval'] = variable_get('bt_tracker_scrape_interval', 900);
    bencode_response_raw(bencode($response));
} else {
    // Let the client know that the tracker is offline.
    bt_message('Tracker is Offline', BITTORRENT_MESSAGE_ERROR);
}
Exemple #6
0
$fn = "{$torrent_dir}/{$id}.torrent";
if (!$row || !is_file($fn) || !is_readable($fn)) {
    stderr($tracker_lang['error'], $tracker_lang['unable_to_read_torrent']);
}
if ($row['banned'] == 'yes' && $row['owner'] != $CURUSER['id'] && get_user_class() < UC_MODERATOR) {
    stderr($tracker_lang['error'], '”пс, а торрентик-то забанен!');
}
sql_query("UPDATE torrents SET hits = hits + 1 WHERE id = " . sqlesc($id));
$name = str_replace(array(',', ';'), '', $name);
require_once "include/BDecode.php";
require_once "include/BEncode.php";
if (strlen($CURUSER['passkey']) != 32) {
    $CURUSER['passkey'] = md5($CURUSER['username'] . get_date_time() . $CURUSER['passhash']);
    sql_query("UPDATE users SET passkey=" . sqlesc($CURUSER[passkey]) . " WHERE id=" . sqlesc($CURUSER[id]));
}
$dict = bdecode(file_get_contents($fn));
//$dict['announce'] = $announce_urls[0]."?passkey=$CURUSER[passkey]";//"$DEFAULTBASEURL/announce.php?passkey=$CURUSER[passkey]";
if (!empty($dict['announce-list'])) {
    $dict['announce-list'][][0] = $announce_urls[0] . "?passkey={$CURUSER['passkey']}";
    // Just add one tracker for multitrackers, we are the last
} else {
    $dict['announce'] = $announce_urls[0] . "?passkey={$CURUSER['passkey']}";
}
//"$DEFAULTBASEURL/announce.php?passkey=$CURUSER[passkey]";
header("Expires: Tue, 1 Jan 1980 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: TBDev Yuna Scatari Edition - http://bit-torrent.kiev.ua");
header("Accept-Ranges: bytes");
Exemple #7
0
         }
         // or else
         die("The tracker is not alive.");
     }
 } else {
     $request = str_replace("/announce", "/request", $tracker);
     $bdata = @file_get_contents($request);
     if (!$bdata) {
         mysql_close($db);
         die("5:Error");
         // extremely unlikely error
     }
     if (substr($bdata, -1, 1) == "e" and substr($bdata, 0, 1) == "l") {
         // the bdecode library goes insane otherwise
         include "bdecode.php";
         $bdata = bdecode($bdata);
         if (!$row) {
             $query = sprintf("INSERT INTO trackers VALUES ('',%s, NOW(), 1)", quote_smart($tracker));
             mysql_query($query);
             $query = sprintf("SELECT trackerid FROM trackers WHERE url = %s", quote_smart($tracker));
             $result = mysql_query($query);
             $row = mysql_fetch_row($result);
         } else {
             $query = sprintf("UPDATE trackers SET timestamp = NOW(), alive = 1 WHERE url = %s ", quote_smart($tracker));
             mysql_query($query);
         }
         // build insert query
         if (isset($bdata[0])) {
             $query = "INSERT INTO `hashes` (`trackerid`, `infohash`) VALUES ";
             foreach ($bdata as $hash) {
                 $query .= sprintf("(%s, %s),", $row[0], quote_smart(pack("H*", $hash)));
Exemple #8
0
    }
}
foreach ($_optional_keys as $key) {
    if (array_key_exists($key, $_GET)) {
        $request[$key] = $_GET[$key];
    }
}
/**
 * Lookup the info_hash and verify that we are indeed tracking it and it supports web seeding. Retrieve the torrent file should all criteria be met.
 */
$result = db_result(db_query("SELECT web_seed FROM {bt_torrents} btt WHERE btt.info_hash = %b", $request['info_hash']));
if (isset($result) || $result == 0) {
    seed_message(400, 'Tracker is currently not tracking that torrent or the torrent does not support web seeding.', TRUE);
}
// TODO: Add server control settings
$torrent = strip_excess(bdecode(db_result(db_query("SELECT metadata FROM {bt_torrents} btt WHERE info_hash = %b", $request['info_hash']))));
if (array_key_exists('length', $torrent['info'])) {
    // Single file torrent
    $torrent_length = $torrent['info']['length'];
} else {
    // Multiple file torrent
    $torrent_length = 0;
    foreach ($torrent['info']['files'] as $file) {
        $torrent_length += $file['length'];
    }
}
/**
 * Verify that the piece exists within the torrent
 */
if ($request['piece'] != 0) {
    $piece_count = $torrent_length / $torrent['info']['piece length'];
Exemple #9
0
 function bdecode_file($filename)
 {
     $f = file_get_contents($filename, FILE_BINARY);
     return bdecode($f);
 }
if (isset($_GET['info_hash']) && isset($_GET['data'])) {
    $info_hash = $_GET['info_hash'];
    // Checks hash is ok
    if (strlen($info_hash) != 20) {
        $info_hash = stripcslashes($_GET['info_hash']);
    }
    if (strlen($info_hash) != 20) {
        die('HASHFAIL');
        // that's virtually impossible
    }
    $info_hash = bin2hex($info_hash);
    $data = $_GET['data'];
    if (substr($data, -1, 1) == "e" and substr($data, 0, 1) == "l") {
        /* this is done so that the bdecode library does not go insane and crash the server
           when it finds data that is not bencoded */
        $data = bdecode($data);
        // now the data is an array
        $db = mysql_connect($dbhost, $dbuname, $dbpasswd);
        mysql_select_db($dbname, $db);
        foreach ($data as $peerinfo) {
            $iparray = explode(":", $peerinfo);
            $ip2 = $iparray[0];
            $port = (int) $iparray[1];
            $seedorpeer = (int) $iparray[2];
            $time = (int) $iparray[3];
            $peer_ip = explode('.', $ip2);
            $peer_ip = pack("C*", $peer_ip[0], $peer_ip[1], $peer_ip[2], $peer_ip[3]);
            $peer_port = pack("n*", (int) $port);
            // What we have here is the same as announce.php (apart from the timestamp)
            // there should be no need to quote the timestamp integer
            $query = sprintf('INSERT INTO `%s` values(%s, %s, FROM_UNIXTIME(%s))', mysql_real_escape_string($info_hash), quote_smart($peer_ip . $peer_port), $seedorpeer, $time);
function bdecode_file($filename)
{
    if (!($fp = fopen($filename, 'rb'))) {
        return NULL;
    }
    $fc = fread($fp, @filesize($filename));
    fclose($fp);
    return bdecode($fc);
}
function bdecode_file($filename)
{
    $file_contents = file_get_contents($filename);
    return bdecode($file_contents);
}