Location: PHPKode > projects > Network Asset Management Archive > nama/getlist.php
<?php
include "datediff.inc";
$now = date("m/j/y h:i:s",time());
include "connect.php";
print '<body bgcolor="#FFFFCC">';
$now = date("j/m/y h:i:s",time());
$LABlist = $_POST['LABlist'];
$SUBNET = $_POST['SUBNET'];
$OSlist = $_POST['OSlist'];
$Submit = $_POST['Submit'];

$currenttime = time();
$lasttime = strtotime($row->LAST_SEEN);
$diffseen = - DateDiff ("d",$currenttime , $lasttime);
$daysseen = floor($diffseen);
if ($Submit=='No Network Gear') {
     $stmt = "Select distinct IP_ADDRESS FROM arp_table a, subnets b where (not (os starts with 'Network Gear')) and (a.subnet = b.subnet) and (a.ip_address<>'0.0.0.0') ";
} else {
     $stmt = "Select distinct IP_ADDRESS FROM arp_table a, subnets b where (a.subnet = b.subnet) and (a.ip_address<>'0.0.0.0') ";
}
if ($Submit=='CRD2') {
     $stmt = "Select distinct IP_ADDRESS, NETBIOS_NAME, MAC_ADDRESS, LAST_SEEN FROM arp_table a, subnets b where (a.subnet = b.subnet) and (a.ip_address<>'0.0.0.0') and (a.netbios_name<>'' ) ";
}
if ($Submit=='No Green') {
$stmt = $stmt .  'and ((owner is null) or (building is null) or (room is null) or (barcode is null) or (os is null))';
}
if ($Submit=='No Green Block List') {
$stmt = $stmt .  'and ((owner is null) or (building is null) or (room is null) or (barcode is null) or (os is null))';
}
if ($Submit=='VIRUS FOUND') {
$stmt = $stmt .  'and ((virus_found=1))';
}
if ($Submit=='CAC INSTALLED') {
$stmt = $stmt .  'and ((cac_type is not null))';
}
if ($Submit=='NO CAC') {
$stmt = $stmt .  "and ((cac_type is null) and (OS starts with 'Win'))";
}
if (sizeof($LABlist) != 0) {
	$hadlab = true;
	if (sizeof($LABlist) == 1) {
	$stmt = $stmt . " and ((LAB = '$LABlist[0]')";
	}
	else {
		$stmt = $stmt . " and ((LAB in (";
		for ($i=0; $i < sizeof($LABlist); $i++) {
		    $stmt = $stmt . $LABlist[$i];
		    if ($i < sizeof($LABlist)-1) {
			$stmt = $stmt . ","; 
		    }
		    else {
			$stmt = $stmt . "))";
		    }
		}
	}
}
if (sizeof($SUBNET) != 0) {
	$hadlab = true;
	if (sizeof($SUBNET) == 1) {
		if (sizeof($LABlist) == 0) {
		     $stmt = $stmt . " and (a.SUBNET = '$SUBNET[0]')";
		}
		else {
		     $stmt = $stmt . " or (a.SUBNET = '$SUBNET[0]')";
		}
	}
	else {
		if (sizeof($LABlist) == 0) {
			$stmt = $stmt . " and (a.SUBNET in ('";
		}
		else {
			$stmt = $stmt . " or (a.SUBNET in ('";
		}
		for ($i=0; $i < sizeof($SUBNET); $i++) {
		    $stmt = $stmt . $SUBNET[$i];
		    if ($i < sizeof($SUBNET)-1) {
			$stmt = $stmt . "','"; 
		    }
		    else {
			$stmt = $stmt . "'))";
		    }
		}
	}
}
if (sizeof($LABlist) != 0) {
        $stmt = $stmt . ")";
}
if (sizeof($OSlist) != 0) {
	$hadlab = true;
	if (sizeof($OSlist) == 1) {
	$stmt = $stmt . " and (OS = '$OSlist[0]')";
	}
	else {
		$stmt = $stmt . " and (OS in ('";
		for ($i=0; $i < sizeof($OSlist); $i++) {
		    $stmt = $stmt . $OSlist[$i];
		    if ($i < sizeof($OSlist)-1) {
			$stmt = $stmt . "','"; 
		    }
		    else {
			$stmt = $stmt . "'))";
		    }
		}
	}
}
$stmt = $stmt . " order by IPNUM";
//echo $stmt;
//echo "<BR>";
$sth = ibase_query($dbh, $stmt);
while ($row = ibase_fetch_object($sth)) {
if (($Submit=='Block List') || ($Submit=='No Green Block List')){
                   echo 'access-list 105 deny ip any host ' . $row->IP_ADDRESS . '<BR>';
} else {
      if ($Submit=='CRD2') {
        $currenttime = time();
        $lasttime = strtotime($row->LAST_SEEN);
        $diffseen = - DateDiff ("d",$currenttime , $lasttime);
        $daysseen = floor($diffseen);
       if ($daysseen<10) {

           $mymac = strtoupper($row->MAC_ADDRESS);
          echo $row->NETBIOS_NAME . "," . $row->IP_ADDRESS, ",";
          echo $mymac[0] . $mymac[1] . ':';
          echo $mymac[2] . $mymac[3] . ':';
          echo $mymac[4] . $mymac[5] . ':';
          echo $mymac[6] . $mymac[7] . ':';
          echo $mymac[8] . $mymac[9] . ':';
          echo $mymac[10] . $mymac[11];
//          echo '		,' . $row->LAST_SEEN;
          echo "<BR>";
        }
      } else {
		   echo $row->IP_ADDRESS . "<BR>";
      }
}
}
?>

Return current item: Network Asset Management Archive