[Avcheck] Avp update hourly
Ralf Hildebrandt
Ralf.Hildebrandt@innominate.com
Wed, 26 Sep 2001 09:22:16 +0200
--BOKacYhQ+x31HxR3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
On Tue, Sep 25, 2001 at 07:53:46PM +0200, Tarjei Huse wrote:
> According to the howto hosted here
> http://www.stahl.bau.tu-bs.de/~hildeb/postfix/, theres a perlscript that checks
> for new bases every hour and updates the bases dir and restarts the daemon. But,
> the text under is only a small sh script that I cannot see restarts the daemon.
> Would someone like to post the perlscript?
Here it is (attached). It's actually what I use. I calls
/var/spool/avp/restart_kavdaemon, which I also attached. It might not
work for you, since I'm not using avcheck-0.4, but something rather old.
--
Ralf.Hildebrandt@innominate.com innominate AG
+49.(0)30.308806-62 fax: -77 networking people
"I'm not under the alcofluence of inkahol that some thinkle peep I am.
It's just the drunker I sit here the longer I get."
--BOKacYhQ+x31HxR3
Content-Type: application/x-perl
Content-Disposition: attachment; filename="AvpUpdate.pl"
#!/usr/bin/perl
# Copyright (c) 1999-2001 Serg Oskin <oskin@macomnet.ru>. All rights reserved.
#
# Automaticaly load/update AVP database from support server.
# Version 0.6.7
#
# Required Bundle::libnet perl-library.
# Load full database when first start.
#
#!!!WARNING!!!WARNING!!!WARNING!!!WARNING!!!WARNING!!!WARNING!!!WARNING!!!WARNING!!!
# Edit AvpUnix.ini for change
# SetFile=AVP.SET (or SetFile=avp.set)
# to
# SetFile=AVP.SET.unix (or SetFile=avp.set.unix)
# and comment next string:
# $no_read_this = "yes";
# --------- This is config -------------
$UpdateServer = "downloads1.kaspersky-labs.com"; # Support server
$UpdateDir = "/updates"; # Directory on support server with avp.set & *.avc files
$UpdateUser = "anonymous"; # ftp username, my be "anonimous"
$UpdatePasswd = "virusalert\@innominate.com"; # if need logged as "anonimous" use your e-mail
# address (type "\@" for "@")
$PassiveMode = 0; # If set to a non-zero value then all data transfers
# will be done using passive mode.
$UpdateTryConnect = 10; # 0 - unlimited
$avpBaseDir = "/var/spool/avp/bases"; # Antivirual database directory
$UpdateExec = "/var/spool/avp/restart_kavdaemon"; # Exec this program after update database
$UpdateVerbose = 1;
$CaseFileName = upper; # Case of database file names (upper or lower)
# ------- This is not config! -----------
if( defined( $no_read_this )) {
print "\nRead !!!WARNING!!! in this file ($0)!\n\n";
exit 100;
}
if( $UpdateVerbose ) {
use IO::Handle;
STDOUT->autoflush(1);
}
if( $CaseFileName =~ /upper/i ) {
$AvpSet = "AVP.SET";
$AvpVnd = "AVP.VND";
$AvpKlb = "AVP.KLB";
} else {
$AvpSet = "avp.set";
$AvpVnd = "avp.vnd";
$AvpKlb = "avp.klb";
}
use File::Basename;
use Net::FTP;
my $ftp;
my $try = $UpdateTryConnect;
my $lasterr = "";
while( $try >= 0 ) {
print "Trying connect to \'$UpdateServer\'..." if( $UpdateVerbose );
if(( $ftp = Net::FTP->new( $UpdateServer, Passive => $PassiveMode )) ne "" ) {
print " ok.\n" if( $UpdateVerbose );
print "Trying login on \'$UpdateServer\'..." if( $UpdateVerbose );
if( $ftp->login( $UpdateUser, $UpdatePasswd )) {
print " ok.\n" if( $UpdateVerbose );
$lasterr = "";
last;
} else {
print " failed.\n" if( $UpdateVerbose );
$lasterr = "Login failed on \'$UpdateServer\'";
}
$ftp->quit;
} else {
print " failed => $@\n" if( $UpdateVerbose );
$lasterr = "Cannot connect to \'$UpdateServer\' => $@";
}
$try-- if( $UpdateTryConnect > 0 );
}
if( $lasterr ne "" ) {
$ftp->quit if( $ftp ne "" );
print $lasterr."\n";
exit 1;
}
print "cwd to $UpdateDir\n" if( $UpdateVerbose );
$ftp->cwd( $UpdateDir );
print "Get listing of files\n" if( $UpdateVerbose );
if(( @ls = $ftp->dir ) < 1 ) {
$ftp->quit;
print "Cannot find any files @ls.\n";
exit 2;
}
my $NeedFile = "";
$#namels = -1;
%sizels = "";
foreach $f ( @ls ) {
next if( $f =~ /^total/i );
my @a = split( /[ \t]+/, $f );
$namels[$#namels+1] = $a[8];
my $n = $a[8];
if( $CaseFileName =~ /upper/i ) {
$n =~ tr/[a-z]/[A-Z]/;
} else {
$n =~ tr/[A-Z]/[a-z]/;
}
$sizels{$n} = $a[4];
}
print "Find \'$AvpSet\' file on server\n" if( $UpdateVerbose );
foreach $f ( @namels ) {
if( $f =~ /^AVP.SET$/i ) {
$NeedFile = $f;
last;
}
}
if( $NeedFile eq "" ) {
$ftp->quit;
print "Cannot find \'$AvpSet\'\n";
exit 3;
}
print "Get \'$AvpSet\' file from server\n" if( $UpdateVerbose );
$ftp->binary();
if( !$ftp->get( $NeedFile, $avpBaseDir."/".$AvpSet.".new" )) {
$ftp->quit;
print "Cannot get \'$NeedFile\' => $@\n";
exit 4;
}
print "Find \'$AvpVnd\' file on server\n" if( $UpdateVerbose );
foreach $f ( @namels ) {
if( $f =~ /^AVP.VND$/i ) {
$NeedFile = $f;
last;
}
}
if( $NeedFile eq "" ) {
$ftp->quit;
print "Cannot find \'$AvpVnd\'\n";
exit 3;
}
print "Get \'$AvpVnd\' file from server\n" if( $UpdateVerbose );
$ftp->binary();
if( !$ftp->get( $NeedFile, $avpBaseDir."/".$AvpVnd.".new" )) {
$ftp->quit;
print "Cannot get \'$NeedFile\' => $@\n";
exit 4;
}
print "Find \'$AvpKlb\' file on server\n" if( $UpdateVerbose );
foreach $f ( @namels ) {
if( $f =~ /^AVP.KLB$/i ) {
$NeedFile = $f;
last;
}
}
if( $NeedFile eq "" ) {
$ftp->quit;
print "Cannot find \'$AvpKlb\'\n";
exit 3;
}
print "Get \'$AvpKlb\' file from server\n" if( $UpdateVerbose );
$ftp->binary();
if( !$ftp->get( $NeedFile, $avpBaseDir."/".$AvpKlb.".new" )) {
$ftp->quit;
print "Cannot get \'$NeedFile\' => $@\n";
exit 4;
}
if( ! open( klb, $avpBaseDir."/".$AvpKlb.".new" )) {
print "Cannot open \'".$avpBaseDir."/".$AvpKlb.".new\' => $!\n";
exit 12;
}
use POSIX qw(mktime);
my %MTime;
my %Size;
while( <klb> ) {
chop;
if( /^[0-9]+\=/ ) {
s/^[0-9]+\=//;
my( $n, $k, $s, $d ) = split( /\,/, $_ );
if( $CaseFileName =~ /upper/i ) {
$n =~ tr/[a-z]/[A-Z]/;
} else {
$n =~ tr/[A-Z]/[a-z]/;
}
$Size{$n} = $s;
my( $d, $m, $y ) = split( /\//, $d );
$MTime{$n} = POSIX::mktime( 0, 0, 12, $d, $m-1, $y-1900 );
}
}
close( klb );
foreach $f ( <$avpBaseDir/*> ) {
$OldBase{basename($f)} = 1;
}
my $Updated = 0;
if( !open( asn, $avpBaseDir."/".$AvpSet.".new" )) {
$ftp->quit;
unlink $avpBaseDir."/".$AvpSet.".new";
print "Cannot open \'".$avpBaseDir."/".$AvpSet.".new\' => $!\n";
exit 5;
}
if( !open( ast, ">".$avpBaseDir."/".$AvpSet.".tmp" )) {
$ftp->quit;
close( asn );
unlink $avpBaseDir."/".$AvpSet.".new";
print "Cannot create \'".$avpBaseDir."/".$AvpSet.".tmp\' => $!\n";
exit 6;
}
print "Find new updates...\n" if( $UpdateVerbose );
while( <asn> ) {
my $orig = $_;
s/\r//;
s/\n//;
if(( /^[ \t]*$/ ) || ( /^[ \t]*;/ )) {
print ast $orig;
next;
}
if( $CaseFileName =~ /upper/i ) {
tr/[a-z]/[A-Z]/;
} else {
tr/[A-Z]/[a-z]/;
}
$asn_file = $_;
print ast $asn_file."\r\n";
$OldBase{$asn_file} = 0;
if( -f $avpBaseDir."/".$asn_file ) {
$dsz = (stat( $avpBaseDir."/".$asn_file ))[7];
$dmt = (stat( $avpBaseDir."/".$asn_file ))[9];
next if(( $sizels{$asn_file} == $dsz) && ( $Size{$asn_file} == $dsz ) &&
( $MTime{$asn_file} == $dmt ));
}
print "New file found: \'$asn_file\', trying to get it..." if( $UpdateVerbose );
my $Found = 0;
foreach $NeedFile ( @namels ) {
my $t = $NeedFile;
if( $CaseFileName =~ /upper/i ) {
$t =~ tr/[a-z]/[A-Z]/;
} else {
$t =~ tr/[A-Z]/[a-z]/;
}
if( $asn_file eq $t ) {
$Found = 1;
$ftp->binary();
if( !$ftp->get( $NeedFile, $avpBaseDir."/".$asn_file )) {
$ftp->quit;
close( ast );
unlink $avpBaseDir."/".$AvpSet.".tmp";
close( asn );
unlink $avpBaseDir."/".$AvpSet.".new";
print "Cannot get \'$NeedFile\' => $@\n";
exit 7;
}
$Updated = 1;
if( defined( $MTime{$asn_file} )) {
utime $MTime{$asn_file}, $MTime{$asn_file}, $avpBaseDir."/".$asn_file;
}
print " ok\n" if( $UpdateVerbose );
last;
}
}
if( $Found == 0 ) {
$ftp->quit;
close( ast );
unlink $avpBaseDir."/".$AvpSet.".tmp";
close( asn );
unlink $avpBaseDir."/".$AvpSet.".new";
print "File \'$asn_file\' not found on server\n";
exit 8;
}
}
$ftp->quit;
close( ast );
close( asn );
$OldBase{$AvpSet} = 0;
$OldBase{$AvpSet.".tmp"} = 0;
$OldBase{$AvpSet.".new"} = 0;
$OldBase{$AvpVnd} = 0;
$OldBase{$AvpVnd.".new"} = 0;
$OldBase{$AvpKlb} = 0;
$OldBase{$AvpKlb.".new"} = 0;
foreach $f ( keys( %OldBase )) {
if( $OldBase{$f} > 0 ) {
unlink $avpBaseDir."/".$f;
}
}
if( ! $Updated ) {
unlink $avpBaseDir."/".$AvpSet.".tmp";
unlink $avpBaseDir."/".$AvpSet.".new";
unlink $avpBaseDir."/".$AvpVnd.".new";
unlink $avpBaseDir."/".$AvpKlb.".new";
print "AVP database don\'t need to update.\n" if( $UpdateVerbose );
exit 0;
}
if( ! rename( $avpBaseDir."/".$AvpSet.".tmp", $avpBaseDir."/".$AvpSet.".unix" )) {
unlink $avpBaseDir."/".$AvpSet.".tmp";
print "Cannot rename \'".$AvpSet.".tmp\' to \'".$avpBaseDir."/".$AvpSet.".unix\' => $!\n";
exit 9;
}
if( ! rename( $avpBaseDir."/".$AvpSet.".new", $avpBaseDir."/".$AvpSet )) {
unlink $avpBaseDir."/".$AvpSet.".new";
print "Cannot rename \'".$AvpSet.".new\' to \'".$avpBaseDir."/".$AvpSet."\' => $!\n";
exit 9;
}
if( ! rename( $avpBaseDir."/".$AvpVnd.".new", $avpBaseDir."/".$AvpVnd )) {
unlink $avpBaseDir."/".$AvpVnd.".new";
print "Cannot rename \'".$AvpVnd.".tmp\' to \'".$avpBaseDir."/".$AvpVnd."\' => $!\n";
exit 10;
}
if( ! rename( $avpBaseDir."/".$AvpKlb.".new", $avpBaseDir."/".$AvpKlb )) {
unlink $avpBaseDir."/".$AvpKlb.".new";
print "Cannot rename \'".$AvpKlb.".tmp\' to \'".$avpBaseDir."/".$AvpKlb."\' => $!\n";
exit 11;
}
unlink $avpBaseDir."/".$AvpSet.".new";
utime $MTime{$AvpSet}, $MTime{$AvpSet}, $avpBaseDir."/".$AvpSet if( defined( $MTime{$AvpSet} ));
utime $MTime{$AvpSet}, $MTime{$AvpSet}, $avpBaseDir."/".$AvpSet.".unix" if( defined( $MTime{$AvpSet} ));
utime $MTime{$AvpVnd}, $MTime{$AvpVnd}, $avpBaseDir."/".$AvpVnd if( defined( $MTime{$AvpVnd} ));
system( $UpdateExec ) if( defined( $UpdateExec ) && ( -x (split( /[ \t]+/, $UpdateExec ))[0] ));
print "AVP database success updated.\n" if( $UpdateVerbose );
exit 0;
--BOKacYhQ+x31HxR3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=restart_kavdaemon
cd /var/spool/avp
/var/spool/avp/kavdaemon -ka && sleep 1
# stop kavdaemon
/usr/bin/env - HOME=/ \
/usr/local/bin/uchroot -u avpd /var/spool/avp \
./kavdaemon -MD -MP -dl -dp -V -* -f=/ctl /tst
# Virenkiller wieder starten
sleep 1 && /usr/sbin/postfix flush
--BOKacYhQ+x31HxR3--