mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 14:23:57 -07:00
r24
Экспорт. Коммит №23. Поправил php анонсер. _Xz_. git-svn-id: https://torrentpier2.googlecode.com/svn/trunk@24 a8ac35ab-4ca4-ca47-4c2d-a49a94f06293
This commit is contained in:
parent
f6343c444a
commit
ed0a64badb
7 changed files with 440 additions and 529 deletions
|
@ -162,8 +162,6 @@ function drop_fast_announce ($lp_info)
|
||||||
return; // if announce interval correct
|
return; // if announce interval correct
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBG_LOG) dbg_log(' ', 'drop_fast_announce-'. (!empty(DB()) ? 'DB' : 'CACHE'));
|
|
||||||
|
|
||||||
$new_ann_intrv = $lp_info['update_time'] + $announce_interval - TIMENOW;
|
$new_ann_intrv = $lp_info['update_time'] + $announce_interval - TIMENOW;
|
||||||
|
|
||||||
dummy_exit($new_ann_intrv);
|
dummy_exit($new_ann_intrv);
|
||||||
|
@ -190,5 +188,318 @@ function msg_die ($msg)
|
||||||
// Start announcer
|
// Start announcer
|
||||||
define('TR_ROOT', './');
|
define('TR_ROOT', './');
|
||||||
require(TR_ROOT .'includes/init_tr.php');
|
require(TR_ROOT .'includes/init_tr.php');
|
||||||
require(TR_ROOT .'includes/tr_announcer.php');
|
|
||||||
|
$seeder = ($left == 0) ? 1 : 0;
|
||||||
|
$stopped = ($event === 'stopped');
|
||||||
|
|
||||||
|
// Stopped event
|
||||||
|
if ($stopped)
|
||||||
|
{
|
||||||
|
CACHE('tr_cache')->rm(PEER_HASH_PREFIX . $peer_hash);
|
||||||
|
if (DBG_LOG) dbg_log(' ', 'stopped');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get last peer info from DB
|
||||||
|
if (!CACHE('tr_cache')->used && !$lp_info)
|
||||||
|
{
|
||||||
|
$lp_info = DB()->fetch_row("
|
||||||
|
SELECT * FROM ". BB_BT_TRACKER ." WHERE peer_hash = '$peer_hash' LIMIT 1
|
||||||
|
");
|
||||||
|
|
||||||
|
if (DBG_LOG) dbg_log(' ', '$lp_info-get_from-DB-'. ($lp_info ? 'hit' : 'miss'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($lp_info)
|
||||||
|
{
|
||||||
|
if (!$stopped)
|
||||||
|
{
|
||||||
|
drop_fast_announce($lp_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
$user_id = $lp_info['user_id'];
|
||||||
|
$topic_id = $lp_info['topic_id'];
|
||||||
|
$releaser = $lp_info['releaser'];
|
||||||
|
$tor_type = $lp_info['tor_type'];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Verify if torrent registered on tracker and user authorized
|
||||||
|
$info_hash_sql = rtrim(DB()->escape($info_hash), ' ');
|
||||||
|
$passkey_sql = DB()->escape($passkey);
|
||||||
|
|
||||||
|
$sql = "
|
||||||
|
SELECT tor.topic_id, tor.poster_id, tor.tor_type, u.*
|
||||||
|
FROM ". BB_BT_TORRENTS ." tor
|
||||||
|
LEFT JOIN ". BB_BT_USERS ." u ON u.auth_key = '$passkey_sql'
|
||||||
|
WHERE tor.info_hash = '$info_hash_sql'
|
||||||
|
LIMIT 1
|
||||||
|
";
|
||||||
|
|
||||||
|
$row = DB()->fetch_row($sql);
|
||||||
|
|
||||||
|
if (empty($row['topic_id']))
|
||||||
|
{
|
||||||
|
msg_die('Torrent not registered, info_hash = ' . bin2hex($info_hash_sql));
|
||||||
|
}
|
||||||
|
if (empty($row['user_id']))
|
||||||
|
{
|
||||||
|
msg_die('Please LOG IN and REDOWNLOAD this torrent (user not found)');
|
||||||
|
}
|
||||||
|
|
||||||
|
$user_id = $row['user_id'];
|
||||||
|
$topic_id = $row['topic_id'];
|
||||||
|
$releaser = (int) ($user_id == $row['poster_id']);
|
||||||
|
$tor_type = $row['tor_type'];
|
||||||
|
|
||||||
|
// Ratio limits
|
||||||
|
if ((TR_RATING_LIMITS || $tr_cfg['limit_concurrent_ips']) && !$stopped)
|
||||||
|
{
|
||||||
|
$user_ratio = ($row['u_down_total'] && $row['u_down_total'] > MIN_DL_FOR_RATIO) ? ($row['u_up_total'] + $row['u_up_release'] + $row['u_up_bonus']) / $row['u_down_total'] : 1;
|
||||||
|
$rating_msg = '';
|
||||||
|
|
||||||
|
if (!$seeder)
|
||||||
|
{
|
||||||
|
foreach ($rating_limits as $ratio => $limit)
|
||||||
|
{
|
||||||
|
if ($user_ratio < $ratio)
|
||||||
|
{
|
||||||
|
$tr_cfg['limit_active_tor'] = 1;
|
||||||
|
$tr_cfg['limit_leech_count'] = $limit;
|
||||||
|
$rating_msg = " (ratio < $ratio)";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit active torrents
|
||||||
|
if (!isset($bb_cfg['unlimited_users'][$user_id]) && $tr_cfg['limit_active_tor'] && (($tr_cfg['limit_seed_count'] && $seeder) || ($tr_cfg['limit_leech_count'] && !$seeder)))
|
||||||
|
{
|
||||||
|
$sql = "SELECT COUNT(DISTINCT topic_id) AS active_torrents
|
||||||
|
FROM ". BB_BT_TRACKER ."
|
||||||
|
WHERE user_id = $user_id
|
||||||
|
AND seeder = $seeder
|
||||||
|
AND topic_id != $topic_id";
|
||||||
|
|
||||||
|
if (!$seeder && $tr_cfg['leech_expire_factor'] && $user_ratio < 0.5)
|
||||||
|
{
|
||||||
|
$sql .= " AND update_time > ". (TIMENOW - 60*$tr_cfg['leech_expire_factor']);
|
||||||
|
}
|
||||||
|
$sql .= " GROUP BY user_id";
|
||||||
|
|
||||||
|
if ($row = DB()->fetch_row($sql))
|
||||||
|
{
|
||||||
|
if ($seeder && $tr_cfg['limit_seed_count'] && $row['active_torrents'] >= $tr_cfg['limit_seed_count'])
|
||||||
|
{
|
||||||
|
msg_die('Only '. $tr_cfg['limit_seed_count'] .' torrent(s) allowed for seeding');
|
||||||
|
}
|
||||||
|
else if (!$seeder && $tr_cfg['limit_leech_count'] && $row['active_torrents'] >= $tr_cfg['limit_leech_count'])
|
||||||
|
{
|
||||||
|
msg_die('Only '. $tr_cfg['limit_leech_count'] .' torrent(s) allowed for leeching'. $rating_msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit concurrent IPs
|
||||||
|
if ($tr_cfg['limit_concurrent_ips'] && (($tr_cfg['limit_seed_ips'] && $seeder) || ($tr_cfg['limit_leech_ips'] && !$seeder)))
|
||||||
|
{
|
||||||
|
$sql = "SELECT COUNT(DISTINCT ip) AS ips
|
||||||
|
FROM ". BB_BT_TRACKER ."
|
||||||
|
WHERE topic_id = $topic_id
|
||||||
|
AND user_id = $user_id
|
||||||
|
AND seeder = $seeder
|
||||||
|
AND ip != '$ip_sql'";
|
||||||
|
|
||||||
|
if (!$seeder && $tr_cfg['leech_expire_factor'])
|
||||||
|
{
|
||||||
|
$sql .= " AND update_time > ". (TIMENOW - 60*$tr_cfg['leech_expire_factor']);
|
||||||
|
}
|
||||||
|
$sql .= " GROUP BY topic_id";
|
||||||
|
|
||||||
|
if ($row = DB()->fetch_row($sql))
|
||||||
|
{
|
||||||
|
if ($seeder && $tr_cfg['limit_seed_ips'] && $row['ips'] >= $tr_cfg['limit_seed_ips'])
|
||||||
|
{
|
||||||
|
msg_die('You can seed only from '. $tr_cfg['limit_seed_ips'] ." IP's");
|
||||||
|
}
|
||||||
|
else if (!$seeder && $tr_cfg['limit_leech_ips'] && $row['ips'] >= $tr_cfg['limit_leech_ips'])
|
||||||
|
{
|
||||||
|
msg_die('You can leech only from '. $tr_cfg['limit_leech_ips'] ." IP's");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Up/Down speed
|
||||||
|
$speed_up = $speed_down = 0;
|
||||||
|
|
||||||
|
if ($lp_info && $lp_info['update_time'] < TIMENOW)
|
||||||
|
{
|
||||||
|
if ($uploaded > $lp_info['uploaded'])
|
||||||
|
{
|
||||||
|
$speed_up = ceil(($uploaded - $lp_info['uploaded']) / (TIMENOW - $lp_info['update_time']));
|
||||||
|
}
|
||||||
|
if ($downloaded > $lp_info['downloaded'])
|
||||||
|
{
|
||||||
|
$speed_down = ceil(($downloaded - $lp_info['downloaded']) / (TIMENOW - $lp_info['update_time']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Up/Down addition
|
||||||
|
$up_add = ($lp_info && $uploaded > $lp_info['uploaded']) ? $uploaded - $lp_info['uploaded'] : 0;
|
||||||
|
$down_add = ($lp_info && $downloaded > $lp_info['downloaded']) ? $downloaded - $lp_info['downloaded'] : 0;
|
||||||
|
|
||||||
|
// Gold/Silver releases
|
||||||
|
if ($bb_cfg['gold_silver_enabled'] && $down_add)
|
||||||
|
{
|
||||||
|
if ($tor_type == TOR_TYPE_GOLD)
|
||||||
|
{
|
||||||
|
$down_add = 0;
|
||||||
|
}
|
||||||
|
// Silver releases
|
||||||
|
else if ($tor_type == TOR_TYPE_SILVER)
|
||||||
|
{
|
||||||
|
$down_add = ceil($down_add/2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert/update peer info
|
||||||
|
$peer_info_updated = false;
|
||||||
|
$update_time = ($stopped) ? 0 : TIMENOW;
|
||||||
|
|
||||||
|
if ($lp_info)
|
||||||
|
{
|
||||||
|
$sql = "UPDATE ". BB_BT_TRACKER ." SET update_time = $update_time";
|
||||||
|
|
||||||
|
$sql .= ", seeder = $seeder";
|
||||||
|
$sql .= ($releaser != $lp_info['releaser']) ? ", releaser = $releaser" : '';
|
||||||
|
|
||||||
|
$sql .= ($tor_type != $lp_info['tor_type']) ? ", tor_type = $tor_type" : '';
|
||||||
|
|
||||||
|
$sql .= ($uploaded != $lp_info['uploaded']) ? ", uploaded = $uploaded" : '';
|
||||||
|
$sql .= ($downloaded != $lp_info['downloaded']) ? ", downloaded = $downloaded" : '';
|
||||||
|
$sql .= ", remain = $left";
|
||||||
|
|
||||||
|
$sql .= ($up_add) ? ", up_add = up_add + $up_add" : '';
|
||||||
|
$sql .= ($down_add) ? ", down_add = down_add + $down_add" : '';
|
||||||
|
|
||||||
|
$sql .= ", speed_up = $speed_up";
|
||||||
|
$sql .= ", speed_down = $speed_down";
|
||||||
|
|
||||||
|
$sql .= " WHERE peer_hash = '$peer_hash'";
|
||||||
|
$sql .= " LIMIT 1";
|
||||||
|
|
||||||
|
DB()->query($sql);
|
||||||
|
|
||||||
|
$peer_info_updated = DB()->affected_rows();
|
||||||
|
|
||||||
|
if (DBG_LOG) dbg_log(' ', 'this_peer-update'. ($peer_info_updated ? '' : '-FAIL'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$lp_info || !$peer_info_updated)
|
||||||
|
{
|
||||||
|
$columns = 'peer_hash, topic_id, user_id, ip, port, seeder, releaser, tor_type, uploaded, downloaded, remain, speed_up, speed_down, up_add, down_add, update_time';
|
||||||
|
$values = "'$peer_hash', $topic_id, $user_id, '$ip_sql', $port, $seeder, $releaser, $tor_type, $uploaded, $downloaded, $left, $speed_up, $speed_down, $up_add, $down_add, $update_time";
|
||||||
|
|
||||||
|
DB()->query("REPLACE INTO ". BB_BT_TRACKER ." ($columns) VALUES ($values)");
|
||||||
|
|
||||||
|
if (DBG_LOG) dbg_log(' ', 'this_peer-insert');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit if stopped
|
||||||
|
if ($stopped)
|
||||||
|
{
|
||||||
|
silent_exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store peer info in cache
|
||||||
|
$lp_info = array(
|
||||||
|
'downloaded' => (float) $downloaded,
|
||||||
|
'releaser' => (int) $releaser,
|
||||||
|
'seeder' => (int) $seeder,
|
||||||
|
'topic_id' => (int) $topic_id,
|
||||||
|
'update_time' => (int) TIMENOW,
|
||||||
|
'uploaded' => (float) $uploaded,
|
||||||
|
'user_id' => (int) $user_id,
|
||||||
|
'tor_type' => (int) $tor_type,
|
||||||
|
);
|
||||||
|
|
||||||
|
$lp_info_cached = CACHE('tr_cache')->set(PEER_HASH_PREFIX . $peer_hash, $lp_info, PEER_HASH_EXPIRE);
|
||||||
|
|
||||||
|
if (DBG_LOG && !$lp_info_cached) dbg_log(' ', '$lp_info-caching-FAIL');
|
||||||
|
|
||||||
|
// Get cached output
|
||||||
|
$output = CACHE('tr_cache')->get(PEERS_LIST_PREFIX . $topic_id);
|
||||||
|
|
||||||
|
if (DBG_LOG) dbg_log(' ', '$output-get_from-CACHE-'. ($output !== false ? 'hit' : 'miss'));
|
||||||
|
|
||||||
|
if (!$output)
|
||||||
|
{
|
||||||
|
// Retrieve peers
|
||||||
|
$numwant = (int) $tr_cfg['numwant'];
|
||||||
|
$compact_mode = ($tr_cfg['compact_mode'] || !empty($compact));
|
||||||
|
|
||||||
|
$rowset = DB()->fetch_rowset("
|
||||||
|
SELECT ip, port
|
||||||
|
FROM ". BB_BT_TRACKER ."
|
||||||
|
WHERE topic_id = $topic_id
|
||||||
|
ORDER BY RAND()
|
||||||
|
LIMIT $numwant
|
||||||
|
");
|
||||||
|
|
||||||
|
if ($compact_mode)
|
||||||
|
{
|
||||||
|
$peers = '';
|
||||||
|
|
||||||
|
foreach ($rowset as $peer)
|
||||||
|
{
|
||||||
|
$peers .= pack('Nn', ip2long(decode_ip($peer['ip'])), $peer['port']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$peers = array();
|
||||||
|
|
||||||
|
foreach ($rowset as $peer)
|
||||||
|
{
|
||||||
|
$peers[] = array(
|
||||||
|
'ip' => decode_ip($peer['ip']),
|
||||||
|
'port' => intval($peer['port']),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$seeders = 0;
|
||||||
|
$leechers = 0;
|
||||||
|
|
||||||
|
if ($tr_cfg['scrape'])
|
||||||
|
{
|
||||||
|
$row = DB()->fetch_row("
|
||||||
|
SELECT seeders, leechers
|
||||||
|
FROM ". BB_BT_TRACKER_SNAP ."
|
||||||
|
WHERE topic_id = $topic_id
|
||||||
|
LIMIT 1
|
||||||
|
");
|
||||||
|
|
||||||
|
$seeders = $row['seeders'];
|
||||||
|
$leechers = $row['leechers'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = array(
|
||||||
|
'interval' => (int) $announce_interval,
|
||||||
|
'min interval' => (int) $announce_interval,
|
||||||
|
'peers' => $peers,
|
||||||
|
'complete' => (int) $seeders,
|
||||||
|
'incomplete' => (int) $leechers,
|
||||||
|
);
|
||||||
|
|
||||||
|
$peers_list_cached = CACHE('tr_cache')->set(PEERS_LIST_PREFIX . $topic_id, $output, PEERS_LIST_EXPIRE);
|
||||||
|
|
||||||
|
if (DBG_LOG && !$peers_list_cached) dbg_log(' ', '$output-caching-FAIL');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return data to client
|
||||||
|
echo bencode($output);
|
||||||
|
|
||||||
|
tracker_exit();
|
||||||
exit;
|
exit;
|
|
@ -5,12 +5,7 @@ if (!defined('IN_TRACKER')) die(basename(__FILE__));
|
||||||
// Exit if tracker is disabled
|
// Exit if tracker is disabled
|
||||||
if ($tr_cfg['off'])
|
if ($tr_cfg['off'])
|
||||||
{
|
{
|
||||||
msg_die($tr_cfg['off_reason']);
|
tr_die($tr_cfg['off_reason']);
|
||||||
}
|
|
||||||
// Redirect browser
|
|
||||||
if ($tr_cfg['browser_redirect_url'])
|
|
||||||
{
|
|
||||||
browser_redirect();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -20,29 +15,24 @@ function tracker_exit ()
|
||||||
{
|
{
|
||||||
global $DBS;
|
global $DBS;
|
||||||
|
|
||||||
if (DBG_LOG)
|
if (DBG_LOG && DBG_LOG_GENTIME)
|
||||||
{
|
{
|
||||||
$gen_time = utime() - TIMESTART;
|
if ($gen_time = utime() - TIMESTART)
|
||||||
$num_queries = !empty($DBS) ? DB()->num_queries : '-';
|
{
|
||||||
$sql_inittime = !empty($DBS) ? DB()->sql_inittime : ' -- ';
|
$sql_init_perc = round($DBS->sql_inittime*100/$gen_time);
|
||||||
$sql_timetotal = !empty($DBS) ? DB()->sql_timetotal : ' -- ';
|
$sql_total_perc = round($DBS->sql_timetotal*100/$gen_time);
|
||||||
$sql_init_perc = !empty($DBS) ? round($sql_inittime*100/$gen_time) : ' - ';
|
|
||||||
$sql_total_perc = !empty($DBS) ? round($sql_timetotal*100/$gen_time) : ' - ';
|
|
||||||
|
|
||||||
$str = array();
|
$str = array();
|
||||||
$str[] = substr(time(), -4, 4);
|
$str[] = substr(time(), -4, 4);
|
||||||
$str[] = sprintf('%.4f', $gen_time);
|
$str[] = sprintf('%.4f', $gen_time);
|
||||||
$str[] = sprintf('%.4f'. LOG_SEPR .'%02d%%', $sql_inittime, $sql_init_perc);
|
$str[] = sprintf('%.4f'. LOG_SEPR .'%02d%%', $DBS->sql_inittime, $sql_init_perc);
|
||||||
$str[] = sprintf('%.4f'. LOG_SEPR .'%02d%%', $sql_timetotal, $sql_total_perc);
|
$str[] = sprintf('%.4f'. LOG_SEPR .'%02d%%', $DBS->sql_timetotal, $sql_total_perc);
|
||||||
$str[] = $num_queries;
|
$str[] = $DBS->num_queries;
|
||||||
$str[] = sprintf('%.1f', LOADAVG);
|
$str[] = sprintf('%.1f', sys('la'));
|
||||||
$str = join(LOG_SEPR, $str) . LOG_LF;
|
$str = join(LOG_SEPR, $str) . LOG_LF;
|
||||||
dbg_log($str, '!!gentime');
|
dbg_log($str, '!!gentime');
|
||||||
}
|
}
|
||||||
/**!/
|
}
|
||||||
bb_log("##\n". ob_get_contents() ."\n##", 'tr_output_'. date('m-d_H'));
|
|
||||||
#*/
|
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,129 +57,105 @@ function error_exit ($msg = '')
|
||||||
tracker_exit();
|
tracker_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
function browser_redirect ()
|
|
||||||
{
|
|
||||||
if (empty($_SERVER['HTTP_USER_AGENT'])) return;
|
|
||||||
|
|
||||||
$user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
|
|
||||||
|
|
||||||
$browser_ids = array(
|
|
||||||
'amaya',
|
|
||||||
'crawler',
|
|
||||||
'dillo',
|
|
||||||
'elinks',
|
|
||||||
'gecko',
|
|
||||||
'googlebot',
|
|
||||||
'ibrowse',
|
|
||||||
'icab',
|
|
||||||
'konqueror',
|
|
||||||
'lynx',
|
|
||||||
'mozilla',
|
|
||||||
'msie',
|
|
||||||
'msnbot',
|
|
||||||
'netpositive',
|
|
||||||
'omniweb',
|
|
||||||
'opera',
|
|
||||||
'safari',
|
|
||||||
'slurp',
|
|
||||||
'w3m',
|
|
||||||
'wget',
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($browser_ids as $browser)
|
|
||||||
{
|
|
||||||
if (strpos($user_agent, $browser) !== false)
|
|
||||||
{
|
|
||||||
if (DBG_LOG)
|
|
||||||
{
|
|
||||||
dbg_log(' ', "redirect/$browser");
|
|
||||||
|
|
||||||
dbg_log(
|
|
||||||
TIMENOW . LOG_SEPR .
|
|
||||||
encode_ip($_SERVER['REMOTE_ADDR']) . LOG_SEPR .
|
|
||||||
$_SERVER['REMOTE_ADDR'] . LOG_SEPR .
|
|
||||||
$_SERVER['QUERY_STRING'] . LOG_SEPR .
|
|
||||||
$_SERVER['HTTP_USER_AGENT'] . LOG_SEPR .
|
|
||||||
LOG_LF,
|
|
||||||
"redirect/$browser.q.log"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
header('Location: '. $GLOBALS['tr_cfg']['browser_redirect_url']);
|
|
||||||
tracker_exit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Database
|
// Database
|
||||||
class sql_db
|
class sql_db
|
||||||
{
|
{
|
||||||
|
var $cfg = array();
|
||||||
|
var $cfg_keys = array('dbhost', 'dbname', 'dbuser', 'dbpasswd', 'charset', 'persist');
|
||||||
var $link = null;
|
var $link = null;
|
||||||
var $result = null;
|
var $result = null;
|
||||||
|
var $db_server = '';
|
||||||
var $selected_db = null;
|
var $selected_db = null;
|
||||||
|
|
||||||
var $pconnect = false;
|
|
||||||
var $locked = false;
|
var $locked = false;
|
||||||
|
|
||||||
var $num_queries = 0;
|
var $num_queries = 0;
|
||||||
var $sql_starttime = 0;
|
var $sql_starttime = 0;
|
||||||
var $sql_inittime = 0;
|
var $sql_inittime = 0;
|
||||||
var $sql_timetotal = 0;
|
var $sql_timetotal = 0;
|
||||||
|
var $sql_last_time = 0;
|
||||||
|
var $slow_time = 0;
|
||||||
|
|
||||||
var $dbg = array();
|
var $dbg = array();
|
||||||
var $dbg_id = 0;
|
var $dbg_id = 0;
|
||||||
var $dbg_user = false;
|
var $dbg_enabled = false;
|
||||||
var $cur_query = null;
|
var $cur_query = null;
|
||||||
|
|
||||||
|
var $DBS = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
function sql_db ($cfg)
|
function sql_db ($cfg_values)
|
||||||
{
|
{
|
||||||
$this->dbg_user = (SQL_DEBUG && $cfg['dbg_user']);
|
global $DBS;
|
||||||
$this->pconnect = $cfg['persist'];
|
|
||||||
|
|
||||||
|
$this->cfg = array_combine($this->cfg_keys, $cfg_values);
|
||||||
|
$this->dbg_enabled = sql_dbg_enabled();
|
||||||
|
$this->slow_time = SQL_SLOW_QUERY_TIME;
|
||||||
|
|
||||||
|
$this->DBS['num_queries'] =& $DBS->num_queries;
|
||||||
|
$this->DBS['sql_inittime'] =& $DBS->sql_inittime;
|
||||||
|
$this->DBS['sql_timetotal'] =& $DBS->sql_timetotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize connection
|
||||||
|
*/
|
||||||
|
function init ()
|
||||||
|
{
|
||||||
// Connect to server
|
// Connect to server
|
||||||
$this->link = @$this->connect($cfg);
|
$this->link = $this->connect();
|
||||||
|
|
||||||
// Select database
|
// Select database
|
||||||
$this->selected_db = @$this->select_db($cfg);
|
$this->selected_db = $this->select_db();
|
||||||
|
|
||||||
// Set charset
|
// Set charset
|
||||||
if ($cfg['charset'] && !@$this->sql_query("SET NAMES {$cfg['charset']}"))
|
if ($this->cfg['charset'] && !@mysql_set_charset($this->cfg['charset'], $this->link))
|
||||||
{
|
{
|
||||||
error_exit("Could not set MySQL charset '{$cfg['charset']}'");
|
if (!$this->sql_query("SET NAMES {$this->cfg['charset']}"))
|
||||||
|
{
|
||||||
|
error_exit("Could not set charset {$this->cfg['charset']}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->num_queries = 0;
|
$this->num_queries = 0;
|
||||||
$this->sql_inittime = $this->sql_timetotal;
|
$this->sql_inittime = $this->sql_timetotal;
|
||||||
|
$this->DBS['sql_inittime'] += $this->sql_inittime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open connection
|
* Open connection
|
||||||
*/
|
*/
|
||||||
function connect ($cfg)
|
function connect ()
|
||||||
{
|
{
|
||||||
$this->cur_query = 'connect';
|
$this->cur_query = 'connect';
|
||||||
$this->debug('start');
|
$this->debug('start');
|
||||||
|
|
||||||
$connect_type = ($this->pconnect) ? 'mysql_pconnect' : 'mysql_connect';
|
$connect_type = ($this->cfg['persist']) ? 'mysql_pconnect' : 'mysql_connect';
|
||||||
|
|
||||||
if (!$link = $connect_type($cfg['dbhost'], $cfg['dbuser'], $cfg['dbpasswd']))
|
if (!$link = $connect_type($this->cfg['dbhost'], $this->cfg['dbuser'], $this->cfg['dbpasswd']))
|
||||||
{
|
{
|
||||||
$this->log_error();
|
$this->log_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
register_shutdown_function(array(&$this, 'sql_close'));
|
register_shutdown_function(array(&$this, 'close'));
|
||||||
|
|
||||||
$this->debug('end');
|
$this->debug('end');
|
||||||
$this->cur_query = null;
|
$this->cur_query = null;
|
||||||
|
|
||||||
if (DBG_LOG) dbg_log(' ', 'DB-connect'. ($link ? '' : '-FAIL'));
|
# if (DBG_LOG) dbg_log(' ', 'DB-connect'. ($link ? '' : '-FAIL'));
|
||||||
|
|
||||||
if (!$link)
|
if (!$link)
|
||||||
{
|
{
|
||||||
dummy_exit(1200);
|
if (function_exists('dummy_exit'))
|
||||||
|
{
|
||||||
|
dummy_exit(mt_rand(1200, 2400));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
die;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $link;
|
return $link;
|
||||||
|
@ -198,34 +164,36 @@ class sql_db
|
||||||
/**
|
/**
|
||||||
* Select database
|
* Select database
|
||||||
*/
|
*/
|
||||||
function select_db ($cfg)
|
function select_db ()
|
||||||
{
|
{
|
||||||
$this->cur_query = 'select db';
|
$this->cur_query = 'select db';
|
||||||
$this->debug('start');
|
$this->debug('start');
|
||||||
|
|
||||||
if (!mysql_select_db($cfg['dbname'], $this->link))
|
if (!mysql_select_db($this->cfg['dbname'], $this->link))
|
||||||
{
|
{
|
||||||
$this->log_error();
|
$this->log_error();
|
||||||
error_exit("Could not select database '{$cfg['dbname']}'");
|
error_exit("Could not select database '{$this->cfg['dbname']}'");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->debug('end');
|
$this->debug('end');
|
||||||
$this->cur_query = null;
|
$this->cur_query = null;
|
||||||
|
|
||||||
return $cfg['dbname'];
|
return $this->cfg['dbname'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base query method
|
* Base query method
|
||||||
*/
|
*/
|
||||||
function sql_query ($query, $type = 'buffered')
|
function sql_query ($query)
|
||||||
{
|
{
|
||||||
|
if (!is_resource($this->link))
|
||||||
|
{
|
||||||
|
$this->init();
|
||||||
|
}
|
||||||
$this->cur_query = $query;
|
$this->cur_query = $query;
|
||||||
$this->debug('start');
|
$this->debug('start');
|
||||||
|
|
||||||
$query_function = ($type === 'unbuffered') ? 'mysql_unbuffered_query' : 'mysql_query';
|
if (!$this->result = mysql_query($query, $this->link))
|
||||||
|
|
||||||
if (!$this->result = $query_function($query, $this->link))
|
|
||||||
{
|
{
|
||||||
$this->log_error();
|
$this->log_error();
|
||||||
}
|
}
|
||||||
|
@ -234,6 +202,7 @@ class sql_db
|
||||||
$this->cur_query = null;
|
$this->cur_query = null;
|
||||||
|
|
||||||
$this->num_queries++;
|
$this->num_queries++;
|
||||||
|
$this->DBS['num_queries']++;
|
||||||
|
|
||||||
return $this->result;
|
return $this->result;
|
||||||
}
|
}
|
||||||
|
@ -241,11 +210,11 @@ class sql_db
|
||||||
/**
|
/**
|
||||||
* Execute query WRAPPER (with error handling)
|
* Execute query WRAPPER (with error handling)
|
||||||
*/
|
*/
|
||||||
function query ($query, $err_msg = '')
|
function query ($query)
|
||||||
{
|
{
|
||||||
if (!$result = $this->sql_query($query))
|
if (!$result = $this->sql_query($query))
|
||||||
{
|
{
|
||||||
$this->trigger_error($err_msg);
|
$this->trigger_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -271,33 +240,33 @@ class sql_db
|
||||||
*/
|
*/
|
||||||
function affected_rows ()
|
function affected_rows ()
|
||||||
{
|
{
|
||||||
return (is_resource($this->link)) ? mysql_affected_rows($this->link) : -1;
|
return is_resource($this->link) ? mysql_affected_rows($this->link) : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch current row
|
* Fetch current row
|
||||||
*/
|
*/
|
||||||
function sql_fetchrow ($result, $result_type = MYSQL_ASSOC)
|
function sql_fetchrow ($result)
|
||||||
{
|
{
|
||||||
return (is_resource($result)) ? mysql_fetch_array($result, $result_type) : false;
|
return is_resource($result) ? mysql_fetch_assoc($result) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Alias of sql_fetchrow()
|
* Alias of sql_fetchrow()
|
||||||
*/
|
*/
|
||||||
function fetch_next ($result, $result_type = MYSQL_ASSOC)
|
function fetch_next ($result)
|
||||||
{
|
{
|
||||||
return $this->sql_fetchrow($result, $result_type);
|
return $this->sql_fetchrow($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch row WRAPPER (with error handling)
|
* Fetch row WRAPPER (with error handling)
|
||||||
*/
|
*/
|
||||||
function fetch_row ($query, $err_msg = '')
|
function fetch_row ($query)
|
||||||
{
|
{
|
||||||
if (!$result = $this->sql_query($query))
|
if (!$result = $this->sql_query($query))
|
||||||
{
|
{
|
||||||
$this->trigger_error($err_msg);
|
$this->trigger_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->sql_fetchrow($result);
|
return $this->sql_fetchrow($result);
|
||||||
|
@ -306,11 +275,11 @@ class sql_db
|
||||||
/**
|
/**
|
||||||
* Fetch all rows
|
* Fetch all rows
|
||||||
*/
|
*/
|
||||||
function sql_fetchrowset ($result, $result_type = MYSQL_ASSOC)
|
function sql_fetchrowset ($result)
|
||||||
{
|
{
|
||||||
$rowset = array();
|
$rowset = array();
|
||||||
|
|
||||||
while ($row = mysql_fetch_array($result, $result_type))
|
while ($row = mysql_fetch_assoc($result))
|
||||||
{
|
{
|
||||||
$rowset[] = $row;
|
$rowset[] = $row;
|
||||||
}
|
}
|
||||||
|
@ -321,11 +290,11 @@ class sql_db
|
||||||
/**
|
/**
|
||||||
* Fetch all rows WRAPPER (with error handling)
|
* Fetch all rows WRAPPER (with error handling)
|
||||||
*/
|
*/
|
||||||
function fetch_rowset ($query, $err_msg = '')
|
function fetch_rowset ($query)
|
||||||
{
|
{
|
||||||
if (!$result = $this->sql_query($query, 'buffered'))
|
if (!$result = $this->sql_query($query))
|
||||||
{
|
{
|
||||||
$this->trigger_error($err_msg);
|
$this->trigger_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->sql_fetchrowset($result);
|
return $this->sql_fetchrowset($result);
|
||||||
|
@ -336,6 +305,10 @@ class sql_db
|
||||||
*/
|
*/
|
||||||
function escape ($v, $check_type = false)
|
function escape ($v, $check_type = false)
|
||||||
{
|
{
|
||||||
|
if (!is_resource($this->link))
|
||||||
|
{
|
||||||
|
$this->init();
|
||||||
|
}
|
||||||
if (!$check_type)
|
if (!$check_type)
|
||||||
{
|
{
|
||||||
return mysql_real_escape_string($v);
|
return mysql_real_escape_string($v);
|
||||||
|
@ -377,7 +350,7 @@ class sql_db
|
||||||
/**
|
/**
|
||||||
* Close sql connection
|
* Close sql connection
|
||||||
*/
|
*/
|
||||||
function sql_close ()
|
function close ()
|
||||||
{
|
{
|
||||||
if (is_resource($this->link))
|
if (is_resource($this->link))
|
||||||
{
|
{
|
||||||
|
@ -386,7 +359,7 @@ class sql_db
|
||||||
|
|
||||||
$this->link = $this->selected_db = null;
|
$this->link = $this->selected_db = null;
|
||||||
|
|
||||||
if (DBG_LOG) dbg_log(str_repeat(' ', $this->num_queries), 'DB-num_queries');
|
if (DBG_LOG) dbg_log(str_repeat(' ', $this->num_queries), 'DB-num_queries-'. php_sapi_name());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -425,20 +398,22 @@ class sql_db
|
||||||
if (SQL_CALC_QUERY_TIME || DBG_LOG || SQL_LOG_SLOW_QUERIES)
|
if (SQL_CALC_QUERY_TIME || DBG_LOG || SQL_LOG_SLOW_QUERIES)
|
||||||
{
|
{
|
||||||
$this->sql_starttime = utime();
|
$this->sql_starttime = utime();
|
||||||
|
$this->sql_last_time = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ($mode == 'end')
|
else if ($mode == 'end')
|
||||||
{
|
{
|
||||||
if (SQL_CALC_QUERY_TIME || DBG_LOG || SQL_LOG_SLOW_QUERIES)
|
if (SQL_CALC_QUERY_TIME || DBG_LOG || SQL_LOG_SLOW_QUERIES)
|
||||||
{
|
{
|
||||||
$cur_query_time = utime() - $this->sql_starttime;
|
$this->sql_last_time = utime() - $this->sql_starttime;
|
||||||
$this->sql_timetotal += $cur_query_time;
|
$this->sql_timetotal += $this->sql_last_time;
|
||||||
|
$this->DBS['sql_timetotal'] += $this->sql_last_time;
|
||||||
|
|
||||||
if (SQL_LOG_SLOW_QUERIES && $cur_query_time > SQL_SLOW_QUERY_TIME)
|
if (SQL_LOG_SLOW_QUERIES && $this->sql_last_time > $this->slow_time)
|
||||||
{
|
{
|
||||||
$msg = date('m-d H:i:s') . LOG_SEPR;
|
$msg = date('m-d H:i:s') . LOG_SEPR;
|
||||||
$msg .= sprintf('%03d', round($cur_query_time));
|
$msg .= sprintf('%03d', round($this->sql_last_time));
|
||||||
$msg .= defined('LOADAVG') ? LOG_SEPR . sprintf('%.1f', LOADAVG) : '';
|
$msg .= LOG_SEPR . sprintf('%.1f', sys('la'));
|
||||||
$msg .= LOG_SEPR . str_compact($this->cur_query);
|
$msg .= LOG_SEPR . str_compact($this->cur_query);
|
||||||
$msg .= LOG_SEPR .' # '. $this->query_info();
|
$msg .= LOG_SEPR .' # '. $this->query_info();
|
||||||
$msg .= LOG_SEPR . $this->debug_find_source();
|
$msg .= LOG_SEPR . $this->debug_find_source();
|
||||||
|
@ -484,7 +459,7 @@ class sql_db
|
||||||
{
|
{
|
||||||
if ($trace['file'] !== __FILE__)
|
if ($trace['file'] !== __FILE__)
|
||||||
{
|
{
|
||||||
$source = str_replace(BB_PATH . DIR_SEPR, '', $trace['file']) .'('. $trace['line'] .')';
|
$source = str_replace(BB_PATH . DIRECTORY_SEPARATOR, '', $trace['file']) .'('. $trace['line'] .')';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -518,42 +493,3 @@ class sql_db
|
||||||
bb_log($msg, 'sql_error_tr');
|
bb_log($msg, 'sql_error_tr');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make the database connection
|
|
||||||
function db_init ()
|
|
||||||
{
|
|
||||||
if (defined('SQL_LAYER'))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
define('SQL_LAYER', 'mysql');
|
|
||||||
|
|
||||||
DB() = new sql_db(array(
|
|
||||||
'dbms' => DBMS,
|
|
||||||
'dbhost' => DBHOST,
|
|
||||||
'dbname' => DBNAME,
|
|
||||||
'dbuser' => DBUSER,
|
|
||||||
'dbpasswd' => DBPASSWD,
|
|
||||||
'charset' => DBCHARSET,
|
|
||||||
'collation' => DBCOLLATION,
|
|
||||||
'persist' => PCONNECT,
|
|
||||||
'dbg_user' => false,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
##### LOG ##### // User req (by passkey)
|
|
||||||
if ($log_passkey && isset($log_passkey[$_GET[$passkey_key]]))
|
|
||||||
{
|
|
||||||
bb_log(
|
|
||||||
md5($_GET['info_hash']) . LOG_SEPR .
|
|
||||||
date('His') . LOG_SEPR .
|
|
||||||
TIMENOW . LOG_SEPR .
|
|
||||||
$_SERVER['QUERY_STRING'] . LOG_SEPR .
|
|
||||||
$_SERVER['REMOTE_ADDR'] . LOG_SEPR .
|
|
||||||
@$_SERVER['HTTP_X_FORWARDED_FOR'] . LOG_SEPR .
|
|
||||||
@$_SERVER['HTTP_USER_AGENT'] . LOG_SEPR .
|
|
||||||
LOG_LF,
|
|
||||||
'passkey_'. $log_passkey[$_GET[$passkey_key]]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
### LOG END ###
|
|
|
@ -1,248 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
if (!defined('IN_TRACKER')) die(basename(__FILE__));
|
|
||||||
|
|
||||||
db_init();
|
|
||||||
|
|
||||||
$seeder = ($left == 0) ? 1 : 0;
|
|
||||||
$stopped = ($event === 'stopped');
|
|
||||||
|
|
||||||
// Stopped event
|
|
||||||
if ($stopped)
|
|
||||||
{
|
|
||||||
CACHE('tr_cache')->rm(PEER_HASH_PREFIX . $peer_hash);
|
|
||||||
if (DBG_LOG) dbg_log(' ', 'stopped');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get last peer info from DB
|
|
||||||
if (!CACHE('tr_cache')->used && !$lp_info)
|
|
||||||
{
|
|
||||||
$lp_info = DB()->fetch_row("
|
|
||||||
SELECT * FROM ". BB_BT_TRACKER ." WHERE peer_hash = '$peer_hash' LIMIT 1
|
|
||||||
");
|
|
||||||
|
|
||||||
if (DBG_LOG) dbg_log(' ', '$lp_info-get_from-DB-'. ($lp_info ? 'hit' : 'miss'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($lp_info)
|
|
||||||
{
|
|
||||||
if (!$stopped)
|
|
||||||
{
|
|
||||||
drop_fast_announce($lp_info);
|
|
||||||
}
|
|
||||||
|
|
||||||
$user_id = $lp_info['user_id'];
|
|
||||||
$topic_id = $lp_info['topic_id'];
|
|
||||||
$releaser = $lp_info['releaser'];
|
|
||||||
$tor_type = $lp_info['tor_type'];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Verify if torrent registered on tracker and user authorized
|
|
||||||
$info_hash_sql = rtrim(DB()->escape($info_hash), ' ');
|
|
||||||
$passkey_sql = DB()->escape($passkey);
|
|
||||||
|
|
||||||
$sql = "
|
|
||||||
SELECT tor.topic_id, tor.poster_id, tor.tor_type, u.*
|
|
||||||
FROM ". BB_BT_TORRENTS ." tor
|
|
||||||
LEFT JOIN ". BB_BT_USERS ." u ON u.auth_key = '$passkey_sql'
|
|
||||||
WHERE tor.info_hash = '$info_hash_sql'
|
|
||||||
LIMIT 1
|
|
||||||
";
|
|
||||||
|
|
||||||
$row = DB()->fetch_row($sql);
|
|
||||||
|
|
||||||
if (empty($row['topic_id']))
|
|
||||||
{
|
|
||||||
msg_die('Torrent not registered, info_hash = ' . bin2hex($info_hash_sql));
|
|
||||||
}
|
|
||||||
if (empty($row['user_id']))
|
|
||||||
{
|
|
||||||
msg_die('Please LOG IN and REDOWNLOAD this torrent (user not found)');
|
|
||||||
}
|
|
||||||
|
|
||||||
$user_id = $row['user_id'];
|
|
||||||
$topic_id = $row['topic_id'];
|
|
||||||
$releaser = (int) ($user_id == $row['poster_id']);
|
|
||||||
$tor_type = $row['tor_type'];
|
|
||||||
|
|
||||||
// Ratio limits
|
|
||||||
if ((TR_RATING_LIMITS || $tr_cfg['limit_concurrent_ips']) && !$stopped)
|
|
||||||
{
|
|
||||||
$user_ratio = ($row['u_down_total'] && $row['u_down_total'] > MIN_DL_FOR_RATIO) ? ($row['u_up_total'] + $row['u_up_release'] + $row['u_up_bonus']) / $row['u_down_total'] : 1;
|
|
||||||
require(TR_ROOT .'includes/tr_ratio.php');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Up/Down speed
|
|
||||||
$speed_up = $speed_down = 0;
|
|
||||||
|
|
||||||
if ($lp_info && $lp_info['update_time'] < TIMENOW)
|
|
||||||
{
|
|
||||||
if ($uploaded > $lp_info['uploaded'])
|
|
||||||
{
|
|
||||||
$speed_up = ceil(($uploaded - $lp_info['uploaded']) / (TIMENOW - $lp_info['update_time']));
|
|
||||||
}
|
|
||||||
if ($downloaded > $lp_info['downloaded'])
|
|
||||||
{
|
|
||||||
$speed_down = ceil(($downloaded - $lp_info['downloaded']) / (TIMENOW - $lp_info['update_time']));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Up/Down addition
|
|
||||||
$up_add = ($lp_info && $uploaded > $lp_info['uploaded']) ? $uploaded - $lp_info['uploaded'] : 0;
|
|
||||||
$down_add = ($lp_info && $downloaded > $lp_info['downloaded']) ? $downloaded - $lp_info['downloaded'] : 0;
|
|
||||||
|
|
||||||
// Gold/Silver releases
|
|
||||||
if ($bb_cfg['gold_silver_enabled'] && $down_add)
|
|
||||||
{
|
|
||||||
if ($tor_type == TOR_TYPE_GOLD)
|
|
||||||
{
|
|
||||||
$down_add = 0;
|
|
||||||
}
|
|
||||||
// Silver releases
|
|
||||||
else if ($tor_type == TOR_TYPE_SILVER)
|
|
||||||
{
|
|
||||||
$down_add = ceil($down_add/2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert/update peer info
|
|
||||||
$peer_info_updated = false;
|
|
||||||
$update_time = ($stopped) ? 0 : TIMENOW;
|
|
||||||
|
|
||||||
if ($lp_info)
|
|
||||||
{
|
|
||||||
$sql = "UPDATE ". BB_BT_TRACKER ." SET update_time = $update_time";
|
|
||||||
|
|
||||||
$sql .= ", seeder = $seeder";
|
|
||||||
$sql .= ($releaser != $lp_info['releaser']) ? ", releaser = $releaser" : '';
|
|
||||||
|
|
||||||
$sql .= ($tor_type != $lp_info['tor_type']) ? ", tor_type = $tor_type" : '';
|
|
||||||
|
|
||||||
$sql .= ($uploaded != $lp_info['uploaded']) ? ", uploaded = $uploaded" : '';
|
|
||||||
$sql .= ($downloaded != $lp_info['downloaded']) ? ", downloaded = $downloaded" : '';
|
|
||||||
$sql .= ", remain = $left";
|
|
||||||
|
|
||||||
$sql .= ($up_add) ? ", up_add = up_add + $up_add" : '';
|
|
||||||
$sql .= ($down_add) ? ", down_add = down_add + $down_add" : '';
|
|
||||||
|
|
||||||
$sql .= ", speed_up = $speed_up";
|
|
||||||
$sql .= ", speed_down = $speed_down";
|
|
||||||
|
|
||||||
$sql .= " WHERE peer_hash = '$peer_hash'";
|
|
||||||
$sql .= " LIMIT 1";
|
|
||||||
|
|
||||||
DB()->query($sql);
|
|
||||||
|
|
||||||
$peer_info_updated = DB()->affected_rows();
|
|
||||||
|
|
||||||
if (DBG_LOG) dbg_log(' ', 'this_peer-update'. ($peer_info_updated ? '' : '-FAIL'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$lp_info || !$peer_info_updated)
|
|
||||||
{
|
|
||||||
$columns = 'peer_hash, topic_id, user_id, ip, port, seeder, releaser, tor_type, uploaded, downloaded, remain, speed_up, speed_down, up_add, down_add, update_time';
|
|
||||||
$values = "'$peer_hash', $topic_id, $user_id, '$ip_sql', $port, $seeder, $releaser, $tor_type, $uploaded, $downloaded, $left, $speed_up, $speed_down, $up_add, $down_add, $update_time";
|
|
||||||
|
|
||||||
DB()->query("REPLACE INTO ". BB_BT_TRACKER ." ($columns) VALUES ($values)");
|
|
||||||
|
|
||||||
if (DBG_LOG) dbg_log(' ', 'this_peer-insert');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exit if stopped
|
|
||||||
if ($stopped)
|
|
||||||
{
|
|
||||||
silent_exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store peer info in cache
|
|
||||||
$lp_info = array(
|
|
||||||
'downloaded' => (float) $downloaded,
|
|
||||||
'releaser' => (int) $releaser,
|
|
||||||
'seeder' => (int) $seeder,
|
|
||||||
'topic_id' => (int) $topic_id,
|
|
||||||
'update_time' => (int) TIMENOW,
|
|
||||||
'uploaded' => (float) $uploaded,
|
|
||||||
'user_id' => (int) $user_id,
|
|
||||||
'tor_type' => (int) $tor_type,
|
|
||||||
);
|
|
||||||
|
|
||||||
$lp_info_cached = CACHE('tr_cache')->set(PEER_HASH_PREFIX . $peer_hash, $lp_info, PEER_HASH_EXPIRE);
|
|
||||||
|
|
||||||
if (DBG_LOG && !$lp_info_cached) dbg_log(' ', '$lp_info-caching-FAIL');
|
|
||||||
|
|
||||||
// Get cached output
|
|
||||||
$output = CACHE('tr_cache')->get(PEERS_LIST_PREFIX . $topic_id);
|
|
||||||
|
|
||||||
if (DBG_LOG) dbg_log(' ', '$output-get_from-CACHE-'. ($output !== false ? 'hit' : 'miss'));
|
|
||||||
|
|
||||||
if (!$output)
|
|
||||||
{
|
|
||||||
// Retrieve peers
|
|
||||||
$numwant = (int) $tr_cfg['numwant'];
|
|
||||||
$compact_mode = ($tr_cfg['compact_mode'] || !empty($compact));
|
|
||||||
|
|
||||||
$rowset = DB()->fetch_rowset("
|
|
||||||
SELECT ip, port
|
|
||||||
FROM ". BB_BT_TRACKER ."
|
|
||||||
WHERE topic_id = $topic_id
|
|
||||||
ORDER BY RAND()
|
|
||||||
LIMIT $numwant
|
|
||||||
");
|
|
||||||
|
|
||||||
if ($compact_mode)
|
|
||||||
{
|
|
||||||
$peers = '';
|
|
||||||
|
|
||||||
foreach ($rowset as $peer)
|
|
||||||
{
|
|
||||||
$peers .= pack('Nn', ip2long(decode_ip($peer['ip'])), $peer['port']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$peers = array();
|
|
||||||
|
|
||||||
foreach ($rowset as $peer)
|
|
||||||
{
|
|
||||||
$peers[] = array(
|
|
||||||
'ip' => decode_ip($peer['ip']),
|
|
||||||
'port' => intval($peer['port']),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$seeders = 0;
|
|
||||||
$leechers = 0;
|
|
||||||
|
|
||||||
if ($tr_cfg['scrape'])
|
|
||||||
{
|
|
||||||
$row = DB()->fetch_row("
|
|
||||||
SELECT seeders, leechers
|
|
||||||
FROM ". BB_BT_TRACKER_SNAP ."
|
|
||||||
WHERE topic_id = $topic_id
|
|
||||||
LIMIT 1
|
|
||||||
");
|
|
||||||
|
|
||||||
$seeders = $row['seeders'];
|
|
||||||
$leechers = $row['leechers'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$output = array(
|
|
||||||
'interval' => (int) $announce_interval,
|
|
||||||
'min interval' => (int) $announce_interval,
|
|
||||||
'peers' => $peers,
|
|
||||||
'complete' => (int) $seeders,
|
|
||||||
'incomplete' => (int) $leechers,
|
|
||||||
);
|
|
||||||
|
|
||||||
$peers_list_cached = CACHE('tr_cache')->set(PEERS_LIST_PREFIX . $topic_id, $output, PEERS_LIST_EXPIRE);
|
|
||||||
|
|
||||||
if (DBG_LOG && !$peers_list_cached) dbg_log(' ', '$output-caching-FAIL');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return data to client
|
|
||||||
echo bencode($output);
|
|
||||||
|
|
||||||
tracker_exit();
|
|
|
@ -1,76 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
if (!defined('IN_TRACKER')) die(basename(__FILE__));
|
|
||||||
|
|
||||||
$rating_msg = '';
|
|
||||||
|
|
||||||
if (!$seeder)
|
|
||||||
{
|
|
||||||
foreach ($rating_limits as $ratio => $limit)
|
|
||||||
{
|
|
||||||
if ($user_ratio < $ratio)
|
|
||||||
{
|
|
||||||
$tr_cfg['limit_active_tor'] = 1;
|
|
||||||
$tr_cfg['limit_leech_count'] = $limit;
|
|
||||||
$rating_msg = " (ratio < $ratio)";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Limit active torrents
|
|
||||||
if (!isset($bb_cfg['unlimited_users'][$user_id]) && $tr_cfg['limit_active_tor'] && (($tr_cfg['limit_seed_count'] && $seeder) || ($tr_cfg['limit_leech_count'] && !$seeder)))
|
|
||||||
{
|
|
||||||
$sql = "SELECT COUNT(DISTINCT topic_id) AS active_torrents
|
|
||||||
FROM ". BB_BT_TRACKER ."
|
|
||||||
WHERE user_id = $user_id
|
|
||||||
AND seeder = $seeder
|
|
||||||
AND topic_id != $topic_id";
|
|
||||||
|
|
||||||
if (!$seeder && $tr_cfg['leech_expire_factor'] && $user_ratio < 0.5)
|
|
||||||
{
|
|
||||||
$sql .= " AND update_time > ". (TIMENOW - 60*$tr_cfg['leech_expire_factor']);
|
|
||||||
}
|
|
||||||
$sql .= " GROUP BY user_id";
|
|
||||||
|
|
||||||
if ($row = DB()->fetch_row($sql))
|
|
||||||
{
|
|
||||||
if ($seeder && $tr_cfg['limit_seed_count'] && $row['active_torrents'] >= $tr_cfg['limit_seed_count'])
|
|
||||||
{
|
|
||||||
msg_die('Only '. $tr_cfg['limit_seed_count'] .' torrent(s) allowed for seeding');
|
|
||||||
}
|
|
||||||
else if (!$seeder && $tr_cfg['limit_leech_count'] && $row['active_torrents'] >= $tr_cfg['limit_leech_count'])
|
|
||||||
{
|
|
||||||
msg_die('Only '. $tr_cfg['limit_leech_count'] .' torrent(s) allowed for leeching'. $rating_msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Limit concurrent IPs
|
|
||||||
if ($tr_cfg['limit_concurrent_ips'] && (($tr_cfg['limit_seed_ips'] && $seeder) || ($tr_cfg['limit_leech_ips'] && !$seeder)))
|
|
||||||
{
|
|
||||||
$sql = "SELECT COUNT(DISTINCT ip) AS ips
|
|
||||||
FROM ". BB_BT_TRACKER ."
|
|
||||||
WHERE topic_id = $topic_id
|
|
||||||
AND user_id = $user_id
|
|
||||||
AND seeder = $seeder
|
|
||||||
AND ip != '$ip_sql'";
|
|
||||||
|
|
||||||
if (!$seeder && $tr_cfg['leech_expire_factor'])
|
|
||||||
{
|
|
||||||
$sql .= " AND update_time > ". (TIMENOW - 60*$tr_cfg['leech_expire_factor']);
|
|
||||||
}
|
|
||||||
$sql .= " GROUP BY topic_id";
|
|
||||||
|
|
||||||
if ($row = DB()->fetch_row($sql))
|
|
||||||
{
|
|
||||||
if ($seeder && $tr_cfg['limit_seed_ips'] && $row['ips'] >= $tr_cfg['limit_seed_ips'])
|
|
||||||
{
|
|
||||||
msg_die('You can seed only from '. $tr_cfg['limit_seed_ips'] ." IP's");
|
|
||||||
}
|
|
||||||
else if (!$seeder && $tr_cfg['limit_leech_ips'] && $row['ips'] >= $tr_cfg['limit_leech_ips'])
|
|
||||||
{
|
|
||||||
msg_die('You can leech only from '. $tr_cfg['limit_leech_ips'] ." IP's");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
if (!defined('IN_TRACKER')) die(basename(__FILE__));
|
|
||||||
|
|
||||||
db_init();
|
|
||||||
|
|
||||||
$info_hash_sql = rtrim(DB()->escape($info_hash), ' ');
|
|
||||||
|
|
||||||
$row = DB()->fetch_row("
|
|
||||||
SELECT tor.complete_count, snap.seeders, snap.leechers
|
|
||||||
FROM ". BB_BT_TORRENTS ." tor
|
|
||||||
LEFT JOIN ". BB_BT_TRACKER_SNAP ." snap ON (snap.topic_id = tor.topic_id)
|
|
||||||
WHERE tor.info_hash = '$info_hash_sql'
|
|
||||||
LIMIT 1
|
|
||||||
");
|
|
||||||
|
|
||||||
$output['files'][$info_hash] = array(
|
|
||||||
'complete' => (int) $row['seeders'],
|
|
||||||
'downloaded' => (int) $row['complete_count'],
|
|
||||||
'incomplete' => (int) $row['leechers'],
|
|
||||||
);
|
|
||||||
|
|
||||||
echo bencode($output);
|
|
||||||
|
|
||||||
tracker_exit();
|
|
|
@ -37,5 +37,24 @@ function msg_die ($msg)
|
||||||
|
|
||||||
define('TR_ROOT', './');
|
define('TR_ROOT', './');
|
||||||
require(TR_ROOT .'includes/init_tr.php');
|
require(TR_ROOT .'includes/init_tr.php');
|
||||||
require(TR_ROOT .'includes/tr_scraper.php');
|
|
||||||
|
$info_hash_sql = rtrim(DB()->escape($info_hash), ' ');
|
||||||
|
|
||||||
|
$row = DB()->fetch_row("
|
||||||
|
SELECT tor.complete_count, snap.seeders, snap.leechers
|
||||||
|
FROM ". BB_BT_TORRENTS ." tor
|
||||||
|
LEFT JOIN ". BB_BT_TRACKER_SNAP ." snap ON (snap.topic_id = tor.topic_id)
|
||||||
|
WHERE tor.info_hash = '$info_hash_sql'
|
||||||
|
LIMIT 1
|
||||||
|
");
|
||||||
|
|
||||||
|
$output['files'][$info_hash] = array(
|
||||||
|
'complete' => (int) $row['seeders'],
|
||||||
|
'downloaded' => (int) $row['complete_count'],
|
||||||
|
'incomplete' => (int) $row['leechers'],
|
||||||
|
);
|
||||||
|
|
||||||
|
echo bencode($output);
|
||||||
|
|
||||||
|
tracker_exit();
|
||||||
exit;
|
exit;
|
|
@ -640,16 +640,12 @@ table.forums { width: 100%; }
|
||||||
.last_topic { margin-top: 1px; white-space: nowrap; }
|
.last_topic { margin-top: 1px; white-space: nowrap; }
|
||||||
.last_topic a { text-decoration: none; }
|
.last_topic a { text-decoration: none; }
|
||||||
.last_post_time { margin-top: 2px; font-size: 10px; white-space: nowrap; }
|
.last_post_time { margin-top: 2px; font-size: 10px; white-space: nowrap; }
|
||||||
.last_time {}
|
|
||||||
.last_author { padding-left: 3px; }
|
.last_author { padding-left: 3px; }
|
||||||
.f_stat_inline { /* Posts: xx Topics: xx */
|
.f_stat_inline { /* Posts: xx Topics: xx */
|
||||||
margin-top: 1px; white-space: nowrap; }
|
margin-top: 1px; white-space: nowrap; }
|
||||||
.f_stat_topics {}
|
.f_stat_topics {}
|
||||||
.f_stat_posts { padding-left: 3px; }
|
.f_stat_posts { padding-left: 3px; }
|
||||||
|
|
||||||
.forums thead { /* Forum TH-Headers */
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
.f_icon { /* Forum Icon cell */
|
.f_icon { /* Forum Icon cell */
|
||||||
width: 46px;
|
width: 46px;
|
||||||
padding: 6px 0 !important;
|
padding: 6px 0 !important;
|
||||||
|
@ -671,14 +667,12 @@ table.forums { width: 100%; }
|
||||||
}
|
}
|
||||||
|
|
||||||
table.forums { border-collapse: collapse; }
|
table.forums { border-collapse: collapse; }
|
||||||
.cat_title { border: 0 none;
|
.cat_title { border: 1px solid #C3CBD1; }
|
||||||
border-top: 1px solid #B7C0C5;
|
.f_tbl_wrap, #board_stats_wrap { border: solid #C3CBD1; border-width: 0 1px; }
|
||||||
border-bottom: 1px solid #C3CBD1; }
|
table.forums th { border-bottom: 1px solid #C3CBD1; }
|
||||||
.f_tbl_wrap, #board_stats_wrap {
|
.forums td.row1 { border: solid #C3CBD1; border-width: 0 1px 1px 0; }
|
||||||
border: 0 none; }
|
.forums td.row2 { border: solid #C3CBD1; border-width: 0 1px 1px 0; }
|
||||||
.forums td.row1 { border: solid #FDFDFD; border-width: 0 1px 1px 0; }
|
td.f_titles { border-right-color: #C3CBD1 !important; }
|
||||||
.forums td.row2 { border: solid #F5F5F5; border-width: 0 1px 1px 0; }
|
|
||||||
td.f_titles { border-right-color: #FAFCFD !important; }
|
|
||||||
td.last_td { border-right-width: 0 !important; }
|
td.last_td { border-right-width: 0 !important; }
|
||||||
|
|
||||||
.cat_footer {
|
.cat_footer {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue