<?php

include ('header.php');


$query_log="insert into log (ip, username, action) values('$_SERVER[REMOTE_ADDR]','".mysql_escape_string($username)."','Open index.php')";
$result_log=$dbconn->execute($query_log);


//$query="select count(*) from nessus_settings where owner='$username'";

$query="select count(nessus_settings.id) from nessus_settings inner join nessus_settings_users on nessus_settings.id=nessus_settings_users.sid where nessus_settings_users.username='$username'";

$result=$dbconn->execute($query);
list($profilecount)=$result->fields;

// if ($profilecount==0) {
// 
// 	echo "<h2>Please create a new profile</h2>";
// }



//        $username = "Anonymous";

echo "
<font face=\"Verdana\" color=\"#666666\" size=\"4\"><b>Welcome $username</b></font><br>

<table>
<tr><td valign=\"top\" width=300>
<font face=\"Verdana\" color=\"#666666\" size=\"4\">System Status</font><font face=\"Verdana\" color=\"#666666\" size=\"2\"><br>";

$query="select count(id) from plugins";
$result=$dbconn->execute($query);
	list($plugincount)=$result->fields;
	echo "There are $plugincount Nessus plugins in the database.<br>";

$query = "select count(id) from nessus_plugins where TO_DAYS(now()) - TO_DAYS(created) <7";
$result = $dbconn->execute($query);
        list($plugincount)=$result->fields;
        if ($plugincount>0) {echo "$plugincount new plugins added within last 7 days.<br>";}

$query="select count(id) from nessus_schedule where status='R' and username='$username'";
$result=$dbconn->execute($query);
list($scancount)=$result->fields;

if ($scancount==1) {
	echo "$scancount Nessus scan is currently running.<br>";
}
else {
	echo "$scancount Nessus scans are currently running.<br>";
}


echo "</font></td><td></td><td valign=\"top\"><font face=\"Verdana\" color=\"#666666\" size=\"4\">Vulnerability Scans Summary:</font><font face=\"Verdana\" color=\"#666666\" size=\"2\"><BR>";
////////////////////////////////


$result=$dbconn->Execute("SELECT count(risk) as count, risk FROM `nessus_results` where username='$username' and falsepositive<>'Y' and scriptid <> 10180 and msg<>'' group by risk");

	$totalrisk=0;

        $prevrisk=0;
        $chartimg="graph1.php?graph=1";
        while (list($riskcount, $risk)=$result->fields) {

                for ($i=0;$i<$risk-$prevrisk-1;$i++) {
                                $missedrisk=$prevrisk+$i+1;
                                $chartimg.="&amp;risk$missedrisk=0";
                        }
                $prevrisk=$risk;
                $chartimg.="&amp;risk$risk=$riskcount";
		$totalrisk=$totalrisk+$riskcount;
                $result->MoveNext();
        }
if($totalrisk>0) {echo "<img src=\"$chartimg\">";}



$query="select count(distinct host) from nessus_results where username='$username'";
$result=$dbconn->execute($query);
list ($syscount) = $result->fields;
echo "<br> Scanned $syscount systems";

$query="select count(distinct scantime, sched_id) from nessus_results where username='$username'";
$result=$dbconn->execute($query);
list ($syscount) = $result->fields;
echo ", $syscount times.";

echo "</font></td></tr></table>";
include ('footer.php');


function getrisk($risk) {

switch ($risk) {
    case 1:
        $risk="Serious";
        break;
    case 2:
        $risk="High";
        break;
    case 3:
        $risk="Medium";
        break;
    case 4:
        $risk="Medium/Low";
        break;
    case 5:
        $risk="Low/Medium";
        break;
    case 6:
        $risk="Low";
        break;
    case 7:
        $risk="Info";
        break;
}

return $risk;
}



?>
