openvpn: bring instances into server field

While here condense the input a little and show the default
port in case it was left empty.

PR: https://forum.opnsense.org/index.php?topic=35337.0
This commit is contained in:
Franco Fichtner 2023-08-14 12:11:22 +02:00
parent 0a4eacfb6a
commit ee4496702d

View File

@ -30,6 +30,7 @@ namespace OPNsense\OpenVPN\FieldTypes;
use OPNsense\Base\FieldTypes\BaseListField;
use OPNsense\Core\Config;
use OPNsense\OpenVPN\OpenVPN;
/**
* @package OPNsense\Base\FieldTypes
@ -47,11 +48,16 @@ class OpenVPNServerField extends BaseListField
isset(Config::getInstance()->object()->openvpn->$ref)
) {
foreach (Config::getInstance()->object()->openvpn->$ref as $server) {
$label = (string)$server->description ?? '';
$label .= ' ( ' . (string)$server->local_port . ' / ' . (string)$server->protocol . ' )';
$label = (string)$server->description ?? '';
$label .= ' (' . (string)$server->local_port . ' / ' . (string)$server->protocol . ')';
self::$internalCacheOptionList[(string)$server->vpnid] = $label;
}
}
foreach ((new OpenVPN())->Instances->Instance->iterateItems() as $node_uuid => $node) {
if ((string)$node->role == 'server') {
self::$internalCacheOptionList[$node_uuid] = (string)$node->description . ' (' . (!empty((string)$node->port) ? (string)$node->port : '1194') . ' / ' . strtoupper((string)$node->proto) . ')';
}
}
natcasesort(self::$internalCacheOptionList);
}
$this->internalOptionList = self::$internalCacheOptionList;