From: Stefan Schantl <stefan.schantl@ipfire.org>
To: development@lists.ipfire.org
Cc: Stefan Schantl <stefan.schantl@ipfire.org>
Subject: [PATCHv2 4/7] Move GetDyndnsRedIP from general-functions.pl to http-client-functions.pl
Date: Fri, 18 Apr 2025 12:54:43 +0200 [thread overview]
Message-ID: <20250418110741.7756-5-stefan.schantl@ipfire.org> (raw)
In-Reply-To: <20250418110741.7756-1-stefan.schantl@ipfire.org>
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 | 25 ---------------------
config/cfgroot/http-client-functions.pl | 30 +++++++++++++++++++++++++
2 files changed, 30 insertions(+), 25 deletions(-)
diff --git a/config/cfgroot/general-functions.pl b/config/cfgroot/general-functions.pl
index 861f95dec..bbd0f9839 100644
--- a/config/cfgroot/general-functions.pl
+++ b/config/cfgroot/general-functions.pl
@@ -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
diff --git a/config/cfgroot/http-client-functions.pl b/config/cfgroot/http-client-functions.pl
index bfb9fdd20..f1f7de309 100644
--- a/config/cfgroot/http-client-functions.pl
+++ b/config/cfgroot/http-client-functions.pl
@@ -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;
--
2.47.2
next prev parent reply other threads:[~2025-04-18 11:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-18 10:54 [PATCHv2 0/7] Introduce perl LWP-based flexible downloader function Stefan Schantl
2025-04-18 10:54 ` [PATCHv2 1/7] http-client-functions.pl: Introduce " Stefan Schantl
2025-04-18 10:54 ` [PATCHv2 2/7] http-client-functions.pl: Add FetchPublicIP function Stefan Schantl
2025-04-18 10:54 ` [PATCHv2 3/7] general-functions.pl: Drop FetchPublicIp function Stefan Schantl
2025-04-18 10:54 ` Stefan Schantl [this message]
2025-04-18 10:54 ` [PATCHv2 5/7] ddns.cgi, wio.cgi: Use GetDyndnsRedIP from http-client-functions.pl file Stefan Schantl
2025-04-18 10:54 ` [PATCHv2 6/7] ids-functions.pl: Use new downloader function from http-client-functions.pl Stefan Schantl
2025-04-18 10:54 ` [PATCHv2 7/7] http-client-functions.pl: Allow to user define the timeout value Stefan Schantl
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=20250418110741.7756-5-stefan.schantl@ipfire.org \
--to=stefan.schantl@ipfire.org \
--cc=development@lists.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