From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <development+bounces-230-archive=lists.ipfire.org@lists.ipfire.org>
Received: from mail02.haj.ipfire.org (localhost [127.0.0.1])
	by mail02.haj.ipfire.org (Postfix) with ESMTP id 4ZfC162fLtz339m
	for <archive@lists.ipfire.org>; Fri, 18 Apr 2025 11:18:02 +0000 (UTC)
Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (secp384r1)
	 client-signature RSA-PSS (4096 bits))
	(Client CN "mail01.haj.ipfire.org", Issuer "R10" (verified OK))
	by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4ZfC126C7Jz336p
	for <development@lists.ipfire.org>; Fri, 18 Apr 2025 11:17:58 +0000 (UTC)
Received: from [127.0.0.1] (localhost [127.0.0.1])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by mail01.ipfire.org (Postfix) with ESMTPSA id 4ZfC1211ylz2yn;
	Fri, 18 Apr 2025 11:17:58 +0000 (UTC)
DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org;
	s=202003ed25519; t=1744975078;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=KIaaJAJxnhPQczA6FFCL5OC7kP89UPy3POzTNjCaKns=;
	b=Eu9tXWMpMa2PBkEMyxFBFJg8Poy1O81q4w5ewy3OU5g5aVYW9dHkFsh+qYJoKeknUPj4i3
	o+IIY6bscFw6gYAQ==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa;
	t=1744975078;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:cc:mime-version:mime-version:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=KIaaJAJxnhPQczA6FFCL5OC7kP89UPy3POzTNjCaKns=;
	b=ns0pVkX37JGIA162LdLtiRIS5zTW/JEAUHuigGq4SuwEIU3SkAByiQGiT1HH6AtXsJz1uH
	JHV7EcwRimeo4G8r46rbC5piFx2FyRY5CzLROiOG276LwIJzU1oIvHgnYq2Hs+aUPrx39Y
	Gh9P/xyaL/AQVN6QhS6KXMRnHSEKYEXY8JwNT3EI515RMNbeuEgU+KBv/fzCiDuJAMpj14
	O/g6ET/i0tBiHub+3x8TIulRKgp6aq+o/xPmHI+EFZnylKThJOi2QRCorQeASyHz+SoMBw
	UHG9ndWrI81y3DkaIFpKLj23nWE6oHK+MaRgg10JRzYw/iDulB1uDhbidQn7xQ==
From: Stefan Schantl <stefan.schantl@ipfire.org>
To: development@lists.ipfire.org
Cc: Stefan Schantl <stefan.schantl@ipfire.org>
Subject: [PATCHv2 2/7] http-client-functions.pl: Add FetchPublicIP function.
Date: Fri, 18 Apr 2025 12:54:41 +0200
Message-ID: <20250418110741.7756-3-stefan.schantl@ipfire.org>
In-Reply-To: <20250418110741.7756-1-stefan.schantl@ipfire.org>
References: <20250418110741.7756-1-stefan.schantl@ipfire.org>
Precedence: list
List-Id: <development.lists.ipfire.org>
List-Subscribe: <https://lists.ipfire.org/>,
 <mailto:development+subscribe@lists.ipfire.org?subject=subscribe>
List-Unsubscribe: <https://lists.ipfire.org/>,
 <mailto:development+unsubscribe@lists.ipfire.org?subject=unsubscribe>
List-Post: <mailto:development@lists.ipfire.org>
List-Help: <mailto:development+help@lists.ipfire.org?subject=help>
Sender: <development@lists.ipfire.org>
Mail-Followup-To: <development@lists.ipfire.org>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

This functions uses the newly introduced downloader to fetch
the pulic IPv4 address on red and will replace the current used one
from the general-functions.pl library.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
---
 config/cfgroot/http-client-functions.pl | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/config/cfgroot/http-client-functions.pl b/config/cfgroot/http-client-functions.pl
index 26ead6908..bfb9fdd20 100644
--- a/config/cfgroot/http-client-functions.pl
+++ b/config/cfgroot/http-client-functions.pl
@@ -287,4 +287,24 @@ sub downloader (%) {
 	}
 }
 
+#
+# Tiny function to grab the public red IPv4 address using LWL.
+#
+sub FetchPublicIp {
+	# 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;
+}
+
 1;
-- 
2.47.2