if (!$ignore) { if ($entry['ifInErrors'] > 0 || $entry['ifOutErrors'] > 0) { $error_img = generate_port_link($entry, "<img src='images/16/chart_curve_error.png' alt='Interface Errors' border=0>", port_errors); } else { $error_img = ''; } $arp_host = dbFetchRow('SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id', array($entry['ipv4_address'])); if ($arp_host) { $arp_name = generate_device_link($arp_host); } else { unset($arp_name); } if ($arp_host) { $arp_if = generate_port_link($arp_host); } else { unset($arp_if); } if ($arp_host['device_id'] == $entry['device_id']) { $arp_name = 'Localhost'; } if ($arp_host['port_id'] == $entry['port_id']) { $arp_if = 'Local port'; } $response[] = array('mac_address' => formatMac($entry['mac_address']), 'ipv4_address' => $entry['ipv4_address'], 'hostname' => generate_device_link($entry), 'interface' => generate_port_link($entry, makeshortif(fixifname(ifLabel($entry['label'])))) . ' ' . $error_img, 'remote_device' => $arp_name, 'remote_interface' => $arp_if); } //end if unset($ignore); } //end foreach $output = array('current' => $current, 'rowCount' => $rowCount, 'rows' => $response, 'total' => $total); echo _json_encode($output);
$tbl->setHeaders(array('Port name', 'Status', 'IPv4 Address', 'Speed In', 'Speed Out', 'Packets In', 'Packets Out', 'Speed', 'Duplex', 'Type', 'MAC Address', 'MTU')); foreach (dbFetchRows('SELECT * FROM `ports` WHERE `device_id` = ?', array($options['d'])) as $port) { if ($port['ifOperStatus'] == 'up') { $port['in_rate'] = $port['ifInOctets_rate'] * 8; $port['out_rate'] = $port['ifOutOctets_rate'] * 8; $in_perc = @round($port['in_rate'] / $port['ifSpeed'] * 100); $out_perc = @round($port['in_rate'] / $port['ifSpeed'] * 100); } if ($port['ifSpeed']) { $port_speed = humanspeed($port['ifSpeed']); } if ($port[ifDuplex] != 'unknown') { $port_duplex = $port['ifDuplex']; } if ($port['ifPhysAddress'] && $port['ifPhysAddress'] != '') { $port_mac = formatMac($port['ifPhysAddress']); } if ($port['ifMtu'] && $port['ifMtu'] != '') { $port_mtu = $port['ifMtu']; } $tbl->addRow(array($port['ifDescr'], $port['ifOperStatus'], '', formatRates($port['in_rate']), formatRates($port['out_rate']), format_bi($port['ifInUcastPkts_rate']) . 'pps', format_bi($port['ifOutUcastPkts_rate']) . 'pps', $port_speed, $port_duplex, '', $port_mac, $port_mtu)); } //end foreach echo $tbl->getTable(); } else { echo $options['list']; echo "Usage of console-ui.php:\n\n -l What log type we want to see:\n eventlog = Event log messages\n syslog = Syslog messages\n\n -d Specify the device id to filter results\n\n --list What to list\n devices = list devices and device id's\n\n --device-stats Lists the port statistics for a given device\n\n Examples:\n #1 php console-ui.php -l eventlog -d 1\n #2 php console-ui.php --list=devices\n\n "; exit; } } }
/** * Display ARP/NDP table addresses. * * Display pages with ARP/NDP tables addresses from devices. * * @param array $vars * @return none * */ function print_arptable($vars) { // With pagination? (display page numbers in header) $pagination = isset($vars['pagination']) && $vars['pagination']; $pageno = isset($vars['pageno']) && !empty($vars['pageno']) ? $vars['pageno'] : 1; $pagesize = isset($vars['pagesize']) && !empty($vars['pagesize']) ? $vars['pagesize'] : 10; $start = $pagesize * $pageno - $pagesize; $param = array(); $where = ' WHERE 1 '; foreach ($vars as $var => $value) { if ($value != '') { switch ($var) { case 'device': case 'device_id': $where .= ' AND I.`device_id` = ?'; $param[] = $value; break; case 'port': case 'port_id': $where .= ' AND I.`port_id` = ?'; $param[] = $value; break; case 'ip_version': $where .= ' AND `ip_version` = ?'; $param[] = $value; break; case 'address': if (isset($vars['searchby']) && $vars['searchby'] == 'ip') { $where .= ' AND `ip_address` LIKE ?'; $value = trim($value); ///FIXME. Need another conversion ("2001:b08:b08" -> "2001:0b08:0b08") -- mike if (Net_IPv6::checkIPv6($value)) { $value = Net_IPv6::uncompress($value, true); } $param[] = '%' . $value . '%'; } else { $where .= ' AND `mac_address` LIKE ?'; $param[] = '%' . str_replace(array(':', ' ', '-', '.', '0x'), '', mres($value)) . '%'; } break; } } } // Show ARP tables only for permitted ports $query_permitted = generate_query_permitted(array('port'), array('port_table' => 'I')); $query = 'FROM `ip_mac` AS M '; $query .= 'LEFT JOIN `ports` AS I ON I.`port_id` = M.`port_id` '; $query .= $where . $query_permitted; $query_count = 'SELECT COUNT(`mac_id`) ' . $query; $query = 'SELECT * ' . $query; $query .= ' ORDER BY M.`mac_address`'; $query .= " LIMIT {$start},{$pagesize}"; // Query ARP/NDP table addresses $entries = dbFetchRows($query, $param); // Query ARP/NDP table address count if ($pagination) { $count = dbFetchCell($query_count, $param); } $list = array('device' => FALSE, 'port' => FALSE); if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') { $list['device'] = TRUE; } if (!isset($vars['port']) || empty($vars['port']) || $vars['page'] == 'search') { $list['port'] = TRUE; } $string = '<table class="table table-bordered table-striped table-hover table-condensed">' . PHP_EOL; if (!$short) { $string .= ' <thead>' . PHP_EOL; $string .= ' <tr>' . PHP_EOL; $string .= ' <th>MAC Address</th>' . PHP_EOL; $string .= ' <th>IP Address</th>' . PHP_EOL; if ($list['device']) { $string .= ' <th>Device</th>' . PHP_EOL; } if ($list['port']) { $string .= ' <th>Interface</th>' . PHP_EOL; } $string .= ' <th>Remote Device</th>' . PHP_EOL; $string .= ' <th>Remote Interface</th>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; $string .= ' </thead>' . PHP_EOL; } $string .= ' <tbody>' . PHP_EOL; foreach ($entries as $entry) { humanize_port($entry); $ip_version = $entry['ip_version']; $ip_address = $ip_version == 6 ? Net_IPv6::compress($entry['ip_address']) : $entry['ip_address']; $arp_host = dbFetchRow('SELECT * FROM `ipv' . $ip_version . '_addresses` AS A LEFT JOIN `ports` AS I ON A.`port_id` = I.`port_id` LEFT JOIN `devices` AS D ON D.`device_id` = I.`device_id` WHERE A.`ipv' . $ip_version . '_address` = ?', array($ip_address)); $arp_name = $arp_host ? generate_device_link($arp_host) : ''; $arp_if = $arp_host ? generate_port_link($arp_host) : ''; if ($arp_host['device_id'] == $entry['device_id']) { $arp_name = 'Self Device'; } if ($arp_host['port_id'] == $entry['port_id']) { $arp_if = 'Self Port'; } $string .= ' <tr>' . PHP_EOL; $string .= ' <td width="160">' . formatMac($entry['mac_address']) . '</td>' . PHP_EOL; $string .= ' <td width="140">' . $ip_address . '</td>' . PHP_EOL; if ($list['device']) { $dev = device_by_id_cache($entry['device_id']); $string .= ' <td class="entity" nowrap>' . generate_device_link($dev) . '</td>' . PHP_EOL; } if ($list['port']) { if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) { $port_error = generate_port_link($entry, '<span class="label label-important">Errors</span>', 'port_errors'); } $string .= ' <td class="entity">' . generate_port_link($entry, short_ifname($entry['label'])) . ' ' . $port_error . '</td>' . PHP_EOL; } $string .= ' <td class="entity" width="200">' . $arp_name . '</td>' . PHP_EOL; $string .= ' <td class="entity">' . $arp_if . '</td>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; } $string .= ' </tbody>' . PHP_EOL; $string .= '</table>'; // Print pagination header if ($pagination) { $string = pagination($vars, $count) . $string . pagination($vars, $count); } // Print ARP/NDP table echo $string; }
if (isset($current)) { $limit_low = $current * $rowCount - $rowCount; $limit_high = $rowCount; } if ($rowCount != -1) { $sql .= " LIMIT {$limit_low},{$limit_high}"; } $sql = "SELECT *,`I`.`ifDescr` AS `interface` {$sql}"; foreach (dbFetchRows($sql, $param) as $interface) { $speed = humanspeed($interface['ifSpeed']); $type = humanmedia($interface['ifType']); if ($_POST['search_type'] == 'ipv6') { list($prefix, $length) = explode("/", $interface['ipv6_network']); $address = Net_IPv6::compress($interface['ipv6_address']) . '/' . $length; } elseif ($_POST['search_type'] == 'mac') { $address = formatMac($interface['ifPhysAddress']); } else { list($prefix, $length) = explode("/", $interface['ipv4_network']); $address = $interface['ipv4_address'] . '/' . $length; } if ($interface['in_errors'] > 0 || $interface['out_errors'] > 0) { $error_img = generate_port_link($interface, "<img src='images/16/chart_curve_error.png' alt='Interface Errors' border=0>", errors); } else { $error_img = ""; } if (port_permitted($interface['port_id'])) { $interface = ifLabel($interface, $interface); $response[] = array('hostname' => generate_device_link($interface), 'interface' => generate_port_link($interface) . ' ' . $error_img, 'address' => $address, 'description' => $interface['ifAlias']); } } $output = array('current' => $current, 'rowCount' => $rowCount, 'rows' => $response, 'total' => $total);
echo "</pre>"; } if (is_array($ma)) { if ($auth || port_permitted($ma['port_id'])) { $rrd_filename = $config['rrd_dir'] . "/" . $ma['hostname'] . "/" . safename("mac_acc-" . $ma['ifIndex'] . "-" . $ma['vlan_id'] . "-" . $ma['mac'] . ".rrd"); if ($debug) { echo $rrd_filename; } if (is_file($rrd_filename)) { if ($debug) { echo "exists"; } $port = get_port_by_id($ma['port_id']); $device = device_by_id_cache($port['device_id']); $title = generate_device_link($device); $title .= " :: Port " . generate_port_link($port); $title .= " :: Mac Accounting"; $title .= " :: " . formatMac($ma['mac']); $auth = TRUE; } else { # graph_error("file not found"); } } else { # graph_error("unauthenticated"); } } else { # graph_error("entry not found"); } } else { # graph_error("invalid id"); }
} else { unset($arp_name); } if ($arp_host) { $arp_if = generate_port_link($arp_host); } else { unset($arp_if); } if ($arp_host['device_id'] == $entry['device_id']) { $arp_name = "Localhost"; } if ($arp_host['port_id'] == $entry['port_id']) { $arp_if = "Local port"; } echo '<tr> <td>' . formatMac($entry['mac_address']) . '</td> <td>' . $entry['ipv4_address'] . '</td> <td>' . generate_device_link($entry) . '</td> <td>' . generate_port_link($entry, makeshortif(fixifname($entry['ifDescr']))) . ' ' . $error_img . '</td> <td>' . $arp_name . '</td> <td>' . $arp_if . '</td> </tr>'; } unset($ignore); } if ($count % $results > 0) { echo ' <tr> <td colspan="6" align="center">' . generate_pagination($count, $results, $page_number) . '</td> </tr>'; } echo '</table>
} else { echo "</td><td width=150 onclick=\"location.href='" . generate_port_url($port) . "'\" >"; if ($port['ifType'] && $port['ifType'] != '') { echo '<span class=box-desc>' . fixiftype($port['ifType']) . '</span>'; } else { echo '-'; } echo '<br />'; if ($ifHardType && $ifHardType != '') { echo '<span class=box-desc>' . $ifHardType . '</span>'; } else { echo '-'; } echo "</td><td width=150 onclick=\"location.href='" . generate_port_url($port) . "'\" >"; if ($port['ifPhysAddress'] && $port['ifPhysAddress'] != '') { echo '<span class=box-desc>' . formatMac($port['ifPhysAddress']) . '</span>'; } else { echo '-'; } echo '<br />'; if ($port['ifMtu'] && $port['ifMtu'] != '') { echo '<span class=box-desc>MTU ' . $port['ifMtu'] . '</span>'; } else { echo '-'; } } //end if echo '</td>'; echo '<td width=375 valign=top class="interface-desc">'; $neighborsCount = 0; $nbLinks = 0;
/** * Display FDB table. * * @param array $vars * @return none * */ function print_fdbtable($vars) { // With pagination? (display page numbers in header) $pagination = isset($vars['pagination']) && $vars['pagination']; $pageno = isset($vars['pageno']) && !empty($vars['pageno']) ? $vars['pageno'] : 1; $pagesize = isset($vars['pagesize']) && !empty($vars['pagesize']) ? $vars['pagesize'] : 10; $start = $pagesize * $pageno - $pagesize; $param = array(); $where = ' WHERE 1 '; foreach ($vars as $var => $value) { if ($value != '') { $cond = array(); switch ($var) { case 'device': case 'device_id': $where .= ' AND I.`device_id` = ?'; $param[] = $value; break; case 'port': case 'port_id': $where .= ' AND I.`port_id` = ?'; $param[] = $value; break; case 'interface': $where .= ' AND I.`ifDescr` LIKE ?'; $param[] = $value; break; case 'vlan_id': if (!is_array($value)) { $value = array($value); } foreach ($value as $v) { $cond[] = '?'; $param[] = $v; } $where .= " AND F.`vlan_id` IN ("; $where .= implode(', ', $cond); $where .= ')'; break; case 'vlan_name': if (!is_array($value)) { $value = array($value); } foreach ($value as $v) { $cond[] = '?'; $param[] = $v; } $where .= " AND V.`vlan_name` IN ("; $where .= implode(', ', $cond); $where .= ')'; break; case 'address': $where .= ' AND F.`mac_address` LIKE ?'; $param[] = '%' . str_replace(array(':', ' ', '-', '.', '0x'), '', mres($value)) . '%'; break; } } } // Show FDB tables only for permitted ports $query_permitted = generate_query_permitted(array('port'), array('port_table' => 'I')); $query = 'FROM `vlans_fdb` AS F '; $query .= 'LEFT JOIN `vlans` as V ON V.`vlan_vlan` = F.`vlan_id` AND V.`device_id` = F.`device_id` '; $query .= 'LEFT JOIN `ports` AS I ON I.`port_id` = F.`port_id` '; $query .= $where . $query_permitted; $query_count = 'SELECT COUNT(*) ' . $query; $query = 'SELECT * ' . $query; $query .= ' ORDER BY F.`mac_address`'; $query .= " LIMIT {$start},{$pagesize}"; // Query addresses $entries = dbFetchRows($query, $param); // Query address count if ($pagination) { $count = dbFetchCell($query_count, $param); } $list = array('device' => FALSE); if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') { $list['device'] = TRUE; } $string = '<table class="table table-bordered table-striped table-hover table-condensed">' . PHP_EOL; if (!$short) { $string .= ' <thead>' . PHP_EOL; $string .= ' <tr>' . PHP_EOL; $string .= ' <th>MAC Address</th>' . PHP_EOL; if ($list['device']) { $string .= ' <th>Device</th>' . PHP_EOL; } $string .= ' <th>Interface</th>' . PHP_EOL; $string .= ' <th>VLAN ID</th>' . PHP_EOL; $string .= ' <th>VLAN Name</th>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; $string .= ' </thead>' . PHP_EOL; } $string .= ' <tbody>' . PHP_EOL; foreach ($entries as $entry) { humanize_port($entry); $string .= ' <tr>' . PHP_EOL; $string .= ' <td width="160">' . formatMac($entry['mac_address']) . '</td>' . PHP_EOL; if ($list['device']) { $dev = device_by_id_cache($entry['device_id']); $string .= ' <td class="entity" nowrap>' . generate_device_link($dev) . '</td>' . PHP_EOL; } if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) { $port_error = generate_port_link($entry, '<span class="label label-important">Errors</span>', 'port_errors'); } $string .= ' <td class="entity">' . generate_port_link($entry, short_ifname($entry['label'])) . ' ' . $port_error . '</td>' . PHP_EOL; $string .= ' <td>Vlan' . $entry['vlan_vlan'] . '</td>' . PHP_EOL; $string .= ' <td>' . $entry['vlan_name'] . '</td>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; } $string .= ' </tbody>' . PHP_EOL; $string .= '</table>'; // Print pagination header if ($pagination) { $string = pagination($vars, $count) . $string . pagination($vars, $count); } // Print FDB table echo $string; }
function displaySetupPage($mac, &$s20Table, $myUrl) { global $daysOfWeek; $devData = $s20Table[$mac]; $timerName = $devData['name']; ?> <div style="text-align:center"> <h2> <form action="<?php echo $myUrl; ?> " method="post"> <?php if (array_key_exists('off', $s20Table[$mac])) { echo $timerName; $isActive = 0; } else { $isActive = 1; ?> <input type = "text" name="newName" value="<?php echo $timerName; ?> " id="inputName"> <?php } if (isset($devData['st']) && $devData['st'] >= 0 && !array_key_exists('off', $s20Table[$mac])) { $stDisplay = $devData['st'] ? "greenCircle100px.png" : "redCircle100px.png"; echo '<img src="' . IMG_PATH . $stDisplay . '" style="width:0.8em;position:relative;top:0.1em;left:0.3em;">'; } $nnext = $devData['next']; if ($isActive) { echo '<br><div id="mayEdit">Socket name above is editable</div>'; } ?> </h2> <p> <hr> <input type="submit" name="toMainPage" value="back<?php echo $mac; ?> " id="backButton"> <?php if ($isActive) { ?> <div> Number of next events displayed in main page for this timer: <select name="numberOfNextEvents"> <?php for ($i = 0; $i < 8; $i++) { echo '<option value="' . $i . '"' . ($nnext == $i ? ' selected="selected"' : ' ') . '>' . $i . '</option>' . "\n"; } ?> </select> <p> <hr> <?php $ip = getIpFromMac($mac, $s20Table); $dev = $s20Table[$mac]; $time = $dev['time']; $serverTime = $dev['serverTime']; $tz = $dev['timeZone']; $serverTzS = date_default_timezone_get(); $serverTz = timezone_open($serverTzS); $serverTzOffset = $serverTz->getOffset(new DateTime()); echo '<div id="socketTime"></div>'; echo '<div id="serverTime"></div>'; echo "<hr>"; ?> S20 mac address - <?php echo formatMac($mac); ?> <hr> <script> var socketTimeRef = <?php echo $time; ?> ; var serverTimeRef = <?php echo $serverTime; ?> ; var socketTz = <?php echo $tz; ?> ; var serverTz = <?php echo $serverTzOffset; ?> ; var t0_ref = new Date().getTime()/1000; function displaySocketTime(){ var now,socketTime,serverTime; now = new Date().getTime()/1000; socketTime = now - t0_ref + socketTimeRef; serverTime = now - t0_ref + serverTimeRef; var socketTimeO = new Date(1000*socketTime); var serverTimeO = new Date(1000*serverTime); var socketTimeS = socketTimeO.toString(); var serverTimeS = serverTimeO.toString(); socketTimeS = socketTimeS.substring(0,24); serverTimeS = serverTimeS.substring(0,24); var msgSckt = "Socket time is " + socketTimeS+", tz="+socketTz; var msgServ = "Server time is " + serverTimeS+", tz="+serverTz; document.getElementById('socketTime').innerHTML = msgSckt; document.getElementById('serverTime').innerHTML = msgServ; } setInterval(displaySocketTime,1000); </script> <p> <button type="submit" name="toMainPage" value="procSetup<?php echo $mac; ?> " id="doneButton">Done</button> <div style="margin-top:10vh;"> <hr> Delete device from the system<p> <button type="submit" name="toMainPage" value="procSetupDel<?php echo $mac; ?> " id="deleteButton">Delete device</button> <hr> </div> <?php } else { $inactiveTimeStamp = $s20Table[$mac]['off']; $inactiveString = gmdate("D M j G:i:s T Y", $inactiveTimeStamp); $now = time(); $delta = $now - $inactiveTimeStamp; $deltaString = secToHourString($delta); $msg = "This device is inactive since " . $inactiveString; $msg = $msg . " (" . $deltaString . "s ago)<p>"; $msg = $msg . "It did not reply to a re-activate command. Is it connected and on-line?<p>"; echo $msg; ?> <hr> <button type="submit" name="toMainPage" value="procSetupDel<?php echo $mac; ?> " id="deleteButton">Delete device</button> <p> <button type="submit" name="toMainPage" value="procSetupCancel<?php echo $mac; ?> " id="cancelButton">Cancel</button> <?php } ?> </form> </div> <?php }
$query .= " AND P.device_id = ?"; $param[] = $_POST['device_id']; } if ($_POST['interface']) { $query .= " AND P.ifDescr LIKE ?"; $param[] = $_POST['interface']; } $query .= " ORDER BY P.ifPhysAddress"; echo '<tr><th>Device</a></th><th>Interface</th><th>MAC Address</th><th>Description</th></tr>'; foreach (dbFetchRows($query, $param) as $entry) { if (!$ignore) { $speed = humanspeed($entry['ifSpeed']); $type = humanmedia($entry['ifType']); if ($entry['in_errors'] > 0 || $entry['out_errors'] > 0) { $error_img = generate_port_link($entry, "<img src='images/16/chart_curve_error.png' alt='Interface Errors' border=0>", errors); } else { $error_img = ""; } if (port_permitted($entry['port_id'])) { $interface = ifLabel($interface, $interface); echo '<tr> <td>' . generate_device_link($entry) . '</td> <td>' . generate_port_link($entry, makeshortif(fixifname($entry['ifDescr']))) . ' ' . $error_img . '</td> <td>' . formatMac($entry['ifPhysAddress']) . '</td> <td>' . $entry['ifAlias'] . "</td>\n </tr>\n"; } } unset($ignore); } echo "</table>"; echo '</div>';
$error_img = generate_port_link($entry, "<img src='images/16/chart_curve_error.png' alt='Interface Errors' border=0>", errors); } else { $error_img = ""; } $arp_host = dbFetchRow("SELECT * FROM ipv4_addresses AS A, ports AS I, devices AS D WHERE A.ipv4_address = ? AND I.port_id = A.port_id AND D.device_id = I.device_id", array($entry['ipv4_address'])); if ($arp_host) { $arp_name = generate_device_link($arp_host); } else { unset($arp_name); } if ($arp_host) { $arp_if = generate_port_link($arp_host); } else { unset($arp_if); } if ($arp_host['device_id'] == $entry['device_id']) { $arp_name = "Localhost"; } if ($arp_host['port_id'] == $entry['port_id']) { $arp_if = "Local port"; } echo '<tr> <td width="160">' . formatMac($entry['mac_address']) . '</td> <td width="200" class="entity">' . generate_device_link($entry) . '</td> <td class="entity">' . generate_port_link($entry, makeshortif(fixifname($entry['ifDescr']))) . ' ' . $error_img . '</td> <td class="entity">VLAN' . $entry['vlan_vlan'] . '</td> <td class="entity">' . $entry['vlan_name'] . '</td> </tr>'; } } echo "</table>";
/** * Display Interface MACs addresses. * * Display pages with MAC addresses from device Interfaces. * * @param array $vars * @return none * */ function print_mac_addresses($vars) { // With pagination? (display page numbers in header) $pagination = isset($vars['pagination']) && $vars['pagination']; $pageno = isset($vars['pageno']) && !empty($vars['pageno']) ? $vars['pageno'] : 1; $pagesize = isset($vars['pagesize']) && !empty($vars['pagesize']) ? $vars['pagesize'] : 10; $start = $pagesize * $pageno - $pagesize; $param = array(); $where = ' WHERE 1 '; foreach ($vars as $var => $value) { if ($value != '') { switch ($var) { case 'device': case 'device_id': $where .= ' AND `device_id` = ?'; $param[] = $value; break; case 'interface': $where .= ' AND `ifDescr` LIKE ?'; $param[] = $value; break; case 'address': $where .= ' AND `ifPhysAddress` LIKE ?'; $param[] = '%' . str_replace(array(':', ' ', '-', '.', '0x'), '', mres($value)) . '%'; break; } } } $where .= ' AND `ifPhysAddress` IS NOT NULL'; //Exclude empty MACs // Show MACs only for permitted ports $query_permitted = generate_query_permitted(array('port')); $query = 'FROM `ports` '; $query .= $where . $query_permitted; $query_count = 'SELECT COUNT(*) ' . $query; $query = 'SELECT * ' . $query; $query .= ' ORDER BY `ifPhysAddress`'; $query .= " LIMIT {$start},{$pagesize}"; // Query addresses $entries = dbFetchRows($query, $param); // Query address count if ($pagination) { $count = dbFetchCell($query_count, $param); } $list = array('device' => FALSE); if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') { $list['device'] = TRUE; } $string = '<table class="table table-bordered table-striped table-hover table-condensed">' . PHP_EOL; if (!$short) { $string .= ' <thead>' . PHP_EOL; $string .= ' <tr>' . PHP_EOL; if ($list['device']) { $string .= ' <th>Device</th>' . PHP_EOL; } $string .= ' <th>Interface</th>' . PHP_EOL; $string .= ' <th>MAC Address</th>' . PHP_EOL; $string .= ' <th>Description</th>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; $string .= ' </thead>' . PHP_EOL; } $string .= ' <tbody>' . PHP_EOL; foreach ($entries as $entry) { if (port_permitted($entry['port_id'])) { humanize_port($entry); $string .= ' <tr>' . PHP_EOL; if ($list['device']) { $dev = device_by_id_cache($entry['device_id']); $string .= ' <td class="entity" nowrap>' . generate_device_link($dev) . '</td>' . PHP_EOL; } if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) { $port_error = generate_port_link($entry, '<span class="label label-important">Errors</span>', 'port_errors'); } $string .= ' <td class="entity">' . generate_port_link($entry, short_ifname($entry['label'])) . ' ' . $port_error . '</td>' . PHP_EOL; $string .= ' <td width="160">' . formatMac($entry['ifPhysAddress']) . '</td>' . PHP_EOL; $string .= ' <td>' . $entry['ifAlias'] . '</td>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; } } $string .= ' </tbody>' . PHP_EOL; $string .= '</table>'; // Print pagination header if ($pagination) { $string = pagination($vars, $count) . $string . pagination($vars, $count); } // Print MAC addresses echo $string; }
if (is_numeric($vars['id'])) { $acc = dbFetchRow('SELECT * FROM `mac_accounting` AS M, `ports` AS I, `devices` AS D WHERE M.ma_id = ? AND I.port_id = M.port_id AND I.device_id = D.device_id', array($vars['id'])); if ($debug) { echo '<pre>'; print_r($acc); echo '</pre>'; } if (is_array($acc)) { if ($auth || port_permitted($acc['port_id'])) { d_echo($config['rrd_dir'] . '/' . $acc['hostname'] . '/' . safename('cip-' . $acc['ifIndex'] . '-' . $acc['mac'] . '.rrd')); if (is_file($config['rrd_dir'] . '/' . $acc['hostname'] . '/' . safename('cip-' . $acc['ifIndex'] . '-' . $acc['mac'] . '.rrd'))) { d_echo('exists'); $rrd_filename = $config['rrd_dir'] . '/' . $acc['hostname'] . '/' . safename('cip-' . $acc['ifIndex'] . '-' . $acc['mac'] . '.rrd'); $port = get_port_by_id($acc['port_id']); $device = device_by_id_cache($port['device_id']); $title = generate_device_link($device); $title .= ' :: Port ' . generate_port_link($port); $title .= ' :: ' . formatMac($acc['mac']); $auth = true; } else { graph_error('file not found'); } } else { graph_error('unauthenticated'); } } else { graph_error('entry not found'); } } else { graph_error('invalid id'); }
/** * Humanize port. * * Returns a the $port array with processed information: * label, humans_speed, human_type, html_class and human_mac * row_class, table_tab_colour * * @param array $ports * @return array $ports * */ function humanize_port(&$port) { global $config, $cache; // Exit if already humanized if ($port['humanized']) { return; } // Process port data to make it pretty for printing. EVOLUTION, BITCHES. // Lots of hacky shit will end up here with if (os); $device =& $GLOBALS['cache']['devices']['id'][$port['device_id']]; $os = $device['os']; $port['human_speed'] = humanspeed($port['ifSpeed']); $port['human_type'] = rewrite_iftype($port['ifType']); $port['html_class'] = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); $port['human_mac'] = formatMac($port['ifPhysAddress']); if (isset($config['os'][$os]['ifname'])) { $port['label'] = $port['ifName']; if ($port['ifName'] == "") { $port['label'] = $port['ifDescr']; } else { $port['label'] = $port['ifName']; } } elseif (isset($config['os'][$os]['ifalias'])) { $port['label'] = $port['ifAlias']; } else { $port['label'] = $port['ifDescr']; if (isset($config['os'][$os]['ifindex'])) { $port['label'] = $port['label'] . " " . $port['ifIndex']; } } // Set entity variables for use by code which uses entities $port['entity_name'] = $port['label']; $port['entity_shortname'] = $port['label']; $port['entity_descr'] = $port['ifAlias']; if ($device['os'] == "speedtouch") { list($port['label']) = explode("thomson", $port['label']); } $port['table_tab_colour'] = "#aaaaaa"; $port['row_class'] = ""; // Default $port['admin_status'] = $port['ifAdminStatus']; if ($port['ifAdminStatus'] == "down") { $port['admin_status'] = 'disabled'; $port['icon'] = 'port-disabled'; } elseif ($port['ifAdminStatus'] == "up") { $port['admin_status'] = 'enabled'; switch ($port['ifOperStatus']) { case 'down': $port['table_tab_colour'] = "#cc0000"; $port['row_class'] = "error"; $port['icon'] = 'port-down'; break; case 'monitoring': // This is monitoring ([e|r]span) ports $port['table_tab_colour'] = "#008C00"; $port['row_class'] = "success"; $port['icon'] = 'port-up'; break; case 'lowerLayerDown': $port['table_tab_colour'] = "#ff6600"; $port['row_class'] = "warning"; $port['icon'] = 'port-down'; break; case 'testing': $port['table_tab_colour'] = "#85004b"; $port['row_class'] = "info"; $port['icon'] = 'port-ignored'; break; case 'up': $port['table_tab_colour'] = "#194B7F"; $port['row_class'] = ""; $port['icon'] = 'port-up'; break; } } // If the device is down, colour the row/tab as 'warning' meaning that the entity is down because of something below it. if ($device['status'] == '0') { $port['table_tab_colour'] = "#ff6600"; $port['row_class'] = "warning"; $port['icon'] = 'port-ignored'; } $port['in_rate'] = $port['ifInOctets_rate'] * 8; $port['out_rate'] = $port['ifOutOctets_rate'] * 8; // Colour in bps based on speed if > 50, else by UI convention. $in_perc = round($port['in_rate'] / $port['ifSpeed'] * 100); if ($port['in_rate'] == 0) { $port['bps_in_style'] = ''; } elseif ($in_perc < '50') { $port['bps_in_style'] = 'color: #008C00;'; } else { $port['bps_in_style'] = 'color: ' . percent_colour($in_perc) . '; '; } // Colour out bps based on speed if > 50, else by UI convention. $out_perc = round($port['out_rate'] / $port['ifSpeed'] * 100); if ($port['out_rate'] == 0) { $port['bps_out_style'] = ''; } elseif ($out_perc < '50') { $port['bps_out_style'] = 'color: #394182;'; } else { $port['bps_out_style'] = 'color: ' . percent_colour($out_perc) . '; '; } // Colour in and out pps based on UI convention $port['pps_in_style'] = $port['ifInUcastPkts_rate'] == 0 ? '' : 'color: #740074;'; $port['pps_out_style'] = $port['ifOutUcastPkts_rate'] == 0 ? '' : 'color: #FF7400;'; $port['humanized'] = TRUE; /// Set this so we can check it later. }
} else { echo "</td><td width=150>"; if ($port['ifType'] && $port['ifType'] != "") { echo "<span class=box-desc>" . fixiftype($port['ifType']) . "</span>"; } else { echo "-"; } echo "<br />"; if ($ifHardType && $ifHardType != "") { echo "<span class=box-desc>" . $ifHardType . "</span>"; } else { echo "-"; } echo "</td><td width=150>"; if ($port['ifPhysAddress'] && $port['ifPhysAddress'] != "") { echo "<span class=box-desc>" . formatMac($port['ifPhysAddress']) . "</span>"; } else { echo "-"; } echo "<br />"; if ($port['ifMtu'] && $port['ifMtu'] != "") { echo "<span class=box-desc>MTU " . $port['ifMtu'] . "</span>"; } else { echo "-"; } } echo "</td>"; echo "<td width=375 valign=top class=interface-desc>"; if (strpos($port['label'], "oopback") === false && !$graph_type) { foreach (dbFetchRows("SELECT * FROM `links` AS L, `ports` AS I, `devices` AS D WHERE L.local_port_id = ? AND L.remote_port_id = I.port_id AND I.device_id = D.device_id", array($if_id)) as $link) { # echo("<img src='images/16/connect.png' align=absmiddle alt='Directly Connected' /> " . generate_port_link($link, makeshortif($link['label'])) . " on " . generate_device_link($link, shorthost($link['hostname'])) . "</a><br />");
} else { echo "</td><td style='width: 150px;'>"; if ($port['ifType'] && $port['ifType'] != "") { echo "<span class=small>" . $port['human_type'] . "</span>"; } else { echo "-"; } echo "<br />"; if ($ifHardType && $ifHardType != "") { echo "<span class=small>" . $ifHardType . "</span>"; } else { echo "-"; } echo "</td><td style='width: 150px;'>"; if ($port['ifPhysAddress'] && $port['ifPhysAddress'] != "") { echo "<span class=small>" . formatMac($port['ifPhysAddress']) . "</span>"; } else { echo "-"; } echo "<br />"; if ($port['ifMtu'] && $port['ifMtu'] != "") { echo "<span class=small>MTU " . $port['ifMtu'] . "</span>"; } else { echo "-"; } } echo "</td>"; echo "<td style='width: 375px' class=small>"; if (strpos($port['label'], "oopback") === false && !$graph_type) { foreach (dbFetchRows("SELECT * FROM `links` AS L, `ports` AS I, `devices` AS D WHERE L.local_port_id = ? AND L.remote_port_id = I.port_id AND I.device_id = D.device_id", array($port['port_id'])) as $link) { # echo("<img src='images/16/connect.png' align=absmiddle alt='Directly Connected' /> " . generate_port_link($link, short_ifname($link['label'])) . " on " . generate_device_link($link, short_hostname($link['hostname'])) . "</a><br />");
/** * Humanize port. * * Returns a the $port array with processed information: * label, humans_speed, human_type, html_class and human_mac * row_class, table_tab_colour * * @param array $ports * @return array $ports * */ function humanize_port(&$port) { global $config; // Process port data to make it pretty for printing. EVOLUTION, BITCHES. // Lots of hacky shit will end up here with if (os); $device = device_by_id_cache($port['device_id']); $os = $device['os']; $port['human_speed'] = humanspeed($port['ifSpeed']); $port['human_type'] = fixiftype($port['ifType']); $port['html_class'] = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); $port['human_mac'] = formatMac($port['ifPhysAddress']); if (isset($config['os'][$os]['ifname'])) { $port['label'] = $port['ifName']; if ($port['ifName'] == "") { $port['label'] = $port['ifDescr']; } else { $port['label'] = $port['ifName']; } } elseif (isset($config['os'][$os]['ifalias'])) { $port['label'] = $port['ifAlias']; } else { $port['label'] = $port['ifDescr']; if (isset($config['os'][$os]['ifindex'])) { $port['label'] = $port['label'] . " " . $port['ifIndex']; } } if ($device['os'] == "speedtouch") { list($port['label']) = explode("thomson", $port['label']); } if ($port['ifAdminStatus'] == "down") { $port['table_tab_colour'] = "#aaaaaa"; $port['row_class'] = ""; } elseif ($port['ifAdminStatus'] == "up" && $port['ifOperStatus'] == "down") { $port['table_tab_colour'] = "#cc0000"; $port['row_class'] = "error"; } elseif ($port['ifAdminStatus'] == "up" && $port['ifOperStatus'] == "lowerLayerDown") { $port['table_tab_colour'] = "#ff6600"; $port['row_class'] = "warning"; } elseif ($port['ifAdminStatus'] == "up" && $port['ifOperStatus'] == "up") { $port['table_tab_colour'] = "#194B7F"; $port['row_class'] = ""; } $port['humanized'] = TRUE; /// Set this so we can check it later. }
print_r($acc); echo "</pre>"; } if (is_array($acc)) { if ($auth || port_permitted($acc['port_id'])) { if ($debug) { echo $config['rrd_dir'] . "/" . $acc['hostname'] . "/" . safename("cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd"); } if (is_file($config['rrd_dir'] . "/" . $acc['hostname'] . "/" . safename("cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd"))) { if ($debug) { echo "exists"; } $rrd_filename = $config['rrd_dir'] . "/" . $acc['hostname'] . "/" . safename("cip-" . $acc['ifIndex'] . "-" . $acc['mac'] . ".rrd"); $port = get_port_by_id($acc['port_id']); $device = device_by_id_cache($port['device_id']); $title = generate_device_link($device); $title .= " :: Port " . generate_port_link($port); $title .= " :: " . formatMac($acc['mac']); $auth = TRUE; } else { graph_error("file not found"); } } else { graph_error("unauthenticated"); } } else { graph_error("entry not found"); } } else { graph_error("invalid id"); }