Location: PHPKode > projects > Cancerbero - The watchdog of the ports > cancerbero-0.6/site/host_form.php
<?php

include_once('include/class_history_links.inc');
include_once("include/dbconnect.php");
include_once("include/functions.php");
include_once("menu.html");

$config = new ReadConfig;
$general = $config->General('gui_debug');
if ($general['gui_debug'] == 1) {
	echo "<div align='center' class='orange'><h2><blink>Debug mode activated</blink></h2></div>\n";
}

$view_type = trim($_GET['view_type']);

if (isset($_GET['host_id'])) {
	$host_id = trim($_GET['host_id']);
	$query = "SELECT ip,hostname  FROM hosts WHERE host_id = '$host_id'";
        $result = mysql_query($query) or die (mysql_error());
	$line = mysql_fetch_array($result, MYSQL_ASSOC);
	$ip = $line["ip"];
	$hostname = $line["hostname"];
}


if (isset($_GET['host'])) {
	$host = trim($_GET['host']);
	$query = "SELECT host_id,ip,hostname  FROM hosts WHERE (ip = '$host' or hostname = '$host')";
        $result = mysql_query($query) or die (mysql_error());
	$line = mysql_fetch_array($result, MYSQL_ASSOC);
	$host_id = $line["host_id"];
	$hostname = $line["hostname"];
	$ip = $line["ip"];
}


if (isset($_GET['service'])) {
	$service = trim($_GET['service']);
	$query = "select h.host_id,s.scan_rec_id as 'Scan ID',DATE(FROM_UNIXTIME(d_scan)) as Date,TIME(FROM_UNIXTIME(d_scan)) as Time,hostname as Hostname,ip as Ip,port as Ports,service as Service,h.comment as Comment from hosts h, scans s, ports p where h.host_id = s.host_id and s.scan_rec_id = p.scan_rec_id and DATE(FROM_UNIXTIME(s.d_scan)) = DATE(FROM_UNIXTIME(h.d_last_scan)) and service like '$service'";
	#$result_service = mysql_query($query) or die (mysql_error());
        $title="<h1>Data of the service \"$service\"</h1>";
}


if (isset($_GET['port'])) {
	$port = trim($_GET['port']);
         $query = "select h.host_id,s.scan_rec_id as 'Scan ID',DATE(FROM_UNIXTIME(d_scan)) as Date,TIME(FROM_UNIXTIME(d_scan)) as Time,hostname as Hostname,ip as Ip,port as Ports,service as Service,h.comment as Comment from hosts h, scans s, ports p where h.host_id = s.host_id and s.scan_rec_id = p.scan_rec_id and DATE(FROM_UNIXTIME(s.d_scan)) =DATE(FROM_UNIXTIME(h.d_last_scan)) and port = '$port'";
        #$result_service = mysql_query($query) or die (mysql_error());
        $title="<h1>Data of the port \"$port\"</h1>";
}

if (isset($_GET['mail'])) {
	$mail = trim($_GET['mail']);
	$query = "select h.host_id,ip as Ip,hostname as Hostname,DATE(FROM_UNIXTIME(d_last_scan)) as 'Last Scan',email as Email,count(email) as 'Numero correos' FROM hosts h, users u WHERE email like '$mail' and h.host_id = u.host_id GROUP BY h.host_id";
	#$query = "create temporary table premail select host_id, num_mails, email FROM users WHERE email like '$mail';";
	$result_mail = mysql_query($query) or die (mysql_error());
	$title="<h1>Data of the mail: \"$mail\"</h1>";
}

if (isset($_GET['owner'])) {
	$owner = trim($_GET['owner']);
	$query = "SELECT owner_id FROM owners WHERE email = '$owner' ";
	#$query = "create temporary table premail select host_id, num_mails, email FROM users WHERE email like '$mail';";
	$result_owner = mysql_query($query) or die (mysql_error());
	$title="<h1>Data of the owner: \"$owner\"</h1>";
	$line = mysql_fetch_array($result_owner, MYSQL_ASSOC);
	$ownerid = $line["owner_id"];
}

