本文整理匯總了PHP中BDecode函數的典型用法代碼示例。如果您正苦於以下問題:PHP BDecode函數的具體用法?PHP BDecode怎麽用?PHP BDecode使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了BDecode函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: show_error_msg
if (mysql_errno() == 1062) {
show_error_msg(T_("UPLOAD_FAILED"), T_("UPLOAD_ALREADY_UPLOADED"), 1);
}
//Update the members uploaded torrent count
/*if ($ret){
SQL_Query_exec("UPDATE users SET torrents = torrents + 1 WHERE id = $userid");*/
if ($id == 0) {
unlink("{$torrent_dir}/{$fname}");
$message = T_("UPLOAD_NO_ID");
show_error_msg(T_("UPLOAD_FAILED"), $message, 1);
}
rename("{$torrent_dir}/{$fname}", "{$torrent_dir}/{$id}.torrent");
// Edit Torrent Comment
require_once "backend/BDecode.php";
require_once "backend/BEncode.php";
$dict = BDecode(file_get_contents($site_config["torrent_dir"] . "/{$id}.torrent"));
$dict['comment'] = "Torrent downloaded from " . $site_config['SITENAME'];
file_put_contents($site_config["torrent_dir"] . "/{$id}.torrent", BEncode($dict));
// End Edit Torrent Comment
if (count($filelist)) {
foreach ($filelist as $file) {
$dir = '';
$size = $file["length"];
$count = count($file["path"]);
for ($i = 0; $i < $count; $i++) {
if ($i + 1 == $count) {
$fname = $dir . $file["path"][$i];
} else {
$dir .= $file["path"][$i] . "/";
}
}
示例2: error_log
$scrape_metadata = @file_get_contents($scrape_url);
if ($scrape_metadata == false) {
if ($extlogtype >= EXTLOG_VERBOSE) {
error_log("FAILED.\r\n", 3, $extlogfile);
}
} else {
if ($extlogtype >= EXTLOG_VERBOSE) {
error_log("done\r\n", 3, $extlogfile);
}
if ($extlogtype >= EXTLOG_VERBOSE) {
error_log("\t\t\tValidating /scrape data... ", 3, $extlogfile);
}
/*
* Decode the scrape response
*/
$decoded_scrape = BDecode($scrape_metadata);
if (!$decoded_scrape) {
if ($extlogtype >= EXTLOG_VERBOSE) {
error_log("FAILED.\r\n", 3, $extlogfile);
}
} else {
if ($extlogtype >= EXTLOG_VERBOSE) {
error_log("done\r\n", 3, $extlogfile);
}
/*
* Now the fun begins... walk through the decoded output and see if the info_hash is in
* the output, for all of the torrents that belong to this tracker.
*/
if ($extlogtype >= EXTLOG_VERBOSE) {
error_log("\t\t\t\tLooking for " . $scrape_info["info_hash"] . "... ", 3, $extlogfile);
}
示例3: _wobi_addWebseedfiles
function _wobi_addWebseedfiles($torrent_file_path, $relative_path, $httplocation, $hash)
{
$prefix = WOBI_PREFIX;
$fd = fopen($torrent_file_path, "rb") or die(errorMessage() . "File upload error 1</p>");
$alltorrent = fread($fd, filesize($torrent_file_path));
fclose($fd);
$array = BDecode($alltorrent);
// Add in Bittornado HTTP seeding spec
//
//add information into database
$info = $array["info"] or die("Invalid torrent file.");
$fsbase = $relative_path;
// We need single file only!
mysql_query("INSERT INTO " . $prefix . "webseedfiles (info_hash,filename,startpiece,endpiece,startpieceoffset,fileorder) values (\"{$hash}\", \"" . mysql_real_escape_string($fsbase) . "\", 0, " . (strlen($array["info"]["pieces"]) / 20 - 1) . ", 0, 0)");
// Edit torrent file
//
$data_array = $array;
$data_array["httpseeds"][0] = WOBI_URL . "/seed.php";
//$data_array["url-list"][0] = $httplocation;
$to_write = BEncode($data_array);
//write torrent file
$write_httpseed = fopen($torrent_file_path, "wb");
fwrite($write_httpseed, $to_write);
fclose($write_httpseed);
//add in piecelength and number of pieces
$query = "UPDATE " . $prefix . "summary SET piecelength=\"" . $info["piece length"] . "\", numpieces=\"" . strlen($array["info"]["pieces"]) / 20 . "\" WHERE info_hash=\"" . $hash . "\"";
quickQuery($query);
}
示例4: insertTorrent
function insertTorrent($torrent, $info_hash, $filename, $user, $cat)
{
global $TABLE_PREFIX, $TORRENTSDIR, $DBDT;
require_once dirname(__FILE__) . "/../../include/BDecode.php";
require_once dirname(__FILE__) . "/../../include/BEncode.php";
$fd = fopen($torrent, "rb") or die('Impossible d ouvrire le torrent');
$alltorrent = fread($fd, filesize($torrent));
$array = BDecode($alltorrent);
// Announce
$announce = str_replace(array("\r\n", "\r", "\n"), "", $array["announce"]);
// Dipslay all tracker announce
$announces = array();
for ($i = 0; $i < count($array["announce-list"]); $i++) {
$current = $array["announce-list"][$i];
if (is_array($current)) {
$announces[$current[0]] = array("seeds" => 0, "leeches" => 0, "downloaded" => 0);
} else {
$announces[$current] = array("seeds" => 0, "leeches" => 0, "downloaded" => 0);
}
}
$announces[$announce] = array("seeds" => 0, "leeches" => 0, "downloaded" => 0);
// description not writen by user, we get info directly from torrent.
if (isset($array["comment"])) {
$info = mysqli_real_escape_string($DBDT, htmlspecialchars($array["comment"]));
} else {
$info = "";
}
// Size
if (isset($array["info"]) && $array["info"]) {
$upfile = $array["info"];
} else {
$upfile = 0;
}
if (isset($upfile["length"])) {
$size = (double) $upfile["length"];
} else {
if (isset($upfile["files"])) {
// multifiles torrent
$size = 0;
foreach ($upfile["files"] as $file) {
$size += (double) $file["length"];
}
} else {
$size = "0";
}
}
// Query :p
$now = date("Y-m-d H:i:s");
$query = "INSERT INTO {$TABLE_PREFIX}files (info_hash, announces, filename, url, info, category, data, size, comment, external,announce_url, uploader,anonymous, bin_hash)\n VALUES (\n '{$info_hash}',\n '" . mysqli_real_escape_string($DBDT, serialize($announces)) . "',\n '" . mysqli_real_escape_string($DBDT, $filename) . "',\n '{$TORRENTSDIR}/{$info_hash}.btf',\n '{$info}',\n '{$cat}',\n '{$now}',\n '{$size}',\n '" . mysqli_real_escape_string($DBDT, $filename) . "',\n 'yes',\n '{$announce}',\n '{$user}',\n 'false',\n '0x{$info_hash}'\n )";
$result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die(is_object($GLOBALS["___mysqli_ston"]) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false));
}
示例5: scrape
function scrape($url, $infohash = '')
{
global $TABLE_PREFIX;
if (isset($url)) {
$extannunce = str_replace('announce', 'scrape', urldecode($url));
if ($infohash != '') {
$ihash = array();
$ihash = explode('\',\'', $infohash);
$info_hash = '';
foreach ($ihash as $myihash) {
$info_hash .= '&info_hash=' . escapeURL($myihash);
}
$info_hash = substr($info_hash, 1);
$stream = get_remote_file($extannunce . '?' . $info_hash);
} else {
$stream = get_remote_file($extannunce);
}
$stream = trim(stristr($stream, 'd5:files'));
if (strpos($stream, 'd5:files') === false) {
$ret = do_sqlquery('UPDATE ' . $TABLE_PREFIX . 'files SET lastupdate=NOW() WHERE announce_url="' . $url . '"' . ($infohash == '' ? '' : ' AND info_hash IN ("' . $infohash . '")'));
write_log('FAILED update external torrent ' . ($infohash == '' ? '' : '(infohash: ' . $infohash . ')') . ' from ' . $url . ' tracker (not connectable)', '');
return;
}
$array = BDecode($stream);
if (!isset($array) || $array == false || !isset($array['files'])) {
$ret = do_sqlquery('UPDATE ' . $TABLE_PREFIX . 'files SET lastupdate=NOW() WHERE announce_url="' . $url . '"' . ($infohash == '' ? '' : ' AND info_hash IN ("' . $infohash . '")'));
write_log('FAILED update external torrent ' . ($infohash == '' ? '' : '(infohash: ' . $infohash . ')') . ' from ' . $url . ' tracker (not bencode data)', '');
return;
}
$files = $array['files'];
if (!is_array($files)) {
$ret = do_sqlquery('UPDATE ' . $TABLE_PREFIX . 'files SET lastupdate=NOW() WHERE announce_url="' . $url . '"' . ($infohash = '' ? '' : ' AND info_hash IN ("' . $infohash . '")'));
write_log('FAILED update external torrent ' . ($infohash == '' ? '' : '(infohash: ' . $infohash . ')') . ' from ' . $url . ' tracker (probably deleted torrent(s))', '');
return;
}
foreach ($files as $hash => $data) {
$seeders = $data['complete'];
$leechers = $data['incomplete'];
$completed = isset($data['downloaded']) ? $data['downloaded'] : 0;
$torrenthash = bin2hex(stripslashes($hash));
$ret = do_sqlquery('UPDATE ' . $TABLE_PREFIX . 'files SET lastupdate=NOW(), lastsuccess=NOW(), seeds=' . $seeders . ', leechers=' . $leechers . ', finished=' . $completed . ' WHERE announce_url = "' . $url . '"' . ($hash == '' ? '' : ' AND info_hash="' . $torrenthash . '";'));
if (mysql_affected_rows() == 1) {
write_log('SUCCESS update external torrent from ' . $url . ' tracker (infohash: ' . $torrenthash . ')', '');
}
}
}
}
示例6: rating_bar
} else {
$row["rating"] = rating_bar("" . $_GET["id"] . "", 5, 'static');
}
$row["rating"];
# <!--
##################################################################
########################################################################-->
$row["size"] = makesize($row["size"]);
// files in torrent - by Lupin 20/10/05
require_once dirname(__FILE__) . "/include/BDecode.php";
if (file_exists($row["url"])) {
$torrenttpl->set("DISPLAY_FILES", TRUE, TRUE);
$ffile = fopen($row["url"], "rb");
$content = fread($ffile, filesize($row["url"]));
fclose($ffile);
$content = BDecode($content);
$numfiles = 0;
if (isset($content["info"]) && $content["info"]) {
$thefile = $content["info"];
if (isset($thefile["length"])) {
$dfiles[$numfiles]["filename"] = htmlspecialchars($thefile["name"]);
$dfiles[$numfiles]["size"] = makesize($thefile["length"]);
$numfiles++;
} elseif (isset($thefile["files"])) {
foreach ($thefile["files"] as $singlefile) {
$dfiles[$numfiles]["filename"] = htmlspecialchars(implode("/", $singlefile["path"]));
$dfiles[$numfiles]["size"] = makesize($singlefile["length"]);
$numfiles++;
}
} else {
// can't be but...
示例7: ParseTorrent
function ParseTorrent($filename)
{
require_once "BDecode.php";
require_once "BEncode.php";
$TorrentInfo = array();
global $array;
//check file type is a torrent
$torrent = explode(".", $filename);
$fileend = end($torrent);
$fileend = strtolower($fileend);
if ($fileend == "torrent") {
$parseme = @file_get_contents("{$filename}");
if ($parseme == FALSE) {
show_error_msg(T_("ERROR"), T_("PARSE_CONTENTS"), 1);
}
if (!isset($parseme)) {
show_error_msg(T_("ERROR"), T_("PARSE_OPEN"), 1);
} else {
$array = BDecode($parseme);
if ($array === FALSE) {
show_error_msg(T_("ERROR"), T_("PARSE_DECODE"), 1);
} else {
if (!@count($array['info'])) {
show_error_msg(T_("ERROR"), T_("PARSE_OPEN"), 1);
} else {
//Get Announce URL
$TorrentInfo[0] = $array["announce"];
//Get Announce List Array
if (isset($array["announce-list"])) {
$TorrentInfo[6] = $array["announce-list"];
}
//Read info, store as (infovariable)
$infovariable = $array["info"];
// Calculates SHA1 Hash
$infohash = sha1(BEncode($infovariable));
$TorrentInfo[1] = $infohash;
// Calculates date from UNIX Epoch
$makedate = date('r', $array["creation date"]);
$TorrentInfo[2] = $makedate;
// The name of the torrent is different to the file name
$TorrentInfo[3] = $infovariable['name'];
//Get File List
if (isset($infovariable["files"])) {
// Multi File Torrent
$filecount = "";
//Get filenames here
$TorrentInfo[8] = $infovariable["files"];
foreach ($infovariable["files"] as $file) {
$filecount += "1";
$multiname = $file['path'];
//Not needed here really
$multitorrentsize = $file['length'];
$torrentsize += $file['length'];
}
$TorrentInfo[4] = $torrentsize;
//Add all parts sizes to get total
$TorrentInfo[5] = $filecount;
//Get file count
} else {
// Single File Torrent
$torrentsize = $infovariable['length'];
$TorrentInfo[4] = $torrentsize;
//Get file count
$TorrentInfo[5] = "1";
}
// Get Torrent Comment
if (isset($array['comment'])) {
$TorrentInfo[7] = $array['comment'];
}
}
}
}
}
return $TorrentInfo;
}
示例8: stripcslashes
include "BDecode.php";
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");
}
$info_hash = bin2hex($info_hash);
if (!file_exists($info_hash) && !file_exists("./multiseed/{$info_hash}")) {
die("EXPIRED");
}
$data = urldecode($_GET['data']);
$bdata = @BDecode($data);
// $bdata is an array of ip addresses:ports:time
if (!$bdata) {
die("CORRUPT");
}
$handle = fopen($info_hash, "rb+");
flock($handle, LOCK_EX);
$peer_num = intval(filesize($info_hash) / 7);
$data = fread($handle, $peer_num * 7);
$peer = array();
foreach ($bdata as $ip) {
$iparray = explode(":", $ip);
$ip2 = $iparray[0];
$port = $iparray[1];
$time = $iparray[2];
$peer_ip = explode('.', $ip2);
示例9: addTorrent
function addTorrent()
{
global $dbhost, $dbuser, $dbpass, $database;
global $_POST, $_FILES;
require_once "funcsv2.php";
require_once "BDecode.php";
require_once "BEncode.php";
$hash = strtolower($_POST["hash"]);
$db = mysql_connect($dbhost, $dbuser, $dbpass) or die("<p class=\"error\">Couldn't connect to database. contact the administrator</p>");
mysql_select_db($database) or die("<p class=\"error\">Can't open the database.</p>");
if (isset($_FILES["torrent"])) {
if ($_FILES["torrent"]["error"] != 4) {
$fd = fopen($_FILES["torrent"]["tmp_name"], "rb") or die("<p class=\"error\">File upload error 1</p>\n");
is_uploaded_file($_FILES["torrent"]["tmp_name"]) or die("<p class=\"error\">File upload error 2</p>\n");
$alltorrent = fread($fd, filesize($_FILES["torrent"]["tmp_name"]));
$array = BDecode($alltorrent);
if (!$array) {
echo "<p class=\"error\">There was an error handling your uploaded torrent. The parser didn't like it.</p>";
endOutput();
exit;
}
$hash = @sha1(BEncode($array["info"]));
fclose($fd);
unlink($_FILES["torrent"]["tmp_name"]);
}
}
if (isset($_POST["filename"])) {
$filename = clean($_POST["filename"]);
} else {
$filename = "";
}
if (isset($_POST["url"])) {
$url = clean($_POST["url"]);
} else {
$url = "";
}
if (isset($_POST["info"])) {
$info = clean($_POST["info"]);
} else {
$info = "";
}
if (isset($_POST["autoset"])) {
if (strcmp($_POST["autoset"], "enabled") == 0) {
if (strlen($filename) == 0 && isset($array["info"]["name"])) {
$filename = $array["info"]["name"];
}
if (strlen($info) == 0 && isset($array["info"]["piece length"])) {
$info = $array["info"]["piece length"] / 1024 * (strlen($array["info"]["pieces"]) / 20) / 1024;
$info = round($info, 2) . " MB";
if (isset($array["comment"])) {
$info .= " - " . $array["comment"];
}
}
}
$filename = mysql_escape_string($filename);
$url = mysql_escape_string($url);
$info = mysql_escape_string($info);
if (strlen($hash) != 40 || !verifyHash($hash)) {
echo "<p class=\"error\">Error: Info hash must be exactly 40 hex bytes.</p>";
endOutput();
}
$query = "INSERT INTO BTPHP_namemap (info_hash, filename, url, info) VALUES (\"{$hash}\", \"{$filename}\", \"{$url}\", \"{$info}\")";
$status = makeTorrent($hash, true);
quickQuery($query);
if ($status) {
echo "<p class=\"error\">Torrent was added successfully.</p>";
} else {
echo "<p class=\"error\">There were some errors. Check if this torrent had been added previously.</p>";
}
}
endOutput();
}
示例10: transfer_setFileVars
/**
* setFileVars
*/
function transfer_setFileVars()
{
global $cfg, $tmpl, $transfer, $transferLabel, $ch;
// set vars for transfer
$transferFilesList = array();
switch ($ch->type) {
case "torrent":
require_once "inc/classes/BDecode.php";
$tFile = $cfg["transfer_file_path"] . $transfer;
if ($fd = @fopen($tFile, "rd")) {
$alltorrent = @fread($fd, @filesize($tFile));
$btmeta = @BDecode($alltorrent);
@fclose($fd);
}
$transferSizeSum = 0;
if (isset($btmeta) && is_array($btmeta) && isset($btmeta['info'])) {
if (array_key_exists('files', $btmeta['info'])) {
foreach ($btmeta['info']['files'] as $filenum => $file) {
$name = is_array($file['path']) ? implode("/", $file['path']) : $file['path'];
$size = isset($file['length']) && is_numeric($file['length']) ? $file['length'] : 0;
$transferSizeSum += $size;
array_push($transferFilesList, array('name' => $name, 'size' => $size != 0 ? formatBytesTokBMBGBTB($size) : 0));
}
} else {
$size = $btmeta["info"]["piece length"] * (strlen($btmeta["info"]["pieces"]) / 20);
$transferSizeSum += $size;
array_push($transferFilesList, array('name' => $btmeta["info"]["name"], 'size' => formatBytesTokBMBGBTB($size)));
}
}
if (empty($transferFilesList)) {
$tmpl->setvar('transferFilesString', "Empty");
$tmpl->setvar('transferFileCount', count($btmeta['info']['files']));
} else {
$tmpl->setloop('transferFilesList', $transferFilesList);
$tmpl->setvar('transferFileCount', count($transferFilesList));
}
$tmpl->setvar('transferSizeSum', $transferSizeSum > 0 ? formatBytesTokBMBGBTB($transferSizeSum) : 0);
return;
case "wget":
$ch = ClientHandler::getInstance('wget');
$ch->setVarsFromFile($transfer);
$transferSizeSum = 0;
if (!empty($ch->url)) {
require_once "inc/classes/SimpleHTTP.php";
$size = SimpleHTTP::getRemoteSize($ch->url);
$transferSizeSum += $size;
array_push($transferFilesList, array('name' => $ch->url, 'size' => formatBytesTokBMBGBTB($size)));
}
if (empty($transferFilesList)) {
$tmpl->setvar('transferFilesString', "Empty");
$tmpl->setvar('transferFileCount', 0);
} else {
$tmpl->setloop('transferFilesList', $transferFilesList);
$tmpl->setvar('transferFileCount', count($transferFilesList));
}
$tmpl->setvar('transferSizeSum', $transferSizeSum > 0 ? formatBytesTokBMBGBTB($transferSizeSum) : 0);
return;
case "nzb":
require_once "inc/classes/NZBFile.php";
$nzb = new NZBFile($transfer);
$transferSizeSum = 0;
if (empty($nzb->files)) {
$tmpl->setvar('transferFilesString', "Empty");
$tmpl->setvar('transferFileCount', 0);
} else {
foreach ($nzb->files as $file) {
$transferSizeSum += $file['size'];
array_push($transferFilesList, array('name' => $file['name'], 'size' => formatBytesTokBMBGBTB($file['size'])));
}
$tmpl->setloop('transferFilesList', $transferFilesList);
$tmpl->setvar('transferFileCount', $nzb->filecount);
}
$tmpl->setvar('transferSizeSum', $transferSizeSum > 0 ? formatBytesTokBMBGBTB($transferSizeSum) : 0);
return;
}
}
示例11: SQL_Query_exec
$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-Disposition: attachment; filename=' . sqlesc($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-Disposition: attachment; filename=' . sqlesc($name) . '');
header('Content-Length: ' . filesize($fn));
header("Content-Type: application/x-bittorrent");
readfile($fn);
示例12: torrent_scrape_url
/**
* Scrape torrent and return stats
*
* @param $scrape
* string: Scrape URL
* @param $hash
* string: SHA1 hash (info_hash) of torrent
* @return
* array:
* All -1 if failed
* - seeds: integer - number of seeders
* - leechers: integer - number of leechers
* - downloaded: integer - number of complete downloads
*
*/
function torrent_scrape_url($scrape, $hash)
{
if (function_exists("curl_exec")) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $scrape . '?info_hash=' . escape_url($hash));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HEADER, false);
$fp = curl_exec($ch);
curl_close($ch);
} else {
ini_set('default_socket_timeout', 10);
$fp = @file_get_contents($scrape . '?info_hash=' . escape_url($hash));
}
$ret = array();
if ($fp) {
$stats = BDecode($fp);
$binhash = pack("H*", $hash);
$binhash = addslashes($binhash);
$seeds = $stats['files'][$binhash]['complete'];
$peers = $stats['files'][$binhash]['incomplete'];
$downloaded = $stats['files'][$binhash]['downloaded'];
$ret['seeds'] = $seeds;
$ret['peers'] = $peers;
$ret['downloaded'] = $downloaded;
}
if ($ret['seeds'] === null) {
$ret['seeds'] = -1;
$ret['peers'] = -1;
$ret['downloaded'] = -1;
}
return $ret;
}
示例13: zip_open
$zip = zip_open($_FILES["zipfile"]["tmp_name"]);
if ($zip == true) {
$db = mysql_connect($dbhost, $dbuser, $dbpass) or die(errorMessage() . "Couldn't connect to the database, contact the administrator</p>");
mysql_select_db($database) or die(errorMessage() . "Can't open the database.</p>");
while ($zip_entry = zip_read($zip)) {
echo "Name: " . zip_entry_name($zip_entry) . "<br>\n";
if (substr(zip_entry_name($zip_entry), -8) == ".torrent") {
$error_status = true;
if (zip_entry_open($zip, $zip_entry, "r")) {
//read in file from zip
$buffer = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
//go through each torrent file and add it if possible
require_once "BDecode.php";
require_once "BEncode.php";
$tracker_url = $website_url . substr($_SERVER['REQUEST_URI'], 0, -16) . "announce.php";
$array = BDecode($buffer);
if (!$array) {
echo errorMessage() . "Error: The parser was unable to load this torrent.</p>\n";
$error_status = false;
}
if (strtolower($array["announce"]) != $tracker_url) {
echo errorMessage() . "Error: The tracker announce URL does not match this:<br>{$tracker_url}<br>Please re-create and re-upload the torrent.</p>\n";
$error_status = false;
}
if (function_exists("sha1")) {
$hash = @sha1(BEncode($array["info"]));
} else {
echo errorMessage() . "Error: It looks like you do not have a hash function available, this will not work.</p>\n";
$error_status = false;
}
//figure out total size of all files in torrent, needed for insertion into database
示例14: ping
$serversig = $_SERVER['SERVER_SIGNATURE'];
echo "Anatomic P2P Supertracker HTML Frontend Version 0.1 BETA on: <br> {$serversig}.<br><br>\r\nThis script lists the status of some of the other supertrackers registered with this supertracker<BR><BR>";
include "BDecode.php";
function ping($url)
{
$url = urldecode($url);
$url .= "?ping=1";
$pull = @file_get_contents($url);
if ($pull === "PONG") {
return TRUE;
} else {
return FALSE;
}
}
$data = @file_get_contents("strackers.dat");
$data = BDecode($data);
if (is_array($data) != 1) {
die("Corrupted Tracker Data");
}
$number = count($data);
if ($number != 0) {
$counter = 0;
foreach ($data as $tracker) {
$counter += "1";
$tracker = urldecode($tracker);
// might be neccessary
if (ping($tracker) === FALSE) {
$number -= "1";
echo "{$counter}. ";
echo $tracker;
print " NO VALID RESPONSE RECEIVED";
示例15: mysql_real_escape_string
$filename .= $info["files"][$fileno]["path"][0];
}
$filename = mysql_real_escape_string($filename);
mysql_query("INSERT INTO " . $prefix . "webseedfiles (info_hash,filename,startpiece,endpiece,startpieceoffset,fileorder) values (\"{$hash}\", \"{$filename}\", {$startpiece}, {$pieceno}, {$startoffset}, {$fileno})");
$fileno++;
}
} else {
//single file
mysql_query("INSERT INTO " . $prefix . "webseedfiles (info_hash,filename,startpiece,endpiece,startpieceoffset,fileorder) values (\"{$hash}\", \"" . mysql_real_escape_string($fsbase) . "\", 0, " . (strlen($array["info"]["pieces"]) / 20 - 1) . ", 0, 0)");
}
}
if ($_POST["getrightseed"] == "enabled" || $_POST["httpseed"] == "enabled") {
//edit torrent file
$read_httpseed = fopen("torrents/" . $filename . ".torrent", "rb");
$binary_data = fread($read_httpseed, filesize("torrents/" . $filename . ".torrent"));
$data_array = BDecode($binary_data);
if ($_POST["httpseed"] == "enabled") {
$data_array["httpseeds"][0] = $website_url . substr($_SERVER['REQUEST_URI'], 0, -15) . "seed.php";
}
if ($_POST["getrightseed"] == "enabled") {
$data_array["url-list"][0] = $_POST["httpftplocation"];
}
$to_write = BEncode($data_array);
fclose($read_httpseed);
//write torrent file
$write_httpseed = fopen("torrents/" . $filename . ".torrent", "wb");
fwrite($write_httpseed, $to_write);
fclose($write_httpseed);
}
//add in piecelength and number of pieces
$query = "UPDATE " . $prefix . "summary SET piecelength=\"" . $info["piece length"] . "\", numpieces=\"" . strlen($array["info"]["pieces"]) / 20 . "\" WHERE info_hash=\"" . $hash . "\"";