Skip to content

Commit

Permalink
Issue #4478 - Fixes decorate_download_location() and check_download_l…
Browse files Browse the repository at this point in the history
…imits() 'missing function' errors.
  • Loading branch information
CaMer0n committed Apr 6, 2021
1 parent 6d0810a commit 240c088
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions e107_plugins/download/request.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require_once(__DIR__.'/../../class2.php');
}


e107::lan('download','download');

class download_request
Expand All @@ -18,7 +17,7 @@ static function request()

$sql = e107::getDb();
$tp = e107::getParser();
$pref = e107::pref('core');
$pref = e107::pref();

if(!is_numeric(e_QUERY) && empty($_GET['id']))
{
Expand Down Expand Up @@ -53,9 +52,9 @@ static function request()
extract($row);
if(check_class($row['download_category_class']) && check_class($row['download_class']))
{
if($pref['download_limits'] && $row['download_active'] == 1)
if(!empty($pref['download_limits']) && $row['download_active'] == 1)
{
check_download_limits();
self::check_download_limits();
}
$mirrorList = explode(chr(1), $row['download_mirror']);
$mstr = "";
Expand All @@ -77,7 +76,11 @@ static function request()
}
$sql->update("download", "download_requested = download_requested + 1, download_mirror = '{$mstr}' WHERE download_id = '" . intval($download_id) . "'");
$sql->update("download_mirror", "mirror_count = mirror_count + 1 WHERE mirror_id = '" . intval($mirror_id) . "'");
header("Location: " . decorate_download_location($gaddress));

if(!empty($gaddress))
{
header("Location: " . self::decorate_download_location($gaddress));
}
exit();
}

Expand Down Expand Up @@ -157,7 +160,7 @@ static function request()

if($pref['download_limits'] && $row['download_active'] == 1)
{
check_download_limits();
self::check_download_limits();
}
extract($row);
if($row['download_mirror'])
Expand Down Expand Up @@ -192,8 +195,10 @@ static function request()
}
$sql->update("download", "download_requested = download_requested + 1, download_mirror = '{$mstr}' WHERE download_id = '" . intval($download_id) . "'");
$sql->update("download_mirror", "mirror_count = mirror_count + 1 WHERE mirror_id = '" . intval($mirror_id) . "'");

header("Location: " . decorate_download_location($gaddress));
if(!empty($gaddress))
{
header("Location: " . self::decorate_download_location($gaddress));
}
exit();
}

Expand All @@ -203,7 +208,7 @@ static function request()
$ip = e107::getIPHandler()->getIP(false);
$request_data = "'0', '{$user_id}', '{$ip}', '{$id}', '" . time() . "'";
//add request info to db
$sql->insert("download_requests", $request_data, false);
$sql->insert("download_requests", $request_data);
// if (preg_match("/Binary\s(.*?)\/.*/", $download_url, $result))
// {
// $bid = $result[1];
Expand All @@ -220,8 +225,8 @@ static function request()
// }
if(strpos($row['download_url'], "http://") !== false || strpos($row['download_url'], "ftp://") !== false || strpos($row['download_url'], "https://") !== false)
{
$download_url = e107::getParser()->parseTemplate($row['download_url'], true); // support for shortcode-driven dynamic URLS.
e107::redirect(decorate_download_location($download_url));
$download_url = e107::getParser()->parseTemplate($row['download_url']); // support for shortcode-driven dynamic URLS.
e107::redirect(self::decorate_download_location($download_url));
// header("Location: {$download_url}");
exit();
}
Expand Down Expand Up @@ -318,7 +323,7 @@ static function request()
if(strpos($image, "http") !== false)
{
e107::redirect($image);
return;
exit();
}
else
{
Expand Down Expand Up @@ -370,9 +375,12 @@ static function request()
}


function check_download_limits()
private static function check_download_limits()
{
global $pref, $sql, $HEADER;
global $HEADER;
$sql = e107::getDb();
$pref = e107::getPref();

// 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";
if($sql->gen($qry))
Expand All @@ -385,7 +393,7 @@ function check_download_limits()
}
else
{
$ip = e107::getIPHandler()->getIP(FALSE);
$ip = e107::getIPHandler()->getIP();
$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";
Expand Down Expand Up @@ -418,7 +426,7 @@ function check_download_limits()
}
else
{
$ip = e107::getIPHandler()->getIP(FALSE);
$ip = e107::getIPHandler()->getIP();
$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";
Expand All @@ -441,11 +449,15 @@ function check_download_limits()
}
}

function decorate_download_location($url)
private static function decorate_download_location($url)
{
$pref = e107::getPref();
if ($pref['download_security_mode'] !== 'nginx-secure_link_md5')

if (varset($pref['download_security_mode']) !== 'nginx-secure_link_md5')
{
return $url;
}

require_once(__DIR__."/handlers/NginxSecureLinkMd5Decorator.php");
$decorator = new NginxSecureLinkMd5Decorator($url, $pref);
return $decorator->decorate();
Expand Down

0 comments on commit 240c088

Please sign in to comment.