Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add allow_wildcards option #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,22 @@
* PERMISSIONS
*/

//
// Wether wildcard is allowed for filename list
// Default: $_CONFIG['allow_wildcards'] = false;
//
$_CONFIG['allow_wildcards'] = false;

//
// The array of folder names that will be hidden from the list.
// Note: to allow usage of '*' or '?', see $_CONFIG['allow_wildcards']
// Default: $_CONFIG['hidden_dirs'] = array();
//
$_CONFIG['hidden_dirs'] = array();

//
// Filenames that will be hidden from the list.
// Note: to allow usage of '*' or '?', see $_CONFIG['allow_wildcards']
// Default: $_CONFIG['hidden_files'] = array(".ftpquota", "index.php", "index.php~", ".htaccess", ".htpasswd");
//
$_CONFIG['hidden_files'] = array(".ftpquota", "index.php", "index.php~", ".htaccess", ".htpasswd");
Expand Down Expand Up @@ -198,6 +206,7 @@
//
// File extensions that are not allowed for uploading.
// For example: $_CONFIG['upload_reject_extension'] = array("php", "html", "htm");
// Note: to allow usage of '*' or '?', see $_CONFIG['allow_wildcards']
// Default: $_CONFIG['upload_reject_extension'] = array();
//
$_CONFIG['upload_reject_extension'] = array("php", "php2", "php3", "php4", "php5", "phtml");
Expand Down Expand Up @@ -2179,7 +2188,7 @@ function uploadFile($location, $userfile)
{
$encodeExplorer->setErrorString("upload_type_not_allowed");
}
else if(is_array(EncodeExplorer::getConfig("upload_reject_extension")) && count(EncodeExplorer::getConfig("upload_reject_extension")) > 0 && in_array($extension, EncodeExplorer::getConfig("upload_reject_extension")))
else if(is_array(EncodeExplorer::getConfig("upload_reject_extension")) && count(EncodeExplorer::getConfig("upload_reject_extension")) > 0 && EncodeExplorer::in_list($extension, EncodeExplorer::getConfig("upload_reject_extension")))
{
$encodeExplorer->setErrorString("upload_type_not_allowed");
}
Expand Down Expand Up @@ -2651,10 +2660,10 @@ function readDir()
{
if(is_dir($this->location->getDir(true, false, false, 0)."/".$object))
{
if(!in_array($object, EncodeExplorer::getConfig('hidden_dirs')))
if(!EncodeExplorer::in_list($object, EncodeExplorer::getConfig('hidden_dirs')))
$this->dirs[] = new Dir($object, $this->location);
}
else if(!in_array($object, EncodeExplorer::getConfig('hidden_files')))
else if(!EncodeExplorer::in_list($object, EncodeExplorer::getConfig('hidden_files')))
$this->files[] = new File($object, $this->location);
}
}
Expand All @@ -2665,6 +2674,24 @@ function readDir()
$encodeExplorer->setErrorString("unable_to_read_dir");;
}
}

//
// Function to check if an object is in a list
// Uses wildcard if allowed
//
public static function in_list($object, $list)
{
if (EncodeExplorer::getConfig('allow_wildcards') === true) {
foreach ($list as $pattern)
{
if (fnmatch($pattern, $object) === true)
return true;
}
return false;
} else {
return in_array($object, $list);
}
}

//
// A recursive function for calculating the total used space
Expand Down