From 79a918c79bcb75bf2c9fa6383ac3183a84a5564e Mon Sep 17 00:00:00 2001 From: Philipp Spitzer Date: Tue, 8 Apr 2014 21:23:33 +0200 Subject: [PATCH] Now in both scripts only fqdn are allowed. --- bin/nsupdate_dyndns | 37 ++++++++++++++++++++----------------- cgi-bin/dyndns.py | 3 --- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/bin/nsupdate_dyndns b/bin/nsupdate_dyndns index 49ed3e3..e49c08f 100755 --- a/bin/nsupdate_dyndns +++ b/bin/nsupdate_dyndns @@ -13,16 +13,20 @@ def ipfamily_by_ip(ip): assert False -def nsupdate_add(hostname, domain, ttl, ip): - """ip_family: A or AAAA""" - command = "update add {hostname}.{domain} {ttl} IN {ip_family} {ip}\n\n".format(hostname=hostname, domain=domain, ttl=ttl, ip_family=ipfamily_by_ip(ip), ip=ip) +def nsupdate_add(fqdn, ttl, ip): + """ + :param fqdn: Fully qualified domain name + :param ip_family: A or AAAA""" + command = "update add {fqdn} {ttl} IN {ip_family} {ip}\n\n".format(fqdn=fqdn, ttl=ttl, ip_family=ipfamily_by_ip(ip), ip=ip) p = Popen(['nsupdate', '-l'], stdin=PIPE) p.communicate(command) -def nsupdate_delete(hostname, domain, ip_family): - """ip_family: A or AAAA""" - command = "update delete {hostname}.{domain} {ip_family}\n\n".format(hostname=hostname, domain=domain, ip_family=ip_family) +def nsupdate_delete(fqdn, ip_family): + """ + :param fqdn: Fully qualified domain name + :param ip_family: A or AAAA""" + command = "update delete {fqdn} {ip_family}\n\n".format(fqdn=fqdn, ip_family=ip_family) p = Popen(['nsupdate', '-l'], stdin=PIPE) p.communicate(command) @@ -30,24 +34,23 @@ def nsupdate_delete(hostname, domain, ip_family): def main(args): if args.delete: if args.ip is None: - nsupdate_delete(args.hostname, args.domain, 'A') - nsupdate_delete(args.hostname, args.domain, 'AAAA') + nsupdate_delete(args.fqdn, 'A') + nsupdate_delete(args.fqdn, 'AAAA') else: - nsupdate_delete(args.hostname, args.domain, ipfamily_by_ip(args.ip)) + nsupdate_delete(args.fqdn, ipfamily_by_ip(args.ip)) else: - nsupdate_delete(args.hostname, args.domain, ipfamily_by_ip(args.ip)) - nsupdate_add(args.hostname, args.domain, args.ttl, args.ip) + nsupdate_delete(args.fqdn, ipfamily_by_ip(args.ip)) + nsupdate_add(args.fqdn, args.ttl, args.ip) if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Add or delete a hostname from dyndns (simplifies call to nsupdate).') + parser = argparse.ArgumentParser(description='Add or delete a domain name from dyndns (simplifies call to nsupdate).') parser.add_argument('-d', '--delete', action='store_true', help='delete instead of add') parser.add_argument('-i', '--ip', help='IP address (either IPv4 or IPv6)') # parser.add_argument('-t', '--ttl', type=int, default=600, help='TTL (default: 600)') - parser.add_argument('hostname', help='hostname to add or delete, e.g. myserver') + parser.add_argument('fqdn', help='fully qualified domain name to add or delete, e.g. myserver.dyn.example.com') args = parser.parse_args() - args.domain = 'dyn.colgarra.priv.at' # <---- TODO args.ttl = 600 # <---- TODO # check ip @@ -59,8 +62,8 @@ if __name__ == '__main__': except ValueError: parser.error('The IP address is not valid') - # check hostname - if re.match(r'[-0-9a-z]+(\.[-0-9a-z]+)*$', args.hostname) is None: - parser.error('The hostname has an invalid format.') + # check fqdn + if re.match(r'[-0-9a-z]+(\.[-0-9a-z]+)*$', args.fqdn) is None: + parser.error('The fqdn has an invalid format.') main(args) diff --git a/cgi-bin/dyndns.py b/cgi-bin/dyndns.py index 417c27a..1a074b2 100755 --- a/cgi-bin/dyndns.py +++ b/cgi-bin/dyndns.py @@ -13,7 +13,6 @@ import ipaddr # Configuration PASSWORD = 'hygCithOrs5' -ZONE = '.dyn.colgarra.priv.at' DEBUG = False @@ -134,8 +133,6 @@ try: # strip zone hostname = hostname.strip() - if hostname.endswith(ZONE): - hostname = hostname[:-len(ZONE)] # check offline if offline is None or offline.lower() == 'no': -- 2.39.5