<?php


include('header.php');

include ('permissions.inc.php');

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


if ($acl=="Y") {


echo "<b>Nmap Port Scan Results</b><br>";


if ($op=="view") {

	$query="select count(id) from portscan where id=$pid and username='$username'";
	$result=$dbconn->execute($query);

	list ($pcount)=$result->fields;

	if ($pcount<>0) {
		$previp="";
		$query="select host, port, type, status, description, version from portscan_results where id=$pid order by host, port";
		$result=$dbconn->execute($query);
		echo "<table summary=\"Nmap Results\" border=\"1\"><tr><td><b>Port</b></td><td><b>Protocol</b></td><td><b>Status</b></td><td><b>Service</b></td><td><b>Version</b></td></tr>";
		while(!$result->EOF) {
			list($phost, $pport, $ptype, $pstatus, $pdescription, $pversion)=$result->fields;
			if ($previp<>$phost) {
				echo "<tr><td colspan=\"5\"><b>$phost</b>";

				$hostos="";
				$query1="select os from portscan_os where id=$pid and host='$phost'";
				$result1=$dbconn->execute($query1);
				while(!$result1->EOF) {
					list($hostos)=$result1->fields;
					$result1->MoveNext();
				}

				echo " - $hostos<td></tr>";
				$previp=$phost;
			}
			echo "<tr>
			<td>$pport</td><td>$ptype</td>
			<td>$pstatus</td><td>$pdescription</td>
			<td>$pversion</td></tr>";
			$result->MoveNext();
		}

		echo "</table>";
	}



}
elseif ($op=="del") {

$query="select count(id) from portscan where id=$pid and username='$username'";
        $result=$dbconn->execute($query);

        list ($pcount)=$result->fields;

        if ($pcount<>0) {
                $query="delete from portscan_results where id=$pid";
                $result=$dbconn->execute($query);
		$query="delete from portscan where id=$pid";
		$query=$dbconn->execute($query);
		echo "Results deleted. <a href=\"portscanres.php\">Back</a> to the results page.";

	}

}
else {

$query="select id, scanip, date_format(submittime, \"%W %M %e, %Y - %r\"), scancomplete from portscan where username='$username' order by id desc";
$result=$dbconn->execute($query);
echo "<table summary=\"Nmap Results\" border=\"1\"><tr><td>&nbsp;</td><td><b>Host</b></td><td><b>Scan Time</b></td><td><b>Status</b></td></tr>";

while(!$result->EOF) {
	list($pid, $pscanip, $ptime, $pstatus)=$result->fields;

	echo "<tr><td><a href=\"portscanres.php?op=view&amp;pid=$pid\">View</a> | <a href=\"portscanres.php?op=del&amp;pid=$pid\">Del</a></td>
		<td>$pscanip</td>
		<td>$ptime</td>
		<td>$pstatus</td>
		</tr>";
	$result->MoveNext();
}
	echo "</table>";


}

}
else {

echo "Access Denied!!!";

}

include('footer.php');

?>
