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 deny display by file name and|or file extension #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion config.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@
),

'deniedExts' => "exe com msi bat php phps phtml php3 php4 cgi pl",

'deniedAcces' => array(
"files"=>array(".gitignore",'.htaccess'),
"ext"=>array("xml","php","bat","exe"),
),

// MISC SETTINGS

Expand Down
4 changes: 2 additions & 2 deletions core/browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ protected function getFiles($dir) {
$thumbDir = "{$this->config['uploadDir']}/{$this->config['thumbsDir']}/$dir";
$dir = "{$this->config['uploadDir']}/$dir";
$return = array();
$files = dir::content($dir, array('types' => "file"));
$files = dir::content($dir, array('types' => "file", 'deniedAcces' => $this->config['deniedAcces']));
if ($files === false)
return $return;

Expand Down Expand Up @@ -799,7 +799,7 @@ protected function getDir($existent=true) {
}

protected function getDirs($dir) {
$dirs = dir::content($dir, array('types' => "dir"));
$dirs = dir::content($dir, array('types' => "dir", 'deniedAcces' => $this->config['deniedAcces']));
$return = array();
if (is_array($dirs)) {
$writable = dir::isWritable($dir);
Expand Down
49 changes: 29 additions & 20 deletions lib/helper_dir.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ static function content($dir, array $options=null) {
$defaultOptions = array(
'types' => "all", // Allowed: "all" or possible return values
// of filetype(), or an array with them
'deniedAcces' => false,
'addPath' => true, // Whether to add directory path to filenames
'pattern' => '/./', // Regular expression pattern for filename
'followLinks' => true
Expand All @@ -117,28 +118,36 @@ static function content($dir, array $options=null) {

$files = array();
while (($file = @readdir($dh)) !== false) {
$type = filetype("$dir/$file");

if ($options['followLinks'] && ($type === "link")) {
$lfile = "$dir/$file";
do {
$ldir = dirname($lfile);
$lfile = @readlink($lfile);
if (substr($lfile, 0, 1) != "/")
$lfile = "$ldir/$lfile";
$type = filetype($lfile);
} while ($type == "link");
}
$deniedAcces = false; //init deny

if( (is_array($options['deniedAcces']["files"])) && in_array($file,$options['deniedAcces']["files"]) OR (is_array($options['deniedAcces']["ext"])) && in_array(strtolower(file::getExtension($file)),$options['deniedAcces']["ext"]) )
$deniedAcces = true ;

if(!$deniedAcces){

$type = filetype("$dir/$file");

if ($options['followLinks'] && ($type === "link")) {
$lfile = "$dir/$file";
do {
$ldir = dirname($lfile);
$lfile = @readlink($lfile);
if (substr($lfile, 0, 1) != "/")
$lfile = "$ldir/$lfile";
$type = filetype($lfile);
} while ($type == "link");
}

if ((($type === "dir") && (($file == ".") || ($file == ".."))) ||
!preg_match($options['pattern'], $file)
)
continue;
if ((($type === "dir") && (($file == ".") || ($file == ".."))) ||
!preg_match($options['pattern'], $file)
)
continue;

if (($options['types'] === "all") || ($type === $options['types']) ||
((is_array($options['types'])) && in_array($type, $options['types']))
)
$files[] = $options['addPath'] ? "$dir/$file" : $file;
if (($options['types'] === "all") || ($type === $options['types']) ||
((is_array($options['types'])) && in_array($type, $options['types']))
)
$files[] = $options['addPath'] ? "$dir/$file" : $file;
}
}
closedir($dh);
usort($files, array("dir", "fileSort"));
Expand Down