Interfaces: Overview - remove legacy version and its related functions and scripts. closes https://github.com/opnsense/core/issues/6832

This commit is contained in:
Ad Schellevis 2023-12-25 14:03:22 +01:00
parent 28b0ba4812
commit 4d495ea6cc
9 changed files with 3 additions and 1022 deletions

3
plist
View File

@ -914,7 +914,6 @@
/usr/local/opnsense/scripts/filter/lib/alias/pf.py
/usr/local/opnsense/scripts/filter/lib/alias/uri.py
/usr/local/opnsense/scripts/filter/lib/states.py
/usr/local/opnsense/scripts/filter/list_counters.py
/usr/local/opnsense/scripts/filter/list_osfp.py
/usr/local/opnsense/scripts/filter/list_pfsync.py
/usr/local/opnsense/scripts/filter/list_rule_ids.py
@ -1073,7 +1072,6 @@
/usr/local/opnsense/scripts/syslog/queryLog.py
/usr/local/opnsense/scripts/system/activity.py
/usr/local/opnsense/scripts/system/certctl.py
/usr/local/opnsense/scripts/system/list_interrupts.py
/usr/local/opnsense/scripts/system/nameservers.php
/usr/local/opnsense/scripts/system/remote_backup.php
/usr/local/opnsense/scripts/system/rfc5246_cipher_suites.csv
@ -2045,7 +2043,6 @@
/usr/local/www/services_opendns.php
/usr/local/www/services_router_advertisements.php
/usr/local/www/status_habackup.php
/usr/local/www/status_interfaces.php
/usr/local/www/status_ntpd.php
/usr/local/www/status_wireless.php
/usr/local/www/system_advanced_admin.php

View File

