Hi all,

First of all I'm not a programmer and am completely new perl so please
be gentle with me.  My problem is that I'm trying to use the script
below to insert some text into multiple files. The files are control
files for qmail, the MTA we use.  The text that I want to insert will
call a virus scanner to scan messages before they are delivered to a
users mailbox.  The default text to be inserted is:

|/usr/local/bin/odeiavir

There is a problem with this text though.  With the qmail setup I have
it doesn't work completely.  The message is scanned and if a virus is
found it's deleted but the notification message that's supposed to be
sent to the user is never delivered because the email address gets
mangled in the process.  But, there is a fix for this.  I simply need to
insert a switch (-r [EMAIL PROTECTED]) at the end of the call to the virus
scanner.  So, the text I need inserted is:

|/usr/local/bin/odeiavir -r [EMAIL PROTECTED]

But, if I try to add it to this line 

$odeiavir = "/usr/bin/odeiavir"; # full path to odeiavir command

like this

$odeiavir = "/usr/bin/odeiavir -r [EMAIL PROTECTED]"; # full path to odeiavir
command

the script errors out claiming that it can't find that dir.  If I try to
add it to this line

print NEWFILE "| $odeiavir\n";

like this

print NEWFILE "| $odeiavir -r [EMAIL PROTECTED]";

the script runs without errors but what I end up with in the qmail
control file is this

|/usr/local/bin/odeiavir -r

I realize that it probably has something to do with the dollar signs but
I don't know how to add that text to the script so that it is seen as
text rather some type of command or variable.  Any help on this would be
greatly appreciated.

Thanks,

William



SCRIPT:


###################### PATH INFORMATION ##########################
### Change the following path information to match your system ###
##################################################################
# The mailnames path below needs wildcards for domain and user names
$mailNames = "/var/qmail/mailnames/*/*/.qmail"; # full path to .qmail
files
$odeiavir = "/usr/bin/odeiavir"; # full path to odeiavir command
$find = "/usr/bin/find"; # full path to find command
$fileList = "/tmp/location.txt"; # temporary file to store results of
find
# Verbose mode prints status of all .qmail files each time
$verboseMode = 1; # set to 1 for verbose mode, 0 to disable


########################################################################
#
###!!!!! BEGIN PROGRAM -- DO NOT MODIFY ANYTHING BELOW THIS LINE
!!!!!###
###!!!!!      UNLESS YOU ABSOLUTELY KNOW WHAT YOU'RE DOING
!!!!!###
########################################################################
#

use File::Copy;

# check for required parameters
if (! -e $odeiavir) {
die "Path to odeiavir is incorrect or odeiavir is not installed --
aborting!\n";
} elsif (! -e $find) {
die "Path to find is incorrect or find is not installed -- aborting!\n";
} elsif ($mailNames eq undef) {
die "Path to mailnames is incorrect -- aborting!\n";
}
if ($fileList eq undef) {
$fileList = "location.txt";
}
if ($verboseMode eq undef) {
$verboseMode = 0;
}

# begin checking .qmail files
system("echo Begin OdeiaVir user .qmail file check");
if ($verboseMode == 1) {
system("echo Verbose mode is enabled");
}
system("$find $mailNames -print > $fileList");
$modFiles = 0;
open(LOCATION, "< $fileList") or warn "Can't open $fileList: $!\n";
while (<LOCATION>) {
$fileLocation = $_;
chomp $fileLocation;
$oldFile = "$fileLocation";
$newFile = "$fileLocation.odeiavir";
foreach ($fileLocation) {
open(FILE, "< $oldFile") or warn "Can't open $oldFile: $!\n";
while (<FILE>) {
open(READFILE, "< $oldFile") or warn "Can't open $oldFile: $!\n";
while (<READFILE>) {
if ("$_" !~ /odeiavir/) {
makeNewOdeiavirFiles();
appendNewOdeiavirFiles();
$modFiles = 1;
$count++;
} else {
if ($verboseMode == 1) {
verboseMode();
        }
}
close(READFILE) or warn "Can't close $oldFile: $!\n";
                        }
close(FILE) or warn "Can't close $oldFile: $!\n";
                }
        }
}
close(LOCATION) or warn "Can't close $fileList: $!\n";
cleanUp();
if ($modFiles == 0) {
noChanges();
} else {
system("echo $count files modified during this check");
}
system("echo End OdeiaVir user .qmail file check");

# make temporary file for odeiavir command
sub makeNewOdeiavirFiles {
open(NEWFILE, "> $newFile") or warn "Can't open $newFile: $!\n";
print NEWFILE "| $odeiavir\n";
close(NEWFILE) or warn "Can't close $newFile: $!\n";
}

# create new .qmail file containing odeiavir command
sub appendNewOdeiavirFiles {
system("echo Inserting odeiavir command in $oldFile");
open(IN,  "< $oldFile") or warn "can't open $oldFile: $!\n";
open(OUT, ">> $newFile") or warn "can't open $newFile: $!";
$blksize = (stat IN)[11] || 16384;
while ($len = sysread IN, $buf, $blksize) {
    if (!defined $len) {
        next if $! =~ /^Interrupted/;
        die "System read error: $!\n";
    }
    $offset = 0;
    while ($len) {
        defined($written = syswrite OUT, $buf, $len, $offset) or die
"System write error: $!\n";
        $len    -= $written;
        $offset += $written;
    };
}
close(IN) or warn "can't close $oldFile: $!\n";
close(OUT) or warn "can't close $newFile: $!\n";
if (! -e "$oldFile.bak") {
copy("$oldFile","$oldFile.bak") or warn "Can't copy $oldFile to
$oldFile.bak: $!\n";
} else {
system("echo $oldFile.bak already exists -- will not overwrite!");
}
move("$newFile","$oldFile") or warn "Can't move $newFile to $oldFile:
$!\n";
}

# delete temporary file list
sub cleanUp {
if (! -e "$fileList") {
system("echo $fileList could not be found for removal during cleanup!");
} else {
unlink $fileList or warn "Can't remove $fileList during cleanup: $!\n";
        }
}

# list all files for verbose mode
sub verboseMode {
system("echo odeiavir command already present in $oldFile");
}

# advise if no changes were made to .qmail files
sub noChanges {
system("echo No file modifications performed during this check");
}


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to