]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
ids-functions.pl: Update generate_dns_servers_file() function.
authorStefan Schantl <stefan.schantl@ipfire.org>
Thu, 9 Jan 2020 15:25:01 +0000 (16:25 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Thu, 9 Jan 2020 15:25:01 +0000 (16:25 +0100)
The function now uses the newly introduced get_nameservers() function
while generating the DNS servers file.

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

index 89ad90c2e3c292bbdca99ac0ecc239e976776f85..3fa19fab7b2fe2b3887051606b9f3ee0956b7fda 100644 (file)
@@ -702,40 +702,31 @@ sub generate_home_net_file() {
 # Function to generate and write the file which contains the configured and used DNS servers.
 #
 sub generate_dns_servers_file() {
-       # Open file which contains the current used DNS configuration.
-       open (FILE, "${General::swroot}/red/dns") or die "Could not read DNS configuration from ${General::swroot}/red/dns. $!\n";
-
-       # Read-in whole file content and store it in a temporary array.
-       my @file_content = split(' ', <FILE>);
-
-       # Close file handle.
-       close(FILE);
+       # Get the used DNS servers.
+       my @nameservers = &General::get_nameservers();
 
        # Format dns servers declaration.
        my $line = "\"\[";
 
-       # Check if the current DNS configuration is using the local recursor mode.
-       if ($file_content[0] eq "local" && $file_content[1] eq "recursor") {
-               # The responsible DNS servers on red are directly used, and because we are not able
-               # to specify each single DNS server address here, we currently have to thread each
-               # address which is not part of the HOME_NET as possible DNS server.
-               $line = "$line" . "!\$HOME_NET";
-
-       } else {
-               # Loop through the array which contains the file content.
-               foreach my $server (@file_content) {
-                       # Remove newlines.
-                       chomp($server);
-
+       # Check if the system has configured nameservers.
+       if (@nameservers) {
+               # Loop through the array of nameservers.
+               foreach my $server (@nameservers) {
                        # Add the DNS server to the line.
                        $line = "$line" . "$server";
 
                        # Check if the current DNS server was the last in the array.
-                       if ($server ne $file_content[-1]) {
+                       if ($server ne $nameservers[-1]) {
                                # Add "," for the next DNS server.
                                $line = "$line" . "\,";
                        }
                }
+       } else {
+               # The responsible DNS servers on red are directly used, and because we are not able
+               # to specify each single DNS server address here, we currently have to thread each
+               # address which is not part of the HOME_NET as possible DNS server.
+               $line = "$line" . "!\$HOME_NET";
+
        }
 
        # Close the line...