PDA

View Full Version : woooo programming genius!


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>

Disch
05-30-2002, 08:22 PM
you = pimp, I gotta get into PHP more. It looks like identical to C++ <img src=smilies/magbiggrin.gif>

Anyway, I was just wondering... you're putting 'continue's at the end of each of your loops. Do you have to do that in PHP? Or is that just habbit. It should loop automatically without 'continue', right?

Oh well.. great job regardless<img src=smilies/thumb.gif>

<P ID="signature"><center>
Get Ready</P>

SwampGas
05-30-2002, 08:29 PM
> Anyway, I was just wondering... you're putting 'continue's
> at the end of each of your loops. Do you have to do that in
> PHP? Or is that just habbit. It should loop automatically
> without 'continue', right?

no, it actually continues or breaks within the if statement..it's just hard to see without indentation.

<P ID="signature">http://www.zophar.net/graphics/sgchar.gif
<table style=filter:glow(color=purple,strength=3)>Swamp Gas</table></P>

Disch
05-30-2002, 08:40 PM
> no, it actually continues or breaks within the if
> statement..it's just hard to see without indentation.
>

*snippit*

while(!feof($fp))
{
? ? ? $line = fgets($fp,1024);
? ? ? $line = chop($line);
? ? ? if (ereg("^DATVersion=(.*)$",$line,$regs))
? ? ? {
? ? ? ? ? ? $datver = $regs[1];
? ? ? ? ? ? break;
? ? ? }
? ? ? continue;
}

*/snippit*

^ continue isn't needed ^

<P ID="signature"><center>
Get Ready</P>

Fla Flash
05-30-2002, 09:32 PM
Nice job Sam.<img src=http://www.zophar.net/wwwthreads/smilies/thumb.gif>

<P ID="signature"><img src=http://www.MdCplus.com/web/rflash/fsig.gif></P>