diff --git a/plinth/modules/dynamicdns/__init__.py b/plinth/modules/dynamicdns/__init__.py
index b234dd5df..9b8cf640f 100644
--- a/plinth/modules/dynamicdns/__init__.py
+++ b/plinth/modules/dynamicdns/__init__.py
@@ -15,6 +15,7 @@ from plinth import app as app_module
from plinth import cfg, glib, kvstore, menu
from plinth.modules.backups.components import BackupRestore
from plinth.modules.names.components import DomainType
+from plinth.modules.privacy import lookup_public_address
from plinth.modules.users.components import UsersAndGroups
from plinth.signals import domain_added, domain_removed
from plinth.utils import format_lazy
@@ -42,6 +43,8 @@ _description = [
'target=\'_blank\'>ddns.freedombox.org or you may find free update '
'URL based services at freedns.afraid.org.'),
+ _('This service uses an external service to lookup public IP address. '
+ 'This can be configured in the privacy app.'),
]
@@ -112,21 +115,12 @@ class DynamicDNSApp(app_module.App):
privileged.clean()
-def _query_external_address(domain):
+def _lookup_public_address(domain):
"""Return the IP address by querying an external server."""
- if not domain['ip_lookup_url']:
- return None
-
- ip_option = '-6' if domain['use_ipv6'] else '-4'
try:
- ip_address = subprocess.check_output([
- 'wget', ip_option, '-o', '/dev/null', '-t', '3', '-T', '3', '-O',
- '-', domain['ip_lookup_url']
- ])
- return ip_address.decode().strip().lower()
- except subprocess.CalledProcessError as exception:
- logger.warning('Unable to lookup external IP with URL %s: %s',
- domain['ip_lookup_url'], exception)
+ ip_type = 'ipv6' if domain['use_ipv6'] else 'ipv4'
+ return lookup_public_address(ip_type)
+ except Exception:
return None
@@ -186,7 +180,7 @@ def _update_dns_for_domain(domain):
try:
dns_address = _query_dns_address(domain)
- external_address = _query_external_address(domain)
+ external_address = _lookup_public_address(domain)
if dns_address == external_address and dns_address is not None:
logger.info('Dynamic domain %s is up-to-date: %s',
domain['domain'], dns_address)
diff --git a/plinth/modules/dynamicdns/forms.py b/plinth/modules/dynamicdns/forms.py
index 51693af62..22c62dee7 100644
--- a/plinth/modules/dynamicdns/forms.py
+++ b/plinth/modules/dynamicdns/forms.py
@@ -39,14 +39,6 @@ class ConfigureForm(forms.Form):
help_password = \
gettext_lazy('Leave this field empty if you want to keep your '
'current password.')
- help_ip_lookup_url = format_lazy(
- gettext_lazy('Optional Value. If your {box_name} is not connected '
- 'directly to the Internet (i.e. connected to a NAT '
- 'router) this URL is used to determine the real '
- 'IP address. The URL should simply return the IP where '
- 'the client comes from (example: '
- 'https://ddns.freedombox.org/ip/).'),
- box_name=gettext_lazy(cfg.box_name))
help_username = \
gettext_lazy('The username that was used when the account was '
'created.')
@@ -95,11 +87,6 @@ class ConfigureForm(forms.Form):
show_password = forms.BooleanField(label=gettext_lazy('Show password'),
required=False)
- ip_lookup_url = forms.CharField(
- label=gettext_lazy('URL to look up public IP'), required=False,
- help_text=help_ip_lookup_url,
- validators=[validators.URLValidator(schemes=['http', 'https'])])
-
use_ipv6 = forms.BooleanField(
label=gettext_lazy('Use IPv6 instead of IPv4'), required=False)
@@ -129,8 +116,7 @@ class ConfigureForm(forms.Form):
if not update_url:
self.add_error('update_url', message)
- param_map = (('username', ''), ('password', ''),
- ('ip_lookup_url', ''))
+ param_map = (('username', ''), ('password', ''))
for field_name, param in param_map:
if (update_url and param in update_url
and not cleaned_data.get(field_name)):
diff --git a/plinth/modules/dynamicdns/privileged.py b/plinth/modules/dynamicdns/privileged.py
index f5e8c090f..2b23d9164 100644
--- a/plinth/modules/dynamicdns/privileged.py
+++ b/plinth/modules/dynamicdns/privileged.py
@@ -53,7 +53,6 @@ def export_config() -> dict[str, bool | dict[str, dict[str, str | None]]]:
'server': input_config.get('server'),
'username': input_config.get('user', '').split(':')[0] or None,
'password': input_config.get('user', '').split(':')[-1] or None,
- 'ip_lookup_url': helper.get('IPURL'),
'update_url': _clean(helper.get('POSTURL')) or None,
'use_http_basic_auth': _clean(helper.get('POSTAUTH')),
'disable_ssl_cert_check': _clean(helper.get('POSTSSLIGNORE')),
diff --git a/plinth/modules/dynamicdns/tests/test_functional.py b/plinth/modules/dynamicdns/tests/test_functional.py
index 5643734af..cd0363e26 100644
--- a/plinth/modules/dynamicdns/tests/test_functional.py
+++ b/plinth/modules/dynamicdns/tests/test_functional.py
@@ -19,7 +19,6 @@ _configs = {
'domain': 'freedombox.example.com',
'username': 'tester',
'password': 'testingtesting',
- 'ip_lookup_url': 'https://ddns.freedombox.org/ip/',
},
'gnudip2': {
'service_type': 'gnudip',
@@ -27,7 +26,6 @@ _configs = {
'domain': 'freedombox2.example.com',
'username': 'tester2',
'password': 'testingtesting2',
- 'ip_lookup_url': 'https://ddns2.freedombox.org/ip/',
},
'noip.com': {
'service_type': 'noip.com',
@@ -37,7 +35,6 @@ _configs = {
'domain': 'freedombox3.example.com',
'username': 'tester3',
'password': 'testingtesting3',
- 'ip_lookup_url': 'https://ddns3.freedombox.org/ip/',
'use_ipv6': True,
},
'freedns.afraid.org': {
@@ -48,7 +45,6 @@ _configs = {
'domain': 'freedombox5.example.com',
'username': '',
'password': '',
- 'ip_lookup_url': '',
'use_ipv6': False,
},
'other': {
@@ -59,7 +55,6 @@ _configs = {
'domain': 'freedombox6.example.com',
'username': 'tester6',
'password': 'testingtesting6',
- 'ip_lookup_url': 'https://ddns6.freedombox.org/ip/',
'use_ipv6': False,
},
}