From 9702252470263975e972e9ea9be9a87bc5541de1 Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Wed, 8 Jan 2020 18:44:41 +0100 Subject: [PATCH] dns.cgi: Move grab_address_from_file function to general-functions.pl Signed-off-by: Stefan Schantl --- config/cfgroot/general-functions.pl | 31 +++++++++++++++++++++++++++ html/cgi-bin/dns.cgi | 33 +---------------------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/config/cfgroot/general-functions.pl b/config/cfgroot/general-functions.pl index aefcfb6878..8450194ce1 100644 --- a/config/cfgroot/general-functions.pl +++ b/config/cfgroot/general-functions.pl @@ -1177,4 +1177,35 @@ sub number_cpu_cores() { return $cores; } +# Tiny function to grab a single IP-address from a given file. +sub grab_address_from_file($) { + my ($file) = @_; + + my $address; + + # Check if the given file exists. + if(-f $file) { + # Open the file for reading. + open(FILE, $file) or die "Could not read from $file. $!\n"; + + # Read the address from the file. + $address = ; + + # Close filehandle. + close(FILE); + + # Remove newlines. + chomp($address); + + # Check if the obtained address is valid. + if (&validip($address)) { + # Return the address. + return $address; + } + } + + # Return nothing. + return; +} + 1; diff --git a/html/cgi-bin/dns.cgi b/html/cgi-bin/dns.cgi index 8094a3a0a2..450d5c4840 100755 --- a/html/cgi-bin/dns.cgi +++ b/html/cgi-bin/dns.cgi @@ -480,7 +480,7 @@ END # Loop through the array which stores the files. foreach my $file (@ISP_nameserver_files) { # Grab the address of the nameserver. - my $address = &grab_address_from_file($file); + my $address = &General::grab_address_from_file($file); # Check if we got an address. if ($address) { @@ -815,37 +815,6 @@ sub red_is_active () { } } -# Tiny function to grab an IP-address of a given file. -sub grab_address_from_file($) { - my ($file) = @_; - - my $address; - - # Check if the given file exists. - if(-f $file) { - # Open the file for reading. - open(FILE, $file) or die "Could not read from $file. $!\n"; - - # Read the address from the file. - $address = ; - - # Close filehandle. - close(FILE); - - # Remove newlines. - chomp($address); - - # Check if the obtained address is valid. - if (&General::validip($address)) { - # Return the address. - return $address; - } - } - - # Return nothing. - return; -} - # Function to check a given nameserver against propper work. sub check_nameserver($$$$) { my ($nameserver, $record, $proto, $tls_hostname) = @_; -- 2.39.2