From: Stefan Schantl Date: Thu, 4 Aug 2022 18:00:21 +0000 (+0200) Subject: general-functions.pl: Use new downloader for FetchPublicIp function. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a4cdd6ae8bf3bea1ed9ca36ee2a3cef0ee4161a5;p=people%2Fstevee%2Fipfire-2.x.git general-functions.pl: Use new downloader for FetchPublicIp function. This helps to drop the Net::SSLeay module and to remove a lot of legacy code. Signed-off-by: Stefan Schantl --- diff --git a/config/cfgroot/general-functions.pl b/config/cfgroot/general-functions.pl index 027ab55332..3d88fbe6c1 100644 --- a/config/cfgroot/general-functions.pl +++ b/config/cfgroot/general-functions.pl @@ -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; } #