@ -3927,220 +3927,6 @@ function interfaces_neighbors_configure($device = null, $ifconfig_details = null
}
}
function get_interfaces_info($include_unlinked = false)
{
global $config;
$all_intf_details = legacy_interfaces_details();
$all_intf_stats = legacy_interface_stats();
$gateways = new \OPNsense\Routing\Gateways();
$ifup = legacy_interface_listget('up');
$result = [];
$interfaces = legacy_config_get_interfaces(['virtual' => false]);
$known_interfaces = [];
foreach (array_keys($interfaces) as $ifdescr) {
$interfaces[$ifdescr]['if'] = get_real_interface($ifdescr);
if (!empty($interfaces[$ifdescr]['if'])) {
$known_interfaces[] = $interfaces[$ifdescr]['if'];
}
$interfaces[$ifdescr]['ifv6'] = get_real_interface($ifdescr, 'inet6');
if (!empty($interfaces[$ifdescr]['ifv6'])) {
$known_interfaces[] = $interfaces[$ifdescr]['ifv6'];
}
}
if ($include_unlinked) {
$unassigned_descr = gettext("Unassigned");
foreach ($all_intf_details as $if => $ifdata) {
if (!in_array($if, $known_interfaces)) {
$interfaces[$if] = ["descr" => $unassigned_descr, "if" => $if, "ifv6" => $if, 'unassigned' => true];
}
}
}
foreach ($interfaces as $ifdescr => $ifinfo) {
$ifinfo['status'] = in_array($ifinfo['if'], $ifup) ? 'up' : 'down';
$ifinfo['statusv6'] = in_array($ifinfo['ifv6'], $ifup) ? 'up' : 'down';
/* undesired side effect of legacy_config_get_interfaces() */
$ifinfo['ipaddr'] = $ifinfo['ipaddrv6'] = null;
if (!empty($all_intf_details[$ifinfo['if']])) {
if (
isset($all_intf_details[$ifinfo['if']]['status']) &&
in_array($all_intf_details[$ifinfo['if']]['status'], array('active', 'running'))
) {
$all_intf_details[$ifinfo['if']]['status'] = $ifinfo['status'];
}
$ifinfo = array_merge($ifinfo, $all_intf_details[$ifinfo['if']]);
}
if (!empty($ifinfo['ipv4'])) {
list ($primary4,, $bits4) = interfaces_primary_address($ifdescr, $all_intf_details);
if (!empty($primary4)) {
$ifinfo['ipaddr'] = $primary4;
$ifinfo['subnet'] = $bits4;
} else {
$ifinfo['ipaddr'] = $ifinfo['ipv4'][0]['ipaddr'];
$ifinfo['subnet'] = $ifinfo['ipv4'][0]['subnetbits'];
}
}
if (!empty($all_intf_details[$ifinfo['ifv6']]['ipv6'])) {
/* rewrite always as it can be a different interface */
$ifinfo['ipv6'] = $all_intf_details[$ifinfo['ifv6']]['ipv6'];
} elseif ($ifinfo['if'] != !$ifinfo['ifv6']) {
/* clear on a mismatch to avoid wrong data here */
$ifinfo['ipv6'] = [];
}
if (!empty($ifinfo['ipv6'])) {
list ($primary6,, $bits6) = interfaces_primary_address6($ifdescr, $all_intf_details);
if (!empty($primary6)) {
$ifinfo['ipaddrv6'] = $primary6;
$ifinfo['subnetv6'] = $bits6;
}
foreach ($ifinfo['ipv6'] as $ipv6addr) {
if (!empty($ipv6addr['link-local'])) {
$ifinfo['linklocal'] = $ipv6addr['ipaddr'];
} elseif (empty($ifinfo['ipaddrv6'])) {
$ifinfo['ipaddrv6'] = $ipv6addr['ipaddr'];
$ifinfo['subnetv6'] = $ipv6addr['subnetbits'];
}
}
$aux = shell_safe('/usr/local/sbin/ifctl -6pi %s', $ifinfo['ifv6']);
if (!empty($aux)) {
$ifinfo['prefixv6'] = explode("\n", $aux);
}
}
$ifinfotmp = $all_intf_stats[$ifinfo['if']];
$ifinfo['inbytes'] = $ifinfotmp['bytes received'];
$ifinfo['outbytes'] = $ifinfotmp['bytes transmitted'];
$ifinfo['inpkts'] = $ifinfotmp['packets received'];
$ifinfo['outpkts'] = $ifinfotmp['packets transmitted'];
$ifinfo['inerrs'] = $ifinfotmp['input errors'];
$ifinfo['outerrs'] = $ifinfotmp['output errors'];
$ifinfo['collisions'] = $ifinfotmp['collisions'];
$link_type = $config['interfaces'][$ifdescr]['ipaddr'] ?? 'none';
switch ($link_type) {
case 'dhcp':
$ifinfo['dhcplink'] = isvalidpid("/var/run/dhclient.{$ifinfo['if']}.pid") ? 'up' : 'down';
break;
/* PPPoE/PPTP/L2TP interface? -> get status from virtual interface */
case 'pppoe':
case 'pptp':
case 'l2tp':
if ($ifinfo['status'] == "up") {
/* XXX get PPPoE link status for dial on demand */
$ifinfo["{$link_type}link"] = "up";
} else {
$ifinfo["{$link_type}link"] = "down";
}
break;
/* PPP interface? -> get uptime for this session and cumulative uptime from the persistent log file in conf */
case 'ppp':
if ($ifinfo['status'] == "up") {
$ifinfo['ppplink'] = "up";
} else {
$ifinfo['ppplink'] = "down";
}
if (empty($ifinfo['status'])) {
$ifinfo['status'] = "down";
}
if (isset($config['ppps']['ppp'])) {
foreach ($config['ppps']['ppp'] as $pppid => $ppp) {
if ($config['interfaces'][$ifdescr]['if'] == $ppp['if']) {
break;
}
}
}
if ($config['interfaces'][$ifdescr]['if'] != $ppp['if'] || empty($ppp['ports'])) {
break;
}
if (!file_exists($ppp['ports'])) {
$ifinfo['nodevice'] = 1;
$ifinfo['pppinfo'] = $ppp['ports'] . " " . gettext("device not present! Is the modem attached to the system?");
}
// Calculate cumulative uptime for PPP link. Useful for connections that have per minute/hour contracts so you don't go over!
if (isset($ppp['uptime'])) {
$ifinfo['ppp_uptime_accumulated'] = "(" . get_ppp_uptime($ifinfo['if']) . ")";
}
break;
default:
break;
}
if (file_exists("/var/run/{$link_type}_{$ifdescr}.pid")) {
$sec = intval(shell_safe('/usr/local/opnsense/scripts/interfaces/ppp-uptime.sh %s', $ifinfo['if']));
if ($sec) {
$ifinfo['ppp_uptime'] = convert_seconds_to_hms($sec);
}
}
switch ($config['interfaces'][$ifdescr]['ipaddrv6'] ?? 'none') {
case 'dhcp6':
$ifinfo['dhcp6link'] = isvalidpid('/var/run/dhcp6c.pid') && file_exists("/var/etc/dhcp6c_{$ifdescr}.conf") ? 'up' : 'down';
break;
/* XXX more to do here in the future */
default:
break;
}
if ($ifinfo['status'] == "up") {
$wifconfiginfo = array();
if (isset($config['interfaces'][$ifdescr]['wireless'])) {
exec("/sbin/ifconfig {$ifinfo['if']} list sta", $wifconfiginfo);
array_shift($wifconfiginfo);
}
foreach ($wifconfiginfo as $ici) {
$elements = preg_split("/[ ]+/i", $ici);
if ($elements[0] != "") {
$ifinfo['bssid'] = $elements[0];
}
if ($elements[3] != "") {
$ifinfo['rate'] = $elements[3];
}
if ($elements[4] != "") {
$ifinfo['rssi'] = $elements[4];
}
}
$gateway = $gateways->getInterfaceGateway($ifdescr, 'inet');
if (!empty($gateway)) {
$ifinfo['gateway'] = $gateway;
}
$gatewayv6 = $gateways->getInterfaceGateway($ifdescr, 'inet6');
if (!empty($gatewayv6)) {
$ifinfo['gatewayv6'] = $gatewayv6;
}
}
$bridge = link_interface_to_bridge($ifdescr);
if ($bridge) {
$bridge_text = shell_safe('/sbin/ifconfig %s', $bridge);
if (stristr($bridge_text, 'blocking') != false) {
$ifinfo['bridge'] = "<b><span class='text-danger'>" . gettext("blocking") . "</span></b> - " . gettext("check for ethernet loops");
$ifinfo['bridgeint'] = $bridge;
} elseif (stristr($bridge_text, 'learning') != false) {
$ifinfo['bridge'] = gettext("learning");
$ifinfo['bridgeint'] = $bridge;
} elseif (stristr($bridge_text, 'forwarding') != false) {
$ifinfo['bridge'] = gettext("forwarding");
$ifinfo['bridgeint'] = $bridge;
}
}
$result[$ifdescr] = $ifinfo;
}
return $result;
}
function convert_seconds_to_hms($sec)
{
$min = $hrs = 0;
@ -4165,126 +3951,6 @@ function convert_seconds_to_hms($sec)
return $result;
}
function huawei_rssi_to_string($rssi)
{
$dbm = array();
$i = 0;
$dbstart = -113;
while ($i < 32) {
$dbm[$i] = $dbstart + ($i * 2);
$i++;
}
$percent = round(($rssi / 31) * 100);
$string = "rssi:{$rssi} level:{$dbm[$rssi]}dBm percent:{$percent}%";
return $string;
}
function huawei_mode_to_string($mode, $submode)
{
$modes[0] = "None";
$modes[1] = "AMPS";
$modes[2] = "CDMA";
$modes[3] = "GSM/GPRS";
$modes[4] = "HDR";
$modes[5] = "WCDMA";
$modes[6] = "GPS";
$submodes[0] = "No Service";
$submodes[1] = "GSM";
$submodes[2] = "GPRS";
$submodes[3] = "EDGE";
$submodes[4] = "WCDMA";
$submodes[5] = "HSDPA";
$submodes[6] = "HSUPA";
$submodes[7] = "HSDPA+HSUPA";
$submodes[8] = "TD-SCDMA";
$submodes[9] = "HSPA+";
$string = "{$modes[$mode]}, {$submodes[$submode]} Mode";
return $string;
}
function huawei_service_to_string($state)
{
$modes[0] = "No";
$modes[1] = "Restricted";
$modes[2] = "Valid";
$modes[3] = "Restricted Regional";
$modes[4] = "Powersaving";
$string = "{$modes[$state]} Service";
return $string;
}
function huawei_simstate_to_string($state)
{
$modes[0] = "Invalid SIM/locked";
$modes[1] = "Valid SIM";
$modes[2] = "Invalid SIM CS";
$modes[3] = "Invalid SIM PS";
$modes[4] = "Invalid SIM CS/PS";
$modes[255] = "Missing SIM";
$string = "{$modes[$state]} State";
return $string;
}
function zte_rssi_to_string($rssi)
{
return huawei_rssi_to_string($rssi);
}
function zte_mode_to_string($mode, $submode)
{
$modes[0] = "No Service";
$modes[1] = "Limited Service";
$modes[2] = "GPRS";
$modes[3] = "GSM";
$modes[4] = "UMTS";
$modes[5] = "EDGE";
$modes[6] = "HSDPA";
$submodes[0] = "CS_ONLY";
$submodes[1] = "PS_ONLY";
$submodes[2] = "CS_PS";
$submodes[3] = "CAMPED";
$string = "{$modes[$mode]}, {$submodes[$submode]} Mode";
return $string;
}
function zte_service_to_string($state)
{
$modes[0] = "Initializing";
$modes[1] = "Network Lock error";
$modes[2] = "Network Locked";
$modes[3] = "Unlocked or correct MCC/MNC";
$string = "{$modes[$state]} Service";
return $string;
}
function zte_simstate_to_string($state)
{
$modes[0] = "No action";
$modes[1] = "Network lock";
$modes[2] = "(U)SIM card lock";
$modes[3] = "Network Lock and (U)SIM card Lock";
$string = "{$modes[$state]} State";
return $string;
}
/* Compute the total uptime from the ppp uptime log file in the conf directory */
function get_ppp_uptime($port)
{
if (file_exists("/conf/{$port}.log")) {
$saved_time = file_get_contents("/conf/{$port}.log");
$uptime_data = explode("\n", $saved_time);
$sec = 0;
foreach ($uptime_data as $upt) {
$sec += intval(substr($upt, 1 + strpos($upt, ' ')));
}
return convert_seconds_to_hms($sec);
}
return gettext('No history data found!');
}
/****f* legacy/is_ipaddr_configured
* NAME
* is_ipaddr_configured

View File

@ -497,7 +497,8 @@
<page-status-interfaces>
<name>Status: Interfaces</name>
<patterns>
<pattern>status_interfaces.php*</pattern>
<pattern>ui/interfaces/overview</pattern>
<pattern>api/interfaces/overview/*</pattern>
</patterns>
</page-status-interfaces>
<page-status-openvpn>

View File

@ -98,8 +98,7 @@
</System>
<Interfaces order="30" cssClass="fa fa-sitemap">
<Assignments order="900" url="/interfaces_assign.php" cssClass="fa fa-pencil fa-fw"/>
<Overview order="910" url="/status_interfaces.php" cssClass="fa fa-tasks fa-fw"/>
<Overview_new VisibleName="Overview [new]" order="915" url="/ui/interfaces/overview" cssClass="fa fa-tasks fa-fw"/>
<Overview VisibleName="Overview" order="910" url="/ui/interfaces/overview" cssClass="fa fa-tasks fa-fw"/>
<Settings order="920" url="/system_advanced_network.php" cssClass="fa fa-cogs fa-fw"/>
<Neighbors order="930" url="/ui/interfaces/neighbor" cssClass="fa fa-users fa-fw"/>
<Wireless order="940" cssClass="fa fa-wifi fa-fw">

View File

@ -1,78 +0,0 @@
#!/usr/local/bin/python3
"""
Copyright (c) 2017-2019 Ad Schellevis <ad@opnsense.org>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------------
list pf byte/packet counter
"""
import tempfile
import subprocess
import os
import sys
import ujson
if __name__ == '__main__':
result = dict()
sp = subprocess.run(['/sbin/pfctl', '-vvsI'], capture_output=True, text=True)
intf = None
for line in sp.stdout.strip().split('\n'):
if line.find('[') == -1 and len(line) > 0 and line[0] not in (' ', '\t'):
intf = line.strip()
result[intf] = {'inbytespass': 0, 'outbytespass': 0, 'inpktspass': 0, 'outpktspass': 0,
'inbytesblock': 0, 'outbytesblock': 0, 'inpktsblock': 0, 'outpktsblock': 0,
'inpkts':0, 'inbytes': 0, 'outpkts': 0, 'outbytes': 0}
if intf is not None and line.find('[') > -1:
packets = int(line.split(' Packets:')[-1].strip().split()[0])
bytes = int(line.split(' Bytes:')[-1].strip().split()[0])
if line.find('In4/Pass:') > -1 or line.find('In6/Pass:') > -1:
result[intf]['inpktspass'] += packets
result[intf]['inbytespass'] += bytes
result[intf]['inpkts'] += packets
result[intf]['inbytes'] += bytes
elif line.find('In4/Block:') > -1 or line.find('In6/Block:') > -1:
result[intf]['inbytesblock'] += packets
result[intf]['inpktsblock'] += bytes
result[intf]['inpkts'] += packets
result[intf]['inbytes'] += bytes
elif line.find('Out4/Pass:') > -1 or line.find('Out6/Pass:') > -1:
result[intf]['outpktspass'] += packets
result[intf]['outbytespass'] += bytes
result[intf]['outpkts'] += packets
result[intf]['outbytes'] += bytes
elif line.find('Out4/Block:') > -1 or line.find('Out6/Block:') > -1:
result[intf]['outpktsblock'] += packets
result[intf]['outbytesblock'] += bytes
result[intf]['outpkts'] += packets
result[intf]['outbytes'] += bytes
# handle command line argument (type selection)
if len(sys.argv) > 1 and sys.argv[1] == 'json':
print(ujson.dumps(result))
else:
# output plain
print('------------------------- COUNTERS -------------------------')
for intf in result:
print('[%s] %s' % (intf, result[intf]))

View File

@ -1,71 +0,0 @@
#!/usr/local/bin/python3
"""
Copyright (c) 2017-2019 Ad Schellevis <ad@opnsense.org>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------------------
list device interrupts stats
"""
import subprocess
import sys
import ujson
if __name__ == '__main__':
result = dict()
sp = subprocess.run(['/usr/bin/vmstat', '-i'], capture_output=True, text=True)
intf = None
interrupts = dict()
interrupt_map = dict()
for line in sp.stdout.split("\n"):
if line.find(':') > -1:
intrp = line.split(':')[0].strip()
parts = ':'.join(line.split(':')[1:]).split()
interrupts[intrp] = {'devices': [], 'total': None, 'rate': None}
for part in parts:
if not part.isdigit():
interrupts[intrp]['devices'].append(part)
devnm = part.split(':')[0]
if devnm not in interrupt_map:
interrupt_map[devnm] = list()
interrupt_map[devnm].append(intrp)
elif interrupts[intrp]['total'] is None:
interrupts[intrp]['total'] = int(part)
else:
interrupts[intrp]['rate'] = int(part)
result['interrupts'] = interrupts # interrupts as reported by vmstat
result['interrupt_map'] = interrupt_map # link device to interrupt
# handle command line argument (type selection)
if len(sys.argv) > 1 and sys.argv[1] == 'json':
print(ujson.dumps(result))
else:
# output plain
if 'interrupts' in result:
for intr in result['interrupts']:
print ('%-10s [%-20s] %-10d %d' % (intr,
','.join(result['interrupts'][intr]['devices']),
result['interrupts'][intr]['total'],
result['interrupts'][intr]['rate']
))

View File

@ -53,12 +53,6 @@ parameters: %s
type:script_output
message:request pfsync info
[list.counters]
command:/usr/local/opnsense/scripts/filter/list_counters.py
parameters: %s
type:script_output
message:request pfctl byte/packet counters
[read.log]
command:/usr/local/opnsense/scripts/filter/read_log.py
parameters: /limit %s /digest %s

View File

@ -22,12 +22,6 @@ parameters:-m%s -f%s
type:script
message:clear log (%s %s)
[list.interrupts]
command:/usr/local/opnsense/scripts/system/list_interrupts.py
parameters:%s
type:script_output
message:Request vmstat interrupt counters
[sysctl]
command:/usr/local/opnsense/scripts/system/sysctl.py
parameters:

View File

@ -1,521 +0,0 @@
<?php
/*
* Copyright (C) 2014-2015 Deciso B.V.
* Copyright (C) 2009 Scott Ullrich <sullrich@gmail.com>
* Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
require_once("guiconfig.inc");
require_once("system.inc");
require_once("interfaces.inc");
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!empty($_POST['if']) && !empty($_POST['submit'])) {
$interface = $_POST['if'];
if ($_POST['submit'] == 'remote') {
configdp_run('interface reconfigure', array($interface));
} elseif (!empty($_POST['status']) && $_POST['status'] == 'up') {
interface_suspend($interface);
} else {
interface_configure(false, $interface, true);
}
header(url_safe('Location: /status_interfaces.php'));
exit;
}
}
include("head.inc");
?>
<body>
<script>
$( document ).ready(function() {
$("#collapse_all").click(function(){
$(".interface_details").collapse('toggle');
});
});
</script>
<style>
.is_unassigned {
font-style: italic;
}
</style>
<?php include("fbegin.inc"); ?>
<section class="page-content-main">
<div class="container-fluid">
<div class="row">
<section class="col-xs-12">
<?php
$mac_man = json_decode(configd_run('interface list macdb'), true);
$pfctl_counters = json_decode(configd_run('filter list counters json'), true);
$vmstat_interrupts = json_decode(configd_run('system list interrupts json'), true);
foreach (get_interfaces_info(true) as $ifdescr => $ifinfo):
if ($ifinfo['if'] == 'pfsync0') {
continue;
}
$ifpfcounters = $pfctl_counters[$ifinfo['if']];
legacy_html_escape_form_data($ifinfo);
$ifdescr = htmlspecialchars($ifdescr);
$ifname = htmlspecialchars($ifinfo['descr']);
?>
<div class="tab-content content-box col-xs-12 __mb">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th class="<?= !empty($ifinfo['unassigned']) ? 'is_unassigned' : ''?>" style="cursor: pointer; width: 100%" data-toggle="collapse" data-target="#status_interfaces_<?=$ifdescr?>">
<i class="fa fa-chevron-down" style="margin-right: .4em; float: left"></i>
<?= $ifname ?> <?= gettext("interface") ?>
<?php
if ($ifdescr != $ifinfo['if']):?>
(<?= $ifdescr ?>, <?= htmlspecialchars($ifinfo['if']) ?>)
<?php
else:?>
(<?= $ifdescr ?>)
<?php
endif;?>
</th>
<?php
if (!isset($first_row)):
$first_row = false; ?>
<th id="collapse_all" style="cursor: pointer; padding-left: .5em; padding-right: .5em" data-toggle="tooltip" title="<?= gettext("collapse/expand all") ?>">
<div class="pull-right">
<i class="fa fa-expand"></i>
</div>
</th>
<?php
endif;?>
</tr>
</thead>
</table>
</div>
<div class="interface_details collapse table-responsive" id="status_interfaces_<?=$ifdescr?>">
<table class="table table-striped">
<tbody>
<tr>
<td style="width:22%"><?= gettext("Status") ?></td>
<td style="width:78%"><?= $ifinfo['status'] ?>
<?php if (empty($ifinfo['enable'])): ?>
<i class="fa fa-warning" title="<?=gettext("administrative disabled");?>" data-toggle="tooltip"></i>
<?php endif ?>
</td>
</tr>
<?php if ((!empty($ifinfo['dhcplink']) || !empty($ifinfo['dhcp6link'])) && !empty($ifinfo['enable'])): ?>
<tr>
<td> <?=gettext("DHCP");?></td>
<td>
<form name="dhcplink_form" method="post">
<input type="hidden" name="if" value="<?= $ifdescr ?>" />
<input type="hidden" name="status" value="<?= ($ifinfo['dhcplink'] == "up" || $ifinfo['dhcp6link'] == "up") ? gettext("up") : gettext("down") ?>" />
<?php if (!empty($ifinfo['dhcplink'])): ?>
<?= gettext("DHCPv4 ") ?><?= $ifinfo['dhcplink'] ?>&nbsp;&nbsp;
<?php endif ?>
<?php if (!empty($ifinfo['dhcp6link'])): ?>
<?= gettext("DHCPv6 ") ?><?= $ifinfo['dhcp6link'] ?>&nbsp;&nbsp;
<?php endif ?>
<button type="submit" name="submit" class="btn btn-primary btn-xs" value="remote"><?= gettext('Reload') ?></button>
<button type="submit" name="submit" class="btn btn-xs" value="local"><?= ($ifinfo['dhcplink'] == "up" || $ifinfo['dhcp6link'] == "up") ? gettext("Release") : gettext("Renew") ?></button>
</form>
</td>
</tr>
<?php endif ?>
<?php if (!empty($ifinfo['pppoelink']) && !empty($ifinfo['enable'])): ?>
<tr>
<td><?=gettext("PPPoE"); ?></td>
<td>
<form name="pppoelink_form" method="post">
<input type="hidden" name="if" value="<?= $ifdescr ?>" />
<input type="hidden" name="status" value="<?= $ifinfo['pppoelink'] ?>" />
<?= $ifinfo['pppoelink'] ?>&nbsp;&nbsp;
<button type="submit" name="submit" class="btn btn-primary btn-xs" value="remote"><?= gettext('Reload') ?></button>
<button type="submit" name="submit" class="btn btn-xs" value="local"><?= $ifinfo['pppoelink'] == "up" ? gettext("Disconnect") : gettext("Connect") ?></button>
</form>
</td>
</tr>
<?php endif ?>
<?php if (!empty($ifinfo['pptplink']) && !empty($ifinfo['enable'])): ?>
<tr>
<td><?= gettext("PPTP") ?></td>
<td>
<form name="pptplink_form" method="post">
<input type="hidden" name="if" value="<?= $ifdescr ?>" />
<input type="hidden" name="status" value="<?= $ifinfo['pptplink'] ?>" />
<?= $ifinfo['pptplink'] ?>&nbsp;&nbsp;
<button type="submit" name="submit" class="btn btn-primary btn-xs" value="remote"><?= gettext('Reload') ?></button>
<button type="submit" name="submit" class="btn btn-xs" value="local"><?= $ifinfo['pptplink'] == "up" ? gettext("Disconnect") : gettext("Connect") ?></button>
</form>
</td>
</tr>
<?php endif ?>
<?php if (!empty($ifinfo['l2tplink']) && !empty($ifinfo['enable'])): ?>
<tr>
<td><?=gettext("L2TP"); ?></td>
<td>
<form name="l2tplink_form" method="post">
<input type="hidden" name="if" value="<?= $ifdescr ?>" />
<input type="hidden" name="status" value="<?= $ifinfo['l2tplink'] ?>" />
<?=$ifinfo['l2tplink'];?>&nbsp;&nbsp;
<button type="submit" name="submit" class="btn btn-primary btn-xs" value="remote"><?= gettext('Reload') ?></button>
<button type="submit" name="submit" class="btn btn-xs" value="local"><?= $ifinfo['l2tplink'] == "up" ? gettext("Disconnect") : gettext("Connect") ?></button>
</form>
</td>
</tr>
<?php endif ?>
<?php if (!empty($ifinfo['ppplink']) && !empty($ifinfo['enable'])): ?>
<tr>
<td><?=gettext("PPP"); ?></td>
<td>
<form name="ppplink_form" method="post">
<input type="hidden" name="if" value="<?= $ifdescr ?>" />
<input type="hidden" name="status" value="<?= $ifinfo['ppplink'] ?>" />
<?= $ifinfo['pppinfo'] ?>
<button type="submit" name="submit" class="btn btn-primary btn-xs" value="remote"><?= gettext('Reload') ?></button>
<?php if ($ifinfo['ppplink'] == "up"): ?>
<button type="submit" name="submit" class="btn btn-xs" value="local"><?= gettext("Disconnect") ?></button>
<?php elseif (!$ifinfo['nodevice']): ?>
<button type="submit" name="submit" class="btn btn-xs" value="local"><?= gettext("Connect") ?></button>
<?php endif ?>
</form>
</td>
</tr>
<?php endif ?>
<?php if (!empty($ifinfo['ppp_uptime']) || !empty($ifinfo['ppp_uptime_accumulated'])): ?>
<tr>
<td><?= empty($ifinfo['ppp_uptime_accumulated']) ? gettext("Uptime") : gettext("Uptime (historical)") ?></td>
<td><?= $ifinfo['ppp_uptime_accumulated'] ?> <?= $ifinfo['ppp_uptime'] ?></td>
</tr>
<?php endif ?>
<?php if ($ifinfo['macaddr']): ?>
<tr>
<td><?=gettext("MAC address");?></td>
<td>
<?php
$mac=$ifinfo['macaddr'];
$mac_hi = strtoupper($mac[0] . $mac[1] . $mac[3] . $mac[4] . $mac[6] . $mac[7]);
if(isset($mac_man[$mac_hi])){ print "<span>" . $mac . " - " . htmlspecialchars($mac_man[$mac_hi]); print "</span>"; }
else {print htmlspecialchars($mac);}
?>
</td>
</tr>
<?php endif ?>
<?php if ($ifinfo['mtu']): ?>
<tr>
<td><?=gettext("MTU");?></td>
<td>
<?=$ifinfo['mtu'];?>
</td>
</tr>
<?php endif ?>
<?php if ($ifinfo['status'] != 'down'):
if (($ifinfo['dhcplink'] ?? '') != 'down' && ($ifinfo['pppoelink'] ?? '') != 'down' && ($ifinfo['pptplink'] ?? '') != 'down'):
if (!empty($ifinfo['ipaddr']) /* set by get_interfaces_info() if active but not directly used */):?>
<tr>
<td><?= gettext("IPv4 address") ?></td>
<td>
<?php foreach($ifinfo['ipv4'] as $ipv4): ?>
<?=$ipv4['ipaddr'];?>/<?=$ipv4['subnetbits'];?> <?= !empty($ipv4['vhid']) ? 'vhid ' . $ipv4['vhid'] : "" ;?>
<br/>
<?php endforeach ?>
</td>
</tr>
<?php
endif;
if (!empty($ifinfo['gateway'])): ?>
<tr>
<td><?= gettext('IPv4 gateway') ?></td>
<td><?= htmlspecialchars(!empty($config['interfaces'][$ifdescr]['gateway']) ? $config['interfaces'][$ifdescr]['gateway'] : gettext('auto-detected')) ?>: <?= $ifinfo['gateway'] ?></td>
</tr>
<?php
endif;
if (!empty($ifinfo['linklocal'])): ?>
<tr>
<td><?= gettext("IPv6 link-local") ?></td>
<td><?= $ifinfo['linklocal'] ?>/64
</tr>
<?php
endif;
if (!empty($ifinfo['ipaddrv6']) /* set by get_interfaces_info() if active but not directly used */ &&
!empty($ifinfo['ipv6'][0]) && !$ifinfo['ipv6'][0]['link-local']): ?>
<tr>
<td><?= gettext("IPv6 address") ?></td>
<td>
<?php
foreach($ifinfo['ipv6'] as $ipv6):
if (!$ipv6['link-local']):?>
<?=$ipv6['ipaddr'];?>/<?=$ipv6['subnetbits'];?> <?= !empty($ipv6['vhid']) ? 'vhid ' . $ipv6['vhid'] : "" ;?> <?= $ipv6['deprecated'] ? 'deprecated' : '' ?>
<br />
<?php
endif;
endforeach;?>
</td>
</tr>
<?php endif ?>
<?php if (array_key_exists('prefixv6', $ifinfo)): ?>
<tr>
<td><?= gettext('IPv6 prefix') ?></td>
<td><?= implode('<br />', $ifinfo['prefixv6']) ?></td>
</tr>
<?php endif ?>
<?php if (!empty($ifinfo['gatewayv6'])): ?>
<tr>
<td><?= gettext('IPv6 gateway') ?></td>
<td><?= htmlspecialchars(!empty($config['interfaces'][$ifdescr]['gatewayv6']) ? $config['interfaces'][$ifdescr]['gatewayv6'] : gettext('auto-detected')) ?>: <?= $ifinfo['gatewayv6'] ?></td>
</tr>
<?php
endif;
$dnsall = get_nameservers($ifdescr);
if (count($dnsall)): ?>
<tr>
<td><?= gettext("DNS servers") ?></td>
<td><?= implode('<br />', $dnsall) ?></td>
</tr>
<?php
endif;
endif;
if (!empty($ifinfo['media'])): ?>
<tr>
<td><?= gettext("Media") ?></td>
<td><?= $ifinfo['media'] ?></td>
</tr>
<?php
endif;
if (!empty($ifinfo['laggproto'])):?>
<tr>
<td><?= gettext("LAGG Protocol") ?></td>
<td><?= $ifinfo['laggproto'] ?></td>
</tr>
<?php
endif;
if (!empty($ifinfo['laggoptions'])):?>
<tr>
<td><?= gettext("LAGG Options") ?></td>
<td>
<?= gettext("flags") ?>=<?= implode(",", $ifinfo['laggoptions']['flags']) ?><br/>
<?php
if (!empty($ifinfo['lagghash'])):?>
<?= gettext("lagghash") ?>=<?=$ifinfo['lagghash'] ?><br/>
<?php
endif;?>
<?= gettext("flowid_shift") ?>:<?=$ifinfo['laggoptions']['flowid_shift'] ?>
<?php
if (!empty($ifinfo['laggoptions']['rr_limit'])):?>
<br/><?= gettext("rr_limit") ?>:<?=$ifinfo['laggoptions']['rr_limit'] ?>
<?php
endif;?>
</td>
</tr>
<?php
endif;
if (!empty($ifinfo['laggstatistics'])):?>
<tr>
<td><?= gettext("LAGG Statistics") ?></td>
<td>
<?= gettext("active ports") ?>:<?= $ifinfo['laggstatistics']['active ports'] ?><br/>
<?= gettext("flapping") ?>:<?= $ifinfo['laggstatistics']['flapping'] ?></td>
</tr>
<?php
endif;
if (!empty($ifinfo['laggport']) && is_array($ifinfo['laggport'])): ?>
<tr>
<td><?=gettext("LAGG Ports");?></td>
<td>
<?php foreach ($ifinfo['laggport'] as $laggport => $laggport_info): ?>
<?= $laggport ?>
<?=gettext('flags')?>=&lt;<?=implode(",", $laggport_info['flags'])?>&gt;
<?=gettext('state')?>=&lt;<?=implode(",", $laggport_info['state'])?>&gt;
<br />
<?php endforeach; ?>
</td>
</tr>
<?php
endif;
if (!empty($ifinfo['channel'])): ?>
<tr>
<td><?= gettext("Channel") ?></td>
<td><?= $ifinfo['channel'] ?></td>
</tr>
<?php
endif;
if (!empty($ifinfo['ssid'])):?>
<tr>
<td><?= gettext("SSID") ?></td>
<td><?= $ifinfo['ssid'] ?></td>
</tr>
<?php
endif;
if (!empty($ifinfo['bssid'])):?>
<tr>
<td><?= gettext("BSSID") ?></td>
<td><?= $ifinfo['bssid'] ?></td>
</tr>
<?php
endif;
if (!empty($ifinfo['rate'])):?>
<tr>
<td><?= gettext("Rate") ?></td>
<td><?= $ifinfo['rate'] ?></td>
</tr>
<?php
endif;
if (!empty($ifinfo['rssi'])): ?>
<tr>
<td><?= gettext("RSSI") ?></td>
<td><?= $ifinfo['rssi'] ?></td>
</tr>
<?php
endif; ?>
<tr>
<td><?= gettext("In/out packets") ?></td>
<td class="text-nowrap"> <?= $ifpfcounters['inpkts'] ?> / <?= $ifpfcounters['outpkts'] ?>
(<?= format_bytes($ifpfcounters['inbytes']);?> / <?=format_bytes($ifpfcounters['outbytes']);?>)
</td>
</tr>
<tr>
<td><?= gettext("In/out packets (pass)") ?></td>
<td class="text-nowrap"> <?= $ifpfcounters['inpktspass'] ?> / <?= $ifpfcounters['outpktspass'] ?>
(<?= format_bytes($ifpfcounters['inbytespass']) ?> / <?= format_bytes($ifpfcounters['outbytespass']) ?>)
</td>
</tr>
<tr>
<td><?= gettext("In/out packets (block)") ?></td>
<td class="text-nowrap"> <?= $ifpfcounters['inpktsblock'] ?> / <?= $ifpfcounters['outpktsblock'] ?>
(<?= format_bytes($ifpfcounters['inbytesblock']) ?> / <?= format_bytes($ifpfcounters['outbytesblock']) ?>)
</td>
</tr>
<?php
if (isset($ifinfo['inerrs'])): ?>
<tr>
<td><?= gettext("In/out errors") ?></td>
<td><?= $ifinfo['inerrs'] . ' / ' . $ifinfo['outerrs'] ?></td>
</tr>
<?php
endif;
if (isset($ifinfo['collisions'])): ?>
<tr>
<td><?= gettext("Collisions") ?></td>
<td><?= $ifinfo['collisions'] ?></td>
</tr>
<?php
endif;
endif;
if (!empty($ifinfo['bridge'])): ?>
<tr>
<td><?= sprintf(gettext('Bridge (%s)'), $ifinfo['bridgeint']) ?></td>
<td>
<?= $ifinfo['bridge'] ?>
</td>
</tr>
<?php
endif;
if (!empty($vmstat_interrupts['interrupt_map'][$ifinfo['if']])):
$intrpts = $vmstat_interrupts['interrupt_map'][$ifinfo['if']];?>
<tr>
<td><?= gettext("Interrupts") ?></td>
<td>
<table class="table table-condensed">
<thead>
<tr>
<th><?=gettext("irq");?></th>
<th><?=gettext("device");?></th>
<th><?=gettext("total");?></th>
<th><?=gettext("rate");?></th>
</tr>
</thead>
<?php
foreach ($intrpts as $intrpt):?>
<tr>
<td><?=$intrpt;?></td>
<td><?=implode(' ', $vmstat_interrupts['interrupts'][$intrpt]['devices']);?></td>
<td><?=$vmstat_interrupts['interrupts'][$intrpt]['total'];?></td>
<td><?=$vmstat_interrupts['interrupts'][$intrpt]['rate'];?></td>
</tr>
<?php
endforeach; ?>
</table>
</td>
</tr>
<?php
endif; ?>
<?php
if (!empty($ifinfo['carp'])):?>
<tr>
<td><?=gettext("CARP");?></td>
<td>
<table class="table table-condensed">
<thead>
<tr>
<th><?=gettext("status");?></th>
<th><?=gettext("vhid");?></th>
<th><?=gettext("advbase");?></th>
<th><?=gettext("advskew");?></th>
</tr>
</thead>
<tbody>
<?php
foreach($ifinfo['carp'] as $carpitem):?>
<tr>
<td><?=$carpitem['status'];?></td>
<td><?=$carpitem['vhid'];?></td>
<td><?=$carpitem['advbase'];?></td>
<td><?=$carpitem['advskew'];?></td>
</tr>
<?php
endforeach;?>
</tbody>
</table>
</td>
</tr>
<?php
endif;?>
</tbody>
</table>
</div>
</div>
<?php
endforeach; ?>
<div class="tab-content content-box col-xs-12 __mb">
<div class="table-responsive">
<table class="table table-striped">
<tr>
<td>
<?= gettext("Using dial-on-demand will bring the connection up again if any packet ".
"triggers it. To substantiate this point: disconnecting manually ".
"will not prevent dial-on-demand from making connections ".
"to the outside. Don't use dial-on-demand if you want to make sure that the line ".
"is kept disconnected.") ?>
</td>
</tr>
</table>
</div>
</div>
</section>
</div>
</div>
</section>
<?php include("foot.inc"); ?>