1 | <?php |
||||
2 | |||||
3 | if ($vars['view'] == 'graphs' || $vars['view'] == 'minigraphs') { |
||||
4 | if (isset($vars['graph'])) { |
||||
5 | $graph_type = 'port_' . $vars['graph']; |
||||
6 | } else { |
||||
7 | $graph_type = 'port_bits'; |
||||
8 | } |
||||
9 | } |
||||
10 | |||||
11 | if (! $vars['view']) { |
||||
12 | $vars['view'] = trim(\LibreNMS\Config::get('ports_page_default'), '/'); |
||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
13 | } |
||||
14 | |||||
15 | $link_array = [ |
||||
16 | 'page' => 'device', |
||||
17 | 'device' => $device['device_id'], |
||||
18 | 'tab' => 'ports', |
||||
19 | ]; |
||||
20 | |||||
21 | print_optionbar_start(); |
||||
22 | |||||
23 | $menu_options['basic'] = 'Basic'; |
||||
24 | $menu_options['details'] = 'Details'; |
||||
25 | $menu_options['arp'] = 'ARP Table'; |
||||
26 | $menu_options['fdb'] = 'FDB Table'; |
||||
27 | |||||
28 | if (dbFetchCell("SELECT * FROM links AS L, ports AS I WHERE I.device_id = '" . $device['device_id'] . "' AND I.port_id = L.local_port_id")) { |
||||
29 | $menu_options['neighbours'] = 'Neighbours'; |
||||
30 | } |
||||
31 | |||||
32 | if (dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `ifType` = 'adsl'")) { |
||||
33 | $menu_options['adsl'] = 'ADSL'; |
||||
34 | } |
||||
35 | |||||
36 | $sep = ''; |
||||
37 | foreach ($menu_options as $option => $text) { |
||||
38 | echo $sep; |
||||
39 | if ($vars['view'] == $option) { |
||||
40 | echo "<span class='pagemenu-selected'>"; |
||||
41 | } |
||||
42 | |||||
43 | echo generate_link($text, $link_array, ['view' => $option]); |
||||
44 | if ($vars['view'] == $option) { |
||||
45 | echo '</span>'; |
||||
46 | } |
||||
47 | |||||
48 | $sep = ' | '; |
||||
49 | } |
||||
50 | |||||
51 | unset($sep); |
||||
52 | |||||
53 | echo ' | Graphs: '; |
||||
54 | |||||
55 | $graph_types = [ |
||||
56 | 'bits' => 'Bits', |
||||
57 | 'upkts' => 'Unicast Packets', |
||||
58 | 'nupkts' => 'Non-Unicast Packets', |
||||
59 | 'errors' => 'Errors', |
||||
60 | ]; |
||||
61 | |||||
62 | if (\LibreNMS\Config::get('enable_ports_etherlike')) { |
||||
63 | $graph_types['etherlike'] = 'Etherlike'; |
||||
64 | } |
||||
65 | |||||
66 | foreach ($graph_types as $type => $descr) { |
||||
67 | echo "$type_sep"; |
||||
68 | if ($vars['graph'] == $type && $vars['view'] == 'graphs') { |
||||
69 | echo "<span class='pagemenu-selected'>"; |
||||
70 | } |
||||
71 | |||||
72 | echo generate_link($descr, $link_array, ['view' => 'graphs', 'graph' => $type]); |
||||
73 | if ($vars['graph'] == $type && $vars['view'] == 'graphs') { |
||||
74 | echo '</span>'; |
||||
75 | } |
||||
76 | |||||
77 | echo ' ('; |
||||
78 | if ($vars['graph'] == $type && $vars['view'] == 'minigraphs') { |
||||
79 | echo "<span class='pagemenu-selected'>"; |
||||
80 | } |
||||
81 | |||||
82 | echo generate_link('Mini', $link_array, ['view' => 'minigraphs', 'graph' => $type]); |
||||
83 | if ($vars['graph'] == $type && $vars['view'] == 'minigraphs') { |
||||
84 | echo '</span>'; |
||||
85 | } |
||||
86 | |||||
87 | echo ')'; |
||||
88 | $type_sep = ' | '; |
||||
89 | }//end foreach |
||||
90 | |||||
91 | print_optionbar_end(); |
||||
92 | |||||
93 | if ($vars['view'] == 'minigraphs') { |
||||
94 | $timeperiods = [ |
||||
95 | '-1day', |
||||
96 | '-1week', |
||||
97 | '-1month', |
||||
98 | '-1year', |
||||
99 | ]; |
||||
100 | $from = '-1day'; |
||||
101 | echo "<div style='display: block; clear: both; margin: auto; min-height: 500px;'>"; |
||||
102 | unset($seperator); |
||||
103 | |||||
104 | foreach (dbFetchRows('select * from ports WHERE device_id = ? AND `disabled` = 0 ORDER BY ifIndex', [$device['device_id']]) as $port) { |
||||
105 | $port = cleanPort($port, $device); |
||||
106 | echo "<div class='minigraph-div'><div style='font-weight: bold;'>" . generate_port_link($port) . '</div>'; |
||||
0 ignored issues
–
show
Are you sure
generate_port_link($port) of type array|string can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
107 | } |
||||
108 | |||||
109 | echo '</div>'; |
||||
110 | } elseif ($vars['view'] == 'arp' || $vars['view'] == 'adsl' || $vars['view'] == 'neighbours' || $vars['view'] == 'fdb') { |
||||
111 | include 'ports/' . $vars['view'] . '.inc.php'; |
||||
112 | } else { |
||||
113 | if ($vars['view'] == 'details') { |
||||
114 | $port_details = 1; |
||||
115 | } ?> |
||||
116 | <div style='margin: 0px;'><table class='table'> |
||||
117 | <tr> |
||||
118 | <th width="350"><A href="<?php echo \LibreNMS\Util\Url::generate($vars, ['sort' => 'port']); ?>">Port</a></th> |
||||
119 | <th width="100">Port Group</a></th> |
||||
120 | <th width="100"></th> |
||||
121 | <th width="120"><a href="<?php echo \LibreNMS\Util\Url::generate($vars, ['sort' => 'traffic']); ?>">Traffic</a></th> |
||||
122 | <th width="75">Speed</th> |
||||
123 | <th width="100">Media</th> |
||||
124 | <th width="100">Mac Address</th> |
||||
125 | <th width="375"></th> |
||||
126 | </tr> |
||||
127 | <?php |
||||
128 | |||||
129 | $i = '1'; |
||||
130 | |||||
131 | global $port_cache, $port_index_cache; |
||||
132 | |||||
133 | $ports = dbFetchRows("SELECT * FROM `ports` WHERE `device_id` = ? AND `deleted` = '0' AND `disabled` = 0 ORDER BY `ifIndex` ASC", [$device['device_id']]); |
||||
134 | // As we've dragged the whole database, lets pre-populate our caches :) |
||||
135 | // FIXME - we should probably split the fetching of link/stack/etc into functions and cache them here too to cut down on single row queries. |
||||
136 | |||||
137 | foreach ($ports as $key => $port) { |
||||
138 | $port_cache[$port['port_id']] = $port; |
||||
139 | $port_index_cache[$port['device_id']][$port['ifIndex']] = $port; |
||||
140 | $ports[$key]['ifOctets_rate'] = $port['ifInOctets_rate'] + $port['ifOutOctets_rate']; |
||||
141 | } |
||||
142 | |||||
143 | switch ($vars['sort']) { |
||||
144 | case 'traffic': |
||||
145 | $ports = array_sort_by_column($ports, 'ifOctets_rate', SORT_DESC); |
||||
146 | break; |
||||
147 | default: |
||||
148 | $ports = array_sort_by_column($ports, 'ifIndex', SORT_ASC); |
||||
149 | break; |
||||
150 | } |
||||
151 | |||||
152 | foreach ($ports as $port) { |
||||
153 | include 'includes/html/print-interface.inc.php'; |
||||
154 | $i++; |
||||
155 | } |
||||
156 | |||||
157 | echo '</table></div>'; |
||||
158 | }//end if |
||||
159 | |||||
160 | $pagetitle[] = 'Ports'; |
||||
161 |