Home » Support Forums for PMBT 2.X » Bug Reports for V2.X » PHP version 5.3.x problem with benc.php
| PHP version 5.3.x problem with benc.php [message #4320] |
Wed, 23 June 2010 14:02  |
|
At the beginning of seeding my torrent client gives the following error:
in-elite.com: Ошибка: invalid bencoding of tracker response: "0x10 Notice: Use of undefined constant type - assumed 'type' in /var/www/in-elite.com/source/modules/Bittorrent/announce.php on line 490x10 0x10 Notice: Use of undefined constant value - assumed 'value' in /var/www/in-elite.com/source/modules/Bittorrent/announce.php on line 490x10 0x10 Notice: Use of undefined constant type - assumed 'type' in /var/www/in-elite.com/source/modules/Bittorrent/announce.php on line 540x10 0x10 Notice: Use of undefined constant value - assumed 'value' in /var/www/in-elite.com/source/modules/Bittorrent/announce.php on line 540x10 d14:failure reason40:torrent not registered with this trackere"
probably a problem with benc.php
database is encoded in utf-8 and my PHP Version 5.3.2
|
|
|
| Re: PHP version 5.3.x problem with benc.php [message #4386 is a reply to message #4320] |
Tue, 06 July 2010 15:15   |
|
|
Yes, I was really right. The problem is in this file ... I do not know yet why but it can not correctly decode torrent file. In order for everything to work you need to change the encoding of the database on windows-1251 (the site itself), and MySQL on cp-1251 encoding, this will display Russian characters correctly. Or, use iso-8859-1
|
|
|
| Re: PHP version 5.3.x problem with benc.php [message #4387 is a reply to message #4386] |
Tue, 06 July 2010 15:31   |
|
I well start with You are not even running phpMyBitTorrent!
We dont use benc.php in PMBT at all in announce.php
I well take a look.
can you provide me with a copy of the announce that you are using?
the closest I can fined is
function err($msg)
{
benc_resp(array("failure reason" => array(type => "string", value => $msg)));
exit();
}
function benc_resp($d)
{
benc_resp_raw(benc(array(type => "dictionary", value => $d)));
}
try to change this to
function err($msg)
{
benc_resp(array("failure reason" => array('type' => "string", 'value' => $msg)));
exit();
}
function benc_resp($d)
{
benc_resp_raw(benc(array('type' => "dictionary", 'value' => $d)));
}
[Updated on: Tue, 06 July 2010 15:46] Report message to a moderator
|
|
|
| Re: PHP version 5.3.x problem with benc.php [message #4388 is a reply to message #4387] |
Wed, 07 July 2010 08:36   |
|
Yes of course you can get a copy of this file ... but he did not quite phpmybittorrent me Integrating for PHP-Nuke on which I'm working ... but as far as I was checking the files and with this engine ... it is not difficult to guess what is used php-My-Bittorrent engine ... Well you can see the work on my site ... Torrent added ok ... You can download and upload them too ... If you are interested in my project you can join the project ...
File "anonce.php"
<?php
/*************************************************************************************************
*
* Bittorrent module
* --------------------
*
* Original idea by Graziano Chiaiese aka "Raulken" - WWW.BITNILE.COM
*
* In-Elite Team
* ------------------
* WWW.IN-ELITE.COM
*
* Начальная идея «Graziano Chiaiese» приглянулась команде In-Elite. И так как данный код давным
* давно не дорабатывался и вообще исчез из сетевых ресурсов, мы решили возобновить данный проект.
* Теперь дальнейшей разработкой и продвижением проекта будет заниматься команда In-Elite.
*
* Вы можете получить подробную информацию на нашем сайте http://www.in-elite.com
*
***************************************************************************************************
* File information: announce.php
* File encoding: utf-8
* File location: modules/Bittorrent/announce.php
***************************************************************************************************/
define("MODULE_FILE","ok");
function dbconnannounce($autoclean = 1) {
global $dbhost, $dbuname, $dbpass, $dbname;
@mysql_connect($dbhost, $dbuname, $dbpass)
or die(mysql_error());
mysql_select_db($dbname)
or die(mysql_error());
/* if ($autoclean)
register_shutdown_function("autoclean");
*/
}
$nologin = true;
require_once("modules/Bittorrent/config.php");
dbconnannounce();
require_once("modules/Bittorrent/include/bittorrent.php");
require_once("modules/Bittorrent/include/benc.php");
//ob_start();
function err($msg) {
benc_resp(array("failure reason" => array(type => "string", value => $msg)));
exit();
}
function benc_resp($d) {
benc_resp_raw(benc(array(type => "dictionary", value => $d)));
}
function benc_resp_raw($x) {
header("Content-Type: text/plain");
header("Pragma: no-cache");
print($x);
}
$req = "info_hash:peer_id:!ip:port:uploaded:downloaded:left:!event";
foreach (explode(":", $req) as $x) {
if ($x[0] == "!") {
$x = substr($x, 1);
$opt = 1;
}
else
$opt = 0;
if (!isset($_GET[$x])) {
if (!$opt)
err("missing key");
continue;
}
$GLOBALS[$x] = unesc($_GET[$x]);
}
foreach (array("info_hash","peer_id") as $x) {
if (strlen($GLOBALS[$x]) != 20)
err("invalid $x (" . strlen($GLOBALS[$x]) . " - " . urlencode($GLOBALS[$x]) . ")");
}
if (empty($ip) || !preg_match('/^(\d{1,3}\.){3}\d{1,3}$/s', $ip))
$ip = $_SERVER["REMOTE_ADDR"];
$port = 0 + $port;
$downloaded = 0 + $downloaded;
$uploaded = 0 + $uploaded;
$left = 0 + $left;
$rsize = 50;
foreach(array("num want", "numwant", "num_want") as $k) {
if (isset($_GET[$k])) {
$rsize = 0 + $_GET[$k];
break;
}
}
if (!$port || $port > 0xffff)
err("invalid port");
if (!isset($event))
$event = "";
$seeder = ($left == 0) ? "yes" : "no";
$sql = "SELECT id, banned, name FROM torrent_torrents WHERE " . hash_where("info_hash", $info_hash);
$res = mysql_query($sql)
or die(mysql_error());
$torrent = mysql_fetch_assoc($res);
if (!$torrent)
err("torrent not registered with this tracker");
$torrentid = $torrent["id"];
$torrentname = $torrent["name"];
$fields = "seeder, peer_id, ip, port, uploaded, downloaded, upload_speed, UNIX_TIMESTAMP(SYSDATE()) - UNIX_TIMESTAMP(last_action) as seconds";
//Raulken
//$res = mysql_query("SELECT $fields FROM torrent_peers WHERE torrent = '$torrentid' AND connectable = 'yes' ORDER BY RAND() LIMIT $rsize");
$res = mysql_query("SELECT $fields FROM torrent_peers WHERE torrent = '$torrentid' ORDER BY RAND() LIMIT $rsize");
$resp = "d" . benc_str("interval") . "i" . $announce_interval . "e" . benc_str("peers") . "l";
unset($self);
while ($row = mysql_fetch_assoc($res)) {
$row["peer_id"] = hash_pad($row["peer_id"]);
if ($row["peer_id"] === $peer_id) {
$self = $row;
continue;
}
$resp .= "d" .
benc_str("ip") . benc_str($row["ip"]) .
benc_str("peer id") . benc_str($row["peer_id"]) .
benc_str("port") . "i" . $row["port"] . "e" .
"e";
}
$resp .= "ee";
$selfwhere = "torrent = '$torrentid' AND " . hash_where("peer_id", $peer_id);
if (!isset($self)) {
$res = mysql_query("SELECT $fields FROM torrent_peers WHERE $selfwhere");
$row = mysql_fetch_assoc($res);
if ($row)
$self = $row;
}
$updateset = array();
if ($event == "stopped") {
if (isset($self)) {
//mysql_query("DELETE FROM peers WHERE id = " . $self["id"]);
mysql_query("DELETE FROM torrent_peers WHERE $selfwhere");
if (mysql_affected_rows()) {
if ($self["seeder"] == "yes")
$updateset[] = "seeders = seeders - 1";
else
$updateset[] = "leechers = leechers - 1";
}
$updateset[] = "tot_peer = tot_peer - 1";
$updateset[] = "speed = speed - '".$self["upload_speed"]."'";
}
}
else {
if ($event == "completed")
$updateset[] = "times_completed = times_completed + 1";
if (isset($self)) {
if ($uploaded>=$self["uploaded"]){
$upload_speed = round( ($uploaded - $self["uploaded"]) / $self["seconds"] );
$updateset[] = "speed = speed -'".$self["upload_speed"]."' + '$upload_speed'";
}else{
$upload_speed = 0;
}
if ($downloaded>=$self["downloaded"]){
$download_speed = round( ($downloaded - $self["downloaded"]) / $self["seconds"] );
}else{
$download_speed=0;
}
//mysql_query("UPDATE peers SET ip = " . sqlesc($ip) . ", port = $port, uploaded = $uploaded, downloaded = $downloaded, to_go = $left, last_action = NOW(), seeder = '$seeder' WHERE id = " . $self["id"]);
mysql_query("UPDATE torrent_peers SET ip = " . sqlesc($ip) . ", port = '$port', uploaded = '$uploaded', downloaded = '$downloaded', to_go = '$left', last_action = NOW(), seeder = '$seeder', download_speed='$download_speed', upload_speed='$upload_speed' WHERE $selfwhere");
if (mysql_affected_rows() && $self["seeder"] != $seeder) {
if ($seeder == "yes") {
$updateset[] = "seeders = seeders + 1";
$updateset[] = "leechers = leechers - 1";
}
else {
$updateset[] = "seeders = seeders - 1";
$updateset[] = "leechers = leechers + 1";
}
}
}else {
$sockres = @fsockopen($ip, $port, $errno, $errstr, 5);
if (!$sockres)
$connectable = "no";
else {
$connectable = "yes";
@fclose($sockres);
}
//Raulken start
if ($seeder=="no"){
$sql_trigger = "SELECT count( A.seeder ) AS tot, A.seeder AS seed, A.ip, sum( B.size ) AS tot_size, max(B.size) as max_size FROM `torrent_peers` A, `torrent_torrents` B WHERE A.ip = '$ip' AND A.`torrent` = B.`id` GROUP BY ip, seed order by seed";
$res_trigger = mysql_query($sql_trigger) or die(mysql_error(). " SQL = $sql_trigger");
if ($row_trigger = mysql_fetch_array($res_trigger)){
$check_seed=true; // false = trigger found
$check_leech=true; // false = trigger found
if ($min_share_seed>0){
if($row_trigger["seed"]=="yes" && $row_trigger["tot_size"]>=$min_share_seed) {
//if row_trigger["seed"]=="no" check only leech
}else{
$check_seed = false;
}
}
if ($min_size_seed>0){
if($row_trigger["seed"]=="yes" && $row_trigger["max_size"]>=$min_size_seed) {
//if row_trigger["seed"]=="no" check only leech
}else{
$check_seed = false;
}
}
if ($row_trigger["seed"]=="yes") $row_trigger = mysql_fetch_array($res_trigger);
if (!$check_seed && $row_trigger){
if ($max_num_file>0){
if($max_num_file>$row_trigger["tot"]){ //a questo punto dovrebbe essere row_trigger["seed"]=="no" altrimenti vuol dire che non fa da leech
}else{
$check_leech= false;
}
}
if ($max_share_size >0){
if($max_share_size>$row_trigger["tot_size"] ){ //a questo punto dovrebbe essere row_trigger["seed"]=="no" altrimenti vuol dire che non fa da leech
}else{
$check_leech = false;
}
}
}
if ($check_seed==false && $check_leech==false) err("Hai superato i limiti senza rispettare le regole, verifica sul sito www.raulken.it le regole per non avere limiti.");
}
}else{
$sql_trigger = "SELECT user_email FROM torrent_seeder_notify A, ".$user_prefix."_users B WHERE A.torrent = '$id' AND A.day<CURDATE() AND A.user=B.user_id";
$res_trigger = mysql_query($sql_trigger) or die(mysql_error(). " SQL = $sql_trigger");
while ($row_trigger = mysql_fetch_array($res_trigger)){
$corpo_email = "Ciao, ricevi questa email perché ne hai fatta espressa richiesta sul servizio BIT TORRENT
Riguardo il TORRENT \"$torrentname\"
Se non stavi scaricando questo file puoi lanciare il torrent facendo click su:
http://www.raulken.it/home/modules.php?name=$name&file=download&id=$id
Per visualizzare il link devi essere autenticato sul sito.
Non riceverai altre email riguardo questo TORRENT per questa giornata.
Per non ricevere ulteriori notifiche riguardo i commenti di questo TORRENT fai click su:
http://www.raulken.it/home/modules.php?name=$name&file=details&id=$id&sn=n";
mail($row_trigger["user_email"], "Inserimento commento al TORRENT \"$torrentname\" su raulken.it", $corpo_email, "From: webmaster@raulken.it");
}
mysql_query("UPDATE torrent_seeder_notify SET DAY = CURDATE() WHERE torrent = '$id' AND day<CURDATE()") or die(mysql_error());
}
//Raulken end
$ret = mysql_query("INSERT INTO torrent_peers (connectable, torrent, peer_id, ip, port, uploaded, downloaded, to_go, started, last_action, seeder) VALUES ('$connectable', '$torrentid', " . sqlesc($peer_id) . ", " . sqlesc($ip) . ", '$port', '$uploaded', '$downloaded', '$left', NOW(), NOW(), '$seeder')");
if ($ret) {
if ($seeder == "yes")
$updateset[] = "seeders = seeders + 1";
else
$updateset[] = "leechers = leechers + 1";
$updateset[] = "tot_peer = tot_peer + 1";
}
}
}
if ($seeder == "yes") {
if ($torrent["banned"] != "yes")
$updateset[] = "visible = 'yes'";
$updateset[] = "last_action = NOW()";
}
if (count($updateset)){
$sql = "UPDATE torrent_torrents SET " . join(",", $updateset) . " WHERE id = '$torrentid'";
mysql_query($sql) or die(mysql_error(). " SQL = $sql");
}
benc_resp_raw($resp);
?>
|
|
| | |
| Re: PHP version 5.3.x problem with benc.php [message #4391 is a reply to message #4320] |
Wed, 07 July 2010 14:11   |
|
Blah, I understand that this is not phpmybittorrent well and you suggest me to insert the code error_reporting (E_ALL & ~ (E_NOTICE | E_USER_NOTICE)); / / We don't get stupid messages
But it is something I will not help save the hash if I have not encoded in utf-8 ....
The problem here in something else ... How do you explain the fact that everything is working fine again until the site and the database is in windows-1251? One has only to change all that fun to utf-8 and added to the database or Egyptian symbols, or general info_hash field is left blank ....?
If you wish you could look at the entire code on my svn repository
http://www.in-elite.com/websvn/listing.php?repname=In-Elite or http://www.in-elite.com/svn/In-Elite/ username and password into the read mode login: svn password: svn
While I have not made the installer that if you need a database I can throw a dump of the database ...
[Updated on: Wed, 07 July 2010 14:12] Report message to a moderator
|
|
|
| Re: PHP version 5.3.x problem with benc.php [message #4392 is a reply to message #4391] |
Wed, 07 July 2010 16:10   |
|
Perhaps the problem with most adding torrent ... because when you add a torrent in the database writes complete nonsense info_hash
File: takeupload.php
<?php
/*************************************************************************************************
*
* Bittorrent module
* --------------------
*
* Original idea by Graziano Chiaiese aka "Raulken" - WWW.BITNILE.COM
*
* In-Elite Team
* ------------------
* WWW.IN-ELITE.COM
*
* Начальная идея «Graziano Chiaiese» приглянулась команде In-Elite. И так как данный код давным
* давно не дорабатывался и вообще исчез из сетевых ресурсов, мы решили возобновить данный проект.
* Теперь дальнейшей разработкой и продвижением проекта будет заниматься команда In-Elite.
*
* Вы можете получить подробную информацию на нашем сайте http://www.in-elite.com
*
***************************************************************************************************
* File information: takeupload.php
* File encoding: utf-8
* File location: modules/Bittorrent/takeupload.php
***************************************************************************************************/
$index = 1;
if (!defined('MODULE_FILE')) {
die ("You can't access this file directly...");
}
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
global $name, $db, $torrent_global_privacy, $file;
require_once("modules/$name/include/bittorrent.php");
require_once("modules/$name/include/benc.php");
require_once("modules/$name/config.php");
if (!is_user($user)){
$pagetitle = "- "._ACCESSDENIED."";
include("header.php");
title("$sitename: "._ACCESSDENIED."");
OpenTable();
echo "<center><b>"._RESTRICTEDAREA."</b><br><br>"
.""._MODULEUSERS."";
$result2 = $db->sql_query("SELECT mod_group FROM ".$prefix."_modules WHERE title='$name'");
$row2 = $db->sql_fetchrow($result2);
if ($row2[mod_group] != 0) {
$result3 = $db->sql_query("SELECT name FROM ".$prefix."_groups WHERE id='$row2[mod_group]'");
$row3 = $db->sql_fetchrow($result3);
echo ""._ADDITIONALYGRP.": <b>$row3[name]</b><br><br>";
}
echo ""._GOBACK."";
CloseTable();
include("footer.php");
die();
}
ini_set("upload_max_filesize",$max_torrent_size);
include("header.php");
OpenTable();
function bark($msg) {
genbark($msg, _btuploadfailed);
}
foreach(explode(":","descr:type:namex") as $v) {
if (!isset($_POST[$v]))
bark(_btmissingdata);
}
if (!isset($_FILES["filex"]))
bark(_btmissingdata);
$f = $_FILES["filex"];
$fname = unesc($f["name"]);
if (empty($fname))
bark(_btemptyfname);
if (!validfilename($fname))
bark(_btinvalidfname);
if (!preg_match('/^(.+)\.torrent$/si', $fname, $matches))
bark(_btfnamenotorrent);
$shortfname = $torrent = $matches[1];
if (!empty($_POST["namex"]))
$torrent = unesc($_POST["namex"]);
$tmpname = $f["tmp_name"];
$fp = @fopen($f["tmp_name"], "rb");
if ($fp){
$page=fread($fp, 1000000);
fclose($fp);
}else{
die(_btferror);
}
$parse_array_torrent = array();
$i=0;
$max=strlen($page);
$parse_array_torrent = ergo($page, $parse_array_torrent, $i, $max);
function print_parse(&$parse_array_read){
foreach ($parse_array_read as $key => $val){
echo "[$key => ";
if (is_array ($val)){
echo "<BLOCKQUOTE dir=ltr style='MARGIN-RIGHT: 0px'><P>";
print_parse($val);
echo "</P></BLOCKQUOTE>";
}else{
echo $val;
}
echo "]";
}
}
// Convert 5 Bytes to 8 Bytes Base32
function _Sha1toBase32($in){
$Table = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
$out = substr($Table, ((ord(substr($in, 0, 1)) >> 3) ) & 0x1F, 1);
$out .= substr($Table, ((ord(substr($in, 0, 1)) << 2) | (ord(substr($in, 1, 1)) >> 6)) & 0x1F, 1);
$out .= substr($Table, ((ord(substr($in, 1, 1)) >> 1) ) & 0x1F, 1);
$a = (ord(substr($in, 1, 1)) << 4) & 0x00FF;
$b = ((ord(substr($in, 2, 1))) >> 4)&0x00FF;
$out .= substr($Table, ( $a | $b )&0x1F, 1);
$a = ( (ord(substr($in, 2, 1))&0x00FF) << 1) &0x00FF;
$b = ((ord(substr($in, 3, 1)) >> 7)) &0x00FF;
$out .= substr($Table, ( $a | $b )&0x1F, 1);
$out .= substr($Table, ((ord(substr($in, 3, 1)) >> 2) ) & 0x1F, 1);
$a = (ord(substr($in, 3, 1)) << 3) & 0x00FF;
$b = ((ord(substr($in, 4, 1)) >> 5)) &0x00FF;
$out .= substr($Table, ( $a|$b ) & 0x1F, 1);
$out .= substr($Table, ((ord(substr($in, 4, 1)) ) ) & 0x1F, 1);
return $out;
}
// Return a base32 representation of a sha1 hash
function Sha1toBase32($Sha1){
//Magnetic link
$ret="";
$Base32 = _Sha1toBase32(substr($Sha1, 0, 5));
$Base32 .= _Sha1toBase32(substr($Sha1, 5, 5));
$Base32 .= _Sha1toBase32(substr($Sha1, 10, 5));
$Base32 .= _Sha1toBase32(substr($Sha1, 15, 5));
$ret = $Base32;
return $ret;
}
function strtohex($strtmp){
//Emule
$max = strlen($strtmp);
$hex = "";
for($i=0; $i<$max;$i++){
$hex .= dechex(ord(substr($strtmp, $i, 1)));
}
return strtoupper($hex);
}
$magnet_link = "";
$ed2k_link = "";
$sql_insert_field = "";
$sql_insert_value = "";
if($parse_array_torrent["0"]["info"]["sha1"]){
$magnet_link = "magnet:?xt=urn:sha1:".addslashes(Sha1toBase32($parse_array_torrent["0"]["info"]["sha1"]))."&dn=".urlencode($parse_array_torrent["0"]["info"]["name"]);
$sql_insert_field .= ", magnet";
$sql_insert_value .= ", '$magnet_link'";
}
if($parse_array_torrent["0"]["info"]["ed2k"]){
$ed2k_link = "ed2k://|file|".urlencode($parse_array_torrent["0"]["info"]["name"])."|".urlencode($parse_array_torrent["0"]["info"]["length"])."|".strtohex($parse_array_torrent["0"]["info"]["ed2k"])."|/";
$sql_insert_field .= ", ed2k";
$sql_insert_value .= ", '$ed2k_link'";
}
if (!is_uploaded_file($tmpname))
bark(_bterrnofileupload);
if (!filesize($tmpname))
bark(_btemptyfile);
$dict = bdec_file($tmpname, 1000000);
if (!isset($dict))
bark(_btnobenc);
function dict_check($d, $s){
if ($d["type"] != "dictionary")
bark(_btnodictionary);
$a = explode(":", $s);
$dd = $d["value"];
$ret = array();
foreach ($a as $k) {
unset($t);
if (preg_match('/^(.*)\((.*)\)$/', $k, $m)) {
$k = $m[1];
$t = $m[2];
}
if (!isset($dd[$k]))
bark(_btdictionarymisskey);
if (isset($t)) {
if ($dd[$k]["type"] != $t)
bark(_btdictionaryinventry);
$ret[] = $dd[$k]["value"];
}
else
$ret[] = $dd[$k];
}
return $ret;
}
function dict_get($d, $k, $t) {
if ($d["type"] != "dictionary")
bark(_btnodictionary);
$dd = $d["value"];
if (!isset($dd[$k]))
return;
$v = $dd[$k];
if ($v["type"] != $t)
bark(_btdictionaryinvetype);
return $v["value"];
}
list($ann, $info) = dict_check($dict, "announce(string):info");
list($dname, $plen, $pieces) = dict_check($info, "name(string):piece length(integer):pieces(string)");
$tracker = "";
$ann = trim($ann);
global $nukeurl, $name, $stealthmode, $announce_urls;
if (!in_array($ann, $announce_urls, false))
if (!$stealthmode){
bark(_btinvannounce."<b>" . $announce_urls[0] . "</b>. "."--".$ann."--");
}else{
$tracker = $ann;
}
if(!preg_match("/announce/",$ann)) bark(_btinvannounce."<b>".$ann. "</b>. "."--".$ann."--");
if(substr($ann, 0, strlen($nukeurl))==$nukeurl and count($announce_urls)==0)
die(str_replace("**name**",$name,_bttrackerdisabled));
if (strlen($pieces) % 20 != 0)
bark(_btinvpieces);
$filelist = array();
$totallen = dict_get($info, "length", "integer");
if (isset($totallen)) {
$filelist[] = array($dname, $totallen);
$typetorrent = "single";
}
else {
$flist = dict_get($info, "files", "list");
if (!isset($flist))
bark(_btmissinglength);
if (!count($flist))
bark(_btnofilesintorrent);
$totallen = 0;
foreach ($flist as $fn) {
list($ll, $ff) = dict_check($fn, "length(integer):path(list)");
$totallen += $ll;
$ffa = array();
foreach ($ff as $ffe) {
if ($ffe["type"] != "string")
bark(_btfnamerror);
$ffa[] = $ffe["value"];
}
if (!count($ffa))
bark(_btfilenamerror);
$ffe = implode("/", $ffa);
$filelist[] = array($ffe, $ll);
}
$typetorrent = "multi";
}
$infohash = pack("H*", sha1($info["string"]));
$descr = unesc($_POST["descr"]);
global $source_url;
if ($source_url == "http://" OR substr($source_url,0,7)!=="http://") $source_url='';
//Raulken
//$maxupload_day_num = 2; //Number of max upload a day
//$maxupload_day_share = 3 * 1024 *1048576; //Max share size to upload a day
//$minupload_size_file = 100 * 1048576; //Min size of
$sql = "SELECT count(size) as num, sum(size) as tot_size FROM `torrent_torrents` where `added` > sysdate() - 1000000 AND owner = '".getuserid($user)."'";
$res = $db->sql_query($sql) or bterror($sql);
$row = $db->sql_fetchrow($res);
if (!is_btadmin($admin) && $minupload_size_file>$totallen){
echo _bttorrenttoosmall1.mksize($minupload_size_file)._bttorrenttoosmall2.mksize($totallen)."</b>.";
CloseTable();
include("footer.php");
die();
}
//Max # num upload on 24h
if (!is_btadmin($admin) && $maxupload_day_num>0 && $maxupload_day_num<=$row["num"]){
echo str_replace("**maxupload**",$maxupload_day_num,_btmaxuploadexceeded);
CloseTable();
include("footer.php");
die();
}
//Max size share upload on 24h
if (!is_btadmin($admin) && $maxupload_day_share>0 && $maxupload_day_share<$row["tot_size"]+$totallen){
$btnumfileexceeded = str_replace("**maxupload",$maxupload_day_share,_btnumfileexceeded);
$btnumfileexceeded = str_replace("**rownum**",$row["num"],$btnumfileexceeded);
$btnumfileexceeded = str_replace("**totsize**",mksize($row["tot_size"]),$btnumfileexceeded);
echo $btnumfileexceeded;
CloseTable();
include("footer.php");
die();
}
//Filtro costruzione dal nome file lungo almeno 4 caratteri
$materia=trim($fname);
$pos = strrpos($materia, '.');
if (!$pos===false)
$materia = substr($materia, 0, $pos);
$search = array (
"'[^a-zA-Z]'", // Remove not lecter
"'([\r\n])[\s]+'" // Remove Blank space
);
$replace = array (
" ",
"\\1"
);
$materia = preg_replace ($search, $replace, $materia);
$materia = explode(" ", $materia);
$sql_filter = "";
foreach($materia as $x){
$x = trim($x);
if(strlen($x)>=3){
$sql_filter .= " OR keyword LIKE ".sqlesc($x)."";
}
}
$sql_filter = "SELECT * FROM torrent_filter WHERE 1=0 ".$sql_filter;
$res = $db->sql_query($sql_filter) or bterror($sql_filter);
if ($row = $db->sql_fetchrow($res)){
Echo _btillegalword;
do{
echo "<li><b>".$row[keyword]."</b> ".$row[reason];
}while ($row = $db->sql_fetchrow($res));
echo _btillegalwordinfo;
CloseTable();
include("footer.php");
die();
}
//Fine filtro
global $jump_check;
if ($jump_check){
$materia=trim($fname);
$pos = strrpos($materia, '.');
if (!$pos===false)
$materia = substr($materia, 0, $pos);
$search = array (
"'[^a-zA-Z]'", // Remove not lecter
"'([\r\n])[\s]+'" // Remove Blank space
);
$replace = array (
" ",
"\\1"
);
$materia = preg_replace ($search, $replace, $materia);
$materia=explode(" ", $materia);
$sql = "";
$sql_filter = "";
foreach($materia as $x){
$x = trim($x);
if(strlen($x)>=5){
$sql .= " OR filename LIKE ".sqlesc($x);
}
}
foreach ($filelist as $file) {
$sql .= " OR size=".sqlesc($file[1]);
}
$sql = "SELECT torrent, filename, size FROM torrent_files WHERE 1=0 ".$sql;
$res = $db->sql_query($sql) or bterror($sql);
if ($row = $db->sql_fetchrow($res)){
Echo _btsearchdupl;
do{
echo "<li><a href='modules.php?name=$name&file=details&id=".$row["torrent"]."&hit=1'>".$row["filename"]."</a> (".mksize($row["size"]).")";
}while ($row = $db->sql_fetchrow($res));
echo _btduplinfo;
CloseTable();
include("footer.php");
die();
}
}
$category = intval($type);
$sql = "SELECT * FROM torrent_categories WHERE id = '".$category."'";
if(! $result = $db->sql_query($sql) ) bterror($sql);
if(! $row = $db->sql_fetchrow($result) ) die(_btillegalcat);
$ip = $_SERVER["REMOTE_ADDR"];
global $evidence, $ownertype;
if ($evidence!=1) $evidence =0;
if ($ownertype<0 || $ownertype>2) $ownertype = 0;
$owner = 0;
if ($ownertype!=2){
$owner = getuserid($user);
}
global $_FILES, $HTTP_POST_FILES;
$filesend = false;
$userfilename = "Photo";
if ( $_FILES[$userfilename]['error'] == "0" ) {
// echo("Value 0, No problem, the file is uploaded.");
$filesend = true;
//continua a scrivere il codice qui per l'upload foto
} elseif ( $_FILES[$userfilename]['error'] == "1" ) {
// echo("Value 1; The uploaded file was bigger then upload_max_filesize in php.ini. ");
die("Il file č troppo grande ed il server non lo accetta, contattare lo staff.");
} elseif ( $_FILES[$userfilename]['error'] == "2" ) {
// echo("Value 2; The uploaded file was bigger then MAX_FILE_SIZE in html-form.");
die("Il file č troppo grande ed il browser ha impedito l'upload");
} elseif ( $_FILES[$userfilename]['error'] == "3" ) {
// echo("Value 3; File partialy uploaded.");
die("File spedito parzialmente riprovare");
} elseif ( $_FILES[$userfilename]['error'] == "4" ) {
//no file send
}else {
//no file send
}
if ($tracker!=""){
/*
$slash_point=strrpos($tracker, '/');
$pos_point=strrpos($tracker, '.');
$tmp_tracker= substr($tracker, 0, $slash_point)."/scrape".substr($tracker, $pos_point)."?info_hash=".urlencode($infohash);
*/
$tmp_tracker=str_replace("announce", "scrape", $tracker)."?info_hash=".urlencode($infohash);
$tracker_db = str_replace("announce","scrape",$tracker);
$use_std_tracker = false;
$parse_array = array();
$i=0;
global $extern_check;
if ($extern_check) {
$fp = @fopen($tmp_tracker, "rb");
if ($fp){
socket_set_timeout($fp, 10);
$page=fread($fp, 1000000);
$status = socket_get_status($fp);
if ($status['timed_out']) {
die(_btsocktout);
}
fclose($fp);
$max=strlen($page);
$parse_array = ergo($page, $parse_array, $i, $max);
//Check data
if ( !is_array($parse_array["0"]["files"][ "$infohash" ]) )
$use_std_tracker = true;
else{
//check seeder
if ($parse_array["0"]["files"][ "$infohash" ]["complete"]<=0) die("Il tracker esterno ha risposto confermando la presenza del file ma con nessuna fonte completa. Ti ricordiamo che il file deve essere giŕ presente sull'altro tracker con almeno un seeder per essere inserito sul nostro sito.");
$sql = "INSERT INTO torrent_torrents (search_text, filename, src_url, owner, visible, info_hash, name, size, numfiles, `type`, descr, ori_descr, category, save_as, added, last_action, evidence, ownertype, ip, seeders, leechers, tot_peer, times_completed, tracker, tracker_update $sql_insert_field) VALUES (" .implode(", ", array_map("sqlesc", array(searchfield("$shortfname $dname $torrent"), $fname, $source_url, $owner, "yes", $infohash, $torrent, $totallen, count($filelist), $typetorrent, parsedescr($descr), $descr, 0 + $_POST["type"], $dname))) .", NOW(), NOW(), '$evidence', '$ownertype', '$ip', ".sqlesc($parse_array["0"]["files"][ "$infohash" ]["complete"]).", ".sqlesc($parse_array["0"]["files"][ "$infohash" ]["incomplete"]).", ".sqlesc($parse_array["0"]["files"][ "$infohash" ]["complete"]+$parse_array["0"]["files"][ "$infohash" ]["incomplete"]).",".sqlesc($parse_array["0"]["files"][ "$infohash" ]["downloaded"]).", '$tracker_db', SYSDATE() $sql_insert_value)";
}
}else{
$use_std_tracker = true;
}
//Strandard Tracker
if ($use_std_tracker){
$add_tracker = "&peer_id=%00%00%00%00%00Azureus9%09%40d%BE%3D%C1%8B&port=666&uploaded=0&downloaded=0&left=1&num_peers=10000";
$tracker.="?info_hash=".urlencode($infohash).$add_tracker;
$fp = @fopen($tracker, "rb");
if (!$fp)
die(_bttrackernotresponding." --".$ann."--");
socket_set_timeout($fp, 10);
$page=fread($fp, 1000000);
$status = socket_get_status($fp);
if ($status['timed_out']) {
die(_btsocktout);
}
fclose($fp);
$peers = substr_count($page, "peer id");
if ($peers<=0){
$max=strlen($page);
$parse_array = ergo($page, $parse_array, $i, $max);
if (!is_array($parse_array["0"]["peers"])){
die(_bttrackerdata);
}
}
$sql = "INSERT INTO torrent_torrents (search_text, filename, src_url, owner, visible, info_hash, name, size, numfiles, type, descr, ori_descr, category, save_as, added, last_action, evidence, ownertype, ip, leechers, tot_peer, tracker, tracker_update $sql_insert_field) VALUES (" .implode(", ", array_map("sqlesc", array(searchfield("$shortfname $dname $torrent"), $fname, $source_url, $owner, "yes", $infohash, $torrent, $totallen, count($filelist), $typetorrent, parsedescr($descr), $descr, 0 + $_POST["type"], $dname))) .", NOW(), NOW(), '$evidence', '$ownertype', '$ip', '$peers', '$peers', '$tracker_db', SYSDATE() $sql_insert_value)";
}
} else {
$sql = "INSERT INTO torrent_torrents (search_text, filename, src_url, owner, visible, info_hash, name, size, numfiles, type, descr, ori_descr, category, save_as, added, last_action, evidence, ownertype, ip, leechers, tot_peer, tracker, tracker_update $sql_insert_field) VALUES (" .implode(", ", array_map("sqlesc", array(searchfield("$shortfname $dname $torrent"), $fname, $source_url, $owner, "yes", $infohash, $torrent, $totallen, count($filelist), $typetorrent, parsedescr($descr), $descr, 0 + $_POST["type"], $dname))) .", NOW(), NOW(), '$evidence', '$ownertype', '$ip', '0', '0', '$tracker_db', SYSDATE() $sql_insert_value)";
}
$db->sql_query("INSERT INTO torrent_trackers (url) VALUES ('".$tracker."');");
}else{
$sql = "INSERT INTO torrent_torrents (search_text, filename, src_url, owner, visible, info_hash, name, size, numfiles, type, descr, ori_descr, category, save_as, added, last_action, evidence, ownertype, ip $sql_insert_field) VALUES (" .implode(", ", array_map("sqlesc", array(searchfield("$shortfname $dname $torrent"), $fname, $source_url, $owner, "no", $infohash, $torrent, $totallen, count($filelist), $typetorrent, parsedescr($descr), $descr, 0 + $_POST["type"], $dname))) .", NOW(), NOW(), '$evidence', '$ownertype', '$ip' $sql_insert_value)";
}
$ret = $db->sql_query($sql) or bterror($sql);
$id = $db->sql_nextid();
//upload code 02 giu 2005 Raulken START
if($filesend){
global $maximagesize;
//Check to ensure the a file was indeed submitted
$filesize = $HTTP_POST_FILES[$userfilename]['size'];
if ( $filesize==0 ) die("Non abbiamo ricevuto nessun file oppure il file era vuoto con dimensione 0 byte");
if ( $filesize>$maximagesize*1024 ) die("Il file non deve essere piů grande di ".$maximagesize." kbyte");
//the is_uploaded_file function returns true if the file was indeed uploaded.
if (is_uploaded_file($HTTP_POST_FILES[$userfilename]['tmp_name'])){
$filename = $HTTP_POST_FILES[$userfilename]['tmp_name'];
$realname = $HTTP_POST_FILES[$userfilename]['name'];
switch( strtolower( substr($realname, strlen($realname)-4)) ){
case ".jpg": break;
case ".gif": break;
case ".png": break;
case ".ico": break;
default:
echo "Il file $realname non č stato preso in considerazione poiché non aveva l'estensione GIF JPG PNG o ICO";
continue;
}
//Check lunghezza nome file
if (strlen($filename)>=132) die("Il nome del file deve essere massimo 100 caratteri");
//Read ad insert image on torrent :-)
$fp = fopen($filename, 'rb');
while( !feof($fp) ){
$buffer = addslashes( fread($fp, 64000) );
$sql = "UPDATE `torrent_torrents` SET `image` = CONCAT(image, '".$buffer."') WHERE `id`='$id';";
if ( !$db->sql_query($sql) ) die("Update immagine fallita");
}
fclose($fp);
}
}
//upload code 02 giu 2005 Raulken END
$db->sql_query("DELETE FROM torrent_files WHERE torrent = '$id'") or bterror("DELETE FROM torrent_files WHERE torrent = '$id'");
$i=0;
foreach ($filelist as $file) {
$ins_camp = "";
$ins_val = "" ;
if ($sha1=$parse_array_torrent["0"]["info"]["files"]["$i"]["sha1"]){
$ins_camp .= ", magnet";
$ins_val .= ", 'magnet:?xt=urn:sha1:".addslashes(Sha1toBase32($sha1))."&dn=".urlencode($file[0])."'";
}
if ($ed2k=$parse_array_torrent["0"]["info"]["files"]["$i"]["ed2k"]){
$ins_camp .= ", ed2k";
$ins_val .= ", 'ed2k://|file|".urlencode($file[0])."|".urlencode($file[1])."|".strtohex($ed2k)."|/'";
}
$sql = "INSERT INTO torrent_files (torrent, filename, size $ins_camp) VALUES ('$id', ".sqlesc($file[0]).", '".$file[1]."' $ins_val)";
// echo $sql;
$db->sql_query($sql) or bterror($sql);
$i++;
}
//print_parse($parse_array_torrent);
move_uploaded_file($tmpname, "$torrent_dir/$id.torrent");
echo "<meta http-equiv=\"refresh\" content=\"3;url=modules.php?name=$name&file=details&id=$id&uploaded=1\">";
$btuploadcomplete = str_replace("**name**",$name,_btuploadcomplete);
$btuploadcomplete = str_replace("**id**",$id,$btuploadcomplete);
echo $btuploadcomplete;
global $notify;
if($notify==1){
$sql = "INSERT INTO torrent_comments_notify (torrent, user, can_send) VALUES ('$id', ".getuserid($user).", 1)";
$db->sql_query($sql) or bterror($sql);
echo _btnotify;
}
CloseTable();
include("footer.php");
?>
|
|
| | |
Goto Forum:
Current Time: Wed Feb 08 11:14:18 GMT 2012
Total time taken to generate the page: 0.00827 seconds
|