error_reporting(E_ERROR|E_PARSE);/* Makes is so Directories are not browseable to the public,
removing only the Public = Read permission, while leaving
the other chmod permissions for the file in tact.
If you have exectue already on, and read off, public viewers will only
be able to view files through links, but not browse
around to see what's inside of directories and see what
you've got laying around. */
//-------------------------------------------------------
// Get file mode
// Get file permissions supported by chmodfunctiongetmod($filename) {$val=0;$perms=fileperms($filename);// Owner; User$val+= (($perms&0x0100) ?0x0100:0x0000);//Read$val+= (($perms&0x0080) ?0x0080:0x0000);//Write$val+= (($perms&0x0040) ?0x0040:0x0000);//Execute
// Group$val+= (($perms&0x0020) ?0x0020:0x0000);//Read$val+= (($perms&0x0010) ?0x0010:0x0000);//Write$val+= (($perms&0x0008) ?0x0008:0x0000);//Execute
// Global; World$val+= (($perms&0x0004) ?0x0004:0x0000);//Read$val+= (($perms&0x0002) ?0x0002:0x0000);//Write$val+= (($perms&0x0001) ?0x0001:0x0000);//Execute
// Misc$val+= (($perms&0x40000) ?0x40000:0x0000);//temporary file (01000000)$val+= (($perms&0x80000) ?0x80000:0x0000);//compressed file (02000000)$val+= (($perms&0x100000) ?0x100000:0x0000);//sparse file (04000000)$val+= (($perms&0x0800) ?0x0800:0x0000);//Hidden file (setuid bit) (04000)$val+= (($perms&0x0400) ?0x0400:0x0000);//System file (setgid bit) (02000)$val+= (($perms&0x0200) ?0x0200:0x0000);//Archive bit (sticky bit) (01000)return$val;
}//-------------------------------------------------------
// Find out if file has modefunctionhasmod($perms,$permission) {# User Read = 0400 (256), Write = 0200 (128), Execute = 0100 (64)
# Group Read = 0040 (32), Write = 0020 (16), Execute = 0010 (8)
# Public Read = 0004 (4), Write = 0002 (2), Execute = 0001 (1)return (($perms&$permission) ==$permission);
}//-------------------------------------------------------
// Take the read option off of all the subdirectories of the included pathfunctionpathlock($dir,$listall=false,$testrun=true) {
echo"START @ ".date("F j, Y, h:i:s A") ."
";
echo ($testrun?'**Test Run Activated (no changes will be made).**
':'**Live Run Activated.**
');
echo$dir." is our directory.
\n";
echo"[...IN PROGRESS...]
";$file_list='';$stack[] =$dir;
while ($stack) {$current_dir=array_pop($stack);
if ($dh=opendir($current_dir)) {
while (($file=readdir($dh)) !==false) {
if ($file!=='.'AND$file!=='..') {$current_file="{$current_dir}/{$file}";
if (is_dir($current_file)) {// BEG ADD PATH$mode=getmod($current_file);//Get the mode$HasPubRead=hasmod($mode,4);
if ($HasPubRead||$listall) {// Can the public read this dir?
//======================================$ch=true;$take=0;// Change the mode:if ($HasPubRead) {$take=4;// Value for Public Read. 4 is the same in octal and decimal.if (!$testrun) {$ch=chmod($current_file,$mode-$take);
}
}
echo$current_file.",current=".decoct($mode) .
(($mode!==$mode-$take) ?",new=".decoct($mode-$take) :'') .
($ch?'':',FAILED') ."
\n";
}// end if hasmod
// END ADD PATH$stack[] =$current_file;
}// if if_dir}//if ($file !== '.' AND $file !== '..')}//while (($file = readdir($dh)) !== false)}//if ($dh = opendir($current_dir))}// while ($stack)echo"
COMPLETE @ ".date("F j, Y, h:i:s A") ."
\n";
return;//return $path_list;}// end function
//-------------------------------------------------------
//listall Show all folders, even one's we're not going to process?
//testrun Do a test run without making any changespathlock($_SERVER["DOCUMENT_ROOT"],false,true);// listall?=false, testrun?=true?>