= $numfolders) or ($totalnumfiles >= $numfiles)){ return "TMF"; }else{ return "LNF"; } } // Make sure the folder & files are current & that the // stats are correct before checking if it is safe to run clearstatcache(); // Let's figure out if we're on the command line or web server.. function clihttp() { if($_ENV['SHELL']) { $d = "CLI"; }elseif($_POST['d'] == "yes") { $d = "HTTP"; } return $d; } // This function finds all files & folders in the starting directory function filelist ($startdir="./"){ $ignoredDirectory[] = "."; $ignoredDirectory[] = ".."; global $directorylist; // I do not know of a way to have it work without this line I know it sucks :P if (is_dir($startdir)){ if ($dh = opendir($startdir)){ while (($file = readdir($dh)) !== false){ if (!(array_search($file,$ignoredDirectory) > -1)){ if (filetype($startdir . $file) == "dir"){ $directorylist[$startdir . $file]['name'] = $file; $directorylist[$startdir . $file]['path'] = $startdir; filelist($startdir . $file . "/"); } else { $directorylist[$startdir . $file]['name'] = $file; $directorylist[$startdir . $file]['path'] = $startdir; } } } closedir($dh); } } return($directorylist); } // This function is to fix the permissions // Its output is in HTML function fixpermshtml(){ $files = filelist(); $j = 0; foreach ($files as $list){ $filesandfolders[] = $list['path'] . $list['name']; } $j = count($filesandfolders); for ($i = 0; $i < $j; $i++){ if (is_dir($filesandfolders[$i])){ chmod($filesandfolders[$i], 0755); print("
$filesandfolders[$i]: 0755
\n"); } else { if (file_exists($filesandfolders[$i])){ if ((substr($filesandfolders[$i], -9) == '.ftpquota')){ chmod($filesandfolders[$i], 0600); print("$filesandfolders[$i]: 0600
\n"); } elseif ((substr($filesandfolders[$i], -3) == '.pl') or (substr($filesandfolders[$i], -3) == '.pm') or (substr($filesandfolders[$i], -4) == '.cgi') or (substr($filesandfolders[$i], -3) == '.py')){ chmod($filesandfolders[$i], 0755); print("$filesandfolders[$i]: 0755
\n"); $file_result = `file $filesandfolders[$i]`; if (!preg_match("/ELF/", $file_result) || !preg_match("/SYSV/", $file_result)){ system("dos2unix $filesandfolders[$i]"); } } elseif ((substr($filesandfolders[$i], -13) == 'wp-config.php') or (substr($filesandfolders[$i], -13) == 'configure.php')){ chmod($filesandfolders[$i], 0444); print("$filesandfolders[$i]: 0444
\n"); } else{ chmod($filesandfolders[$i], 0644); print("$filesandfolders[$i]: 0644
\n"); } } } } } // This function is to fix the permissions // Its output is for the CLI function fixpermscmd(){ echo "Fixing permissions on Files & Folders.";
echo "\nSetting folders to 755 & files to 644. ";
system ('find ./ -type d -exec chmod 755 {} \;');
system ('find ./ -type f -exec chmod 644 {} \;');
echo "\nDone.";
echo "\nSetting .cgi & .pl files to 755. ";
system ('find ./ -name \*.cgi -exec chmod 755 {} \;');
system ('find ./ -name \*.pl -exec chmod 755 {} \;');
system ('find ./ -name \*.pm -exec chmod 755 {} \;');
system ('find ./ -name \*.py -exec chmod 755 {} \;');
echo "\nDone.";
echo "\nAlso setting .ftpquota files to 600. ";
system ('find ./ -name .ftpquota -exec chmod 600 {} \;');
echo "\nDone.";
}
// This gives you an idea of the number of
// files & folders before running the script
// in HTTP/HTML mode
function numfilesandfolders(){
print "Number of folders ";
system ("find ./ -type d | wc -l");
print "
Number of files ";
system ("find ./ -type f | wc -l");
print "
Please note that a large number of Folders & files will slow this down.";
}
// This tells you how much memory the script has used
function memoryabused(){
$d = clihttp();
if (is_callable(memory_get_usage)){
if ($d == "CLI"){
print "Memory usage in bytes " . memory_get_usage() . "\n";
}else{
print "
Memory usage in bytes " . memory_get_usage() . "
"; } } else { if ($d == "CLI"){ print "I can't get the Memory usage.\n"; }else{ print "I can't get the Memory usage.
"; } } } // This spits out the HTML form function showform(){ print "\n";
print"Fixing permissions on Files & Folders.\n";
print"
Setting folders to 755 & files to 644.\n";
print"
Setting .cgi, .pl, .pm, & .py files to 755.\n";
print"
Also setting .ftpquota files to 600.\n";
$f = killfortomany(highFoldersHTML, highFilesHTML);
if($f == "LNF"){
fixpermshtml();
}else{
print "
The account has to many files to dare running it in this folder.\n";
}
memoryabused();
print"
";
$scriptEnd = timeabused();
echo "Script executed in ".bcsub($scriptEnd, $scriptStart, 4)." seconds.";
print"
\n"; numfilesandfolders(); showform(); memoryabused(); print"
"; } ?>