From d289e42fa25eee1684d169788614a22a7e556d4b Mon Sep 17 00:00:00 2001 From: akpu1 Date: Tue, 21 Jun 2016 00:30:58 +1000 Subject: Removed WHITELIST_MIME; added FILTER_MODE as per clsr's suggestion --- php/includes/settings.inc.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'php') diff --git a/php/includes/settings.inc.php b/php/includes/settings.inc.php index 19a3987..6e70569 100644 --- a/php/includes/settings.inc.php +++ b/php/includes/settings.inc.php @@ -90,17 +90,15 @@ define('ID_CHARSET', 'abcdefghijklmnopqrstuvwxyz'); /** - * Blocked mime types - * @param string[] $FILTER_MIME blocked mime types + * Filtered mime types + * @param string[] $FILTER_MIME allowed/blocked mime types */ $FILTER_MIME = array(""); - /** - * Whitelisted mime types - * @param string[] $WHITELIST_MIME_MIME allowed mime types + * Filter mode: whitelist (true) or blacklist (false) + * @param bool $FILTER_MODE mime type filter mode */ -$WHITELIST_MIME = array(""); - +$FILTER_MODE = false; /** * Double dot file extensions * -- cgit v1.2.3 From 7feb42edec849e7b70723e13292ac53674a8e453 Mon Sep 17 00:00:00 2001 From: akpu1 Date: Tue, 21 Jun 2016 00:42:43 +1000 Subject: Changed logic to use FILTER_MODE to determine whether whitelist/blacklist --- php/upload.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'php') diff --git a/php/upload.php b/php/upload.php index 9b58ba4..e82a7c4 100644 --- a/php/upload.php +++ b/php/upload.php @@ -74,7 +74,7 @@ function generateName($file) function uploadFile($file) { global $db; - global $WHITELIST_MIME; + global $FILTER_MODE; global $FILTER_MIME; // Handle file errors @@ -84,14 +84,15 @@ function uploadFile($file) // Check if mime type is blocked if (!empty($FILTER_MIME)) { - if (in_array($file->mime, $FILTER_MIME)) { - throw new UploadException(UPLOAD_ERR_EXTENSION); - } - } - if (!empty($WHITELIST_MIME)) { - if (!in_array($file->mime, $WHITELIST_MIME)) { - throw new UploadException(UPLOAD_ERR_EXTENSION); - } + if($FILTER_MODE == true) { //whitelist mode + if (!in_array($file->mime, $FILTER_MIME)) { + throw new UploadException(UPLOAD_ERR_EXTENSION); + } + else { //blacklist mode + if (in_array($file->mime, $FILTER_MIME)) { + throw new UploadException(UPLOAD_ERR_EXTENSION); + } + } } -- cgit v1.2.3 From 142100b1213ee4a547d85b5587b2bce16d6b5e30 Mon Sep 17 00:00:00 2001 From: akpu1 Date: Tue, 21 Jun 2016 06:57:18 +1000 Subject: Fixed indenting in line with PSR2 --- php/upload.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'php') diff --git a/php/upload.php b/php/upload.php index e82a7c4..1c7a27f 100644 --- a/php/upload.php +++ b/php/upload.php @@ -84,15 +84,15 @@ function uploadFile($file) // Check if mime type is blocked if (!empty($FILTER_MIME)) { - if($FILTER_MODE == true) { //whitelist mode + if ($FILTER_MODE == true) { //whitelist mode if (!in_array($file->mime, $FILTER_MIME)) { - throw new UploadException(UPLOAD_ERR_EXTENSION); + throw new UploadException(UPLOAD_ERR_EXTENSION); } - else { //blacklist mode + else { //blacklist mode if (in_array($file->mime, $FILTER_MIME)) { - throw new UploadException(UPLOAD_ERR_EXTENSION); + throw new UploadException(UPLOAD_ERR_EXTENSION); } - } + } } -- cgit v1.2.3 From e01670d1bb7204051e076069f50fd68d55e8c92c Mon Sep 17 00:00:00 2001 From: akpu1 Date: Tue, 21 Jun 2016 07:38:02 +1000 Subject: Fixed indenting in line with PSR2 --- php/upload.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'php') diff --git a/php/upload.php b/php/upload.php index 1c7a27f..503ea0f 100644 --- a/php/upload.php +++ b/php/upload.php @@ -84,15 +84,15 @@ function uploadFile($file) // Check if mime type is blocked if (!empty($FILTER_MIME)) { - if ($FILTER_MODE == true) { //whitelist mode - if (!in_array($file->mime, $FILTER_MIME)) { + if ($FILTER_MODE == true) { //whitelist mode + if (!in_array($file->mime, $FILTER_MIME)) { throw new UploadException(UPLOAD_ERR_EXTENSION); } - else { //blacklist mode - if (in_array($file->mime, $FILTER_MIME)) { - throw new UploadException(UPLOAD_ERR_EXTENSION); - } - } + } else { //blacklist mode + if (in_array($file->mime, $FILTER_MIME)) { + throw new UploadException(UPLOAD_ERR_EXTENSION); + } + } } -- cgit v1.2.3