1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-13 10:04:35 +02:00

Improved: Downloads >> Preferences >> Protection

- MOD: Refactored NGINX secure_link_md5 decorator into interface and
       class in Downloads plugin
- NEW: Downloads plugin: Admin preferences UX improvement:
       Preferences >> Protection now shows the user a list of
       supported NGINX variables pulled from
       NginxSecureLinkMd5Decorator
This commit is contained in:
Nick Liu
2018-04-30 06:24:20 -05:00
parent fa08c915a3
commit 0d7f7dc543
5 changed files with 76 additions and 26 deletions

View File

@@ -0,0 +1,52 @@
<?php
require_once('SecureLinkDecorator.php');
class NginxSecureLinkMd5Decorator implements SecureLinkDecorator
{
protected $url = null;
protected $prefs = array();
const SUPPORTED_VARIABLES = array(
'$secure_link_expires',
'$uri',
'$remote_addr'
);
static function supported_variables() {
return self::SUPPORTED_VARIABLES;
}
function __construct($url, $preferences)
{
$this->url = $url;
$this->prefs = $preferences;
}
public function decorate()
{
$prefs = $this->prefs;
$url = $this->url;
$expiry = intval($prefs['download_security_link_expiry']);
if ($expiry <= 0)
$expiry = PHP_INT_MAX;
else
$expiry = time() + $expiry;
$url_parts = parse_url($url);
$evaluation = str_replace(
self::supported_variables(),
array(
$expiry,
$url_parts['path'],
$_SERVER['REMOTE_ADDR']
),
$prefs['download_security_expression']
);
$query_string = $url_parts['query'];
parse_str($query_string, $query_args);
$query_args['md5'] = md5($evaluation);
if (strpos($prefs['download_security_expression'], '$secure_link_expires') !== false)
$query_args['expires'] = $expiry;
require_once(__DIR__.'/../includes/shim_http_build_url.php');
return http_build_url($url_parts, array('query' => http_build_query($query_args)));
}
}

View File

@@ -0,0 +1,6 @@
<?php
interface SecureLinkDecorator
{
public function decorate();
}