From 3c0746d90b0f6f1ff8e4166c43fa1be1b5fef6c6 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Tue, 10 Jul 2018 20:27:45 +0200 Subject: [PATCH] Firewall/alias, prefer mvc aliases in isAlias(), at the moment we need to keep scanning both (legacy,mvc) to make sure the migration can actually run. for https://github.com/opnsense/core/issues/1858 --- .../app/library/OPNsense/Firewall/Util.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/opnsense/mvc/app/library/OPNsense/Firewall/Util.php b/src/opnsense/mvc/app/library/OPNsense/Firewall/Util.php index 30b7b424f..375077c07 100644 --- a/src/opnsense/mvc/app/library/OPNsense/Firewall/Util.php +++ b/src/opnsense/mvc/app/library/OPNsense/Firewall/Util.php @@ -29,6 +29,7 @@ namespace OPNsense\Firewall; use \OPNsense\Core\Config; +use \OPNsense\Firewall\Alias; /** * Class Util, common static firewall support functions @@ -72,15 +73,27 @@ class Util * check if name exists in alias config section * @param string $name name * @return boolean + * @throws \OPNsense\Base\ModelException */ public static function isAlias($name) { - if (!empty($name) && !empty(Config::getInstance()->object()->aliases)) { - foreach (Config::getInstance()->object()->aliases->children() as $node) { - if ($node->name == $name) { + if (!empty($name) ){ + $aliasMdl = new Alias(); + // MVC defined aliases + foreach ($aliasMdl->aliases->alias->__items as $alias) { + if ((string)$alias->name == $name) { return true; } } + // legacy style aliases + $cnf = Config::getInstance()->object(); + if (!empty($cnf->aliases)) { + foreach ($cnf->aliases->children() as $node) { + if ($node->name == $name) { + return true; + } + } + } } return false; }