<?php /** * Observium * * This file is part of Observium. * * @package observium * @subpackage graphs * @copyright (C) 2006-2014 Adam Armstrong * */ if (!is_array($vars['id'])) { $vars['id'] = array($vars['id']); } $auth = TRUE; foreach ($vars['id'] as $ifid) { if (!$auth && !port_permitted($ifid)) { $auth = FALSE; } } $title = "Multi Port :: "; // EOF
$i = 0; while ($i < count($linkdone)) { $thislink = $pw_a['device_id'] . $pw_a['port_id']; if ($linkdone[$i] == $thislink) { $skip = "yes"; } $i++; } if ($peer_device_id) { $peer_device = get_device_by_id_cache($peer_device_id); } $pw_b = dbFetchRow("SELECT * from `devices` AS D, `ports` AS I, `pseudowires` AS P WHERE D.device_id = ? AND D.device_id = I.device_id\n AND P.cpwVcID = ? AND P.port_id = I.port_id", array($pw_a['peer_device_id'], $pw_a['cpwVcID'])); if (!port_permitted($pw_a['port_id'])) { $skip = "yes"; } if (!port_permitted($pw_b['port_id'])) { $skip = "yes"; } if ($skip) { unset($skip); } else { if ($bg == "ffffff") { $bg = "e5e5e5"; } else { $bg = "ffffff"; } echo "<tr style=\"background-color: #{$bg};\"><td rowspan=2 style='font-size:18px; padding:4px;'>" . $pw_a['cpwVcID'] . "</td><td>" . generate_port_link($pw_a) . "</td>\n <td rowspan=2> <img src='images/16/arrow_right.png'> </td>\n <td>" . generate_device_link($peer_device) . "</td><td>" . generate_port_link($pw_b) . "</td></tr>"; echo "<tr style=\"background-color: #{$bg};\"><td colspan=2>" . $pw_a['ifAlias'] . "</td><td>" . $pw_b['ifAlias'] . "</td></tr>"; if ($vars['view'] == "minigraphs") { echo "<tr style=\"background-color: #{$bg};\"><td></td><td colspan=2>"; if ($pw_a) {
function generate_ap_link($args, $text = NULL, $type = NULL, $escape = FALSE) { global $config; humanize_port($args); if (!$text) { $text = rewrite_ifname($args['port_label'], !$escape); } // Negative escape flag for exclude double escape if ($type) { $args['graph_type'] = $type; } if (!isset($args['graph_type'])) { $args['graph_type'] = 'port_bits'; } if (!isset($args['hostname'])) { $args = array_merge($args, device_by_id_cache($args['device_id'])); } $content = "<div class=entity-title>" . $args['text'] . " - " . rewrite_ifname($args['port_label'], !$escape) . "</div>"; if ($args['ifAlias']) { $content .= $args['ifAlias'] . "<br />"; } $content .= "<div style=\\'width: 850px\\'>"; $graph_array['type'] = $args['graph_type']; $graph_array['legend'] = "yes"; $graph_array['height'] = "100"; $graph_array['width'] = "340"; $graph_array['to'] = $config['time']['now']; $graph_array['from'] = $config['time']['day']; $graph_array['id'] = $args['accesspoint_id']; $content .= generate_graph_tag($graph_array); $graph_array['from'] = $config['time']['week']; $content .= generate_graph_tag($graph_array); $graph_array['from'] = $config['time']['month']; $content .= generate_graph_tag($graph_array); $graph_array['from'] = $config['time']['year']; $content .= generate_graph_tag($graph_array); $content .= "</div>"; $url = generate_ap_url($args); if (port_permitted($args['interface_id'], $args['device_id'])) { return overlib_link($url, $text, $content, $class, $escape); } else { return rewrite_ifname($text); } }
<?php /** * Observium * * This file is part of Observium. * * @package observium * @subpackage graphs * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ if (!is_array($vars['id'])) { $vars['id'] = array($vars['id']); } $auth = TRUE; foreach ($vars['id'] as $port_id) { if (!$auth && !port_permitted($port_id)) { $auth = FALSE; } } $title = "Multi Port :: " . count($vars['id']) . " ports :: "; // EOF
<?php if ($vars['tab'] == 'port' && is_numeric($vars['device']) && port_permitted($vars['port'])) { $check_device = get_device_id_by_port_id($vars['port']); $permit_ports = 1; } if (!is_numeric($vars['device'])) { $vars['device'] = device_by_name($vars['device']); } if (device_permitted($vars['device']) || $check_device == $vars['device']) { $selected['iface'] = 'selected'; $tab = str_replace('.', '', mres($vars['tab'])); if (!$tab) { $tab = 'overview'; } $select[$tab] = 'active'; $device = device_by_id_cache($vars['device']); $attribs = get_dev_attribs($device['device_id']); $entity_state = get_dev_entity_state($device['device_id']); // print_r($entity_state); $pagetitle[] = $device['hostname']; if ($config['os'][$device['os']]['group']) { $device['os_group'] = $config['os'][$device['os']]['group']; } echo '<div class="panel panel-default">'; echo '<table class="device-header-table" style="margin: 0px 7px 7px 7px;" cellspacing="0" class="devicetable" width="99%">'; require 'includes/device-header.inc.php'; echo '</table>'; echo '</div>'; if (device_permitted($device['device_id'])) { echo '<ul class="nav nav-tabs">';
$ifbreak = 1; } if ($config['int_core']) { echo ' <li><a href="iftype/type=core/"><img src="images/16/brick_link.png" border="0" align="absmiddle" /> Core</a></li>'; $ifbreak = 1; } } if ($ifbreak) { echo ' <li role="presentation" class="divider"></li>'; } if (isset($interface_alerts)) { echo ' <li><a href="ports/alerted=yes/"><img src="images/16/link_error.png" border="0" align="absmiddle" /> Alerts (' . $interface_alerts . ')</a></li>'; } $deleted_ports = 0; foreach (dbFetchRows("SELECT * FROM `ports` AS P, `devices` as D WHERE P.`deleted` = '1' AND D.device_id = P.device_id") as $interface) { if (port_permitted($interface['port_id'], $interface['device_id'])) { $deleted_ports++; } } ?> <li><a href="ports/state=down/"><img src="images/16/if-disconnect.png" border="0" align="absmiddle" /> Down</a></li> <li><a href="ports/state=admindown/"><img src="images/16/if-disable.png" border="0" align="absmiddle" /> Disabled</a></li> <?php if ($deleted_ports) { echo ' <li><a href="deleted-ports/"><img src="images/16/cross.png" border="0" align="absmiddle" /> Deleted (' . $deleted_ports . ')</a></li>'; } ?> </ul> </li>
case 'errors': $ports = array_sort($ports, 'ifErrors_rate', SORT_DESC); break; case 'speed': $ports = array_sort($ports, 'ifSpeed', SORT_DESC); break; case 'port': $ports = array_sort($ports, 'ifDescr', SORT_ASC); break; case 'media': $ports = array_sort($ports, 'ifType', SORT_ASC); break; case 'descr': $ports = array_sort($ports, 'ifAlias', SORT_ASC); break; case 'device': default: $ports = array_sort($ports, 'hostname', SORT_ASC); } //end switch $csv[] = array('Device', 'Port', 'Speed', 'Down', 'Up', 'Media', 'Description'); foreach ($ports as $port) { if (port_permitted($port['port_id'], $port['device_id'])) { $speed = humanspeed($port['ifSpeed']); $type = humanmedia($port['ifType']); $port['in_rate'] = formatRates($port['ifInOctets_rate'] * 8); $port['out_rate'] = formatRates($port['ifOutOctets_rate'] * 8); $port = ifLabel($port, $device); $csv[] = array($port['hostname'], fixIfName($port['label']), $speed, $port['in_rate'], $port['out_rate'], $type, $port['ifAlias']); } }
$query .= " AND F.`mac_address` LIKE ?"; $param = array("%" . str_replace(array(':', ' ', '-', '.', '0x'), '', mres($_POST['string'])) . "%"); if (is_numeric($_POST['device_id'])) { $query .= " AND P.device_id = ?"; $param[] = $_POST['device_id']; } $query .= " ORDER BY F.mac_address"; echo '<thead><tr> <th>MAC Address</th> <th>Device</th> <th>Interface</th> <th>VLAN ID</th> <th>VLAN Name</th> </tr></thead>'; foreach (dbFetchRows($query, $param) as $entry) { if (port_permitted($entry['port_id'])) { //why are they here for? //$speed = humanspeed($entry['ifSpeed']); //$type = humanmedia($entry['ifType']); 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>", 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) {
echo '<b>' . generate_port_link($link_if, makeshortif($link_if['label'])) . ' on ' . generate_device_link($link_if, shorthost($link_if['hostname'])); if ($int_links_v6[$int_link]) { echo " <b style='color: #a10000;'>v6</b>"; } if ($int_links_v4[$int_link]) { echo " <b style='color: #00a100'>v4</b>"; } $br = '<br />'; } //end foreach } //end if // unset($int_links, $int_links_v6, $int_links_v4, $int_links_phys, $br); } //end if if ($port_details && $config['enable_port_relationship'] === true && port_permitted($port['port_id'], $device['device_id'])) { foreach (dbFetchRows('SELECT * FROM `pseudowires` WHERE `port_id` = ?', array($port['port_id'])) as $pseudowire) { // `port_id`,`peer_device_id`,`peer_ldp_id`,`cpwVcID`,`cpwOid` $pw_peer_dev = dbFetchRow('SELECT * FROM `devices` WHERE `device_id` = ?', array($pseudowire['peer_device_id'])); $pw_peer_int = dbFetchRow('SELECT * FROM `ports` AS I, pseudowires AS P WHERE I.device_id = ? AND P.cpwVcID = ? AND P.port_id = I.port_id', array($pseudowire['peer_device_id'], $pseudowire['cpwVcID'])); $pw_peer_int = ifNameDescr($pw_peer_int); echo "{$br}<img src='images/16/arrow_switch.png' align=absmiddle><b> " . generate_port_link($pw_peer_int, makeshortif($pw_peer_int['label'])) . ' on ' . generate_device_link($pw_peer_dev, shorthost($pw_peer_dev['hostname'])) . '</b>'; $br = '<br />'; } foreach (dbFetchRows('SELECT * FROM `ports` WHERE `pagpGroupIfIndex` = ? and `device_id` = ?', array($port['ifIndex'], $device['device_id'])) as $member) { echo "{$br}<img src='images/16/brick_link.png' align=absmiddle> <strong>" . generate_port_link($member) . ' (PAgP)</strong>'; $br = '<br />'; } if ($port['pagpGroupIfIndex'] && $port['pagpGroupIfIndex'] != $port['ifIndex']) { $parent = dbFetchRow('SELECT * FROM `ports` WHERE `ifIndex` = ? and `device_id` = ?', array($port['pagpGroupIfIndex'], $device['device_id'])); echo "{$br}<img src='images/16/bricks.png' align=absmiddle> <strong>" . generate_port_link($parent) . ' (PAgP)</strong>';
/** * Display IPv4/IPv6 addresses. * * Display pages with IP addresses from device Interfaces. * * @param array $vars * @return none * */ function print_addresses($vars) { // With pagination? (display page numbers in header) $pagination = isset($vars['pagination']) && $vars['pagination']; pagination($vars, 0, TRUE); // Get default pagesize/pageno $pageno = $vars['pageno']; $pagesize = $vars['pagesize']; $start = $pagesize * $pageno - $pagesize; if (in_array($vars['search'], array('6', 'v6', 'ipv6')) || in_array($vars['view'], array('6', 'v6', 'ipv6'))) { $address_type = 'ipv6'; } else { $address_type = 'ipv4'; } $ip_array = array(); $param = array(); $where = ' WHERE 1 '; $param_netscaler = array(); $where_netscaler = " WHERE `vsvr_ip` != '0.0.0.0' AND `vsvr_ip` != '' "; foreach ($vars as $var => $value) { if ($value != '') { switch ($var) { case 'device': case 'device_id': $where .= generate_query_values($value, 'I.device_id'); $where_netscaler .= generate_query_values($value, 'N.device_id'); break; case 'interface': $where .= generate_query_values($value, 'I.ifDescr', 'LIKE%'); break; case 'network': list($net, $mask) = explode('/', $value); if (is_numeric(stripos($net, ':abcdef'))) { $address_type = 'ipv6'; } $where .= generate_query_values($value, 'N.ip_network', 'LIKE%'); break; case 'address': list($addr, $mask) = explode('/', $value); if (is_numeric(stripos($addr, ':abcdef'))) { $address_type = 'ipv6'; } switch ($address_type) { case 'ipv6': $ip_valid = Net_IPv6::checkIPv6($addr); break; case 'ipv4': $ip_valid = Net_IPv4::validateIP($addr); break; } if ($ip_valid) { // If address valid -> seek occurrence in network if (!$mask) { $mask = $address_type === 'ipv4' ? '32' : '128'; } $where_netscaler .= generate_query_values($addr, 'N.vsvr_ip'); } else { // If address not valid -> seek LIKE $where .= generate_query_values($addr, 'A.ip_address', '%LIKE%'); $where_netscaler .= generate_query_values($addr, 'N.vsvr_ip', '%LIKE%'); } break; } } } $query_device_permitted = generate_query_permitted(array('device'), array('device_table' => 'D')); $query_port_permitted = generate_query_permitted(array('port'), array('port_table' => 'I')); // Also search netscaler Vserver IPs $query_netscaler = 'FROM `netscaler_vservers` AS N '; $query_netscaler .= 'LEFT JOIN `devices` AS D ON N.`device_id` = D.`device_id` '; $query_netscaler .= $where_netscaler . $query_device_permitted; //$query_netscaler_count = 'SELECT COUNT(`vsvr_id`) ' . $query_netscaler; $query_netscaler = 'SELECT * ' . $query_netscaler; $query_netscaler .= ' ORDER BY N.`vsvr_ip`'; // Override by address type if ($address_type == 'ipv6') { $query_netscaler = str_replace(array('vsvr_ip', '0.0.0.0'), array('vsvr_ipv6', '0:0:0:0:0:0:0:0'), $query_netscaler); //$query_netscaler_count = str_replace(array('vsvr_ip', '0.0.0.0'), array('vsvr_ipv6', '0:0:0:0:0:0:0:0'), $query_netscaler_count); } $entries = dbFetchRows($query_netscaler, $param_netscaler); // Rewrite netscaler addresses foreach ($entries as $entry) { $ip_address = $address_type == 'ipv4' ? $entry['vsvr_ip'] : $entry['vsvr_' . $address_type]; $ip_network = $address_type == 'ipv4' ? $entry['vsvr_ip'] . '/32' : $entry['vsvr_' . $address_type] . '/128'; $ip_array[] = array('type' => 'netscaler_vsvr', 'device_id' => $entry['device_id'], 'hostname' => $entry['hostname'], 'vsvr_id' => $entry['vsvr_id'], 'vsvr_label' => $entry['vsvr_label'], 'ifAlias' => 'Netscaler: ' . $entry['vsvr_type'] . '/' . $entry['vsvr_entitytype'], $address_type . '_address' => $ip_address, $address_type . '_network' => $ip_network); } //print_message($query_netscaler_count); $query = 'FROM `ip_addresses` AS A '; $query .= 'LEFT JOIN `ports` AS I ON I.`port_id` = A.`port_id` '; $query .= 'LEFT JOIN `devices` AS D ON I.`device_id` = D.`device_id` '; $query .= 'LEFT JOIN `ip_networks` AS N ON N.`ip_network_id` = A.`ip_network_id` '; $query .= $where . $query_port_permitted; //$query_count = 'SELECT COUNT(`ip_address_id`) ' . $query; $query = 'SELECT * ' . $query; $query .= ' ORDER BY A.`ip_address`'; if ($ip_valid) { $pagination = FALSE; } // Override by address type $query = str_replace(array('ip_address', 'ip_network'), array($address_type . '_address', $address_type . '_network'), $query); //$query_count = str_replace(array('ip_address', 'ip_network'), array($address_type.'_address', $address_type.'_network'), $query_count); // Query addresses $entries = dbFetchRows($query, $param); $ip_array = array_merge($ip_array, $entries); $ip_array = array_sort($ip_array, $address_type . '_address'); // Query address count //if ($pagination) { $count = dbFetchCell($query_count, $param); } if ($pagination) { $count = count($ip_array); $ip_array = array_slice($ip_array, $start, $pagesize); } $list = array('device' => FALSE); if (!isset($vars['device']) || empty($vars['device']) || $vars['page'] == 'search') { $list['device'] = TRUE; } $string = generate_box_open($vars['header']); $string .= '<table class="' . OBS_CLASS_TABLE_STRIPED . '">' . 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>Address</th>' . PHP_EOL; $string .= ' <th>Description</th>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; $string .= ' </thead>' . PHP_EOL; } $string .= ' <tbody>' . PHP_EOL; foreach ($ip_array as $entry) { $address_show = TRUE; if ($ip_valid) { // If address not in specified network, don't show entry. if ($address_type === 'ipv4') { $address_show = Net_IPv4::ipInNetwork($entry[$address_type . '_address'], $addr . '/' . $mask); } else { $address_show = Net_IPv6::isInNetmask($entry[$address_type . '_address'], $addr, $mask); } } if ($address_show) { list($prefix, $length) = explode('/', $entry[$address_type . '_network']); if (port_permitted($entry['port_id']) || $entry['type'] == 'netscaler_vsvr') { if ($entry['type'] == 'netscaler_vsvr') { $entity_link = generate_entity_link($entry['type'], $entry); } else { humanize_port($entry); if ($entry['ifInErrors_delta'] > 0 || $entry['ifOutErrors_delta'] > 0) { $port_error = generate_port_link($entry, '<span class="label label-important">Errors</span>', 'port_errors'); } $entity_link = generate_port_link($entry, $entry['port_label_short']) . ' ' . $port_error; } $device_link = generate_device_link($entry); $string .= ' <tr>' . PHP_EOL; if ($list['device']) { $string .= ' <td class="entity" style="white-space: nowrap">' . $device_link . '</td>' . PHP_EOL; } $string .= ' <td class="entity">' . $entity_link . '</td>' . PHP_EOL; if ($address_type === 'ipv6') { $entry[$address_type . '_address'] = Net_IPv6::compress($entry[$address_type . '_address']); } $string .= ' <td>' . generate_popup_link('ip', $entry[$address_type . '_address'] . '/' . $length) . '</td>' . PHP_EOL; $string .= ' <td>' . $entry['ifAlias'] . '</td>' . PHP_EOL; $string .= ' </tr>' . PHP_EOL; } } } $string .= ' </tbody>' . PHP_EOL; $string .= '</table>'; $string .= generate_box_close(); // Print pagination header if ($pagination) { $string = pagination($vars, $count) . $string . pagination($vars, $count); } // Print addresses echo $string; }
$cache['locations']['entries'][$device['location_country']]['entries'][$device['location_state']]['entries'][$device['location_county']]['entries'][$device['location_city']]['level'] = 'location_city'; $cache['locations']['entries'][$device['location_country']]['entries'][$device['location_state']]['entries'][$device['location_county']]['entries'][$device['location_city']]['entries'][$device['location']]['count']++; $cache['locations']['entries'][$device['location_country']]['entries'][$device['location_state']]['entries'][$device['location_county']]['entries'][$device['location_city']]['entries'][$device['location']]['level'] = 'location'; } } #echo("<pre>"); #print_r($cache['locations']); #echo("</pre>"); // Ports foreach (dbFetchRows("SELECT device_id, ports.port_id, ifAdminStatus, ifOperStatus, `deleted`, `ignore`, `ifOutErrors_delta`, `ifInErrors_delta` FROM `ports` LEFT JOIN `ports-state` ON `ports`.`port_id` = `ports-state`.`port_id`") as $port) { if (!$config['web_show_disabled']) { if ($cache['devices']['id'][$port['device_id']]['disabled']) { continue; } } if (port_permitted($port)) { $ports['count']++; if ($port['ifAdminStatus'] == "down") { $ports['disabled']++; } else { if ($port['ifOperStatus'] == "up") { $ports['up']++; } if ($port['ifOperStatus'] == "down" || $port['ifOperStatus'] == "lowerLayerDown") { $ports['down']++; if (!$port['ignore']) { $ports['alerts']++; } } } if ($port['ignore']) {
print_error('<h4>No device specified</h4> A valid device was not specified in the URL. Please retype and try again.'); return; } // Allow people to see this page if they have permission to see one of the ports, but don't show them tabs. $permit_tabs = array(); if ($vars['tab'] == "port" && is_numeric($vars['device']) && (isset($vars['port']) || isset($vars['ifdescr']))) { // If we've been given a 'ifdescr' variable, try to work out the port_id from this if (!is_numeric($vars['port']) && !empty($vars['ifdescr'])) { $ifdescr = base64_decode($vars['ifdescr']); if (!$ifdescr) { $ifdescr = $vars['ifdescr']; } $vars['port'] = get_port_id_by_ifDescr($vars['device'], $ifdescr); } if (port_permitted($vars['port']) && $vars['device'] == get_device_id_by_port_id($vars['port'])) { $permit_tabs['ports'] = TRUE; } } if ($vars['tab'] == "health" && is_numeric($vars['id']) && isset($vars['id'])) { if (is_entity_permitted($vars['id'], 'sensor')) { $permit_tabs['health'] = TRUE; } } // print_vars($permit_tabs); // If there is no valid device specified in the URL, generate an error. if (!isset($cache['devices']['id'][$vars['device']]) && !count($permit_tabs)) { print_error('<h4>No valid device specified</h4> A valid device was not specified in the URL. Please retype and try again.'); return; }
/** * Returns an HTML port page link with mouse-over popup to permitted users or a text label to non-permitted users * * @param array $port array * @param string $text text to be used as port label * @param string $type graph type to be used in graphs (bits, nupkts, etc) * * @return string HTML link or text string */ function generate_port_link($port, $text = NULL, $type = NULL, $escape = FALSE, $short = FALSE) { humanize_port($port); //if (!isset($port['html_class'])) { $port['html_class'] = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); } //if (!isset($text)) { $text = rewrite_ifname($port['port_label'], !$escape); } // Negative escape flag for exclude double escape // Fixme -- does this function even need alternative $text? I think not. It's a hangover from before label. if (!isset($text) && !$short) { $text = $port['port_label']; } elseif (!isset($text) && $short) { $text = $port['port_label_short']; } if (port_permitted($port['port_id'], $port['device_id'])) { $url = generate_port_url($port); if ($escape) { $text = escape_html($text); } return '<a href="' . $url . '" class="entity-popup ' . $port['html_class'] . '" data-eid="' . $port['port_id'] . '" data-etype="port">' . $text . '</a>'; } else { return rewrite_ifname($text); } }
function port_permitted_array(&$ports) { // Strip out the ports the user isn't allowed to see, if they don't have global rights if ($_SESSION['userlevel'] < '7') { foreach ($ports as $key => $port) { if (!port_permitted($port['port_id'], $port['device_id'])) { unset($ports[$key]); } } } }
<?php if ($_GET['id'] && is_numeric($_GET['id'])) { $atm_vp_id = $_GET['id']; } $vp = dbFetchRow('SELECT * FROM `juniAtmVp` as J, `ports` AS I, `devices` AS D WHERE J.juniAtmVp_id = ? AND I.port_id = J.port_id AND I.device_id = D.device_id', array($atm_vp_id)); if ($auth || port_permitted($vp['port_id'])) { $port = $vp; $device = device_by_id_cache($port['device_id']); $title = generate_device_link($device); $title .= ' :: Port ' . generate_port_link($port); $title .= ' :: VP ' . $vp['vp_id']; $auth = true; $rrd_filename = rrd_name($vp['hostname'], array('vp', $vp['ifIndex'], $vp['vp_id'])); }
* @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited * */ $config['install_dir'] = "../.."; require_once $config['install_dir'] . "/includes/sql-config.inc.php"; include $config['html_dir'] . "/includes/functions.inc.php"; include $config['html_dir'] . "/includes/authenticate.inc.php"; if (!$_SESSION['authenticated']) { print_error('Session expired, please log in again!'); exit; } $vars = get_vars(); $vars['page'] = "popup"; switch ($vars['entity_type']) { case "port": if (is_numeric($vars['entity_id']) && port_permitted($vars['entity_id'])) { $port = get_port_by_id($vars['entity_id']); echo generate_port_popup($port); } else { print_warning("You are not permitted to view this port."); } exit; break; case "device": if (is_numeric($vars['entity_id']) && device_permitted($vars['entity_id'])) { $device = device_by_id_cache($vars['entity_id']); echo generate_device_popup($device, $vars, $start, $end); } else { print_warning("You are not permitted to view this device."); } exit;
* @subpackage graphing * @author T. Lechat <*****@*****.**>, Manuel Kasper <*****@*****.**>, Jonathan Watt <*****@*****.**> * @copyright 2004-2006 T. Lechat <*****@*****.**>, Manuel Kasper <*****@*****.**>, Jonathan Watt <*****@*****.**> * @license BSD * */ include_once "../includes/defaults.inc.php"; include_once "../config.php"; include_once "../includes/definitions.inc.php"; include_once "../includes/common.inc.php"; include_once "../includes/dbFacile.php"; include_once "../includes/rewrites.inc.php"; include_once "includes/functions.inc.php"; include_once "includes/authenticate.inc.php"; include_once "../includes/snmp.inc.php"; if (is_numeric($_GET['id']) && ($config['allow_unauth_graphs'] || port_permitted($_GET['id']))) { $port = get_port_by_id($_GET['id']); $device = device_by_id_cache($port['device_id']); $title = generate_device_link($device); $title .= " :: Port " . generate_port_link($port); $auth = TRUE; } else { echo "Unauthenticad"; die; } header("Content-type: image/svg+xml"); /********** HTTP GET Based Conf ***********/ $ifnum = @$port['ifIndex']; // BSD / SNMP interface name / number $ifname = htmlentities(@$port['ifDescr']); //Interface name that will be showed on top right of graph
<?php if (is_numeric($vars['id']) && ($auth || port_permitted($vars['id']))) { $port = get_port_by_id($vars['id']); $device = device_by_id_cache($port['device_id']); $title = generate_device_link($device); $title .= " :: Port " . generate_port_link($port); $graph_title = shorthost($device['hostname']) . "::" . strtolower(makeshortif($port['ifDescr'])); $auth = TRUE; $rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/port-" . safename($port['ifIndex'] . ".rrd"); }
function generate_ap_link($args, $text = null, $type = null) { global $config; $args = ifNameDescr($args); if (!$text) { $text = fixIfName($args['label']); } if ($type) { $args['graph_type'] = $type; } if (!isset($args['graph_type'])) { $args['graph_type'] = 'port_bits'; } if (!isset($args['hostname'])) { $args = array_merge($args, device_by_id_cache($args['device_id'])); } $content = '<div class=list-large>' . $args['text'] . ' - ' . fixifName($args['label']) . '</div>'; if ($args['ifAlias']) { $content .= $args['ifAlias'] . '<br />'; } $content .= "<div style=\\'width: 850px\\'>"; $graph_array = array(); $graph_array['type'] = $args['graph_type']; $graph_array['legend'] = 'yes'; $graph_array['height'] = '100'; $graph_array['width'] = '340'; $graph_array['to'] = $config['time']['now']; $graph_array['from'] = $config['time']['day']; $graph_array['id'] = $args['accesspoint_id']; $content .= generate_graph_tag($graph_array); $graph_array['from'] = $config['time']['week']; $content .= generate_graph_tag($graph_array); $graph_array['from'] = $config['time']['month']; $content .= generate_graph_tag($graph_array); $graph_array['from'] = $config['time']['year']; $content .= generate_graph_tag($graph_array); $content .= '</div>'; $url = generate_ap_url($args); if (port_permitted($args['interface_id'], $args['device_id'])) { return overlib_link($url, $text, $content, null); } else { return fixifName($text); } }
/** * 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']; pagination($vars, 0, TRUE); // Get default pagesize/pageno $pageno = $vars['pageno']; $pagesize = $vars['pagesize']; $start = $pagesize * $pageno - $pagesize; $param = array(); $where = ' WHERE 1 '; foreach ($vars as $var => $value) { if ($value != '') { switch ($var) { case 'device': case 'device_id': $where .= generate_query_values($value, 'device_id'); break; case 'interface': $where .= ' AND `ifDescr` LIKE ?'; $param[] = $value; break; case 'address': $where .= ' AND `ifPhysAddress` LIKE ?'; # FIXME hm? mres in a dbFacile parameter? $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" style="white-space: 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 style="width: 160px;">' . $entry['human_mac'] . '</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; }
$i++; } if (!$already) { $nodes[] = $device['device_id']; } } $sql = "SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'"; foreach (dbFetchRows($sql) as $device) { if (device_permitted($device['device_id'])) { echo "<div style='text-align: center; margin: 2px; border: solid 2px #d0D0D0; float: left; margin-right: 2px; padding: 3px; width: 118px; height: 85px; background: #ffbbbb;'>\n <strong>" . generate_device_link($device, shorthost($device['hostname'])) . "</strong><br />\n <span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>Device Down</span><br />\n <span class=body-date-1>" . truncate($device['location'], 35) . "</span>\n </div>"; } } if ($config['warn']['ifdown']) { $sql = "SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'"; foreach (dbFetchRows($sql) as $interface) { if (port_permitted($interface['port_id'])) { echo "<div style='text-align: center; margin: 2px; border: solid 2px #D0D0D0; float: left; margin-right: 2px; padding: 3px; width: 118px; height: 85px; background: #ffddaa;'>\n <strong>" . generate_device_link($interface, shorthost($interface['hostname'])) . "</strong><br />\n <span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>Port Down</span><br />\n <strong>" . generate_port_link($interface, makeshortif($interface['ifDescr'])) . "</strong><br />\n <span class=body-date-1>" . truncate($interface['ifAlias'], 15) . "</span>\n </div>"; } } } $sql = "SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'"; foreach (dbFetchRows($sql) as $service) { if (device_permitted($service['device_id'])) { echo "<div style='text-align: center; margin: 2px; border: solid 2px #D0D0D0; float: left; margin-right: 2px; padding: 3px; width: 118px; height: 85px; background: #ffddaa;'>\n <strong>" . generate_device_link($service, shorthost($service['hostname'])) . "</strong><br />\n <span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>Service Down</span><br />\n <strong>" . $service['service_type'] . "</strong><br />\n <span class=body-date-1>" . truncate($interface['ifAlias'], 15) . "</span>\n </center></div>"; } } $sql = "SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus = 'start' AND bgpPeerState != 'established' AND B.device_id = D.device_id"; foreach (dbFetchRows($sql) as $peer) { if (device_permitted($peer['device_id'])) { echo "<div style='text-align: center; margin: 2px; border: solid 2px #D0D0D0; float: left; margin-right: 2px; padding: 3px; width: 118px; height: 85px; background: #ffddaa;'>\n <strong>" . generate_device_link($peer, shorthost($peer['hostname'])) . "</strong><br />\n <span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>BGP Down</span><br />\n <strong>" . $peer['bgpPeerIdentifier'] . "</strong><br />\n <span class=body-date-1>AS" . $peer['bgpPeerRemoteAs'] . " " . truncate($peer['astext'], 10) . "</span>\n </div>"; }
function get_status_array($status) { // Mike: I know that there are duplicated variables, but later will remove global global $config; global $cache; $param = array(); if ($_SESSION['userlevel'] >= 5) { $query_perms = ''; $query_user = ''; } else { $query_perms = 'LEFT JOIN devices_perms AS P ON D.device_id = P.device_id '; $query_user = '******'; $param[] = $_SESSION['user_id']; } // Don't show ignored and disabled devices $query_device = ' AND D.ignore = 0 '; if (!$config['web_show_disabled']) { $query_device .= 'AND D.disabled = 0 '; } // Show Device Status if ($status['devices']) { $query = 'SELECT * FROM `devices` AS D '; $query .= $query_perms; $query .= 'WHERE D.status = 0' . $query_device . $query_user; $query .= 'ORDER BY D.hostname ASC'; $entries = dbFetchRows($query, $param); foreach ($entries as $device) { $boxes[] = array('sev' => 100, 'class' => 'Device', 'event' => 'Down', 'device_link' => generate_device_link($device, shorthost($device['hostname'])), 'time' => deviceUptime($device, 'short-3')); } } // Uptime if ($status['uptime']) { if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0) { $query = 'SELECT * FROM `devices` AS D '; $query .= $query_perms; $query .= 'WHERE D.status = 1 AND D.uptime > 0 AND D.uptime < ' . $config['uptime_warning'] . $query_device . $query_user; $query .= 'ORDER BY D.hostname ASC'; $entries = dbFetchRows($query, $param); foreach ($entries as $device) { $boxes[] = array('sev' => 10, 'class' => 'Device', 'event' => 'Rebooted', 'device_link' => generate_device_link($device, shorthost($device['hostname'])), 'time' => deviceUptime($device, 'short-3'), 'location' => $device['location']); } } } // Ports Down if ($status['ports'] || $status['links']) { // warning about deprecated option: $config['warn']['ifdown'] if (isset($config['warn']['ifdown']) && !$config['warn']['ifdown']) { echo ' <div class="alert"> <button type="button" class="close" data-dismiss="alert">×</button> <p><i class="oicon-bell"></i> <strong>Config option obsolete</strong></p> <p>Please note that config option <strong>$config[\'warn\'][\'ifdown\']</strong> is now obsolete.<br />Use options: <strong>$config[\'frontpage\'][\'device_status\'][\'ports\']</strong> and <strong>$config[\'frontpage\'][\'device_status\'][\'errors\']</strong></p> <p>To remove this message, delete <strong>$config[\'warn\'][\'ifdown\']</strong> from configuration file.</p> </div>'; } $query = 'SELECT * FROM `ports` AS I '; if ($status['links'] && !$status['ports']) { $query .= 'INNER JOIN links as L ON I.port_id = L.local_port_id '; } $query .= 'LEFT JOIN `devices` AS D ON I.device_id = D.device_id '; $query .= $query_perms; $query .= "WHERE I.ifOperStatus = 'down' AND I.ifAdminStatus = 'up' AND I.ignore = 0 AND I.deleted = 0 "; if ($status['links'] && !$status['ports']) { $query .= ' AND L.active = 1 '; } $query .= $query_device . $query_user; $query .= ' AND I.ifLastChange >= DATE_SUB(NOW(), INTERVAL 24 HOUR) '; $query .= 'ORDER BY I.ifLastChange DESC, D.hostname ASC, I.ifDescr * 1 ASC '; $entries = dbFetchRows($query, $param); //$count = count($entries); $i = 1; foreach ($entries as $port) { if ($i > 200) { // Limit to 200 ports on overview page $string .= ' <tr><td></td><td><span class="badge badge-info">Port</span></td>'; $string .= '<td><span class="label label-important">Port Down</span></td>'; $string .= '<td colspan=3>Too many ports down. See <strong><a href="' . generate_url(array('page' => 'ports'), array('state' => 'down')) . '">All DOWN ports</a></strong>.</td></tr>' . PHP_EOL; break; } humanize_port($port); $boxes[] = array('sev' => 50, 'class' => 'Port', 'event' => 'Down', 'device_link' => generate_device_link($port, shorthost($port['hostname'])), 'entity_link' => generate_port_link($port, truncate(makeshortif($port['label']), 13, '')), 'time' => formatUptime($config['time']['now'] - strtotime($port['ifLastChange'])), 'location' => $device['location']); // We don't do anything with this here at the moment. There is no comment on it, what is it for? // if ($status['links'] && !$status['ports']) { $string .= ' ('.strtoupper($port['protocol']).': ' .$port['remote_hostname'].' / ' .$port['remote_port'] .')'; } } } // Ports Errors (only deltas) if ($status['errors']) { foreach ($cache['ports_errored'] as $port_id) { $port = get_port_by_id($port_id); if (port_permitted($port)) { $device = device_by_id_cache($port['device_id']); humanize_port($port); if ($port['ifInErrors_delta']) { $port['string'] .= 'Rx: ' . $port['ifInErrors_delta']; } if ($port['ifInErrors_delta'] && $port['ifOutErrors_delta']) { $port['string'] .= ', '; } if ($port['ifOutErrors_delta']) { $port['string'] .= 'Tx: ' . $port['ifOutErrors_delta']; } $boxes[] = array('sev' => 75, 'class' => 'Port', 'event' => 'Errors', 'device_link' => generate_device_link($device, shorthost($device['hostname'])), 'entity_link' => generate_port_link($port, truncate(makeshortif($port['label']), 13, '')), 'time' => $port['string'], 'location' => $device['location']); } } } // Services if ($status['services']) { $query = 'SELECT * FROM `services` AS S '; $query .= 'LEFT JOIN `devices` AS D ON S.device_id = D.device_id '; $query .= $query_perms; $query .= "WHERE S.service_status = 'down' AND S.service_ignore = 0" . $query_device . $query_user; $query .= 'ORDER BY D.hostname ASC'; $entries = dbFetchRows($query, $param); foreach ($entries as $service) { $boxes[] = array('sev' => 50, 'class' => 'Service', 'event' => 'Down', 'device_link' => generate_device_link($service, shorthost($service['hostname'])), 'entity_link' => $service['service_type'], 'time' => formatUptime($config['time']['now'] - strtotime($service['service_changed']), 'short'), 'location' => $device['location']); } } // BGP if ($status['bgp']) { if (isset($config['enable_bgp']) && $config['enable_bgp']) { // Description for BGP states $bgpstates = 'IDLE - Router is searching routing table to see whether a route exists to reach the neighbor. 
'; $bgpstates .= 'CONNECT - Router found a route to the neighbor and has completed the three-way TCP handshake. 
'; $bgpstates .= 'OPEN SENT - Open message sent, with parameters for the BGP session. 
'; $bgpstates .= 'OPEN CONFIRM - Router received agreement on the parameters for establishing session. 
'; $bgpstates .= 'ACTIVE - Router did not receive agreement on parameters of establishment. 
'; //$bgpstates .= 'ESTABLISHED - Peering is established; routing begins.'; $query = 'SELECT * FROM `devices` AS D '; $query .= 'LEFT JOIN bgpPeers AS B ON B.device_id = D.device_id '; $query .= $query_perms; $query .= "WHERE (bgpPeerAdminStatus = 'start' OR bgpPeerAdminStatus = 'running') AND bgpPeerState != 'established' " . $query_device . $query_user; $query .= 'ORDER BY D.hostname ASC'; $entries = dbFetchRows($query, $param); foreach ($entries as $peer) { $peer_ip = strstr($peer['bgpPeerRemoteAddr'], ':') ? Net_IPv6::compress($peer['bgpPeerRemoteAddr']) : $peer['bgpPeerRemoteAddr']; if (strstr($peer['bgpPeerRemoteAddr'], ':')) { $peer['wide'] = TRUE; } $boxes[] = array('sev' => 75, 'class' => 'BGP Peer', 'event' => 'Down', 'device_link' => generate_device_link($peer, shorthost($peer['hostname'])), 'entity_link' => $peer_ip, 'wide' => $peer['wide'], 'time' => formatUptime($peer['bgpPeerFsmEstablishedTime'], 'shorter'), 'location' => $device['location']); } } } $string .= ' </tbody>' . PHP_EOL; $string .= '</table>'; // Final print all statuses return $boxes; }