diff --git a/.codeclimate.yml b/.codeclimate.yml index 72d1a0307..fe51f29f1 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,5 +1,6 @@ --- -engines: +version: "2" +plugins: csslint: enabled: false duplication: @@ -36,20 +37,25 @@ engines: config: file_extensions: "php" rulesets: "cleancode,unusedcode,codesize" -ratings: - paths: - - "**.css" - - "**.js" - - "**.php" -exclude_paths: -- e107_admin/core_image.php -- e107_plugins/log/js/awesomechart.js -- e107_docs/**/* -- e107_images/**/* -- e107_handlers/hybridauth/**/* -- e107_handlers/jsshrink/**/* -- e107_handlers/phpmailer/**/* -- e107_handlers/phpthumb/**/* -- e107_handlers/xmlrpc/**/* -- e107_web/**/* - +exclude_patterns: +- "config/" +- "db/" +- "dist/" +- "features/" +- "**/node_modules/" +- "script/" +- "**/spec/" +- "**/test/" +- "**/tests/" +- "**/vendor/" +- "**/*.d.ts" +- "e107_admin/core_image.php" +- "e107_plugins/log/js/awesomechart.js" +- "e107_docs/**/*" +- "e107_images/**/*" +- "e107_handlers/hybridauth/**/*" +- "e107_handlers/jsshrink/**/*" +- "e107_handlers/phpmailer/**/*" +- "e107_handlers/phpthumb/**/*" +- "e107_handlers/xmlrpc/**/*" +- "e107_web/**/*" diff --git a/e107_plugins/download/handlers/NginxSecureLinkMd5Decorator.php b/e107_plugins/download/handlers/NginxSecureLinkMd5Decorator.php new file mode 100644 index 000000000..7e36cbace --- /dev/null +++ b/e107_plugins/download/handlers/NginxSecureLinkMd5Decorator.php @@ -0,0 +1,52 @@ +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'] = str_replace(array('+', '/', '='), array('-', '_', ''), base64_encode(md5($evaluation, true))); + if (strpos($prefs['download_security_expression'], '$secure_link_expires') !== false) + $query_args['expires'] = $expiry; + require_once(__DIR__ . '/../vendor/shim_http_build_url.php'); + return http_build_url($url_parts, array('query' => http_build_query($query_args))); + } +} \ No newline at end of file diff --git a/e107_plugins/download/handlers/SecureLinkDecorator.php b/e107_plugins/download/handlers/SecureLinkDecorator.php new file mode 100644 index 000000000..0dd48ab93 --- /dev/null +++ b/e107_plugins/download/handlers/SecureLinkDecorator.php @@ -0,0 +1,6 @@ + LAN_DL_SECURITY_MODE_NONE, + 'nginx-secure_link_md5' => LAN_DL_SECURITY_MODE_NGINX_SECURELINKMD5 + ); // optional - required only in case of e.g. tables JOIN. This also could be done with custom model (set it in init()) //protected $editQry = "SELECT * FROM #release WHERE release_id = {ID}"; @@ -1133,22 +1137,32 @@ $columnInfo = array( global $admin_log,$pref; $tp = e107::getParser(); + + $expected_params = array( + 'download_php', 'download_view', 'download_sort', 'download_order', + 'mirror_order', 'recent_download_days', 'agree_flag', 'download_email', + 'agree_text', 'download_denied', 'download_reportbroken', + 'download_security_mode', 'download_security_expression', 'download_security_link_expiry' + ); $temp = array(); - $temp['download_php'] = $_POST['download_php']; - $temp['download_view'] = $_POST['download_view']; - $temp['download_sort'] = $_POST['download_sort']; - $temp['download_order'] = $_POST['download_order']; - $temp['mirror_order'] = $_POST['mirror_order']; - $temp['recent_download_days'] = $_POST['recent_download_days']; - $temp['agree_flag'] = $_POST['agree_flag']; - $temp['download_email'] = $_POST['download_email']; - $temp['agree_text'] = $tp->toDB($_POST['agree_text']); - $temp['download_denied'] = $tp->toDB($_POST['download_denied']); - $temp['download_reportbroken'] = $_POST['download_reportbroken']; - - if ($_POST['download_subsub']) $temp['download_subsub'] = '1'; else $temp['download_subsub'] = '0'; - if ($_POST['download_incinfo']) $temp['download_incinfo'] = '1'; else $temp['download_incinfo'] = '0'; + foreach($expected_params as $expected_param) + { + $temp[$expected_param] = $_POST[$expected_param]; + } + + $temp['download_subsub'] = $_POST['download_subsub'] ? '1' : '0'; + $temp['download_incinfo'] = $_POST['download_incinfo'] ? '1' : '0'; + + if ($_POST['download_security_mode'] !== 'nginx-secure_link_md5') + { + unset($temp['download_security_mode']); + unset($temp['download_security_expression']); + unset($temp['download_security_link_expiry']); + e107::getConfig('core')->removePref('download_security_mode'); + e107::getConfig('core')->removePref('download_security_expression'); + e107::getConfig('core')->removePref('download_security_link_expiry'); + } e107::getConfig('core')->setPref($temp)->save(false); @@ -2093,14 +2107,33 @@ $columnInfo = array( } } + private function supported_secure_link_variables_html() + { + require_once(__DIR__."/../handlers/NginxSecureLinkMd5Decorator.php"); + $supported_secure_link_variables_html = "
$variable