mirror of
https://github.com/netbirdio/plugins.git
synced 2026-05-22 18:44:07 -07:00
dns/ddclient: AWS Route53 (#3550)
--------- Co-authored-by: Franco Fichtner <franco@lastsummer.de>
This commit is contained in:
co-authored by
Franco Fichtner
parent
301349705e
commit
16cddd15d2
@@ -1,7 +1,6 @@
|
||||
PLUGIN_NAME= ddclient
|
||||
PLUGIN_VERSION= 1.14
|
||||
PLUGIN_REVISION= 1
|
||||
PLUGIN_DEPENDS= ddclient-devel
|
||||
PLUGIN_VERSION= 1.15
|
||||
PLUGIN_DEPENDS= ddclient-devel py${PLUGIN_PYTHON}-boto3
|
||||
PLUGIN_COMMENT= Dynamic DNS client
|
||||
PLUGIN_MAINTAINER= ad@opnsense.org
|
||||
|
||||
|
||||
+8
-1
@@ -62,7 +62,7 @@
|
||||
<id>account.zone</id>
|
||||
<label>Zone</label>
|
||||
<type>text</type>
|
||||
<style>optional_setting service_zoneedit1 service_cloudflare service_nsupdate service_gandi service_godaddy service_nfsn service_hetzner</style>
|
||||
<style>optional_setting service_aws service_zoneedit1 service_cloudflare service_nsupdate service_gandi service_godaddy service_nfsn service_hetzner</style>
|
||||
<help>Zone containing the host entry.</help>
|
||||
</field>
|
||||
<field>
|
||||
@@ -73,6 +73,13 @@
|
||||
<allownew>true</allownew>
|
||||
<help>Hostname to update</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>account.ttl</id>
|
||||
<label>TTL</label>
|
||||
<type>text</type>
|
||||
<style>optional_setting service_aws</style>
|
||||
<help>Time to Live for the DNS entry</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>account.checkip</id>
|
||||
<label>Check ip method</label>
|
||||
|
||||
@@ -171,6 +171,12 @@
|
||||
<default>1</default>
|
||||
<Required>Y</Required>
|
||||
</force_ssl>
|
||||
<ttl type="IntegerField">
|
||||
<default>300</default>
|
||||
<Required>Y</Required>
|
||||
<MinimumValue>1</MinimumValue>
|
||||
<MaximumValue>604800</MaximumValue>
|
||||
</ttl>
|
||||
<interface type="InterfaceField">
|
||||
<Required>N</Required>
|
||||
<multiple>N</multiple>
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
"""
|
||||
AWS Route53 DNS provider
|
||||
Usage:
|
||||
AWS access key: username
|
||||
AWS secret key: password
|
||||
Route53 Hosted Zone ID: resource ID (use advanced settings)
|
||||
"""
|
||||
import syslog
|
||||
import boto3
|
||||
from . import BaseAccount
|
||||
|
||||
|
||||
class AWS(BaseAccount):
|
||||
_services = ['aws']
|
||||
|
||||
def __init__(self, account: dict):
|
||||
super().__init__(account)
|
||||
|
||||
@staticmethod
|
||||
def known_services():
|
||||
return AWS._services
|
||||
|
||||
@staticmethod
|
||||
def match(account):
|
||||
return account.get('service') in AWS._services
|
||||
|
||||
def execute(self):
|
||||
""" AWS DNS update
|
||||
"""
|
||||
|
||||
if super().execute():
|
||||
if not self.current_address:
|
||||
syslog.syslog(
|
||||
syslog.LOG_WARNING,
|
||||
f"No address found for {self.description}"
|
||||
)
|
||||
return False
|
||||
client = boto3.client('route53',
|
||||
aws_access_key_id = self.settings.get('username'),
|
||||
aws_secret_access_key = self.settings.get('password'))
|
||||
ip = str(self.current_address)
|
||||
if ':' in ip:
|
||||
addrType = 'AAAA'
|
||||
else:
|
||||
addrType = 'A'
|
||||
TTL = self.settings.get('ttl')
|
||||
changeBatch = {
|
||||
'Changes': [{
|
||||
'Action': 'UPSERT',
|
||||
'ResourceRecordSet': {
|
||||
'Name': host,
|
||||
'Type': addrType,
|
||||
'TTL': int(TTL),
|
||||
'ResourceRecords': [{'Value': ip}]
|
||||
}
|
||||
} for host in self.settings.get('hostnames').split(",")]
|
||||
}
|
||||
try:
|
||||
response = client.change_resource_record_sets(
|
||||
HostedZoneId = self.settings.get('zone'),
|
||||
ChangeBatch = changeBatch)
|
||||
except Exception as e:
|
||||
syslog.syslog(syslog.LOG_ERR, str(e))
|
||||
return False
|
||||
|
||||
syslog.syslog(
|
||||
syslog.LOG_NOTICE,
|
||||
f"Account {self.description} set new ip {self.current_address}, ID {response['ChangeInfo']['Id']}")
|
||||
|
||||
self.update_state(address=self.current_address)
|
||||
return True
|
||||
@@ -24,6 +24,7 @@
|
||||
"checkip": "{{ account.checkip }}",
|
||||
"checkip_timeout": {{ account.checkip_timeout }},
|
||||
"force_ssl": {{ "true" if account.force_ssl == '1' else "false"}},
|
||||
"ttl": "{{ account.ttl }}",
|
||||
"interface": "{%if account.interface %}{{physical_interface(account.interface)}}{% endif%}",
|
||||
"description": "{{ account.description }}"
|
||||
}{{ "," if not loop.last else ""}}
|
||||
|
||||
Reference in New Issue
Block a user