diff --git a/src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuSystem.php b/src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuSystem.php index 3e391f91b..07f67ae28 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuSystem.php +++ b/src/opnsense/mvc/app/models/OPNsense/Base/Menu/MenuSystem.php @@ -1,29 +1,30 @@ + * Copyright (C) 2015 Deciso B.V. + * All rights reserved. * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: + * 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. + * 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. + * 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. + * 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. */ namespace OPNsense\Base\Menu; @@ -196,8 +197,27 @@ class MenuSystem $config = Config::getInstance()->object(); // collect interfaces for dynamic (interface) menu tabs... - $iftargets = array("if" => array(), "wl" => array(), "fw" => array(), "dhcp4" => array(), "dhcp6" => array()); + $iftargets = ['if' => [], 'gr' => [], 'wl' => [], 'fw' => [], 'dhcp4' => [], 'dhcp6' => []]; + $ifgroups = []; + if ($config->interfaces->count() > 0) { + if ($config->ifgroups->count() > 0) { + foreach ($config->ifgroups->children() as $key => $node) { + if (empty($node->members)) { + continue; + } + /* we need both if and gr reference */ + $iftargets['if'][(string)$node->ifname] = (string)$node->ifname; + $iftargets['gr'][(string)$node->ifname] = (string)$node->ifname; + foreach (explode(' ', (string)$node->members) as $member) { + if (!array_key_exists($member, $ifgroups)) { + $ifgroups[$member] = []; + } + array_push($ifgroups[$member], (string)$node->ifname); + } + } + } + foreach ($config->interfaces->children() as $key => $node) { // Interfaces tab if (empty($node->virtual)) { @@ -227,15 +247,32 @@ class MenuSystem natcasesort($iftargets[$tab]); } - // add interfaces to "Interfaces" menu tab... + // add groups and interfaces to "Interfaces" menu tab... $ordid = 0; foreach ($iftargets['if'] as $key => $descr) { - $this->appendItem('Interfaces', $key, array( - 'url' => '/interfaces.php?if=' . $key, - 'visiblename' => '[' . $descr . ']', - 'cssclass' => 'fa fa-sitemap', - 'order' => $ordid++, - )); + if (array_key_exists($key, $iftargets['gr'])) { + $this->appendItem('Interfaces', $key, array( + 'visiblename' => '[' . $descr . ']', + 'cssclass' => 'fa fa-sitemap', + 'order' => $ordid++, + )); + } elseif (!array_key_exists($key, $ifgroups)) { + $this->appendItem('Interfaces', $key, array( + 'url' => '/interfaces.php?if=' . $key, + 'visiblename' => '[' . $descr . ']', + 'cssclass' => 'fa fa-sitemap', + 'order' => $ordid++, + )); + } + } + + foreach ($ifgroups as $key => $groupings) { + foreach ($groupings as $grouping) { + $this->appendItem('Interfaces.' . $grouping, $key, array( + 'url' => '/interfaces.php?if=' . $key, + 'visiblename' => '[' . $iftargets['if'][$key] . ']', + )); + } } $ordid = 100;