]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
ids-functions.pl: Add get_subscription_code() function.
authorStefan Schantl <stefan.schantl@ipfire.org>
Thu, 24 Mar 2022 20:17:08 +0000 (21:17 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Thu, 24 Mar 2022 20:17:08 +0000 (21:17 +0100)
This function can be used to obtain the subscription code of a given
configured provider.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
config/cfgroot/ids-functions.pl

index 61aecc250bba2ce1ab806582c39c7f18ed831926..6819d787933c17f73067898407ce1e863d2ffb98 100644 (file)
@@ -1607,6 +1607,34 @@ END
        close(FILE);
 }
 
+#
+## Function to get the subscription code of a configured provider.
+#
+sub get_subscription_code($) {
+       my ($provider) = @_;
+
+       my %configured_providers = ();
+
+       # Read-in providers settings file.
+       &General::readhasharray($providers_settings_file, \%configured_providers);
+
+       # Loop through the hash of configured providers.
+       foreach my $id (keys %configured_providers) {
+               # Assign nice human-readable values to the data fields.
+               my $provider_handle = $configured_providers{$id}[0];
+               my $subscription_code = $configured_providers{$id}[1];
+
+               # Check if the current processed provider is the requested one.
+               if ($provider_handle eq $provider) {
+                       # Return the obtained subscription code.
+                       return $subscription_code;
+               }
+       }
+
+       # No subscription code found - return nothing.
+       return;
+}
+
 #
 ## Function to get the ruleset date for a given provider.
 ##