function generate_port_popup($port, $text = NULL, $type = NULL) { global $config; if (!isset($port['os'])) { $port = array_merge($port, device_by_id_cache($port['device_id'])); } humanize_port($port); if (!$text) { $text = rewrite_ifname($port['label']); } if ($type) { $port['graph_type'] = $type; } if (!isset($port['graph_type'])) { $port['graph_type'] = 'port_bits'; } $class = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); if (!isset($port['os'])) { $port = array_merge($port, device_by_id_cache($port['device_id'])); } $content = generate_device_popup_header($port); $content .= generate_port_popup_header($port); $content .= '<div style="width: 700px">'; $graph_array['type'] = $port['graph_type']; $graph_array['legend'] = "yes"; $graph_array['height'] = "100"; $graph_array['width'] = "275"; $graph_array['to'] = $config['time']['now']; $graph_array['from'] = $config['time']['day']; $graph_array['id'] = $port['port_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>"; return $content; }
function generate_port_link($port, $text = null, $type = null, $overlib = 1, $single_graph = 0) { global $config; $graph_array = array(); $port = ifNameDescr($port); if (!$text) { $text = fixIfName($port['label']); } if ($type) { $port['graph_type'] = $type; } if (!isset($port['graph_type'])) { $port['graph_type'] = 'port_bits'; } $class = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); if (!isset($port['hostname'])) { $port = array_merge($port, device_by_id_cache($port['device_id'])); } $content = '<div class=list-large>' . $port['hostname'] . ' - ' . fixifName($port['label']) . '</div>'; if ($port['ifAlias']) { $content .= escape_quotes($port['ifAlias']) . '<br />'; } $content .= "<div style=\\'width: 850px\\'>"; $graph_array['type'] = $port['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'] = $port['port_id']; $content .= generate_graph_tag($graph_array); if ($single_graph == 0) { $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_port_url($port); if ($overlib == 0) { return $content; } else { if (port_permitted($port['port_id'], $port['device_id'])) { return overlib_link($url, $text, $content, $class); } else { return fixifName($text); } } }
/** * 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. }
<th style="width: 250px;"><span style="font-weight: bold;" class="interface">Description</span></th> <th style="width: 150px;">Device</th> <th style="width: 100px;">Interface</th> <th style="width: 100px;">Speed</th> <th style="width: 100px;">Circuit</th> <th>Notes</th> </tr> </thead> <?php foreach ($ports as $port) { $done = "yes"; unset($class); $port['ifAlias'] = str_ireplace($type . ": ", "", $port['ifAlias']); $port['ifAlias'] = str_ireplace("[PNI]", "Private", $port['ifAlias']); $ifclass = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); if ($bg == "#ffffff") { $bg = "#e5e5e5"; } else { $bg = "#ffffff"; } echo "<tr class='iftype'>\n <td><span class=entity-title>" . generate_port_link($port, $port['port_descr_descr']) . "</span>"; # <span class=small style='float: left;'>".generate_device_link($port)." ".generate_port_link($port)." </span>"); if (dbFetchCell("SELECT count(*) FROM mac_accounting WHERE port_id = ?", array($port['port_id']))) { echo "<span style='float: right;'><a href='device/device=" . $port['device_id'] . "/tab=port/port=" . $port['port_id'] . "/view=macaccounting/'><img src='images/16/chart_curve.png' align='absmiddle'> MAC Accounting</a></span>"; } echo "</td>"; echo ' <td style="width: 150px;" class="strong">' . generate_device_link($port) . '</td> <td style="width: 150px;" class="strong">' . generate_port_link($port, short_ifname($port['ifDescr'])) . '</td> <td style="width: 75px;">' . $port['port_descr_speed'] . '</td> <td style="width: 150px;">' . $port['port_descr_circuit'] . '</td>
/** * @dataProvider providerIfclass */ public function testIfclass($ifOperStatus, $ifAdminStatus, $result) { $this->assertSame($result, ifclass($ifOperStatus, $ifAdminStatus)); }
function generateiflink($interface, $text = 0, $type = NULL) { global $twoday; global $now; global $config; global $day; global $month; $interface = ifNameDescr($interface); if (!$text) { $text = fixIfName($interface['label']); } if (isset($type)) { $interface['graph_type'] = $type; } else { $interface['graph_type'] = 'port_bits'; } if (!isset($interface['hostname'])) { $interface = array_merge($interface, device_by_id_cache($interface['device_id'])); } $class = ifclass($interface['ifOperStatus'], $interface['ifAdminStatus']); $graph_url = $config['base_url'] . "/graph.php?port=" . $interface['interface_id'] . "&from={$day}&to={$now}&width=400&height=100&type=" . $interface['graph_type']; $graph_url_month = $config['base_url'] . "/graph.php?port=" . $interface['interface_id'] . "&from={$month}&to={$now}&width=400&height=100&type=" . $interface['graph_type']; $device_id = getifhost($interface['interface_id']); $url = $config['base_url'] . "/device/{$device_id}/interface/" . $interface['interface_id'] . "/"; $contents = "<div class=list-large>" . $interface['hostname'] . " - " . fixifName($interface['label']) . "</div>"; if ($interface['ifAlias']) { $contents .= htmlentities($interface['ifAlias'] . "<br />"); } $contents .= "<img src=\\'{$graph_url}\\'><br /><img src=\\'{$graph_url_month}\\'>"; $link = overlib_link($url, $text, $contents, $class); return $link; }
function generate_port_link($port, $text = NULL, $type = NULL) { global $config; if (isset($port['humanized']) == FALSE) { humanize_port($port); } if (!$text) { $text = fixIfName($port['label']); } if ($type) { $port['graph_type'] = $type; } if (!isset($port['graph_type'])) { $port['graph_type'] = 'port_bits'; } $class = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); if (!isset($port['os'])) { $port = array_merge($port, device_by_id_cache($port['device_id'])); } $content = generate_device_link_header($port); $content .= generate_port_link_header($port); $content .= '<div style="width: 700px">'; $graph_array['type'] = $port['graph_type']; $graph_array['legend'] = "yes"; $graph_array['height'] = "100"; $graph_array['width'] = "275"; $graph_array['to'] = $config['time']['now']; $graph_array['from'] = $config['time']['day']; $graph_array['id'] = $port['port_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_port_url($port); if (port_permitted($port['port_id'], $port['device_id'])) { return overlib_link($url, $text, $content, $class); } else { return fixifName($text); } }
} $types = implode(' + ', $types_array); echo "<tr bgcolor='{$bg}'>\n <td><span class=list-large>Total Graph for ports of type : " . $types . "</span></td></tr>"; echo "<tr bgcolor='{$bg}'><td>"; $graph_type = "multi_bits"; $interface['interface_id'] = $if_list; include "includes/print-interface-graphs.inc.php"; echo "</td></tr>"; $sql = "select * from ports as I, devices as D WHERE {$type_where} AND I.device_id = D.device_id ORDER BY I.ifAlias"; $query = mysql_query($sql); while ($interface = mysql_fetch_array($query)) { $done = "yes"; unset($class); $interface['ifAlias'] = str_ireplace($type . ": ", "", $interface['ifAlias']); $interface['ifAlias'] = str_ireplace("[PNI]", "Private", $interface['ifAlias']); $ifclass = ifclass($interface['ifOperStatus'], $interface['ifAdminStatus']); if ($bg == "#ffffff") { $bg = "#e5e5e5"; } else { $bg = "#ffffff"; } echo "<tr bgcolor='{$bg}'>\n <td><span class=list-large>" . generateiflink($interface, $interface['ifAlias']) . "</span><br /> \n <span class=interface-desc style='float: left;'>" . generatedevicelink($interface) . " " . generateiflink($interface) . " </span>"; if (mysql_result(mysql_query("SELECT count(*) FROM mac_accounting WHERE interface_id = '" . $interface['interface_id'] . "'"), 0)) { echo "<span style='float: right;'><a href='" . $config['base_url'] . "/device/" . $interface['device_id'] . "/interface/" . $interface['interface_id'] . "/macaccounting/'><img src='/images/16/chart_curve.png' align='absmiddle'> MAC Accounting</a></span>"; } echo "</td></tr><tr bgcolor='{$bg}'><td>"; if (file_exists($config['rrd_dir'] . "/" . $interface['hostname'] . "/" . $interface['ifIndex'] . ".rrd")) { $graph_type = "port_bits"; include "includes/print-interface-graphs.inc.php"; } echo "</td></tr>";
function generate_port_link($port, $text = NULL, $type = NULL) { global $config; $port = ifNameDescr($port); if (!$text) { $text = fixIfName($port['label']); } if ($type) { $port['graph_type'] = $type; } if (!isset($port['graph_type'])) { $port['graph_type'] = 'port_bits'; } $class = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); if (!isset($port['hostname'])) { $port = array_merge($port, device_by_id_cache($port['device_id'])); } $content = "<div class=list-large>" . $port['hostname'] . " - " . fixifName($port['label']) . "</div>"; if ($port['ifAlias']) { $content .= $port['ifAlias'] . "<br />"; } $content .= "<div style=\\'width: 850px\\'>"; $graph_array['type'] = $port['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'] = $port['port_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_port_url($port); if (port_permitted($port['port_id'], $port['device_id'])) { return overlib_link($url, $text, $content, $class); } else { return fixifName($text); } }
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); // If we can get the device data from the global cache, do it, else pull it from the db (mostly for external scripts) if (is_array($GLOBALS['cache']['devices']['id'][$port['device_id']])) { $device =& $GLOBALS['cache']['devices']['id'][$port['device_id']]; } else { $device = device_by_id_cache($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'] = format_mac($port['ifPhysAddress']); // Here definition override for ifDescr, because Calix switch ifDescr <> ifName since fw 2.2 // Note, only for 'calix' os now if ($os == 'calix') { unset($config['os'][$os]['ifname']); $version_parts = explode('.', $device['version']); if ($version_parts[0] > 2 || $version_parts[0] == 2 && $version_parts[1] > 1) { $config['os'][$os]['ifname'] = 1; } } if (isset($config['os'][$os]['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['ifIndex']; } else { $port['label'] = $port['ifDescr']; } } // 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['row_class'] = "warning"; $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. }
function generate_port_link($port, $text = NULL, $type = NULL) { global $config; humanize_port($port); if (!isset($port['html_class'])) { $port['html_class'] = ifclass($port['ifOperStatus'], $port['ifAdminStatus']); } if (!isset($text)) { $text = rewrite_ifname($port['label']); } #if (!isset($port['os'])) { $port = array_merge($port, device_by_id_cache($port['device_id'])); } $url = generate_port_url($port); if (port_permitted($port['port_id'], $port['device_id'])) { 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); } }