<?php


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

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


if ($acl=="Y") {


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

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

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

if (file_exists($nessus_md5)) {
$md52=md5_file($nessus_md5);
if($md51<>$md52) {
	wwwcopy ("$nessus_url/$nessus_file", "$nessus_file");
	if (file_exists($nessus_file)) {
		echo "New plugins downloaded and will be installed shortly.";
	}
	else {
		echo "It was a problem to download new Nessus plugins.";
	}
}
else {
	echo "No new plugins available at this time.";
}
}
else {
	echo "It was a problem to download Nessus plugins.";
}
}

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);
}



?>
