ids.cgi: Introduce and use get_provider_name() function.

This function is used to grab the name of a provider by the given
handle.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
This commit is contained in:
Stefan Schantl
2021-03-20 18:07:57 +01:00
parent fed57fe7f0
commit 019e5e9baf

View File

@@ -900,20 +900,10 @@ END
# Loop throgh the list of providers.
foreach my $provider (@ruleset_providers) {
my $option_string;
# Get the translation required string for the current provider.
my $tr_string = $IDS::Ruleset::Providers{$provider}{'tr_string'};
# Check if a translation string is available in the language files.
if ($Lang::tr{$tr_string}) {
# Use the translated string from the language file.
$option_string = $Lang::tr{$tr_string};
} else {
# Fallback and use the provider summary from the providers file.
$option_string = $IDS::Ruleset::Providers{$provider}{'summary'};
}
# Call get_provider_name function to obtain the provider name.
my $option_string = &get_provider_name($provider);
# Print option.
print "<option value='$provider' $selected{'RULES'}{$provider}>$option_string</option>\n";
}
print <<END;
@@ -1399,6 +1389,29 @@ sub read_enabled_disabled_sids_file($) {
return %temphash;
}
#
## Function to get the provider name from the language file or providers file for a given handle.
#
sub get_provider_name($) {
my ($handle) = @_;
my $provider_name;
# Get the required translation string for the given provider handle.
my $tr_string = $IDS::Ruleset::Providers{$handle}{'tr_string'};
# Check if the translation string is available in the language files.
if ($Lang::tr{$tr_string}) {
# Use the translated string from the language file.
$provider_name = $Lang::tr{$tr_string};
} else {
# Fallback and use the provider summary from the providers file.
$provider_name = $IDS::Ruleset::Providers{$handle}{'summary'};
}
# Return the obtained provider name.
return $provider_name;
}
#
## Private function to convert a given rulefile to a category name.
## ( No file extension anymore and if the name contained a dot, it