<?php
/*
FolderPerms.php - tweezy FileWatch companion
30/7/10
FileWatch.class doesn't check or report on directory permissions, only files.
Use this little script to check directory permissions on your site.
*/
$StartFolder = './';
$RecurseLevel = 99;
$ShowList = true; // list directories if true, otherwise just show summary
$Except = '755,750,700'; // comma-sep list of permissions not to list in detail (if $ShowList=true)
//________________________________________________________________________________
// no need to edit below here
//---------------------------
echo 'Directory permissions for '.$StartFolder;
if($RecurseLevel>0) echo " and $RecurseLevel levels below";
echo '<hr />';
if(!isset($FollowSymlinks)) $FollowSymlinks=false;
if(!isset($Except)) $Except='';
$Except=explode(',', $Except);
$DirList = FileDirPerm($StartFolder, $RecurseLevel, $FollowSymlinks);
// count directories for each perm value..
$PermCount=array();
foreach($DirList as $FolderName=>$PermValue)
{
if(isset($PermCount[$PermValue]))
{ $PermCount[$PermValue]++; }
else
{ $PermCount[$PermValue]=1; }
}
// show the results..
echo '<pre>';
foreach($PermCount as $Perm=>$Count)
{ echo "$Perm ... $Count directories\r\n"; }
echo "\r\n\r\n";
if($ShowList)
{
foreach($DirList as $Dirname=>$Perm)
{ if(!in_array($Perm, $Except)) echo "$Perm $Dirname\r\n"; }
}
echo '</pre>';
exit;
// from twzInc ===============================================================================================
function FileDirPerm($FolderName, $RecurseLevel=999, $FollowSymlinks=false, $ThisLevel=0) { if(substr($FolderName,-1)<>'/') $FolderName.='/'; if($ThisLevel<=0) $ThisLevel=0; $DirList=array(); if (@$handle = opendir($FolderName)) { while (false !== ($Filename=readdir($handle))) { $DirList[$FolderName]=substr(decoct(fileperms($FolderName)), -3); if ($Filename != "." and $Filename != "..") { if(is_dir($FolderName.$Filename) and $ThisLevel<$RecurseLevel and ($FollowSymlinks or !is_link($FolderName.$Filename))) { $DirList=array_merge($DirList, call_user_func(__FUNCTION__, ($FolderName.$Filename), $RecurseLevel, $FollowSymlinks, ($ThisLevel+1))); } } } closedir($handle); } return $DirList; }
?>
|