Issues (2963)

includes/html/print-interface.inc.php (3 issues)

1
<script>
2
$(function () {
3
    $('[data-toggle="popover"]').popover()
4
})
5
</script>
6
<?php
7
8
use App\Models\Port;
9
use LibreNMS\Config;
10
use LibreNMS\Util\IP;
11
use LibreNMS\Util\Number;
12
13
// This file prints a table row for each interface
14
$port['device_id'] = $device['device_id'];
15
$port['hostname'] = $device['hostname'];
16
17
$if_id = $port['port_id'];
18
19
$port = cleanPort($port);
20
21
if ($int_colour) {
22
    $row_colour = $int_colour;
23
} else {
24
    if (! is_integer($i / 2)) {
25
        $row_colour = Config::get('list_colour.even');
26
    } else {
27
        $row_colour = Config::get('list_colour.odd');
28
    }
29
}
30
31
$port_adsl = dbFetchRow('SELECT * FROM `ports_adsl` WHERE `port_id` = ?', [$port['port_id']]);
32
33
if ($port['ifInErrors_delta'] > 0 || $port['ifOutErrors_delta'] > 0) {
34
    $error_img = generate_port_link($port, "<i class='fa fa-flag fa-lg' style='color:red' aria-hidden='true'></i>", 'port_errors');
35
} else {
36
    $error_img = '';
37
}
38
39
if (dbFetchCell('SELECT COUNT(*) FROM `mac_accounting` WHERE `port_id` = ?', [$port['port_id']])) {
40
    $mac = "<a href='" . generate_port_url($port, ['view' => 'macaccounting']) . "'><i class='fa fa-pie-chart fa-lg icon-theme' aria-hidden='true'></i></a>";
41
} else {
42
    $mac = '';
43
}
44
45
echo "<tr style=\"background-color: $row_colour;\" valign=top onmouseover=\"this.style.backgroundColor='" . Config::get('list_colour.highlight') . "';\" onmouseout=\"this.style.backgroundColor='$row_colour';\" style='cursor: pointer;'>
46
    <td valign=top width=350>";
47
48
if (Auth::user()->hasGlobalRead()) {
49
    $port_data = array_to_htmljson($port);
50
    echo '<i class="fa fa-tag" data-toggle="popover" data-content="' . $port_data . '" data-html="true"></i>';
51
}
52
53
    echo '        <span class=list-large>
54
        ' . generate_port_link($port, $port['label']) . " $error_img $mac
55
        </span><br /><span class=interface-desc>" . $port['ifAlias'] . '</span>';
