<?php

include ('header.php');


if ($op=="stop") {

if (!is_numeric($schedid)) {die("Can not access this page");}
$query="select count(id) from nessus_schedule where username='$username' and id=$schedid";
$result=$dbconn->execute($query);

list($allowaccess)=$result->fields;
if ($allowaccess<>1) {die("Can not access this page");}

$host=mysql_escape_string($host);

$query="select count(host) from nessus_scan where host='$host' and status='R' and sched_id=$schedid";
$result=$dbconn->execute($query);
list($allowaccess)=$result->fields;
if ($allowaccess==1) {



	$query="update nessus_scan set status='P' where sched_id=$schedid and host='$host' and status='R'";
	$result=$dbconn->execute($query);

}
else {

	die("Can not access this page");

}


}


echo "<font face=\"Verdana\" color=\"#666666\" size=\"4\">Scan Live Stats</font><br><font face=\"Verdana\" color=\"#666666\" size=\"2\">";

$query="select nessus_live_stats.host, nessus_live_stats.action, nessus_live_stats.percent, nessus_schedule.name, nessus_schedule.id from nessus_live_stats
left join nessus_schedule on nessus_live_stats.sid=nessus_schedule.id where nessus_live_stats.username='$username' and nessus_schedule.status='R' order by nessus_schedule.name, inet_aton(nessus_live_stats.host)";
$result=$dbconn->execute($query);




echo "<a href=\"livestats.php\">Refresh Stats</a><br/></font>";

echo "<table summary=\"Scans\" border=1 cellspacing=\"0\" cellpadding=\"0\" style=\"border-collapse: collapse\"><tr><td><font face=\"Verdana\" color=\"#666666\" size=\"2\"><b>Schedule</b></font></td><td><font face=\"Verdana\" color=\"#666666\" size=\"2\"><b>Scanner</b></font></td><td><font face=\"Verdana\" color=\"#666666\" size=\"2\"><b>Host</b></font></td><td><font face=\"Verdana\" color=\"#666666\" size=\"2\"><b>Action</b></font></td><td><font face=\"Verdana\" color=\"#666666\" size=\"2\"><b>Completed %</b></font></td><td><font face=\"Verdana\" color=\"#666666\" size=\"2\"><b>Action</b></font></td></tr>";
while (!$result->EOF)
{
	list($host, $action, $percent, $name, $schedid)=$result->fields;

	$query1="select t1.name from nessus_servers as t1, nessus_scan as t2, nessus_live_stats as t3 where t1.id=t2.server_id and t2.host=t3.host and t2.host='$host' and t2.status='R';";
	$result1=$dbconn->execute($query1);
	list($scannerhost_name)=$result1->fields;


	echo "<tr><td><font face=\"Verdana\" color=\"#666666\" size=\"2\">$name</font></td><td><font face=\"Verdana\" color=\"#666666\" size=\"2\">$scannerhost_name</font></td><td><font face=\"Verdana\" color=\"#666666\" size=\"2\">$host</font></td><td><font face=\"Verdana\" color=\"#666666\" size=\"2\">$action</font></td><td><font face=\"Verdana\" color=\"#666666\" size=\"2\">".round($percent,0)."%</font></td><td><a href=\"livestats.php?op=stop&amp;schedid=$schedid&amp;host=$host\">Stop</a></td></tr>";
	$result->MoveNext();
}

echo "</table>";

include ('footer.php');

?>
