SwampGas
05-30-2002, 08:10 PM
i have my mail server scan my mail for viruses and reject them, since i was getting so many of them. i use mcafee's uvscan (the linux version of virusscan) and i wrote a simple php script to be run at midnight via crontab which updates the virus dat files automatically...check it out:
<code>
[?php
// auto update mcafee dat
set_time_limit(0);
$path = "/usr/local/uvscan";
// check current dat number
if (!$fp = fopen($path."/update.ini","r"))
die("Cannot open update.ini!");
while(!feof($fp))
{
$line = fgets($fp,1024);
$line = chop($line);
// find the [ZIP] header...
if ($line == "[ZIP]")
{
while(!feof($fp))
{
$line = fgets($fp,1024);
$line = chop($line);
if (ereg("^DATVersion=(.*)$",$line,$regs))
{
$datver = $regs[1];
break;
}
continue;
}
break;
}
continue;
}
fclose($fp);
if (!$datver)
die("DATVersion not found in update.ini?!?");
// get current ini
if (!$currini = file("http://download.nai.com/products/datfiles/4.x/nai/update.ini"))
die("Cannot get current INI");
while(list($ln,$line) = each($currini))
{
$line = chop($line);
if ($line == "[ZIP]")
{
while(list($ln,$line) = each($currini))
{
$line = chop($line);
if (ereg("^DATVersion=(.*)$",$line,$regs))
{
$newdatver = $regs[1];
break;
}
continue;
}
break;
}
continue;
}
if (!newdatver)
die("Cannot access new datver");
if ($newdatver > $datver)
{
// now retrieve the new dat
$fs = ftp_connect("ftp.mcafee.com");
$fl = ftp_login($fs,"anonymous","sg@m.com");
if (!fs || !fl)
die("cannot connect to mcafee");
if (!ftp_get($fs,$path."/dat-$newdatver.tar","/pub/antivirus/datfiles/4.x/dat-$newdatver.tar",FTP_BINARY))
die("cannot retrieve dat-$newdatver.tar");
ftp_close;
exec("tar xf $path/dat-$newdatver.tar $path");
// write the new ini file
unlink($path."/update.ini");
reset($currini);
$cini = implode("",$currini);
$fp = fopen($path."/update.ini","w");
fputs($fp,$cini);
fclose($fp);
mail("me","MCAFEE DAT UPDATE","Upgrade $datver to $newdatver.");
}
?]</code>
1337 <img src=smilies/magbiggrin.gif>
<P ID="signature">http://www.zophar.net/graphics/sgchar.gif
<table style=filter:glow(color=purple,strength=3)>Swamp Gas</table></P>
<code>
[?php
// auto update mcafee dat
set_time_limit(0);
$path = "/usr/local/uvscan";
// check current dat number
if (!$fp = fopen($path."/update.ini","r"))
die("Cannot open update.ini!");
while(!feof($fp))
{
$line = fgets($fp,1024);
$line = chop($line);
// find the [ZIP] header...
if ($line == "[ZIP]")
{
while(!feof($fp))
{
$line = fgets($fp,1024);
$line = chop($line);
if (ereg("^DATVersion=(.*)$",$line,$regs))
{
$datver = $regs[1];
break;
}
continue;
}
break;
}
continue;
}
fclose($fp);
if (!$datver)
die("DATVersion not found in update.ini?!?");
// get current ini
if (!$currini = file("http://download.nai.com/products/datfiles/4.x/nai/update.ini"))
die("Cannot get current INI");
while(list($ln,$line) = each($currini))
{
$line = chop($line);
if ($line == "[ZIP]")
{
while(list($ln,$line) = each($currini))
{
$line = chop($line);
if (ereg("^DATVersion=(.*)$",$line,$regs))
{
$newdatver = $regs[1];
break;
}
continue;
}
break;
}
continue;
}
if (!newdatver)
die("Cannot access new datver");
if ($newdatver > $datver)
{
// now retrieve the new dat
$fs = ftp_connect("ftp.mcafee.com");
$fl = ftp_login($fs,"anonymous","sg@m.com");
if (!fs || !fl)
die("cannot connect to mcafee");
if (!ftp_get($fs,$path."/dat-$newdatver.tar","/pub/antivirus/datfiles/4.x/dat-$newdatver.tar",FTP_BINARY))
die("cannot retrieve dat-$newdatver.tar");
ftp_close;
exec("tar xf $path/dat-$newdatver.tar $path");
// write the new ini file
unlink($path."/update.ini");
reset($currini);
$cini = implode("",$currini);
$fp = fopen($path."/update.ini","w");
fputs($fp,$cini);
fclose($fp);
mail("me","MCAFEE DAT UPDATE","Upgrade $datver to $newdatver.");
}
?]</code>
1337 <img src=smilies/magbiggrin.gif>
<P ID="signature">http://www.zophar.net/graphics/sgchar.gif
<table style=filter:glow(color=purple,strength=3)>Swamp Gas</table></P>