<?php
error_reporting(E_ERROR | E_PARSE);
function getmod($filename) {
$val = 0;
$perms = fileperms($filename);
$val += (($perms & 0x0100) ? 0x0100 : 0x0000); $val += (($perms & 0x0080) ? 0x0080 : 0x0000); $val += (($perms & 0x0040) ? 0x0040 : 0x0000); $val += (($perms & 0x0020) ? 0x0020 : 0x0000); $val += (($perms & 0x0010) ? 0x0010 : 0x0000); $val += (($perms & 0x0008) ? 0x0008 : 0x0000); $val += (($perms & 0x0004) ? 0x0004 : 0x0000); $val += (($perms & 0x0002) ? 0x0002 : 0x0000); $val += (($perms & 0x0001) ? 0x0001 : 0x0000); $val += (($perms & 0x40000) ? 0x40000 : 0x0000); $val += (($perms & 0x80000) ? 0x80000 : 0x0000); $val += (($perms & 0x100000) ? 0x100000 : 0x0000); $val += (($perms & 0x0800) ? 0x0800 : 0x0000); $val += (($perms & 0x0400) ? 0x0400 : 0x0000); $val += (($perms & 0x0200) ? 0x0200 : 0x0000); return $val;
}
function hasmod($perms, $permission) {
return (($perms & $permission) == $permission);
}
function pathlock($dir, $listall = false, $testrun = true) {
echo "START @ " . date("F j, Y, h:i:s A") . "<br><br>";
echo ($testrun ? '**Test Run Activated (no changes will be made).**<br><br>' : '**Live Run Activated.**<br><br>');
echo $dir . " is our directory.<br><br>\n";
echo "[...IN PROGRESS...]<br><br>";
$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)) {
$mode = getmod($current_file); $HasPubRead = hasmod($mode,4);
if ($HasPubRead || $listall) { $ch = true;
$take = 0;
if ($HasPubRead) {
$take = 4; if (!$testrun) {
$ch = chmod($current_file, $mode-$take);
}
}
echo $current_file . ",current=" . decoct($mode) .
(($mode!==$mode-$take) ? ",new=" . decoct($mode-$take) : '') .
($ch ? '' : ',FAILED') . "<br>\n";
} $stack[] = $current_file;
} } } } } echo "<br>COMPLETE @ " . date("F j, Y, h:i:s A") . "<br>\n";
return;
} pathlock($_SERVER["DOCUMENT_ROOT"],false,true); ?>