]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - config/cfgroot/general-functions.pl
dns.cgi: Move grab_address_from_file function to general-functions.pl
[people/pmueller/ipfire-2.x.git] / config / cfgroot / general-functions.pl
index aefcfb6878442555edc1b73cdaf5ceb8793c88ef..8450194ce1035c21df7edbf41f5f3946443fd2c5 100644 (file)
@@ -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 = <FILE>;
+
+               # 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;