if (isset($_GET['scan_rec_id'])) {
	$scan_id = trim($_GET['scan_rec_id']);
	$query = "SELECT hosts.host_id,hosts.ip,hosts.hostname FROM scans,hosts WHERE scans.host_id = hosts.host_id AND scan_rec_id = $scan_id";
	$result = mysql_query($query) or die (mysql_error());
	$line = mysql_fetch_array($result, MYSQL_ASSOC);
	$host_id = $line["host_id"];
	$ip = $line["ip"];
	$hostname = $line["hostname"];
}

if (isset($host_id)){
	$query_sum = "SELECT count(*) AS Total FROM users WHERE host_id = '$host_id'";
	$result_sum = mysql_query($query_sum) or die (mysql_error());
	$line = mysql_fetch_array($result_sum, MYSQL_ASSOC);
	$sum_mails_per_host = $line["Total"];

	$query_table_users = "CREATE temporary table users_per_host SELECT email,count(*) as Mails,host_id FROM users WHERE host_id = '$host_id' group by email;";
	$result_table_users = mysql_query($query_table_users) or die (mysql_error());
}

if (isset($ip)){
	$hostname_changed = '0';
	$hostname_dns = gethostbyaddr ($ip);
	if ($hostname_dns == $ip) {
		#NO DNS host
		$hostname_dns = 'NO DNS';
	}
	if ($hostname_dns != $hostname) {
		$hostname_changed = '1';
	}
}

