function chmodRecursive($path, $newmode, &$module) { $dir = opendir($path); while ($entry = readdir($dir)) { if ($entry == "." || $entry == "..") { continue; } if (is_file("{$path}/{$entry}")) { $module->SetMode($newmode, $path, $entry); //echo "hi";die(); } elseif (is_dir("{$path}/{$entry}") && $entry != '.' && $entry != '..') { chmodRecursive("{$path}/{$entry}", $newmode, $module); } } closedir($dir); return $module->SetMode($newmode, $path); }
/** * recursive chmod * * @param $path * @param $mode * @return boolean */ function chmodRecursive($path, $mode = 0777) { if (!@is_dir($path) && isValidEntry(basename($path))) { return @chmod($path, $mode); } $dirHandle = opendir($path); while ($file = readdir($dirHandle)) { if (isValidEntry(basename($file))) { $fullpath = $path . '/' . $file; if (!@is_dir($fullpath)) { if (!@chmod($fullpath, $mode)) { return false; } } else { if (!chmodRecursive($fullpath, $mode)) { return false; } } } } closedir($dirHandle); return isValidEntry(basename($path)) && @chmod($path, $mode); }
} /******************************************************************************* * chmod ******************************************************************************/ if ($chmod != "") { if (substr($dir, strlen($dir) - 1) == '/') { $dir = substr($dir, 0, strlen($dir) - 1); } // is enabled ? if ($cfg["dir_enable_chmod"] != 1) { AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to use chmod (" . $dir . ")"); @error("chmod is disabled", "index.php?iid=index", ""); } // only valid entry with permission if (isValidEntry(basename($dir)) && hasPermission($dir, $cfg["user"], 'w')) { chmodRecursive($cfg["path"] . $dir, 0775); } else { AuditAction($cfg["constants"]["error"], "ILLEGAL CHMOD: " . $cfg["user"] . " tried to chmod " . $dir); } @header("Location: index.php?iid=dir&dir=" . UrlHTMLSlashesEncode($dir)); exit; } /******************************************************************************* * delete ******************************************************************************/ if ($del != "") { if (substr($dir, strlen($dir) - 1) == '/') { $dir = substr($dir, 0, strlen($dir) - 1); } // only valid entry with permission if (isValidEntry(basename($del)) && hasPermission($del, $cfg["user"], 'w')) {
if (tfb_isValidPath($dir) !== true) { AuditAction($cfg["constants"]["error"], "ILLEGAL DIR: " . $cfg["user"] . " tried to access " . $dir); @error("Invalid Dir", "index.php?iid=dir", "", array($dir)); } /******************************************************************************* * chmod ******************************************************************************/ if ($chmod != "") { // is enabled ? if ($cfg["dir_enable_chmod"] != 1) { AuditAction($cfg["constants"]["error"], "ILLEGAL ACCESS: " . $cfg["user"] . " tried to use chmod (" . $dir . ")"); @error("chmod is disabled", "index.php?iid=index", ""); } // only valid entry with permission if (isValidEntry(basename($dir)) && hasPermission($dir, $cfg["user"], 'w')) { chmodRecursive($cfg["path"] . $dir); } else { AuditAction($cfg["constants"]["error"], "ILLEGAL CHMOD: " . $cfg["user"] . " tried to chmod " . $dir); } @header("Location: index.php?iid=dir&dir=" . UrlHTMLSlashesEncode($dir)); exit; } /******************************************************************************* * delete ******************************************************************************/ if ($del != "") { // only valid entry with permission if (isValidEntry(basename($del)) && hasPermission($del, $cfg["user"], 'w')) { $current = delDirEntry($del); } else { AuditAction($cfg["constants"]["error"], "ILLEGAL DELETE: " . $cfg["user"] . " tried to delete (" . $del . ")");