<?php
include "../connect.php";
if (!extension_loaded('odbtp')) {
dl('../php_odbtp.so');
}
$con = odbtp_connect($StatsScannerAddress,'DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\\STAT Scanner Output DB.mdb' ) or die;
odbtp_set_attr( ODB_ATTR_FULLCOLINFO, TRUE );
print '<body bgcolor="#FFFFCC">';
$now = date("j/m/y h:i:s",time());
$submit = $_POST['Submit'];
$LABlist = $_POST['LABlist'];
$SUBNET = $_POST['SUBNET'];
$OSlist = $_POST['OSlist'];
include('datediff.inc');
$now = date("m/j/y h:i:s",time());
ibase_timefmt("%m/%d/%Y %H:%M:%S",IBASE_TIMESTAMP);
$currenttime = time();
$fromdate = date("m/j/y",time()-(45*60*60*24));
$stmt = "Select a.*, c.lab as mylab, c.iaso as liaso FROM arp_table a, subnets b, lab c where (a.subnet = b.subnet) and (b.lab = c.serial) and (a.ip_address<>'0.0.0.0') ";
if (sizeof($LABlist) != 0) {
$hadlab = true;
if (sizeof($LABlist) == 1) {
$stmt = $stmt . " and ((b.LAB = '$LABlist[0]')";
}
else {
$stmt = $stmt . " and ((b.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) {
if ($OSlist[0] == 'NULL') {
$stmt = $stmt . " and (OS is null)";
} else {
$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;
$current_subnet = 'None';
$sth = ibase_query($dbh, $stmt);
if ($submit == 'Generate List') {
while ($row = ibase_fetch_object($sth)) {
if ($current_subnet != $row->SUBNET) {
print '<b><center>Subnet: ' . $row->SUBNET . '</b></center><br>';
$current_subnet = $row->SUBNET;
}
$stmt2 = "select display_name as sa from owner where serial= '$row->OWNER'";
//echo $stmt2 . '<br>';
$stmt3 = "select display_name as iaso from owner where serial = '$row->IASO'";
print 'IP Address: <b>' . $row->IP_ADDRESS . '</b> MAC Address: <b>' . strtoupper($row->MAC_ADDRESS) . '</b><br>';
print ' First Seen: <b>' . $row->FIRST_SEEN . '</b> Last Seen: <b>' . $row->LAST_SEEN . '</b><br>';
print 'DNS Name: <input type="text" name="DNS_NAME[]" value="' . $row->DNS_NAME. '" size="25" maxlength="25"></b> Netbios Name: <input type="text" name="NETBIOS_NAME[]" value="' . $row->NETBIOS_NAME . '" size="25" maxlength="25"></b><br>';
print 'LAB: <B>' . $row->MYLAB . ' </b>';
print 'LIASO: <b>' . $row->LIASO . ' </b><br>';
if ($row->IASO != '') {
$sth3=ibase_query($dbh,$stmt3);
$row3 = ibase_fetch_object($sth3);
print 'IASO: <b>' . $row3->IASO . ' </b><br>';
ibase_free_result($sth3);
}
if ($row->OWNER != '') {
$sth2=ibase_query($dbh,$stmt2);
$row2 = ibase_fetch_object($sth2);
print 'System Admin: <b>' . $row2->SA . ' </b><br>';
ibase_free_result($sth2);
}
print 'System Description: <input type="text" name="SYS_DESC[]" value="' . $row->SYS_DESC. '" size="50" maxlength="50"></b><br>';
print 'BUILDING: <input type="text" name="BUILDING[]" value="' . $row->BUILDING. '" size="25" maxlength="25"></b> ROOM: <input type="text" name="ROOM[]" value="' . $row->ROOM . '" size="25" maxlength="25"></b><br>';
print 'Barcode #: <input type="text" name="BARCODE[]" value="' . $row->BARCODE. '" size="10" maxlength="10"></b><br>';
print 'OS: <input type="text" name="OS[]" value="' . $row->OS. '" size="30" maxlength="30"></b><input type="text" name="OS2[]" value="" size="40" maxlength="40"></b><br>';
print '<input type="checkbox" name="webserver" value="webserver"> WEBSERVER<br>';
print '<input type="checkbox" name="pdc" value="pdc">DOMAIN CONTROLLER<br><hr><br><br>';
}
}
else {
print '<table border="2">';
print '<tr nowrap><td width="24">IP ADDRESS</td><td width="24">MAC ADDRESS</td>';
print '<td nowrap">Stats ACCESS</td>';
print '<td nowrap">DNS NAME</td>';
print '<td width="24">NETBIOS_NAME</td>';
print '<td>LAB</td>';
print '<td nowrap>IASO</td>';
print '<td nowrap>System Admin</td>';
print '<td width="24">SYS_DESC</td>';
print '<td width="24">BUILDING</td>';
print '<td width="24">ROOM</td>';
print '<td width="24">BARCODE</td>';
print '<td width="24">OS</td>';
print '<td>WEBSERVER</td>';
print '<td>PDC</td>';
print '<td>Virus Server</td>';
print '<td>Virus Defs</td>';
print '<td width="24">FIRST_SEEN</td>';
print '<td width="24">LAST_SEEN</td>';
print '<td>ELAPSED TIME</td>';
print '</tr>';
while ($row = ibase_fetch_object($sth)) {
$lasttime = strtotime($row->LAST_SEEN);
$diff = - DateDiff ("d",$currenttime , $lasttime);
$days = floor($diff);
$diffh = ($diff - $days) * 24;
//echo $diff . " " . $days . " " . $diffh;
$hours = floor($diffh);
$diffm = ($diffh - $hours) * 60;
$mins = floor($diffm);
$diffs = ($diffm - $mins) * 60;
$secs = floor($diffs);
$mydiff = '';
if ($days >= 1) {
if ($days == 1) {
$mydiff = $days . ' day';
} else {
$mydiff = $days . ' days';
}
}
if ($hours >= 1) {
if ($hours == 1) {
$mydiff = $mydiff . ' ' . $hours . ' hour';
} else {
$mydiff = $mydiff . ' ' . $hours . ' hours';
}
}
if ($mins >= 1) {
if ($mins > 9) {
$mydiff = $mydiff . ' ' . $mins . ' min';
} else {
$mydiff = $mydiff . ' 0' . $mins . ' min';
}
}
if ($secs >= 1) {
if ($secs > 9) {
$mydiff = $mydiff . ' ' . $secs . ' sec';
} else {
$mydiff = $mydiff . ' 0' . $secs . ' sec';
}
}
$stmt2 = "select display_name as sa from owner where serial= '$row->OWNER'";
$stmt3 = "select display_name as iaso from owner where serial = '$row->IASO'";
if ($diff>30) {
//green print '<tr bgcolor="D3EED3">';
print '<tr bgcolor="EED3D6">';
} else {
if ($diff>15) {
print '<tr bgcolor="EED3D6">';
} else {
print '<tr>';
}
}
$TEMP = strtoupper($row->MAC_ADDRESS);
$MACADDRESS = '';
for ($k=0; $k<6; $k++) {
$MACADDRESS .= $TEMP[($k * 2)];
$MACADDRESS .= $TEMP[($k * 2)+1];
if ($k<>5) {
$MACADDRESS .= '-';
}
}
$myquery = "select [SCAN Summary TABLE].Access from [MACHINE TABLE], [SCAN Summary TABLE] where ([SCAN Summary TABLE].[MACHINE ID]=[MACHINE TABLE].[MACHINE ID]) and ([MACHINE TABLE].[MAC ADDRESS]='" . $MACADDRESS . "');";
//echo $myquery;
$good=0;
if ($qry = odbtp_query($myquery)) {
$rec = odbtp_fetch_array($qry);
$good=1;
}
print '<td nowrap>' . $row->IP_ADDRESS . ' </td><td nowrap>' . $MACADDRESS . '</td>';
print '<td nowrap>' . $rec[0] . ' </td>';
print '<td nowrap>' . $row->DNS_NAME . ' </td>';
print '<td nowrap>' . $row->NETBIOS_NAME . ' </td>';
print '<td>' . $row->MYLAB . ' </td>';
if ($row->IASO != '') {
$sth3=ibase_query($dbh,$stmt3);
$row3 = ibase_fetch_object($sth3);
print '<td nowrap>' . $row3->IASO . ' </td>';
ibase_free_result($sth3);
} else {
print '<td> </td>';
}
if ($row->OWNER != '') {
$sth2=ibase_query($dbh,$stmt2);
$row2 = ibase_fetch_object($sth2);
print '<td nowrap>' . $row2->SA . ' </td>';
ibase_free_result($sth2);
} else {
print '<td> </td>';
}
print '<td nowrap>' . $row->SYS_DESC . ' </td>';
print '<td nowrap>' . $row->BUILDING . ' </td>';
print '<td nowrap>' . $row->ROOM . ' </td>';
print '<td nowrap>' . $row->BARCODE . ' </td>';
print '<td nowrap>' . $row->OS . ' </td>';
print '<td>' . $row->WEBSERVER . ' </td>';
print '<td>' . $row->PDC . ' </td>';
print '<td nowrap>' . $row->AV_SERVER . ' </td>';
print '<td nowrap>' . $row->ANTIVIRUS . ' </td>';
print '<td nowrap>' . $row->FIRST_SEEN . ' </td>';
print '<td nowrap>' . $row->LAST_SEEN . ' </td>';
print '<td nowrap>' . $mydiff . ' </td>';
print '</tr>';
}
odbtp_close();
print '</table>';
}