mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-07-22 11:59:33 +00:00
dynamicdns: Use the public IP lookup URL from privacy app
- Drop the configuration field from all the forms. - Those using a different value for public IP lookup URL must now set the value again in the privacy app. Privacy app will show the review notification again for this reason. Tests: - Functional and unit tests pass. - Printing the external IP address during the update task shows correct value. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Benedek Nagy <contact@nbenedek.me>
This commit is contained in:
parent
ed519187c5
commit
26a61d67b9
@ -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</a> or you may find free update '
|
||||
'URL based services at <a href=\'http://freedns.afraid.org/\' '
|
||||
'target=\'_blank\'>freedns.afraid.org</a>.'),
|
||||
_('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)
|
||||
|
||||
@ -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', '<User>'), ('password', '<Pass>'),
|
||||
('ip_lookup_url', '<Ip>'))
|
||||
param_map = (('username', '<User>'), ('password', '<Pass>'))
|
||||
for field_name, param in param_map:
|
||||
if (update_url and param in update_url
|
||||
and not cleaned_data.get(field_name)):
|
||||
|
||||
@ -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')),
|
||||
|
||||
@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user