switch($view_type)
{
	case "rescan_host":
		$query = "UPDATE hosts SET priority = 9 WHERE host_id = '$host_id';";
		$result = mysql_query($query) or die (mysql_error());
	case "view":

		$sure = "";
		if (isset($_GET["sure"]))
		$sure = trim($_GET["sure"]);
		
		$query_priority = mysql_query("SELECT priority FROM hosts WHERE host_id = '$host_id'") or die (mysql_error());
		$priority_value = mysql_fetch_assoc($query_priority);
		
		if (($priority_value['priority'] == 1) && ($sure == "yes")) {
			$update_priority = mysql_query("UPDATE hosts SET priority = 6 WHERE host_id = '$host_id'") or die (mysql_error());
		}
		
		
		$query = "SELECT host_id,r.range_id,s.sensor_id,ip as Ip,hostname as Hostname,sensor_name as Sensor,range as Range,range_name,DATE(FROM_UNIXTIME(d_last_scan)) as 'Last Scan',ping as 'Pings failed',priority as Priority,h.comment as Comment, 'Host' AS object, host_id AS object_index FROM hosts h, sensors s, ranges r WHERE host_id = '$host_id' and h.range_id = r.range_id and r.sensor_id = s.sensor_id";
		$result = mysql_query($query) or die (mysql_error());
		if (mysql_num_rows($result) != 0){

			echo "<div align='center'><h1>Host Info: $hostname($ip)</h1></div>\n";
			echo "<table width=95%>\n";
			if ($priority_value['priority'] == 1 && ($sure != "yes")) {  //host deleted
				$title="<h1>Host Info</h1>";
			} elseif ($priority_value['priority'] == 0) {
					$menu_bar = menu_bar(array('edit'=>'1','whitelist'=>'2','trash'=>'1','owners'=>'addusers','ask_dns'=>$hostname_changed),$host_id);
				echo "<div class='buttonbar'>$menu_bar</div>\n";
				$title="<h1>Host Info</h1>";
			} else {
				$menu_bar = menu_bar(array('rescan'=>'1','edit'=>'1','whitelist'=>'1','trash'=>'1','owners'=>'addusers','ask_dns'=>$hostname_changed),$host_id);
				echo "<div class='buttonbar'>$menu_bar</div>\n";
				$title="<h1>Host Info</h1>";
			}

			echo "<td align='left' valign='top' width=250>";
	        	draw_all ($title,$result);

		} else {
			echo "<div align='center'><h1>Host Unknown!!!</h1></div>";
			break;
		}
		echo "&nbsp";

		print_users('Host',$host_id,$sum_mails_per_host);

		echo "</td>";
		echo "<td align='left' valign='top'>";

		if ($priority_value['priority'] == 1 && ($sure != "yes")) {  //host deleted
			echo "<table class='cancerbero' width = 650>\n";
			echo "
			<td>
			<div align='center'><p><h1>Host $hostname ($ip) has been deleted.</h1></div>
			<div align='center'><h2> Do you want restore it?</h2></div>
			<form action='host_form.php' method='get' onsubmit='return checkform(this);'>
			<input type='hidden' name='sure' value='yes'>
			<input type='hidden' name='host_id' value='$host_id'>
			<input type='hidden' name='view_type' value='view'>
			<p><div align='center'><input class='lowred' type='submit' name='restore' value='yes'></div>
			</td>
			";
			echo "</table>\n";
			break;
		}

		$query = "SELECT scan_rec_id as 'Scan ID',DATE(FROM_UNIXTIME(d_scan)) as Date,open_ports as Ports,CONCAT_WS(' - ',os_guessed, os_gen) AS OS, number_of_alerts Alerts FROM scans WHERE host_id = '$host_id' ORDER BY Date DESC";
		#$result = mysql_query($query) or die (mysql_error());
		$query_bottom = "SELECT priority, FROM_UNIXTIME((d_last_scan+range_delay_scan*86400), '%m-%e-%y / %k:%i') as next_date_scan, (d_last_scan+range_delay_scan*43200) as next_scan, unix_timestamp() as now  FROM hosts,ranges WHERE host_id = '$host_id' and hosts.range_id = ranges.range_id;";
		$result_bottom = mysql_query($query_bottom) or die (mysql_error());
		$bot = mysql_fetch_assoc($result_bottom);
		$title="<h1>Scans done for $ip</h1>";
		if ($bot["priority"] == 0) {
			$bottom = "<h1>Host in Whitelist.</h1><p><h1>Not been scanned</h1>";
		} elseif ($bot["priority"] == 9) {
			$bottom = "<h1>User Scan solicited.</h1><p><h1>Will do as soon as I can</h1>";
		} elseif ($bot["next_scan"] < $bot["now"] && $bot["priority"] > 6) {
			$bottom = "<h1>Queued.</h1><p><h1>As soon as I can</h1>";
		} elseif ($bot["next_scan"] > $bot["now"] && $bot["priority"] == 6) {
			$bottom = "<h1>Scan not needed.</h1><p><h1>Next scan: $bot[next_date_scan]</h1>";
		} elseif ($bot["priority"] > 3) {
			if ($bot["next_date_scan"] == "01-16-70 / 1:00") {
				$bottom = "<h1>Never scanned.</h1><p><h1>It will be scanned as soon as seen alive</h1>";
			} else {
				$bottom = "<h1>Need scan from $bot[next_date_scan].</h1><p><h1>It will be scanned as soon as seen alive</h1>";
			}
		} else {
			$bottom = "$bot[next_date_scan]";
		}

		echo "<div id='scans'>";
		draw_table ($title,$query,650,$bottom);
		echo "</div>";

		#menu_owner();

		echo "</td>";

		break;

	case "view_scan":

		$query = "SELECT t.sensor_id,r.range_id,h.host_id, scan_rec_id as 'Scan ID',ip as Ip,hostname as Hostname,sensor_name as Sensor, range as Range,range_name, DATE(FROM_UNIXTIME(d_scan)) as Date,TIME(FROM_UNIXTIME(d_scan)) as Time,open_ports as Ports,CONCAT_WS(' - ',os_guessed, os_gen) AS OS, 'Host' AS object, h.host_id AS object_index FROM sensors t, ranges r, scans s, hosts h WHERE h.range_id = r.range_id and r.sensor_id = t.sensor_id and h.host_id = s.host_id AND scan_rec_id = '$scan_id';";
		$result = mysql_query($query) or die (mysql_error());

		$query_priority = mysql_query("SELECT priority FROM hosts WHERE host_id = '$host_id'") or die (mysql_error());
		$priority_value = mysql_fetch_assoc($query_priority);

		if (mysql_num_rows($result) != 0){
			echo "<div align='center'><h1>Data Info of Scan ID: $scan_id</h1></div>";
			echo "<table width = 95%>";
			if ($priority_value['priority'] == 1 && ($sure != "yes")) {  //host deleted
				$title="<h1>Data Info</h1>";
			} elseif ($priority_value['priority'] == 0) {
				$menu_bar = menu_bar(array('edit'=>'1','whitelist'=>'2','trash'=>'5','owners'=>'addusers','ask_dns'=>$hostname_changed),$host_id);
				echo "<div class='buttonbar'> $menu_bar</div>";
				#menu_host(array(rescan=>'1',edit=>'1',whitelist=>'2',trash=>'1',owners=>'addusers'));
				$title="<h1>Data Info</h1>";
			} else {
				$menu_bar = menu_bar(array('rescan'=>'1','edit'=>'1','whitelist'=>'1','trash'=>'5','owners'=>'addusers','ask_dns'=>$hostname_changed),$host_id);
				echo "<div class='buttonbar'>$menu_bar</div>";
				#menu_host(array(rescan=>'1',edit=>'1',whitelist=>'1',trash=>'1',owners=>'addusers'));
				$title="<h1>Data Info</h1>";
			}
			echo "<td valign='top' width = 250>";
			draw_all ($title,$result);
			//draw_host ($title,$result,$host_id);
		} else {
			echo "<div align='center'><h1>Scan Unknown!!!</h1></div>";
			break;
		}

		echo "&nbsp";

		print_users('Host',$host_id,$sum_mails_per_host);

		echo "</td>";
		echo "<td align='left' valign='top'>";

		$query = "SELECT port AS Port,service AS Service,CONCAT_WS(' - ',product,extra_info,port_version) AS Fullversion FROM ports WHERE scan_rec_id = $scan_id";
                #$result = mysql_query($query) or die (mysql_error());
		$title = "<h1>Ports open</h1>";
		draw_table ($title,$query,650);	
		break;

	case "view_alerts":

		$query = "SELECT t.sensor_id,r.range_id,h.host_id, scan_rec_id as 'Scan ID',ip as Ip,hostname as Hostname,sensor_name as Sensor, range as Range,range_name, DATE(FROM_UNIXTIME(d_scan)) as Date,TIME(FROM_UNIXTIME(d_scan)) as Time,open_ports as Ports,CONCAT_WS(' - ',os_guessed, os_gen) AS OS, 'Host' AS object, h.host_id AS object_index FROM sensors t, ranges r, scans s, hosts h WHERE h.range_id = r.range_id and r.sensor_id = t.sensor_id and h.host_id = s.host_id AND scan_rec_id = '$scan_id';";
		$result = mysql_query($query) or die (mysql_error());

		$query_priority = mysql_query("SELECT priority FROM hosts WHERE host_id = '$host_id'") or die (mysql_error());
		$priority_value = mysql_fetch_assoc($query_priority);

		if (mysql_num_rows($result) != 0){
			echo "<div align='center'><h1>Data Info of Scan ID: $scan_id</h1></div>";
			echo "<table width = 95%>";
			if ($priority_value['priority'] == 1 && ($sure != "yes")) {  //host deleted
				$title="<h1>Data Info</h1>";
			} elseif ($priority_value['priority'] == 0) {
				$menu_bar = menu_bar(array('edit'=>'1','whitelist'=>'2','trash'=>'1','owners'=>'addusers','ask_dns'=>$hostname_changed),$host_id);
				echo "<div class='buttonbar'> $menu_bar</div>";
				#menu_host(array(rescan=>'1',edit=>'1',whitelist=>'2',trash=>'1',owners=>'addusers'));
				$title="<h1>Data Info</h1>";
			} else {
				$menu_bar = menu_bar(array('rescan'=>'1','edit'=>'1','whitelist'=>'1','trash'=>'1','owners'=>'addusers','ask_dns'=>$hostname_changed),$host_id);
				echo "<div class='buttonbar'>$menu_bar</div>";
				#menu_host(array(rescan=>'1',edit=>'1',whitelist=>'1',trash=>'1',owners=>'addusers'));
				$title="<h1>Data Info</h1>";
			}
			echo "<td valign='top' width = 250>";
			draw_all ($title,$result);
			//draw_host ($title,$result,$host_id);
		} else {
			echo "<div align='center'><h1>Scan Unknown!!!</h1></div>";
			break;
		}

		echo "&nbsp";

		print_users('Host',$host_id,$sum_mails_per_host);

		echo "</td>";
		echo "<td align='left' valign='top'>";
		
		$alertid = "";
		if (isset($_GET["alertid"])) $alertid = trim($_GET["alertid"]);
		$checked = "";
		if (isset($_GET["check"])) $check =  trim($_GET["check"]);
		
		If ( $alertid >= 1 ) {
			$result = mysql_query("SELECT alert_checked FROM alerts WHERE alert_id = '$alertid'") or die (mysql_error());
			$status = mysql_result($result,0);
			if ($status == 'unchecked') {
				mysql_query("UPDATE alerts SET alert_checked = 'checked' WHERE alert_id = '$alertid'") or die (mysql_error());
			} elseif ($status == 'checked') {
				mysql_query("UPDATE alerts SET alert_checked = 'unchecked' WHERE alert_id = '$alertid'") or die (mysql_error());
			}
		}

		$query = "SELECT scan_rec_id, alert_id AS ID, FROM_UNIXTIME(d_scan, '%Y-%m-%d / %k:%i ') as Date,hosts.host_id, hostname AS Hostname, ip AS Ip, alerts.alert_name AS Alert, message AS Message, alert_level AS Level, alert_checked AS Checked FROM hosts, scans, alerts, alert_type, ranges WHERE hosts.host_id = scans.host_id AND hosts.range_id = ranges.range_id AND scans.scan_rec_id = alerts.last_scan_id AND alerts.alert_name = alert_type.alert_name AND scan_rec_id = $scan_id";
                #$result = mysql_query($query) or die (mysql_error());
		$title = "<h1>Alerts detected</h1>";
		draw_table ($title,$query,650);	
		break;

	case "view_mail":

		draw_table ($title,$query,800);

		break;

	case "view_list":

		draw_table ($title,$query,800);

		break;

	case "edit":
		$query = "SELECT * FROM hosts WHERE host_id = '$host_id';";
		$result = mysql_query($query) or die (mysql_error());
		include("table_host_edit.php");
		$return = $h->get_history_go(-1);
		echo "<p>&nbsp;<p><div align='center'><h2><a href='$return'>Return to $hostname ($ip)</a></h2></div>";
		break;
	case "del_host_white_list":
		# Remove a host from the white list.
		
		$query = "SELECT priority FROM hosts WHERE host_id = '$host_id';";
		$result = mysql_query($query) or die (mysql_error());
		$line = mysql_fetch_array($result, MYSQL_ASSOC);
		$priority = $line["priority"];

		$query2 = "SELECT white_list_id FROM white_list WHERE white_list = '$ip/32' OR white_list = '$ip'";
		$result2 = mysql_query($query2) or die (mysql_error());
		$line2 = mysql_fetch_array($result2, MYSQL_ASSOC);
		$white_list_id = $line2["white_list_id"];

		$sure = "";
		if (isset($_GET["sure"]))
		$sure = trim($_GET["sure"]);
		
		if ( $sure == "yes" ) {
			echo "Deleting from white list...";
			$restore_host = mysql_query("UPDATE hosts SET priority = 6 WHERE host_id = '$host_id';")or die (mysql_error());
			$del_white_list = mysql_query("DELETE FROM white_list WHERE white_list_id = $white_list_id") or die (mysql_error());
			echo "...Done <br>";
			echo "Host $hostname($ip) remove from white list.";
			$return = $h->get_history_go(-2);
			echo "<p>&nbsp;<p><div align='center'><h2><a href='$return'>Return to $hostname ($ip)</a></h2></div>";
			break;
		} else {
			if ($priority != 0){
				echo "
				<div class='row'>
				<div align='center'><h1>Host $hostname ($ip) is not in the white list.</h1></div>
				";
				$return = $h->get_history_go(-1);
				echo "<p>&nbsp;<p><div align='center'><h2><a href='$return'>Return to $hostname ($ip)</a></h2></div>";
				break;
			}
			if ($priority == 0 && $white_list_id == 0) {
				echo "
				<div class='row'>
				<div align='center'><h1>Host $hostname ($ip) belongs to a white list range and it can't be deleted. Check white list ranges in the sensor configuration.</h1></div>
				";
				$return = $h->get_history_go(-1);
				echo "<p>&nbsp;<p><div align='center'><h2><a href='$return'>Return to $hostname ($ip)</a></h2></div>";
				break;
			}
			#Show a warning with the host that will be deleted from the white list.
			echo "
			<div class='row'>
			<div align='center'><h1>Host $hostname ($ip) is going to be deleted from the white list.</h1></div>
			<div align='center'><h2> Are you sure?</h2></div>
			<form action='host_form.php' method='get' onsubmit='return checkform(this);'>
			<input type='hidden' name='sure' value='yes'>
			<input type='hidden' name='host_id' value='$host_id'>
			<input type='hidden' name='view_type' value='del_host_white_list'>
			<p><div align='center'><input class='lowred' type='submit' name='delete' value='yes'></div>
			";
			$return = $h->get_history_go(-1);
			echo "<p>&nbsp;<p><div align='center'><h2><a href='$return'>Return to $hostname ($ip)</a></h2></div>";
			break;
		}
		
		break;

	case "add_host_white_list":
		# Add a unique host in the white list.
		
		$query = "SELECT range_id,priority FROM hosts WHERE host_id = '$host_id';";
        	$result = mysql_query($query) or die (mysql_error());
		$line = mysql_fetch_array($result, MYSQL_ASSOC);
		$range_id = $line["range_id"];
		$priority = $line["priority"];

		$sure = "";
		if (isset($_GET["sure"]))
		$sure = trim($_GET["sure"]);
		
		if ( $sure == "yes" ) {
			echo "Adding to the white list...";
			$add_host = mysql_query("UPDATE hosts SET priority = 0 WHERE host_id = '$host_id';")or die (mysql_error());
			$add_white_list = mysql_query("INSERT INTO white_list VALUES (NULL,$range_id,'$ip','$hostname($ip)',CONCAT('Added ',FROM_UNIXTIME(unix_timestamp(),'%m-%e-%y / %k:%i')));") or die (mysql_error());
			echo "...Done <br>";
			echo "Host $hostname($ip) in the white list.";
			$return = $h->get_history_go(-2);
			echo "<p>&nbsp;<p><div align='center'><h2><a href='$return'>Return to $hostname ($ip)</a></h2></div>";
			break;
		} else {
			if ($priority == 0){
				echo "
				<div class='row'>
				<div align='center'><h1>Host $hostname ($ip) is already in the white list.</h1></div>
				";
				break;
			}
			#Show a warning with the host will pass to the white list.
			echo "
			<div class='row'>
			<div align='center'><h1>Host $hostname ($ip) is going to be added to the white list.</h1></div>
			<div align='center'><h2> Are you sure?</h2></div>
			<form action='host_form.php' method='get' onsubmit='return checkform(this);'>
			<input type='hidden' name='sure' value='yes'>
			<input type='hidden' name='host_id' value='$host_id'>
			<input type='hidden' name='view_type' value='add_host_white_list'>
			<p><div align='center'><input class='lowred' type='submit' name='delete' value='yes'></div>
			";
			$return = $h->get_history_go(-1);
			echo "<p>&nbsp;<p><div align='center'><h2><a href='$return'>Return to $hostname ($ip)</a></h2></div>";
			break;
		}
	case "delete_scan":
		# Delete a unique scan from the DB.
		$scan_id = trim($_GET['scan_rec_id']);
		
		$sure = "";
		if (isset($_GET["sure"]))
		$sure = trim($_GET["sure"]);
		
		if ( $sure == "yes" ) {
			echo "Deleting...";
			$delete_scan = mysql_query("DELETE scans,ports FROM scans LEFT JOIN ports ON scans.scan_rec_id = ports.scan_rec_id WHERE scans.scan_rec_id = '$scan_id'");
			$update_last_scan = mysql_query ("UPDATE hosts SET hosts.d_last_scan = (SELECT * FROM ((SELECT d_scan FROM scans where host_id = '$host_id') UNION (SELECT 0) ORDER BY d_scan desc LIMIT 1) AS tmp) WHERE hosts.host_id = '$host_id';") or die (mysql_error());
			echo "...Done <br>";
			echo "Scan $scan_id deleted.";
			$return = "host_form.php?view_type=view&host_id=$host_id";
			echo "<p>&nbsp;<p><div align='center'><h2><a href='$return'>Return to $hostname ($ip)</a></h2></div>";
			break;
		} else {
			#Show a warning with the scan that will be deleted.
			echo "
			<div class='row'>
			<div align='center'><h1>Scan $scan_id and is goint to be deleted.</h1></div>
			<div align='center'><h2> Are you sure?</h2></div>
			<form action='host_form.php' method='get' onsubmit='return checkform(this);'>
			<input type='hidden' name='sure' value='yes'>
			<input type='hidden' name='scan_rec_id' value='$scan_id'>
			<input type='hidden' name='view_type' value='delete_scan'>
			<p><div align='center'><input class='lowred' type='submit' name='delete' value='yes'></div>
			";
			$return = $h->get_history_go(-1);
			echo "<p>&nbsp;<p><div align='center'><h2><a href='$return'>Return to previous page</a></h2></div>";
			break;
		}
	case "delete_mail":
		# Delete a email of a host from the DB.
		$host_mail_id = trim($_GET['host_mail_id']);
		$email = trim($_GET['email']);

		$query = "SELECT hostname,ip FROM hosts WHERE host_id = '$host_mail_id';";
        	$result = mysql_query($query) or die (mysql_error());
		$line = mysql_fetch_array($result, MYSQL_ASSOC);
		$ip = $line["ip"];
		$hostname = $line["hostname"];

		$sure = "";
		if (isset($_GET["sure"]))
		$sure = trim($_GET["sure"]);
		
		if ( $sure == "yes" ) {
			echo "Deleting...";
			$delete_scan = mysql_query("DELETE FROM users WHERE email = '$email' AND host_id = '$host_mail_id'");
			echo "...Done <br>";
			echo "Mail address $email of host $hostname ($ip) was deleted.";
			$return = $h->get_history_go(-2);
			echo "<p>&nbsp;<p><div align='center'><h2><a href='$return'>Return $hostname ($ip)</a></h2></div>";
			break;
		} else {
			#Show a warning with the mail that will be deleted.
			echo "
			<div class='row'>
			<div align='center'><h1>Mail address $email of host $hostname ($ip) is goint to be deleted.</h1></div>
			<div align='center'><h2> Are you sure?</h2></div>
			<form action='host_form.php' method='get' onsubmit='return checkform(this);'>
			<input type='hidden' name='sure' value='yes'>
			<input type='hidden' name='email' value='$email'>
			<input type='hidden' name='host_mail_id' value='$host_mail_id'>
			<input type='hidden' name='view_type' value='delete_mail'>
			<p><div align='center'><input class='lowred' type='submit' name='delete' value='yes'></div>
			";
			$return = $h->get_history_go(-1);
			echo "<p>&nbsp;<p><div align='center'><h2><a href='$return'>Return $hostname ($ip)</a></h2></div>";
			break;
		}
	case "delete_host":
		# Delete a host and his scans from the DB.
		$host_id = trim($_GET['host_id']);
		
		$sure = "";
		if (isset($_GET["sure"]))
		$sure = trim($_GET["sure"]);
		
		if ( $sure == "yes" ) {
			echo "Deleting...";
			$delete_data_host = mysql_query("DELETE scans,ports FROM users RIGHT JOIN hosts ON users.host_id = hosts.host_id LEFT JOIN scans ON hosts.host_id = scans.host_id LEFT JOIN ports ON scans.scan_rec_id = ports.scan_rec_id WHERE hosts.host_id = $host_id");
			$delete_host = mysql_query("UPDATE hosts SET priority = 1, d_last_scan = 0 WHERE host_id = $host_id;") or die (mysql_error());
			echo "...Done <br>";
			echo "Host $hostname($ip) deleted.";
			$return = "search_forms.php?search=host";
			echo "<p>&nbsp;<p><div align='center'><h2><a href='$return'>Look for another host</a></h2></div>";
			break;
		} else {
			#Show a warning with the scan that will be deleted.
			echo "
			<div class='row'>
			<div align='center'><h1>Host $hostname($ip) and is goint to be deleted.</h1></div>
			<div align='center'><h2> Are you sure?</h2></div>
			<form action='host_form.php' method='get' onsubmit='return checkform(this);'>
			<input type='hidden' name='sure' value='yes'>
			<input type='hidden' name='host_id' value='$host_id'>
			<input type='hidden' name='view_type' value='delete_host'>
			<p><div align='center'><input class='lowred' type='submit' name='delete' value='yes'></div>
			";
			$return = $h->get_history_go(-1);
			echo "<p>&nbsp;<p><div align='center'><h2><a href='$return'>Return $hostname ($ip)</a></h2></div>";
			break;
		}

	case "ask_dns":
		
		$sure = "";
		if (isset($_GET["sure"]))
		$sure = trim($_GET["sure"]);

		if ($sure == 'yes') {
			echo "Updating...";
			$query = "UPDATE hosts SET hostname = '$hostname_dns' WHERE host_id = '$host_id';";
			$result = mysql_query($query) or die (mysql_error());
			echo "...Done <br>";
			echo "Host $hostname($ip) has been changed to $hostname_dns($ip).";
			$return = "host_form.php?host_id=$host_id&view_type=view";
			echo "<p>&nbsp;<p><div align='center'><h2><a href='$return'>Return to $hostname_dns ($ip)</a></h2></div>";

		} else {
			#Show a warning with the host that will be deleted from the white list.
			echo "
			<div class='row'>
			<div align='center'><h1>Host $hostname ($ip) has changed his DNS name for $hostname_dns.</h1></div>
			<div align='center'><h2> Do you want replace it in the database?</h2></div>
			<form action='host_form.php' method='get' onsubmit='return checkform(this);'>
			<input type='hidden' name='sure' value='yes'>
			<input type='hidden' name='host_id' value='$host_id'>
			<input type='hidden' name='view_type' value='ask_dns'>
			<p><div align='center'><input class='lowred' type='submit' name='ask to dns' value='yes'></div>
			";
			$return = "host_form.php?host_id=$host_id&view_type=view";
			echo "<p>&nbsp;<p><div align='center'><h2><a href='$return'>Return to $hostname ($ip)</a></h2></div>";
		}
		break;
	default:
	include("index.php");
}
echo "</td>";
echo "</table>";

?>
Return current item: Cancerbero - The watchdog of the ports