Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@
<label>Interface to monitor</label>
<type>dropdown</type>
</field>
<field>
<id>account.dynipv6host</id>
<label>Dynamic ipv6 host</label>
<type>text</type>
<advanced>true</advanced>
<help>Swap the interface identifier of the ipv6 address with the given partial ipv6 address</help>
</field>
<field>
<id>account.checkip_timeout</id>
<label>Check ip timeout</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@
</check001>
</Constraints>
</checkip>
<dynipv6host type="TextField">
<Required>N</Required>
<mask>/^::(([0-9a-fA-F]{1,4}:){0,3}[0-9a-fA-F]{1,4})?$/u</mask>
<ValidationMessage>Entry is not a valid partial ipv6 address definition (e.g. ::1000).</ValidationMessage>
</dynipv6host>
<checkip_timeout type="IntegerField">
<Default>10</Default>
<Required>Y</Required>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ def execute(self):
service = self.settings.get('checkip'),
proto = 'https' if self.settings.get('force_ssl', False) else 'http',
timeout = str(self.settings.get('checkip_timeout', '10')),
interface = self.settings['interface'] if self.settings.get('interface' ,'').strip() != '' else None
interface = self.settings['interface'] if self.settings.get('interface' ,'').strip() != '' else None,
dynipv6host = self.settings['dynipv6host'] if self.settings.get('dynipv6host' ,'').strip() != '' else None
)

if self._current_address == None:
Expand Down
27 changes: 24 additions & 3 deletions dns/ddclient/src/opnsense/scripts/ddclient/lib/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,30 @@ def extract_address(host, txt):
return ""


def checkip(service, proto='https', timeout='10', interface=None):
def transform_ip(ip, ipv6host=None):
""" Changes ipv6 addresses if interface identifier is given
:param ip: ip address
:param ipv6host: 64 bit interface identifier
:return str
"""
if (
ipv6host and
isinstance(ip, ipaddress.IPv6Address)
):
# extract 64 bit long prefix
prefix = ':'.join(str(ip).split(':')[:4])
# normalize 64 bit interface identifier
host = ':'.join(str(ipaddress.ip_address(ipv6host).exploded).split(':')[4:])
ip = ipaddress.ip_address(f"{prefix}:{host}")
return ip


def checkip(service, proto='https', timeout='10', interface=None, dynipv6host=None):
""" find ip address using external services defined in checkip_service_list
:param proto: protocol
:param timeout: timeout in seconds
:param interface: bind to interface
:param dynipv6host: optional partial ipv6 address
:return: str
"""
if service.startswith('web_'):
Expand All @@ -84,8 +103,10 @@ def checkip(service, proto='https', timeout='10', interface=None):
params.append(interface)
url = checkip_service_list[service] % proto
params.append(url)
return extract_address(urlparse(url).hostname,
extracted_address = extract_address(urlparse(url).hostname,
subprocess.run(params, capture_output=True, text=True).stdout)
address = ipaddress.ip_address(extracted_address)
return str(transform_ip(address, dynipv6host))
elif service in ['if', 'if6'] and interface is not None:
# return first non private IPv[4|6] interface address
ifcfg = subprocess.run(['/sbin/ifconfig', interface], capture_output=True, text=True).stdout
Expand All @@ -96,7 +117,7 @@ def checkip(service, proto='https', timeout='10', interface=None):
try:
address = ipaddress.ip_address(parts[1])
if address.is_global:
return str(address)
return str(transform_ip(address, dynipv6host))
except ValueError:
continue
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"zone": "{{ account.zone }}",
"checkip": "{{ account.checkip }}",
"interface": "{% if account.interface %}{{physical_interface(account.interface)}}{% endif %}",
"dynipv6host": "{{ account.dynipv6host }}",
"checkip_timeout": {{ account.checkip_timeout }},
"force_ssl": {{ "true" if account.force_ssl == '1' else "false"}},
"ttl": "{{ account.ttl }}",
Expand Down