56
57
if ($port['ifAlias']) {
58
    echo '<br />';
59
}
60
61
unset($break);
62
63
if ($port_details) {
64
    foreach (dbFetchRows('SELECT * FROM `ipv4_addresses` WHERE `port_id` = ?', [$port['port_id']]) as $ip) {
65
        echo "$break <a class=interface-desc href=\"javascript:popUp('ajax/netcmd?cmd=whois&amp;query=$ip[ipv4_address]')\">" . $ip['ipv4_address'] . '/' . $ip['ipv4_prefixlen'] . '</a>';
66
        $break = '<br />';
67
    }
68
69
    foreach (dbFetchRows('SELECT * FROM `ipv6_addresses` WHERE `port_id` = ?', [$port['port_id']]) as $ip6) {
70
        echo "$break <a class=interface-desc href=\"javascript:popUp('ajax/netcmd?cmd=whois&amp;query=" . $ip6['ipv6_address'] . "')\">" . IP::parse($ip6['ipv6_address'], true) . '/' . $ip6['ipv6_prefixlen'] . '</a>';
71
        $break = '<br />';
72
    }
73
}
74
75
echo '</span>';
76
77
$port_group_name_list = Port::find($port['port_id'])->groups->pluck('name')->toArray() ?: ['Default'];
78
79
echo '</td><td width=100>';
80
echo implode('<br>', $port_group_name_list);
81
echo "</td><td width=100 onclick=\"location.href='" . generate_port_url($port) . "'\" >";
82
83
if ($port_details) {
84
    $port['graph_type'] = 'port_bits';
85
    echo generate_port_link($port, "<img src='graph.php?type=port_bits&amp;id=" . $port['port_id'] . '&amp;from=' . Config::get('time.day') . '&amp;to=' . Config::get('time.now') . '&amp;width=100&amp;height=20&amp;legend=no&amp;bg=' . str_replace('#', '', $row_colour) . "00'>");
0 ignored issues
show
Are you sure generate_port_link($port... $row_colour) . '00'>') of type array|string can be used in echo? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

85
    echo /** @scrutinizer ignore-type */ generate_port_link($port, "<img src='graph.php?type=port_bits&amp;id=" . $port['port_id'] . '&amp;from=' . Config::get('time.day') . '&amp;to=' . Config::get('time.now') . '&amp;width=100&amp;height=20&amp;legend=no&amp;bg=' . str_replace('#', '', $row_colour) . "00'>");
Loading history...
86
    $port['graph_type'] = 'port_upkts';
87
    echo generate_port_link($port, "<img src='graph.php?type=port_upkts&amp;id=" . $port['port_id'] . '&amp;from=' . Config::get('time.day') . '&amp;to=' . Config::get('time.now') . '&amp;width=100&amp;height=20&amp;legend=no&amp;bg=' . str_replace('#', '', $row_colour) . "00'>");
0 ignored issues
show
Are you sure generate_port_link($port... $row_colour) . '00'>') of type array|string can be used in echo? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
    echo /** @scrutinizer ignore-type */ generate_port_link($port, "<img src='graph.php?type=port_upkts&amp;id=" . $port['port_id'] . '&amp;from=' . Config::get('time.day') . '&amp;to=' . Config::get('time.now') . '&amp;width=100&amp;height=20&amp;legend=no&amp;bg=' . str_replace('#', '', $row_colour) . "00'>");
Loading history...
88
    $port['graph_type'] = 'port_errors';
89
    echo generate_port_link($port, "<img src='graph.php?type=port_errors&amp;id=" . $port['port_id'] . '&amp;from=' . Config::get('time.day') . '&amp;to=' . Config::get('time.now') . '&amp;width=100&amp;height=20&amp;legend=no&amp;bg=' . str_replace('#', '', $row_colour) . "00'>");
0 ignored issues
show
Are you sure generate_port_link($port... $row_colour) . '00'>') of type array|string can be used in echo? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

89
    echo /** @scrutinizer ignore-type */ generate_port_link($port, "<img src='graph.php?type=port_errors&amp;id=" . $port['port_id'] . '&amp;from=' . Config::get('time.day') . '&amp;to=' . Config::get('time.now') . '&amp;width=100&amp;height=20&amp;legend=no&amp;bg=' . str_replace('#', '', $row_colour) . "00'>");
Loading history...
90
}
91
92
echo "</td><td width=120 onclick=\"location.href='" . generate_port_url($port) . "'\" >";
93
94
if ($port['ifOperStatus'] == 'up') {
95
    $port['in_rate'] = ($port['ifInOctets_rate'] * 8);
96
    $port['out_rate'] = ($port['ifOutOctets_rate'] * 8);
97
    $in_perc = empty($port['ifSpeed']) ? 0 : round(($port['in_rate'] / $port['ifSpeed'] * 100));
98
    $out_perc = empty($port['ifSpeed']) ? 0 : round(($port['in_rate'] / $port['ifSpeed'] * 100));
99
    echo "<i class='fa fa-long-arrow-left fa-lg' style='color:green' aria-hidden='true'></i> <span style='color: " . percent_colour($in_perc) . "'>" . Number::formatSi($port['in_rate'], 2, 3, 'bps') . "<br />
100
        <i class='fa fa-long-arrow-right fa-lg' style='color:blue' aria-hidden='true'></i> <span style='color: " . percent_colour($out_perc) . "'>" . Number::formatSi($port['out_rate'], 2, 3, 'bps') . "<br />
101
        <i class='fa fa-long-arrow-left fa-lg' style='color:purple' aria-hidden='true'></i> " . Number::formatBi($port['ifInUcastPkts_rate'], 2, 3, 'pps') . "</span><br />
102
        <i class='fa fa-long-arrow-right fa-lg' style='color:darkorange' aria-hidden='true'></i> " . Number::formatBi($port['ifOutUcastPkts_rate'], 2, 3, 'pps') . '</span>';
103
}
104
105
echo "</td><td width=75 onclick=\"location.href='" . generate_port_url($port) . "'\" >";
106
if ($port['ifSpeed']) {
107
    echo '<span class=box-desc>' . \LibreNMS\Util\Number::formatSi($port['ifSpeed'], 2, 3, 'bps') . '</span>';
108
}
109
110
echo '<br />';
111
112
if ($port['ifDuplex'] != 'unknown') {
113
    echo '<span class=box-desc>' . $port['ifDuplex'] . '</span>';
114
} else {
115
    echo '-';
116
}
117
118
$vlans = dbFetchColumn(
119
    'SELECT vlan FROM `ports_vlans` AS PV, vlans AS V ' .
120
    'WHERE PV.`port_id`=? AND PV.`device_id`=? AND V.`vlan_vlan`=PV.vlan AND V.device_id = PV.device_id',
121
    [$port['port_id'], $device['device_id']]
122
);
123
$vlan_count = count($vlans);
124
125
if ($vlan_count > 1) {
126
    echo '<p class=box-desc><span class=purple><a href="';
127
    echo \LibreNMS\Util\Url::deviceUrl((int) $device['device_id'], ['tab' => 'vlans']);
128
    echo '" title="';
129
    echo implode(', ', $vlans);
130
    echo '">VLANs: ';
131
    echo $vlan_count;
132
    echo '</a></span></p>';
133
} elseif ($vlan_count == 1 || $port['ifVlan']) {
134
    echo '<p class=box-desc><span class=blue>VLAN: ';
135
    echo $vlans[0] ?: $port['ifVlan'];
136
    echo '</span></p>';
137
} elseif ($port['ifVrf']) {
138
    $vrf = dbFetchRow('SELECT * FROM vrfs WHERE vrf_id = ?', [$port['ifVrf']]);
139
    echo "<p style='color: green;'>" . $vrf['vrf_name'] . '</p>';
140
}//end if
141
142
if ($port_adsl['adslLineCoding']) {
143
    echo "</td><td width=150 onclick=\"location.href='" . generate_port_url($port) . "'\" >";
144
    echo $port_adsl['adslLineCoding'] . '/' . rewrite_adslLineType($port_adsl['adslLineType']);
145
    echo '<br />';
146
    // ATU-C is CO       -> ATU-C TX is the download speed for the CPE
147
    // ATU-R is the CPE  -> ATU-R TX is the upload speed of the CPE
148
    echo 'Sync:' . Number::formatSi($port_adsl['adslAtucChanCurrTxRate'], 2, 3, 'bps') . '/' . Number::formatSi($port_adsl['adslAturChanCurrTxRate'], 2, 3, 'bps');
149
    echo '<br />';
150
    // This is the Receive Max AttainableRate, so :
151
    //    adslAturCurrAttainableRate is DownloadMaxRate
152
    //    adslAtucCurrAttainableRate is UploadMaxRate
153
    echo 'Max:' . Number::formatSi($port_adsl['adslAturCurrAttainableRate'], 2, 3, 'bps') . '/' . Number::formatSi($port_adsl['adslAtucCurrAttainableRate'], 2, 3, 'bps');
154
    echo "</td><td width=150 onclick=\"location.href='" . generate_port_url($port) . "'\" >";
155
    echo 'Atten:' . $port_adsl['adslAturCurrAtn'] . 'dB/' . $port_adsl['adslAtucCurrAtn'] . 'dB';
156
    echo '<br />';
157
    echo 'SNR:' . $port_adsl['adslAturCurrSnrMgn'] . 'dB/' . $port_adsl['adslAtucCurrSnrMgn'] . 'dB';
158
} else {
159
    echo "</td><td width=150 onclick=\"location.href='" . generate_port_url($port) . "'\" >";
160
    if ($port['ifType'] && $port['ifType'] != '') {
161
        echo '<span class=box-desc>' . \LibreNMS\Util\Rewrite::normalizeIfType($port['ifType']) . '</span>';
162
    } else {
163
        echo '-';
164
    }
165
166
    echo '<br />';
167
    if ($ifHardType && $ifHardType != '') {
168
        echo '<span class=box-desc>' . $ifHardType . '</span>';
169
    } else {
170
        echo '-';
171
    }
172
173
    echo "</td><td width=150 onclick=\"location.href='" . generate_port_url($port) . "'\" >";
174
    if ($port['ifPhysAddress'] && $port['ifPhysAddress'] != '') {
175
        echo '<span class=box-desc>' . \LibreNMS\Util\Rewrite::readableMac($port['ifPhysAddress']) . '</span>';
176
    } else {
177
        echo '-';
178
    }
179
180
    echo '<br />';
181
    if ($port['ifMtu'] && $port['ifMtu'] != '') {
182
        echo '<span class=box-desc>MTU ' . $port['ifMtu'] . '</span>';
183
    } else {
184
        echo '-';
185
    }
186
}//end if
187
188
echo '</td>';
189
echo '<td width=375 valign=top class="interface-desc">';
190
191
$neighborsCount = 0;
192
$nbLinks = 0;
193
$int_links = [];
194
if (strpos($port['label'], 'oopback') === false && ! $graph_type) {
195
    foreach (dbFetchRows('SELECT * FROM `links` AS L, `ports` AS I, `devices` AS D WHERE L.local_port_id = ? AND L.remote_port_id = I.port_id AND I.device_id = D.device_id', [$if_id]) as $link) {
196
        $int_links[$link['port_id']] = $link['port_id'];
197
        $int_links_phys[$link['port_id']] = 1;
198
        $nbLinks++;
199
    }
200
201
    unset($br);
202
203
    if ($port_details && Config::get('enable_port_relationship') === true) {
204
        // Show which other devices are on the same subnet as this interface
205
        foreach (dbFetchRows("SELECT `ipv4_network_id` FROM `ipv4_addresses` WHERE `port_id` = ? AND `ipv4_address` NOT LIKE '127.%'", [$port['port_id']]) as $net) {
206
            $ipv4_network_id = $net['ipv4_network_id'];
207
            $sql = 'SELECT I.port_id FROM ipv4_addresses AS A, ports AS I, devices AS D
208
                WHERE A.port_id = I.port_id
209
                AND A.ipv4_network_id = ? AND D.device_id = I.device_id
210
                AND D.device_id != ?';
211
            $array = [
212
                $net['ipv4_network_id'],
213
                $device['device_id'],
214
            ];
215
            foreach (dbFetchRows($sql, $array) as $new) {
216
                echo $new['ipv4_network_id'];
217
                $this_ifid = $new['port_id'];
218
                $this_hostid = $new['device_id'];
219
                $this_hostname = $new['hostname'];
220
                $this_ifname = \LibreNMS\Util\Rewrite::normalizeIfName($new['label']);
221
                $int_links[$this_ifid] = $this_ifid;
222
                $int_links_v4[$this_ifid] = 1;
223
            }
224
        }//end foreach
225
226
        foreach (dbFetchRows('SELECT ipv6_network_id FROM ipv6_addresses WHERE port_id = ?', [$port['port_id']]) as $net) {
227
            $ipv6_network_id = $net['ipv6_network_id'];
228
            $sql = "SELECT I.port_id FROM ipv6_addresses AS A, ports AS I, devices AS D
229
                WHERE A.port_id = I.port_id
230
                AND A.ipv6_network_id = ? AND D.device_id = I.device_id
231
                AND D.device_id != ? AND A.ipv6_origin != 'linklayer' AND A.ipv6_origin != 'wellknown'";
232
            $array = [
233
                $net['ipv6_network_id'],
234
                $device['device_id'],
235
            ];
236
237
            foreach (dbFetchRows($sql, $array) as $new) {
238
                echo $new['ipv6_network_id'];
239
                $this_ifid = $new['port_id'];
240
                $this_hostid = $new['device_id'];
241
                $this_hostname = $new['hostname'];
242
                $this_ifname = \LibreNMS\Util\Rewrite::normalizeIfName($new['label']);
243
                $int_links[$this_ifid] = $this_ifid;
244
                $int_links_v6[$this_ifid] = 1;
245
            }
246
        }//end foreach
247
    }//end if
248
249
    if (count($int_links) > 3) {
250
        echo '<div class="collapse-neighbors"><i class="neighbors-button fa fa-plus fa-lg" aria-hidden="true"></i>
251
               <span class="neighbors-interface-list-firsts" style="display: inline;">';
252
    }
253
254
    if ($port_details && Config::get('enable_port_relationship') === true && port_permitted($int_link, $device['device_id'])) {
255
        foreach ($int_links as $int_link) {
256
            $neighborsCount++;
257
            if ($neighborsCount == 4) {
258
                echo '<span class="neighbors-list-continued" style="display: inline;"></br>[...]</span>';
259
                echo '</span>';
260
                echo '<span class="neighbors-interface-list" style="display: none;">';
261
            }
262
            $link_if = dbFetchRow('SELECT * from ports AS I, devices AS D WHERE I.device_id = D.device_id and I.port_id = ?', [$int_link]);
263
            $link_if = cleanPort($link_if);
264
            echo "$br";
265
266
            if ($int_links_phys[$int_link]) {
267
                echo "<i class='fa fa-plus fa-lg' style='color:black' aria-hidden='true'></i> ";
268
            } else {
269
                echo "<i class='fa fa-arrow-right fa-lg' style='color:green' aria-hidden='true'></i> ";
270
            }
271
272
            echo '<b>' . generate_port_link($link_if, makeshortif($link_if['label'])) . ' on ' . generate_device_link($link_if);
273
274
            if ($int_links_v6[$int_link]) {
275
                echo " <b style='color: #a10000;'>v6</b>";
276
            }
277
278
            if ($int_links_v4[$int_link]) {
279
                echo " <b style='color: #00a100'>v4</b>";
280
            }
281
282
            $br = '<br />';
283
        }//end foreach
284
    }//end if
285
286
    // unset($int_links, $int_links_v6, $int_links_v4, $int_links_phys, $br);
287
}//end if
288
289
if ($port_details && Config::get('enable_port_relationship') === true && port_permitted($port['port_id'], $device['device_id'])) {
290
    foreach (dbFetchRows('SELECT * FROM `pseudowires` WHERE `port_id` = ?', [$port['port_id']]) as $pseudowire) {
291
        // `port_id`,`peer_device_id`,`peer_ldp_id`,`cpwVcID`,`cpwOid`
292
        $pw_peer_dev = dbFetchRow('SELECT * FROM `devices` WHERE `device_id` = ?', [$pseudowire['peer_device_id']]);
293
        $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', [$pseudowire['peer_device_id'], $pseudowire['cpwVcID']]);
294
295
        $pw_peer_int = cleanPort($pw_peer_int);
296
        echo "$br<i class='fa fa-cube fa-lg' style='color:green' aria-hidden='true'></i><b> " . generate_port_link($pw_peer_int, makeshortif($pw_peer_int['label'])) . ' on ' . generate_device_link($pw_peer_dev) . '</b>';
297
        $br = '<br />';
298
    }
299
300
    foreach (dbFetchRows('SELECT * FROM `ports` WHERE `pagpGroupIfIndex` = ? and `device_id` = ?', [$port['ifIndex'], $device['device_id']]) as $member) {
301
        $member = cleanPort($member);
302
        echo "$br<i class='fa fa-cube fa-lg icon-theme' aria-hidden='true'></i> <strong>" . generate_port_link($member) . ' (PAgP)</strong>';
303
        $br = '<br />';
304
    }
305
306
    if ($port['pagpGroupIfIndex'] && $port['pagpGroupIfIndex'] != $port['ifIndex']) {
307
        $parent = dbFetchRow('SELECT * FROM `ports` WHERE `ifIndex` = ? and `device_id` = ?', [$port['pagpGroupIfIndex'], $device['device_id']]);
308
        $parent = cleanPort($parent);
309
        echo "$br<i class='fa fa-cube fa-lg icon-theme' aria-hidden='true'></i> <strong>" . generate_port_link($parent) . ' (PAgP)</strong>';
310
        $br = '<br />';
311
    }
312
313
    foreach (dbFetchRows('SELECT * FROM `ports_stack` WHERE `port_id_low` = ? and `device_id` = ?', [$port['ifIndex'], $device['device_id']]) as $higher_if) {
314
        if ($higher_if['port_id_high']) {
315
            $this_port = get_port_by_index_cache($device['device_id'], $higher_if['port_id_high']);
316
            $this_port = cleanPort($this_port);
317
            echo "$br<i class='fa fa-expand fa-lg icon-theme' aria-hidden='true'></i> <strong>" . generate_port_link($this_port) . '</strong>';
318
            $br = '<br />';
319
        }
320
    }
321
322
    foreach (dbFetchRows('SELECT * FROM `ports_stack` WHERE `port_id_high` = ? and `device_id` = ?', [$port['ifIndex'], $device['device_id']]) as $lower_if) {
323
        if ($lower_if['port_id_low']) {
324
            $this_port = get_port_by_index_cache($device['device_id'], $lower_if['port_id_low']);
325
            $this_port = cleanPort($this_port);
326
            echo "$br<i class='fa fa-compress fa-lg icon-theme' aria-hidden='true'></i> <strong>" . generate_port_link($this_port) . '</strong>';
327
            $br = '<br />';
328
        }
329
    }
330
}//end if
331
332
unset($int_links, $int_links_v6, $int_links_v4, $int_links_phys, $br);
333
334
if ($nbLinks > 3) {
335
    echo '</span></div>';
336
}
337
echo '</td></tr>';
338
339
// If we're showing graphs, generate the graph and print the img tags
340
if ($graph_type == 'etherlike') {
341
    $graph_file = get_port_rrdfile_path($device['hostname'], $if_id, 'dot3');
342
} else {
343
    $graph_file = get_port_rrdfile_path($device['hostname'], $if_id);
344
}
345
346
if ($graph_type && is_file($graph_file)) {
347
    $type = $graph_type;
348
349
    echo "<tr style='background-color: $row_colour; padding: 0px;'><td colspan=7>";
350
351
    include 'includes/html/print-interface-graphs.inc.php';
352
353
    echo '</td></tr>';
354
}
355