1<?php 2 3/** 4 * Observium Network Management and Monitoring System 5 * Copyright (C) 2006-2015, Adam Armstrong - http://www.observium.org 6 * 7 * @package observium 8 * @subpackage webui 9 * @author Adam Armstrong <adama@observium.org> 10 * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2019 Observium Limited 11 * 12 */ 13 14$where = ' WHERE `device_id` = ? AND `deleted` != ?'; 15$params = array($device['device_id'], '1'); 16$ports['total'] = dbFetchCell("SELECT COUNT(*) FROM `ports` $where", $params); 17$ports['up'] = dbFetchCell("SELECT COUNT(*) FROM `ports` $where AND `ifAdminStatus` = 'up' AND `ifOperStatus` IN ('up', 'testing', 'monitoring')", $params); 18$ports['down'] = dbFetchCell("SELECT COUNT(*) FROM `ports` $where AND `ifAdminStatus` = 'up' AND `ifOperStatus` IN ('lowerLayerDown', 'down')", $params); 19$ports['shutdown'] = dbFetchCell("SELECT COUNT(*) FROM `ports` $where AND `ifAdminStatus` = 'down'", $params); 20$ports['deleted'] = dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `device_id` = ? AND `deleted` = ?", $params); 21 22if ($ports['down']) { $ports_colour = $warn_colour_a; } else { $ports_colour = $list_colour_a; } 23 24if ($ports['total']) 25{ 26 echo generate_box_open(array('title' => 'Ports', 27 'icon' => $config['icon']['port'], 28 'url' => generate_url(array('page' => 'device', 'device' => $device['device_id'], 'tab' => 'ports')))); 29 30 $graph_array['height'] = "100"; 31 $graph_array['width'] = "512"; 32 $graph_array['to'] = $config['time']['now']; 33 $graph_array['device'] = $device['device_id']; 34 $graph_array['type'] = "device_bits"; 35 $graph_array['from'] = $config['time']['day']; 36 $graph_array['legend'] = "no"; 37 $graph_array['style'] = array('width: 100%', 'max-width: 593px'); // Override default width 38 $graph = generate_graph_tag($graph_array); 39 unset($graph_array['style']); 40 41 $link_array = $graph_array; 42 $link_array['page'] = "graphs"; 43 unset($link_array['height'], $link_array['width']); 44 $link = generate_url($link_array); 45 46 $graph_array['width'] = "210"; 47 $overlib_content = generate_overlib_content($graph_array, $device['hostname'] . " - Device Traffic"); 48 49 echo('<table class="table table-condensed table-striped "> 50 <tr><td colspan=4>'); 51 52 echo(overlib_link($link, $graph, $overlib_content, NULL)); 53 54 echo('</td></tr> 55 <tr style="background-color: ' . $ports_colour . '; align: center;"> 56 <td style="width: 25%; text-align: center;"><i class="'.$config['icon']['port'].'" title="Total Ports"></i> ' . $ports['total'] . '</td> 57 <td style="width: 25%; text-align: center;" class="green"><i class="'.$config['icon']['up'].'" title="Up Ports"></i> ' . $ports['up'] . '</td> 58 <td style="width: 25%; text-align: center;" class="red"> <i class="'.$config['icon']['down'].'" title="Down Ports"></i> ' . $ports['down'] . '</td> 59 <td style="width: 25%; text-align: center;" class="grey"> <i class="'.$config['icon']['shutdown'].'" title="Shutdown Ports"></i> ' . $ports['shutdown'] . '</td> 60 </tr>'); 61 62 echo('<tr><td colspan=4 style="padding-left: 10px; font-size: 11px; font-weight: bold;">'); 63 64 /** 65 * Start ports sorting based on port type, name and number 66 * Full sort order: 67 * 1. Port type (physical ports always first) 68 * 2. Port base name (TenGig, Gigabit, etc) 69 * 3. Module number 70 * 4. Port number 71 * 5. Port subinterface number 72 */ 73 // FIXME. Make function on this logic and use where required 74 // Custom order for port types. See human type names here: $rewrite_iftype 75 $port_types = array( 76 'Ethernet', 77 '802.3ad LAg', 78 'L2 VLAN (802.1Q)', 79 'L3 VLAN (IP)', 80 'L3 VLAN (IPX)', 81 'Virtual/Internal', 82 'Tunnel', 83 'Loopback', 84 'Other', 85 ); 86 $port_links = array(); 87 foreach (dbFetchRows("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` != ?;", array($device['device_id'], '1')) as $data) 88 { 89 humanize_port($data); 90 if (!in_array($data['human_type'], $port_types)) 91 { 92 $port_types[] = $data['human_type']; 93 } 94 95 // Index example for TenGigabitEthernet3/10.324: 96 // $ports_links['Ethernet'][] = array('port_label_base' => 'TenGigabitEthernet', 'port_label_num' => '3/10.324') 97 $label_num = str_replace(array(':', '_'), array('/', '-'), $data['port_label_num']); 98 //$label_num = preg_replace('![^\d\.\/]!', '', substr($data['port_label'], strlen($data['port_label_base']))); // Remove base part and all not-numeric chars 99 //preg_match('!^(\d+)(?:\/(\d+)(?:\.(\d+))*)*!', $label_num, $label_nums); // Split by slash and point (1/1.324) 100 $label_nums = array(0,0,0); 101 $i = 2; 102 //r(array_reverse(explode('/', $label_num))); 103 foreach (array_reverse(explode('/', $label_num)) as $num) 104 { 105 //$num = preg_replace('/[^0-9.]/', '', $num); // Remove all not-numeric chars 106 if ($i == 2) // && strpos($num, '-') !== FALSE) 107 { 108 $num = str_replace('-', '.', $num); 109 list($label_nums[$i], $label_nums[$i+1]) = explode('.', $num, 2); 110 } else { 111 $label_nums[$i] = $num; 112 } 113 $i--; 114 } 115 if (!is_numeric($label_nums[3])) { $label_nums[3] = 0; } 116 117 $ports_links[$data['human_type']][$data['ifIndex']] = array( 118 'label' => $data['port_label'], 119 'label_base' => $data['port_label_base'], 120 //'label_num' => $data['port_label_num'], 121 'label_num0' => $label_nums[0], 122 'label_num1' => $label_nums[1], 123 'label_num2' => $label_nums[2], 124 'label_num3' => $label_nums[3], 125 'link' => generate_port_link($data, $data['port_label_short']) 126 ); 127 } 128 // First sort iteration (by port type) 129 $all_links = array(); 130 foreach ($port_types as $port_type) 131 { 132 if (!isset($ports_links[$port_type])) { continue; } 133 // Second sort iteration (by port label base name and port numbers) 134 $ports_links[$port_type] = array_sort_by($ports_links[$port_type], 'label_base', SORT_DESC, SORT_STRING, 135 'label_num0', SORT_ASC, SORT_NUMERIC, 136 'label_num1', SORT_ASC, SORT_NUMERIC, 137 'label_num2', SORT_ASC, SORT_NUMERIC, 138 'label_num3', SORT_ASC, SORT_NUMERIC); 139 /* FIXME. This part not completed, wait ;) 140 if ($port_type == 'Ethernet') 141 { 142 // Try to use ports template div 143 $hw = strtolower(safename($device['hardware'])); 144 if (is_file('ports/'.$device['os'].'_'.$hw.'.inc.php')) 145 { 146 print_debug('Include ports template for device: ports/'.$device['os'].'_'.$hw.'.inc.php'); 147 148 include('ports/'.$device['os'].'_'.$hw.'.inc.php'); 149 } 150 else if (is_file('ports/'.$device['os'].'_generic.inc.php')) 151 { 152 print_debug('Include ports template for device: ports/'.$device['os'].'_generic.inc.php'); 153 154 include('ports/'.$device['os'].'_generic.inc.php'); 155 } 156 } 157 */ 158 foreach ($ports_links[$port_type] as $link) 159 { 160 $all_links[] = $link['link']; 161 } 162 } 163 //r($ports_links); 164 /* END ports sorting */ 165 echo(implode(', ', $all_links)); 166 167 echo('</td></tr>'); 168 echo('</table>'); 169 170 echo generate_box_close(); 171 172 unset($ifsep); 173} 174 175// EOF 176