browse-v1.1.phps

<?
// bttrack.py --port 6969 --dfile /home/erik/.dfile --timeout_check_interval 1 --allowed_dir /var/www/torrents --scrape_allowed specific --allow_get 1
$start = gettimeofday();
error_reporting(E_WARN);

function duration($ts)
{
  $mins = floor((time() - $ts) / 60);
  $hours = floor($mins / 60);
  $mins -= $hours * 60;
  $days = floor($hours / 24);
  $hours -= $days * 24;
  $weeks = floor($days / 7);
  $days -= $weeks * 7;
  $t = "";
  if ($weeks > 0)
    return $weeks. " week" . ($weeks > 1 ? "s" : "");
  if ($days > 0)
    return $days." day" . ($days > 1 ? "s" : "");
  if ($hours > 0)
    return $hours." hour" . ($hours > 1 ? "s" : "");
  if ($mins > 0)
    return $mins." min" . ($mins > 1 ? "s" : "");
  return "< 1 min";
}
$msql = mysql_connect('192.168.0.1','pilsk','fisk');
mysql_select_db('bt');


$dfile = '/home/erik/.dfile';
$dmtime = filemtime($dfile);

$keys = array();
if(isset($_GET['s']) && strlen($_GET['s']) > 2)
{ // search at least 2 chars to proceed
  $search = split('[\(\) ._\+-]', $_GET['s']);
  foreach($search as $key)
  {
    $key = mysql_real_escape_string($key);
    if(strlen($key) >= 1 && @!in_array($key, $keys, true))
    { // i want a search key with at least 1 char
      $keys[] = $key;
    }
  }
  if(count($keys) != 0)
  {
    $s = 'AND torrents.name LIKE "%'.join('%',$keys).'%"';
  }
}


?>
<html>
<head>
<title>Torrent Status</title>
<style type="text/css">
td {
    font-family: Verdana, sans-serif;
    font-size: 11px;
}
td, th {
    font-family: Verdana, sans-serif;
    font-size: 11px;
}
a:HOVER, a.p:HOVER {
    text-decoration: underline;
    color: #006296;
}
a {
    text-decoration: none;
    color: #4b703e;
}
a.p {
    color: #Ff3300;
}
fieldset {
    padding: 0px 5px 5px 5px;
    background-color: #F3F1ED;
    margin: 0 0 0 0;
}
.med, input, select, label {
    font: 12px Verdana, sans-serif;
}
</style>
</head>
<body>
<form action="" method="get">
<table align="center" cellspacing="1" cellpadding="5" border="0" bgcolor="#3d7d30"><tr bgcolor="#7ebd68"><td>
<input type="text" name="s" value="<?=$_GET['s']?>" size="30" maxlength="255"></td><td>
<input type="submit" value="Search" size="10">
</td></tr></table>
</form>
<table cellspacing="1" cellpadding="2" border="0" bgcolor="#3d7d30" width="750" style="margin-bottom: 5px" align="center">
<tr bgcolor="#7ebd68"><th width="90">Category</th><th width="360">Name</th><th width="80">Added</th><th width="80">Size</th><th width="70">Seeders</th><th width="70">Leechers</th></tr>
<?

include('./include/size_readable.php');
include('/home/erik/public_html/timer.php');

$res = mysql_query('select torrents.info_hash as hash, torrents.name, torrents.seeders, torrents.leechers, unix_timestamp(torrents.added) as added, times_completed as completed, torrents.last_action, torrents.size, categories.name as cat from torrents left join categories on torrents.category = categories.id where visible="yes" '.$s.' order by name') or die(mysql_error());

$leechers = $seeders = $size = $completed = 0;

if(mysql_num_rows($res) <= 0)
{
  echo '<tr bgcolor="#ffffff"><td colspan="6"><b>No torrents found.</b></td></tr>';
} else
{
  while($row = mysql_fetch_assoc($res))
  {
    //var_dump($row);
    $hash = bin2hex($row['hash']);
    $name = $row['name'];
    if(is_readable('./torrents/'.$hash.'.torrent'))
    {
      $name = '<a href="./torrents/'.$hash.'.torrent">'.$name.'</a>';
    }
    echo "<tr bgcolor=\"#ffffff\"><td>".$row['cat']."</td><td>".$name."</td><td>".duration($row['added'])." ago</td><td>".size_readable($row['size'])."</td><td>".number_format($row['seeders'])."</td><td>".number_format($row['leechers'])."</td></tr>\n";
    $seeders = $seeders + $row['seeders'];
    $leechers = $leechers + $row['leechers'];
    $completed = $completed + $row['completed'];
    $size = $size + $row['size'];
  }
  echo '<tr bgcolor="#7ebd68"><td colspan="3"><b>Total:</b></td><td><b>'.size_readable($size).'</b></td><td><b>'.number_format($seeders).'</b></td><td><b>'.number_format($leechers).'</b></td></tr>';
}
mysql_close($msql);
?>
</table>
<br>
<div align="center" style="margin-left: auto; margin-right: auto; padding-bottom: 15px; width: 100%">
Generation time: <?=function_timer($start, gettimeofday(), 1000)?>ms. Last update: <?=duration($dmtime)?> ago.
</div>
<pre>
</pre>
</body>
</html>