From: Michael Tremer <michael.tremer@ipfire.org>
To: Stefan Schantl <stefan.schantl@ipfire.org>
Cc: development@lists.ipfire.org
Subject: Re: [PATCH 2/3] general-functions.pl: Use new downloader for FetchPublicIp function.
Date: Sun, 23 Mar 2025 12:08:54 +0000 [thread overview]
Message-ID: <E7A34802-C759-4074-A0E8-E5E07587742E@ipfire.org> (raw)
In-Reply-To: <20250322145724.4593-2-stefan.schantl@ipfire.org>
This is much better and cleaner code than before. Well done!
> On 22 Mar 2025, at 14:57, Stefan Schantl <stefan.schantl@ipfire.org> wrote:
>
> 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 | 32 +++++++++++++----------------
> 1 file changed, 14 insertions(+), 18 deletions(-)
>
> diff --git a/config/cfgroot/general-functions.pl b/config/cfgroot/general-functions.pl
> index cb8df69c6..a132cf315 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.
> @@ -979,23 +978,20 @@ sub findhasharraykey {
> }
>
> 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;
> }
>
> #
> --
> 2.47.2
>
>
next prev parent reply other threads:[~2025-03-23 12:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-22 14:57 [PATCH 1/3] general-functions.pl: Add LWP-based flexible downloader function Stefan Schantl
2025-03-22 14:57 ` [PATCH 2/3] general-functions.pl: Use new downloader for FetchPublicIp function Stefan Schantl
2025-03-23 12:08 ` Michael Tremer [this message]
2025-03-22 14:57 ` [PATCH 3/3] ids-functions.pl: Use new general downloader function Stefan Schantl
2025-03-23 12:08 ` [PATCH 1/3] general-functions.pl: Add LWP-based flexible " Michael Tremer
2025-03-23 19:00 ` Stefan Schantl
2025-03-24 10:02 ` Michael Tremer
2025-03-26 12:47 ` Stefan Schantl
2025-03-26 16:18 ` Michael Tremer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E7A34802-C759-4074-A0E8-E5E07587742E@ipfire.org \
--to=michael.tremer@ipfire.org \
--cc=development@lists.ipfire.org \
--cc=stefan.schantl@ipfire.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox