]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
Move GetDyndnsRedIP from general-functions.pl to
authorStefan Schantl <stefan.schantl@ipfire.org>
Fri, 18 Apr 2025 10:10:02 +0000 (12:10 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Fri, 18 Apr 2025 10:10:02 +0000 (12:10 +0200)
http-client-functions.pl

This function depends on the previously FetchPublicIp function
and so also has to be moved.

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

index 861f95decce2cc97d661696cbd3012dcbb514e8a..bbd0f9839fd8dcc1dd13af395e2f6762a2356207 100644 (file)
@@ -998,31 +998,6 @@ sub DyndnsServiceSync ($;$;$) {
     }
     return 0;
 }
-#
-# This sub returns the red IP used to compare in DyndnsServiceSync
-#
-sub GetDyndnsRedIP {
-    my %settings;
-    &General::readhash("${General::swroot}/ddns/settings", \%settings);
-
-    open(IP, "${General::swroot}/red/local-ipaddress") or return 'unavailable';
-    my $ip = <IP>;
-    close(IP);
-    chomp $ip;
-
-    # 100.64.0.0/10 is reserved for dual-stack lite (http://tools.ietf.org/html/rfc6598).
-    if (&General::IpInSubnet ($ip,'10.0.0.0','255.0.0.0') ||
-        &General::IpInSubnet ($ip,'172.16.0.0.','255.240.0.0') ||
-        &General::IpInSubnet ($ip,'192.168.0.0','255.255.0.0') ||
-        &General::IpInSubnet ($ip,'100.64.0.0', '255.192.0.0'))
-    {
-       if ($settings{'BEHINDROUTER'} eq 'FETCH_IP') {
-           my $RealIP = &General::FetchPublicIp;
-           $ip = (&General::validip ($RealIP) ?  $RealIP : 'unavailable');
-       }
-    }
-    return $ip;
-}
 
 # Translate ICMP code to text
 # ref: http://www.iana.org/assignments/icmp-parameters
index bfb9fdd201ed68ad75cfa58255073f642f05b1a0..f1f7de309025b0ebfb0e985252855a2b2d19046c 100644 (file)
@@ -307,4 +307,34 @@ sub FetchPublicIp {
        return;
 }
 
+#
+# This sub returns the red IP used to compare in DyndnsServiceSync
+#
+sub GetDyndnsRedIP {
+       my %settings;
+
+       # Read-in ddns settings.
+       &General::readhash("${General::swroot}/ddns/settings", \%settings);
+
+       # Try to grab the address from the local-ipaddress file.
+       my $ip = &General::grab_address_from_file("${General::swroot}/red/local-ipaddress") or return 'unavailable';
+
+       # 100.64.0.0/10 is reserved for dual-stack lite (http://tools.ietf.org/html/rfc6598).
+       if (&General::IpInSubnet ($ip,'10.0.0.0','255.0.0.0') ||
+               &General::IpInSubnet ($ip,'172.16.0.0.','255.240.0.0') ||
+               &General::IpInSubnet ($ip,'192.168.0.0','255.255.0.0') ||
+               &General::IpInSubnet ($ip,'100.64.0.0', '255.192.0.0'))
+       {
+               if ($settings{'BEHINDROUTER'} eq 'FETCH_IP') {
+                       # Call function to omit the real address.
+                       my $RealIP = &FetchPublicIp;
+
+                       # Check if the grabbed address is valid.
+                       $ip = (&General::validip ($RealIP) ?  $RealIP : 'unavailable');
+               }
+       }
+
+       return $ip;
+}
+
 1;