function movefile($from, $to = ".") { if (!file_exists($from)) { return false; } if (is_dir($from)) { if (!file_exists($to) || !is_dir($to)) { mkdir($to); } foreach (scandir($from) as $f) { if (!in_array($f, array(".", ".."))) { movefile($from . "/" . $f, $to . "/" . $f); } } return true; } else { return rename($from, $to); } }
function subtractAndCopyPotfileForHashcat($passwordfile, $johnpotfile) { global $name, $stamp, $tmpdir, $app, $f, $passwordfile_hashcat; $passwordfile_stamped = sprintf("%s_%s_%s_%s_%s", $name, basename($passwordfile), "hashcat", "hashfile", $stamp); if (empty($passwordfile_hashcat)) { return ""; } fwrite($f, "cut -f 1 --delim=: {$johnpotfile} | sed 's/^\\\$\\([A-Z]\\+\\)\\\$//' | sort | uniq > {$tmpdir}/tempcutfile \n"); fwrite($f, "sort {$passwordfile} | uniq > {$tmpdir}/tempsorted \n"); fwrite($f, "comm -23 {$tmpdir}/tempsorted {$tmpdir}/tempcutfile > {$tmpdir}/{$passwordfile_stamped} \n"); movefile($passwordfile_stamped); fwrite($f, "rm {$tmpdir}/tempsorted {$tmpdir}/tempcutfile \n"); return $passwordfile_stamped; }
/** * 移动文件夹 * @param string $oldDir 原文件夹 * @param string $targetDir 移动后的文件夹名 * @param boolean $overWrite 是否覆盖已有文件夹(true:覆盖已有文件夹,false:不覆盖已有文件夹)默认覆盖 * @return boolean 移动成功返回true,否则返回false */ function movedir($oldDir, $targetDir, $overWrite = true) { $oldDir = path_absolute($oldDir); $targetDir = path_absolute($targetDir); @clearstatcache(); $targetDir = substr($targetDir, -1) == '/' ? $targetDir : $targetDir . '/'; $oldDir = substr($oldDir, -1) == '/' ? $oldDir : $oldDir . '/'; if (!is_dir($oldDir)) { return false; } if (!file_exists($targetDir)) { makedir($targetDir); } $resource = opendir($oldDir); if (!$resource) { return false; } while (($file = readdir($resource)) !== false) { if ($file == '.' || $file == '..') { continue; } if (!is_dir($oldDir . $file)) { movefile($oldDir . $file, $targetDir . $file, $overWrite); } else { movedir($oldDir . $file, $targetDir . $file, $overWrite); } } closedir($resource); @clearstatcache(); return rmdir($oldDir); }