[3/4] ddns.cgi: Get the address of the DDNS hosts only when needed

Message ID 20261201143155.1798388-4-antonio@mandelbit.com
State Staged
Commit f1f7e1629e8dc0c3868ddfc578c3bd4babe82e81
Headers
Series Use the address ddns publishes in the DDNS sync check (#14766) |

Commit Message

Antonio Quartulli 1 Dec 2026, 2:31 p.m. UTC
GetDyndnsRedIP() can fetch the public address from a server, which was
done on every page load, even without any enabled host.

Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
---
 html/cgi-bin/ddns.cgi | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
  

Patch

diff --git a/html/cgi-bin/ddns.cgi b/html/cgi-bin/ddns.cgi
index e5fe7166f..2c075a4c8 100644
--- a/html/cgi-bin/ddns.cgi
+++ b/html/cgi-bin/ddns.cgi
@@ -445,8 +445,9 @@  print $form->render();
 -e $datafile or die "Unable to open $datafile.";
 @current = &General::read_file($datafile, { keep_newlines => 1 });
 
-# Get IP address of the red interface.
-my $ip = &HTTPClient::GetDyndnsRedIP();
+# The address of the hosts, which may have to be fetched from a server: only
+# get it when needed
+my $ip;
 my $id = 0;
 my $toggle_enabled;
 
@@ -484,6 +485,7 @@  if (@current) {
 			$fqdn =~ s/^[\*\@]\.//;
 
 			if (&Network::check_fqdn($fqdn)) {
+				$ip //= &HTTPClient::GetDyndnsRedIP();
 				$sync = (&HTTPClient::DyndnsServiceSync ($ip,$temp[1], $temp[2]) ? "has-text-success" : "has-text-danger");
 			}