]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
general-functions.pl: Use new downloader for FetchPublicIp function.
authorStefan Schantl <stefan.schantl@ipfire.org>
Thu, 4 Aug 2022 18:00:21 +0000 (20:00 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Sun, 3 Mar 2024 11:56:02 +0000 (12:56 +0100)
This helps to drop the Net::SSLeay module and to remove a lot of legacy
code.

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

index 027ab553328c89a3e9603d51c5d2a3c188fb76a8..3d88fbe6c1108c88ad5a0535e2c58c35e62189ad 100644 (file)
@@ -17,7 +17,6 @@ package General;
 use strict;
 use Socket;
 use IO::Socket;
-use Net::SSLeay;
 use Net::IPv4Addr qw(:all);
 
 # Load module to move files.
@@ -1046,23 +1045,20 @@ sub srtarray
 }
 
 sub FetchPublicIp {
-    my %proxysettings;
-    &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
-    if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
-        my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?)?$/);
-        Net::SSLeay::set_proxy($peer,$peerport,$proxysettings{'UPSTREAM_USER'},$proxysettings{'UPSTREAM_PASSWORD'} );
-    }
-    my $user_agent = &MakeUserAgent();
-    my ($out, $response) = Net::SSLeay::get_http(  'checkip4.dns.lightningwirelabs.com',
-                                                   80,
-                                                   "/",
-                                                   Net::SSLeay::make_headers('User-Agent' => $user_agent )
-                                               );
-    if ($response =~ m%HTTP/1\.. 200 OK%) {
-       $out =~ /Your IP address is: (\d+.\d+.\d+.\d+)/;
-       return $1;
-    }
-    return '';
+       # URL to grab the public IP.
+       my $url = "https://checkip4.dns.lightningwirelabs.com";
+
+       # Call downloader to fetch the public IP.
+       my $response = &downloader("URL" => $url);
+
+       # Omit the address from the resonse message.
+       if ($response =~ /Your IP address is: (\d+.\d+.\d+.\d+)/) {
+               # Return the address.
+               return $1;
+       }
+
+       # Unable to grab the address - Return nothing.
+       return;
 }
 
 #