1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-03 05:07:27 +02:00

Download request.php - LAN fix and code cleanup

This commit is contained in:
Moc
2013-05-20 15:36:08 +02:00
parent 152d66b0a1
commit 5034dc0e49

View File

@@ -1,15 +1,15 @@
<?php <?php
require_once("../../class2.php"); require_once("../../class2.php");
include_lan(e_PLUGIN."download/languages/".e_LANGUAGE."/".e_LANGUAGE."_front.php"); include_lan(e_PLUGIN."download/languages/".e_LANGUAGE."/download.php");
$id = FALSE; $id = FALSE;
if (!is_numeric(e_QUERY)) if (!is_numeric(e_QUERY))
{ {
if ($sql->db_Select('download', 'download_id', "download_url='".$tp -> toDB(e_QUERY)."'")) if ($sql->select('download', 'download_id', "download_url='".$tp->toDB(e_QUERY)."'"))
{ {
$row = $sql->db_Fetch(); $row = $sql->fetch();
$type = 'file'; $type = 'file';
$id = $row['download_id']; $id = $row['download_id'];
} }
@@ -33,9 +33,9 @@ if(strstr(e_QUERY, "mirror"))
$download_id = intval($download_id); $download_id = intval($download_id);
$mirror_id = intval($mirror_id); $mirror_id = intval($mirror_id);
$qry = "SELECT d.*, dc.download_category_class FROM #download as d LEFT JOIN #download_category AS dc ON dc.download_category_id = d.download_category WHERE d.download_id = {$download_id}"; $qry = "SELECT d.*, dc.download_category_class FROM #download as d LEFT JOIN #download_category AS dc ON dc.download_category_id = d.download_category WHERE d.download_id = {$download_id}";
if ($sql->db_Select_gen($qry)) if ($sql->gen($qry))
{ {
$row = $sql->db_Fetch(); $row = $sql->fetch();
extract($row); extract($row);
if (check_class($download_category_class) && check_class($download_class)) if (check_class($download_category_class) && check_class($download_class))
{ {
@@ -61,8 +61,8 @@ if(strstr(e_QUERY, "mirror"))
$mstr .= $mid.",".$address.",".$requests.chr(1); $mstr .= $mid.",".$address.",".$requests.chr(1);
} }
} }
$sql->db_Update("download", "download_requested = download_requested + 1, download_mirror = '{$mstr}' WHERE download_id = '".intval($download_id)."'"); $sql->update("download", "download_requested = download_requested + 1, download_mirror = '{$mstr}' WHERE download_id = '".intval($download_id)."'");
$sql->db_Update("download_mirror", "mirror_count = mirror_count + 1 WHERE mirror_id = '".intval($mirror_id)."'"); $sql->update("download_mirror", "mirror_count = mirror_count + 1 WHERE mirror_id = '".intval($mirror_id)."'");
header("Location: {$gaddress}"); header("Location: {$gaddress}");
exit(); exit();
} }
@@ -112,7 +112,7 @@ if ($type == "file")
$qry = "SELECT d.*, dc.download_category_class FROM #download as d LEFT JOIN #download_category AS dc ON dc.download_category_id = d.download_category WHERE d.download_id = {$id}"; $qry = "SELECT d.*, dc.download_category_class FROM #download as d LEFT JOIN #download_category AS dc ON dc.download_category_id = d.download_category WHERE d.download_id = {$id}";
if ($sql->gen($qry)) if ($sql->gen($qry))
{ {
$row = $sql->db_Fetch(); $row = $sql->fetch();
$row['download_url'] = $tp->replaceConstants($row['download_url']); $row['download_url'] = $tp->replaceConstants($row['download_url']);
@@ -161,15 +161,15 @@ if ($type == "file")
$mstr .= $mid.",".$address.",".$requests.chr(1); $mstr .= $mid.",".$address.",".$requests.chr(1);
} }
} }
$sql -> db_Update("download", "download_requested = download_requested + 1, download_mirror = '{$mstr}' WHERE download_id = '".intval($download_id)."'"); $sql->update("download", "download_requested = download_requested + 1, download_mirror = '{$mstr}' WHERE download_id = '".intval($download_id)."'");
$sql -> db_Update("download_mirror", "mirror_count = mirror_count + 1 WHERE mirror_id = '".intval($mirror_id)."'"); $sql->update("download_mirror", "mirror_count = mirror_count + 1 WHERE mirror_id = '".intval($mirror_id)."'");
header("Location: ".$gaddress); header("Location: ".$gaddress);
exit(); exit();
} }
// increment download count // increment download count
$sql->db_Update("download", "download_requested = download_requested + 1 WHERE download_id = '{$id}'"); $sql->update("download", "download_requested = download_requested + 1 WHERE download_id = '{$id}'");
$user_id = USER ? USERID : 0; $user_id = USER ? USERID : 0;
$ip = e107::getIPHandler()->getIP(FALSE); $ip = e107::getIPHandler()->getIP(FALSE);
$request_data = "'0', '{$user_id}', '{$ip}', '{$id}', '".time()."'"; $request_data = "'0', '{$user_id}', '{$ip}', '{$id}', '".time()."'";
@@ -250,8 +250,8 @@ if ($type == "file")
exit(); exit();
} }
$sql->db_Select($table, "*", "{$table}_id = '{$id}'"); $sql->select($table, "*", "{$table}_id = '{$id}'");
$row = $sql->db_Fetch(); $row = $sql->fetch();
extract($row); extract($row);
$image = ($table == "upload" ? $upload_ss : $download_image); $image = ($table == "upload" ? $upload_ss : $download_image);
if (preg_match("/Binary\s(.*?)\/.*/", $image, $result)) if (preg_match("/Binary\s(.*?)\/.*/", $image, $result))
@@ -319,28 +319,28 @@ else
function check_download_limits() function check_download_limits()
{ {
global $pref, $sql, $ns, $HEADER, $e107, $tp; global $pref, $sql, $ns, $HEADER, $e107, $tp;
// Check download count limits // Check download count limits
$qry = "SELECT gen_intdata, gen_chardata, (gen_intdata/gen_chardata) as count_perday FROM #generic WHERE gen_type = 'download_limit' AND gen_datestamp IN (".USERCLASS_LIST.") AND (gen_chardata >= 0 AND gen_intdata >= 0) ORDER BY count_perday DESC"; $qry = "SELECT gen_intdata, gen_chardata, (gen_intdata/gen_chardata) as count_perday FROM #generic WHERE gen_type = 'download_limit' AND gen_datestamp IN (".USERCLASS_LIST.") AND (gen_chardata >= 0 AND gen_intdata >= 0) ORDER BY count_perday DESC";
if($sql->db_Select_gen($qry)) if($sql->gen($qry))
{ {
$limits = $sql->db_Fetch(); $limits = $sql->fetch();
$cutoff = time() - (86400 * $limits['gen_chardata']); $cutoff = time() - (86400 * $limits['gen_chardata']);
if(USER) if(USER)
{ {
$where = "dr.download_request_datestamp > {$cutoff} AND dr.download_request_userid = ".USERID; $where = "dr.download_request_datestamp > {$cutoff} AND dr.download_request_userid = ".USERID;
} else { }
else
{
$ip = e107::getIPHandler()->getIP(FALSE); $ip = e107::getIPHandler()->getIP(FALSE);
$where = "dr.download_request_datestamp > {$cutoff} AND dr.download_request_ip = '{$ip}'"; $where = "dr.download_request_datestamp > {$cutoff} AND dr.download_request_ip = '{$ip}'";
} }
$qry = "SELECT COUNT(d.download_id) as count FROM #download_requests as dr LEFT JOIN #download as d ON dr.download_request_download_id = d.download_id AND d.download_active = 1 WHERE {$where} GROUP by dr.download_request_userid"; $qry = "SELECT COUNT(d.download_id) as count FROM #download_requests as dr LEFT JOIN #download as d ON dr.download_request_download_id = d.download_id AND d.download_active = 1 WHERE {$where} GROUP by dr.download_request_userid";
if($sql->db_Select_gen($qry)) if($sql->gen($qry))
{ {
$row=$sql->db_Fetch(); $row = $sql->fetch();
if($row['count'] >= $limits['gen_intdata']) if($row['count'] >= $limits['gen_intdata'])
{ {
// Exceeded download count limit // Exceeded download count limit
@@ -354,18 +354,24 @@ function check_download_limits()
} }
// Check download bandwidth limits // Check download bandwidth limits
$qry = "SELECT gen_user_id, gen_ip, (gen_user_id/gen_ip) as bw_perday FROM #generic WHERE gen_type='download_limit' AND gen_datestamp IN (".USERCLASS_LIST.") AND (gen_user_id >= 0 AND gen_ip >= 0) ORDER BY bw_perday DESC"; $qry = "SELECT gen_user_id, gen_ip, (gen_user_id/gen_ip) as bw_perday FROM #generic WHERE gen_type='download_limit' AND gen_datestamp IN (".USERCLASS_LIST.") AND (gen_user_id >= 0 AND gen_ip >= 0) ORDER BY bw_perday DESC";
if($sql->db_Select_gen($qry)) { if($sql->gen($qry))
$limit = $sql->db_Fetch(); {
$limit = $sql->fetch();
$cutoff = time() - (86400*$limit['gen_ip']); $cutoff = time() - (86400*$limit['gen_ip']);
if(USER) { if(USER)
{
$where = "dr.download_request_datestamp > {$cutoff} AND dr.download_request_userid = ".USERID; $where = "dr.download_request_datestamp > {$cutoff} AND dr.download_request_userid = ".USERID;
} else { }
else
{
$ip = e107::getIPHandler()->getIP(FALSE); $ip = e107::getIPHandler()->getIP(FALSE);
$where = "dr.download_request_datestamp > {$cutoff} AND dr.download_request_ip = '{$ip}'"; $where = "dr.download_request_datestamp > {$cutoff} AND dr.download_request_ip = '{$ip}'";
} }
$qry = "SELECT SUM(d.download_filesize) as total_bw FROM #download_requests as dr LEFT JOIN #download as d ON dr.download_request_download_id = d.download_id AND d.download_active = 1 WHERE {$where} GROUP by dr.download_request_userid"; $qry = "SELECT SUM(d.download_filesize) as total_bw FROM #download_requests as dr LEFT JOIN #download as d ON dr.download_request_download_id = d.download_id AND d.download_active = 1 WHERE {$where} GROUP by dr.download_request_userid";
if($sql->db_Select_gen($qry)) { if($sql->gen($qry))
$row=$sql->db_Fetch(); {
$row = $sql->fetch();
if($row['total_bw'] / 1024 > $limit['gen_user_id']) if($row['total_bw'] / 1024 > $limit['gen_user_id'])
{ //Exceed bandwith limit { //Exceed bandwith limit
header("Location: ".e_BASE."download.php?error.{$cutoff}.2"); header("Location: ".e_BASE."download.php?error.{$cutoff}.2");