Issues (2963)

includes/html/pages/device/port.inc.php (1 issue)

1
<?php
2
3
$vars['view'] = basename($vars['view'] ?? 'graphs');
4
5
$port = dbFetchRow('SELECT * FROM `ports` WHERE `port_id` = ?', [$vars['port']]);
6
7
$port_details = 1;
8
9
$hostname = $device['hostname'];
10
$hostid = $device['port_id'];
11
$ifname = $port['ifDescr'];
12
$ifIndex = $port['ifIndex'];
13
$speed = \LibreNMS\Util\Number::formatSi($port['ifSpeed'], 2, 3, 'bps');
14
15
$ifalias = $port['name'];
16
17
if ($port['ifPhysAddress']) {
18
    $mac = "$port[ifPhysAddress]";
19
}
20
21
$color = 'black';
22
if ($port['ifAdminStatus'] == 'down') {
23
    $status = "<span class='grey'>Disabled</span>";
24
}
25
26
if ($port['ifAdminStatus'] == 'up' && $port['ifOperStatus'] != 'up') {
27
    $status = "<span class='red'>Enabled / Disconnected</span>";
28
}
29
30
if ($port['ifAdminStatus'] == 'up' && $port['ifOperStatus'] == 'up') {
31
    $status = "<span class='green'>Enabled / Connected</span>";
32
}
33
34
$i = 1;
35
$inf = \LibreNMS\Util\Rewrite::normalizeIfName($ifname);
36
37
$bg = '#ffffff';
38
39
$show_all = 1;
40
41
echo "<div class=ifcell style='margin: 0px;'><table width=100% cellpadding=10 cellspacing=0>";
42
43
require 'includes/html/print-interface.inc.php';
44
45
echo '</table></div>';
46
47
$pos = strpos(strtolower($ifname), 'vlan');
48
if ($pos !== false) {
49
    $broke = 'yes';
50
}
51
52
$pos = strpos(strtolower($ifname), 'loopback');
53
54
if ($pos !== false) {
55
    $broke = 'yes';
56
}
57
58
echo "<div style='clear: both;'>";
59
60
print_optionbar_start();
61
62
$link_array = [
63
    'page'   => 'device',
64
    'device' => $device['device_id'],
65
    'tab'    => 'port',
66
    'port'   => $port['port_id'],
67
];
68
69
$menu_options['graphs'] = 'Graphs';
70
$menu_options['realtime'] = 'Real time';
71
// FIXME CONDITIONAL
72
$menu_options['arp'] = 'ARP Table';
73
$menu_options['fdb'] = 'FDB Table';
74
$menu_options['events'] = 'Eventlog';
75
$menu_options['notes'] = 'Notes';
76
77
if (dbFetchCell("SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ? AND `entPhysicalIndex` = ?  AND entPhysicalIndex_measured = 'ports'", [$device['device_id'], $port['ifIndex']])) {
78
    $menu_options['sensors'] = 'Health';
79
}
80
81
if (dbFetchCell("SELECT COUNT(*) FROM `ports_adsl` WHERE `port_id` = '" . $port['port_id'] . "'")) {
82
    $menu_options['adsl'] = 'ADSL';
83
}
84
85
if (dbFetchCell("SELECT COUNT(*) FROM `ports` WHERE `pagpGroupIfIndex` = '" . $port['ifIndex'] . "' and `device_id` = '" . $device['device_id'] . "'")) {
86
    $menu_options['pagp'] = 'PAgP';
87
}
88
89
if (dbFetchCell("SELECT COUNT(*) FROM `ports_vlans` WHERE `port_id` = '" . $port['port_id'] . "' and `device_id` = '" . $device['device_id'] . "'")) {
90
    $menu_options['vlans'] = 'VLANs';
91
}
92
93
// Are there any CBQoS components for this device?
94
$component = new LibreNMS\Component();
95
$options = [];         // Re-init array in case it has been declared previously.
96
$options['filter']['type'] = ['=', 'Cisco-CBQOS'];
97
$components = $component->getComponents($device['device_id'], $options);
98
$components = $components[$device['device_id']] ?? [];        // We only care about our device id.
99
if (count($components) > 0) {
100
    $menu_options['cbqos'] = 'CBQoS';
101
}
102
103
if (LibreNMS\Plugins::countHooks('port_container')) {
0 ignored issues
show
Bug Best Practice introduced by
The expression LibreNMS\Plugins::countHooks('port_container') of type false|integer is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
104
    // Checking if any plugin implements the port_container. If yes, allow to display the menu_option
105
    $menu_options['plugins'] = 'Plugins';
106
}
107
108
$sep = '';
109
foreach ($menu_options as $option => $text) {
110
    echo $sep;
111
    if ($vars['view'] == $option) {
112
        echo "<span class='pagemenu-selected'>";
113
    }
114
115
    echo generate_link($text, $link_array, ['view' => $option]);
116
    if ($vars['view'] == $option) {
117
        echo '</span>';
118
    }
119
120
    $sep = ' | ';
121
}
122
123
unset($sep);
124
125
if (dbFetchCell("SELECT count(*) FROM mac_accounting WHERE port_id = '" . $port['port_id'] . "'") > '0') {
126
    echo generate_link($descr, $link_array, ['view' => 'macaccounting', 'graph' => $type]);
127
128
    echo ' | Mac Accounting : ';
129
    if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'graphs') {
130
        echo "<span class='pagemenu-selected'>";
131
    }
132
133
    echo generate_link('Bits', $link_array, ['view' => 'macaccounting', 'subview' => 'graphs', 'graph' => 'bits']);
