<?php
//
// $Id: getnessus.php,v 1.3 2004/11/18 23:06:39 greg_k Exp $
//

include ('header.php');
include ('permissions.inc.php');

$acl=checkacl("admin", $dbconn);

if ($acl=="Y") {

    //Get Inprotect Settings
    $query="select nessus_install_url, nessus_install_file, inprotect_path from inprotect_settings limit 1";
    $result=$dbconn->execute($query);
    list($nessus_url, $nessus_file, $inprotect_path)=$result->fields;

    chdir("$inprotect_path/nessus/");
    if (file_exists($nessus_file)) {
        $md51=md5_file($nessus_file);
    }

    wwwcopy ("$nessus_url/$nessus_file", "$nessus_file");

    if (file_exists($nessus_file)) {
        $md52=md5_file($nessus_file);
        if($md51<>$md52) {
            echo "Downloaded new Nessus release.";
        }
        else {
            echo "No new Nessus release available at this time.";
        }
    }
    else {
        echo "It was a problem to download Nessus.";
    }
}
else {
    echo "Can not access this page.";
}

include('footer.php');

function wwwcopy($file,$nfile)
{
    $fp = @fopen($file,"rb") or die("Can not download file</tr></table></body></html>");
    $fp2 = @fopen($nfile,"w") or die("Can not create new file</tr></table></body></html>");

    while(!feof($fp))
    {
        $cont= fread($fp,8192);
        fwrite($fp2,$cont);
    }
    fclose($fp);
    fclose($fp2);
}
?>
