mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-15 00:54:41 +00:00
Firewall/Alias, performance regression in get_alias_description, take 1: move to our static firewall class
This commit is contained in:
parent
ebbc086f11
commit
e639924c9b
@ -144,20 +144,5 @@ function legacy_move_config_list_items($source, $id, $items) {
|
||||
*/
|
||||
function get_alias_description($name)
|
||||
{
|
||||
// MVC defined aliases
|
||||
foreach ((new \OPNsense\Firewall\Alias())->aliasIterator() as $alias) {
|
||||
if ($alias['name'] == $name) {
|
||||
if (!empty($alias['descr'])) {
|
||||
return $alias['descr'];
|
||||
} elseif (!empty($alias['description'])) {
|
||||
return $alias['description'];
|
||||
} elseif (!empty($alias['content'])) {
|
||||
$tmp = array_slice(explode("\n", $alias['content']), 0, 10);
|
||||
asort($tmp);
|
||||
return implode("<br/>", $tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return OPNsense\Firewall\Util::aliasDescription($name);
|
||||
}
|
||||
|
||||
@ -113,6 +113,33 @@ class Util
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* return alias descriptions
|
||||
* @param string $name name
|
||||
* @return string
|
||||
*/
|
||||
public static function aliasDescription($name)
|
||||
{
|
||||
if (self::$aliasObject == null) {
|
||||
// Cache the alias object to avoid object creation overhead.
|
||||
self::$aliasObject = new Alias();
|
||||
}
|
||||
foreach (self::$aliasObject->aliasIterator() as $alias) {
|
||||
if ($alias['name'] == $name) {
|
||||
if (!empty($alias['descr'])) {
|
||||
return $alias['descr'];
|
||||
} elseif (!empty($alias['description'])) {
|
||||
return $alias['description'];
|
||||
} elseif (!empty($alias['content'])) {
|
||||
$tmp = array_slice(explode("\n", $alias['content']), 0, 10);
|
||||
asort($tmp);
|
||||
return implode("<br/>", $tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch port alias contents, other alias types are handled using tables so there usually no need
|
||||
* to know the contents within any of the scripts.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user