Ejemplo n.º 1
0
 /**
  * Info
  * @param type $d
  * @return string
  */
 static function benc_dict($d)
 {
     $s = "d";
     $keys = array_keys($d);
     sort($keys);
     foreach ($keys as $k) {
         $v = $d[$k];
         $s .= Bcode::benc_str($k);
         $s .= Bcode::benc($v);
     }
     $s .= "e";
     return $s;
 }
Ejemplo n.º 2
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 = Bcode::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(Bcode::benc($dict));
} catch (Exception $e) {
    echo $e->getMessage(), "\n";
}
Ejemplo n.º 3
0
 $db->save_as = $filename;
 $db->search_text = searchfield("{$torrentName} {$dname}");
 $db->nfo = $nfo;
 $db->size = $totallen;
 $db->added = time();
 $db->type = $type;
 $db->userid = USER_ID;
 $db->numfiles = count($filelist);
 $db->category = $_POST['type'];
 $db->youtube = $_POST['youtube'];
 $db->imdb = $_POST['imdb'];
 $db->freeleech = isset($_POST['freeleech']) ? 1 : 0;
 $db->insert();
 $fp = fopen(PATH_TORRENTS . "{$id}.torrent", "w");
 if ($fp) {
     @fwrite($fp, Bcode::benc($dict), strlen(Bcode::benc($dict)));
     fclose($fp);
     $db->query("INSERT INTO {PREFIX}torrents_files (file_torrent, file_name, file_size) VALUES " . file_list($filelist, $id));
     if (isset($_POST['imdb']) && !empty($_POST['imdb'])) {
         $link = $_POST['imdb'];
     } else {
         $link = $descr;
     }
     $m = preg_match("/tt\\d{7}/", $link, $ids);
     if ($m) {
         $link = "http://www.imdb.com/title/" . $ids[0];
         $db = new DB("torrents");
         $db->torrent_imdb = $link;
         $db->update("torrent_id = '" . $db->escape($id) . "'");
         preg_match("#tt(?P<imdbId>[0-9]{7,7})#", $link, $matches);
         if (count($matches) == 0) {
Ejemplo n.º 4
0
include "../init.php";
if (isset($_POST['upload'])) {
    try {
        if (!isset($_FILES['torrent'])) {
            throw new Exception("Missing torrent data");
        }
        if (empty($_FILES['torrent']['name'])) {
            throw new Exception("No torrent file selected");
        }
        $file = $_FILES['torrent'];
        $ext = explode(".", $file['name']);
        $ext = end($ext);
        if ($ext != "torrent") {
            throw new Exception("A torrent file has to end with .torrent");
        }
        $filetmp = $_FILES['torrent']['tmp_name'];
        $dict = Bcode::bdec_file($filetmp, filesize($filetmp));
        list($ann, $info) = Bcode::dict_check($dict, "announce(string):info");
        $infohash = strtoupper(sha1($info["string"]));
        $filename = $infohash;
        $file_path = _configs()->paths->torrents . $filename;
        $magnet_link = 'magnet:?xt=urn:btih:' . $infohash . "&tr=" . implode("&tr=", _configs()->trackers);
        if (move_uploaded_file($file['tmp_name'], $file_path . '.torrent')) {
            $array = array("error" => false, "message" => "The torrent has been successfully uploaded", "url" => _configs()->website->url . $filename, "magnet" => $magnet_link);
            die(json_encode($array));
        }
    } catch (Exception $e) {
        $array = array("error" => true, "message" => $e->getMessage());
        die(json_encode($array));
    }
}
Ejemplo n.º 5
0
 /**
  * error Handler.
  * @param string $msg 
  */
 private function halt($msg = null)
 {
     if (!$this->configs['system']['live'] && !$this->announce_debug) {
         $error_message = null;
         $error_message .= "MYSQL_ERROR - " . $this->db_name . "<br />\n";
         $error_message .= "<b>Database error:</b> " . $msg . "<br />\n";
         $error_message .= "<b>MYSQL Error</b>: " . $this->errno . " (" . $this->error . ")<br />\n";
         echo $error_message;
     }
     if (!$this->announce_debug) {
         die("This page is unavailable at the moment. Please try again.");
     } else {
         Bcode::benc_resp(array('failure reason' => array('type' => 'string', 'value' => "MYSQL Error: {$msg} in " . $this->table)));
         die;
     }
 }
Ejemplo n.º 6
0
            $db->ip = $data['ip'];
            $db->port = $data['port'];
            $db->uploaded = 0;
            $db->downloaded = 0;
            $db->to_go = $data['left'];
            $db->seeder = $data['seeder'];
            $db->started = time();
            $db->last_action = time();
            $db->passkey = $data['passkey'];
            $db->connectable = $data['connectable'];
            $db->insert();
            if ($data['seeder']) {
                $torrent_query[] = "torrent_seeders = torrent_seeders + 1";
            } else {
                $torrent_query[] = "torrent_leechers = torrent_leechers + 1";
            }
        }
    }
    if ($data['seeder']) {
        $torrent_query[] = "torrent_visible = 1";
        $torrent_query[] = "torrent_last_action = '" . time() . "'";
    }
    $db = new DB();
    if (count($torrent_query)) {
        $db->query("UPDATE {PREFIX}torrents SET " . implode(", ", $torrent_query) . " WHERE torrent_id = '{$torrent_id}'");
    }
    Bcode::benc_resp_raw(implode("", $callback));
} catch (Exception $e) {
    Bcode::benc_resp(array('failure reason' => array('type' => 'string', 'value' => $e->getMessage())));
    exit;
}