Add ability to resolve compatibility-level conditionals

https://sourceforge.net/p/webadmin/bugs/5653/
This commit is contained in:
Ilia Ross
2025-01-18 15:17:39 +02:00
parent 0928edaa08
commit 314d6c5efc
2 changed files with 19 additions and 1 deletions

View File

@ -89,7 +89,7 @@ print &ui_table_start($text{'general_title_others'}, "width=100%", 4);
&option_radios_freefield("mynetworks", 60, $text{'default'});
&option_select("mynetworks_style",
[ [ "", $text{'default'} ],
[ [ &resolve_current_value("mynetworks_style"), $text{'default'} ],
[ "subnet", $text{'opts_mynetworks_subnet'} ],
[ "class", $text{'opts_mynetworks_class'} ],
[ "host", $text{'opts_mynetworks_host'} ] ]);

View File

@ -163,6 +163,24 @@ if ($key) {
return $out;
}
# resolve_current_value(parameter_name)
# Returns the value of the parameter, with compatibility-level conditionals
sub resolve_current_value
{
my ($parameter_name) = @_;
my $raw_value = &get_current_value($parameter_name);
my $compatibility_level = &get_current_value("compatibility_level");
if ($raw_value =~ /\{\{\$compatibility_level\}\s*([<>=!]+)\s*\{(\d+)\}\s*\?\s*\{(.*?)\}\s*:\s*\{(.*?)\}\}/) {
my ($op, $lvl, $tval, $fval) = ($1, $2, $3, $4);
return undef if ($op !~ /^([<>]=?|==|!=)$/);
return eval "\$compatibility_level $op $lvl" ? $tval : $fval;
}
return $raw_value;
}
# if_default_value(parameter_name)
# returns if the value is the default value
sub if_default_value