134
    if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'graphs') {
135
        echo '</span>';
136
    }
137
138
    echo '(';
139
    if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'minigraphs') {
140
        echo "<span class='pagemenu-selected'>";
141
    }
142
143
    echo generate_link('Mini', $link_array, ['view' => 'macaccounting', 'subview' => 'minigraphs', 'graph' => 'bits']);
144
    if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'minigraphs') {
145
        echo '</span>';
146
    }
147
148
    echo '|';
149
150
    if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'top10') {
151
        echo "<span class='pagemenu-selected'>";
152
    }
153
154
    echo generate_link('Top10', $link_array, ['view' => 'macaccounting', 'subview' => 'top10', 'graph' => 'bits']);
155
    if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'bits' && $vars['subview'] == 'top10') {
156
        echo '</span>';
157
    }
158
159
    echo ') | ';
160
161
    if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'graphs') {
162
        echo "<span class='pagemenu-selected'>";
163
    }
164
165
    echo generate_link('Packets', $link_array, ['view' => 'macaccounting', 'subview' => 'graphs', 'graph' => 'pkts']);
166
    if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'graphs') {
167
        echo '</span>';
168
    }
169
170
    echo '(';
171
    if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'minigraphs') {
172
        echo "<span class='pagemenu-selected'>";
173
    }
174
175
    echo generate_link('Mini', $link_array, ['view' => 'macaccounting', 'subview' => 'minigraphs', 'graph' => 'pkts']);
176
    if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'minigraphs') {
177
        echo '</span>';
178
    }
179
180
    echo '|';
181
    if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'top10') {
182
        echo "<span class='pagemenu-selected'>";
183
    }
184
185
    echo generate_link('Top10', $link_array, ['view' => 'macaccounting', 'subview' => 'top10', 'graph' => 'pkts']);
186
    if ($vars['view'] == 'macaccounting' && $vars['graph'] == 'pkts' && $vars['subview'] == 'top10') {
187
        echo '</span>';
188
    }
189
190
    echo ')';
191
}//end if
192
193
if (dbFetchCell("SELECT COUNT(*) FROM juniAtmVp WHERE port_id = '" . $port['port_id'] . "'") > '0') {
194
    // FIXME ATM VPs
195
    // FIXME URLs BROKEN
196
    echo ' | ATM VPs : ';
197
    if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') {
198
        echo "<span class='pagemenu-selected'>";
199
    }
200
201
    echo "<a href='" . \LibreNMS\Util\Url::generate(['page' => 'device', 'device' => $device['device_id'], 'tab' => 'port', 'port' => $port['port_id']]) . "/junose-atm-vp/bits/'>Bits</a>";
202
    if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') {
203
        echo '</span>';
204
    }
205
206
    echo ' | ';
207
    if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'packets') {
208
        echo "<span class='pagemenu-selected'>";
209
    }
210
211
    echo "<a href='" . \LibreNMS\Util\Url::generate(['page' => 'device', 'device' => $device['device_id'], 'tab' => 'port', 'port' => $port['port_id']]) . "/junose-atm-vp/packets/'>Packets</a>";
212
    if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') {
213
        echo '</span>';
214
    }
215
216
    echo ' | ';
217
    if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'cells') {
218
        echo "<span class='pagemenu-selected'>";
219
    }
220
221
    echo "<a href='" . \LibreNMS\Util\Url::generate(['page' => 'device', 'device' => $device['device_id'], 'tab' => 'port', 'port' => $port['port_id']]) . "/junose-atm-vp/cells/'>Cells</a>";
222
    if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') {
223
        echo '</span>';
224
    }
225
226
    echo ' | ';
227
    if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'errors') {
228
        echo "<span class='pagemenu-selected'>";
229
    }
230
231
    echo "<a href='" . \LibreNMS\Util\Url::generate(['page' => 'device', 'device' => $device['device_id'], 'tab' => 'port', 'port' => $port['port_id']]) . "/junose-atm-vp/errors/'>Errors</a>";
232
    if ($vars['view'] == 'junose-atm-vp' && $vars['graph'] == 'bits') {
233
        echo '</span>';
234
    }
235
}//end if
236
237
if (Auth::user()->hasGlobalAdmin() && \LibreNMS\Config::get('enable_billing') == 1) {
238
    $bills = dbFetchRows('SELECT `bill_id` FROM `bill_ports` WHERE `port_id`=?', [$port['port_id']]);
239
    if (count($bills) === 1) {
240
        echo "<span style='float: right;'><a href='" . \LibreNMS\Util\Url::generate(['page' => 'bill', 'bill_id' => $bills[0]['bill_id']]) . "'><i class='fa fa-money fa-lg icon-theme' aria-hidden='true'></i> View Bill</a></span>";
241
    } elseif (count($bills) > 1) {
242
        echo "<span style='float: right;'><a href='" . \LibreNMS\Util\Url::generate(['page' => 'bills']) . "'><i class='fa fa-money fa-lg icon-theme' aria-hidden='true'></i> View Bills</a></span>";
243
    } else {
244
        echo "<span style='float: right;'><a href='" . \LibreNMS\Util\Url::generate(['page' => 'bills', 'view' => 'add', 'port' => $port['port_id']]) . "'><i class='fa fa-money fa-lg icon-theme' aria-hidden='true'></i> Create Bill</a></span>";
245
    }
246
}
247
248
print_optionbar_end();
249
250
echo "<div style='margin: 5px;'>";
251
252
require 'includes/html/pages/device/port/' . $vars['view'] . '.inc.php';
253
254
echo '</div>';
255