diff --git a/update-record.py b/update-record.py index 519056a..72330c4 100755 --- a/update-record.py +++ b/update-record.py @@ -19,7 +19,7 @@ # end errorCheck -def updateRecord(mode, username, password, domain, sub, record_type, ttl, content=None, config_section="live", verbose=False): +def updateRecord(mode, username, password, domain, sub, record_type, ttl, content=None, config_section="live", update_only_changes=True, verbose=False): debug_mode = False api_url = ApiClient.API_LIVE_URL if (config_section == "ote"): @@ -30,7 +30,6 @@ if (verbose): print("login:", ret) - # check domain ret = errorCheck(api_client.call_api(api_method='nameserver.list', method_params={'domain': domain})) if (verbose): @@ -42,11 +41,14 @@ # looking if subdomain exists ret = errorCheck(api_client.call_api(api_method='nameserver.info', method_params={'domain': domain})) records = ret['resData']['record'] + if (verbose): + print(records) + fqdn = sub + '.' + domain if (mode == "delete" or mode == "update"): recordFound = False for r in records: - if (r['name'] == domain and r['type'] == record_type): + if (r['name'] == fqdn and r['type'] == record_type): recordFound = True if (verbose): print('entry:', r) @@ -62,6 +64,8 @@ print('delete:', ret) # update entry elif (mode == "update"): + if (update_only_changes and content == r['content']): + continue ret = errorCheck(api_client.call_api(api_method='nameserver.updateRecord', method_params={'id': r['id'], 'type': record_type, 'content': content, 'ttl': ttl})) if (verbose): print('update:', ret) @@ -124,6 +128,7 @@ record_type=args.record_type, ttl=args.ttl, config_section=args.config_section, + update_only_changes=args.update_only_changes, verbose=args.verbose ) # end main @@ -136,6 +141,7 @@ parser.add_argument('content', metavar='content', nargs='?', default=None, help='ip or string to fill/update into subdomain domain entry') parser.add_argument('-r', '--record-type', metavar='type', required=True, choices=['A', 'AAAA', 'TXT', 'CNAME', 'TLSA'], help='record type (A, AAAA, TXT, CNAME, TLSA)') parser.add_argument('-m', '--mode', metavar='mode', required=True, choices=['create', 'update', 'delete'], help='operation mode (create, update, delete)\nupdate:update all existing records if one exists, or create if not existing\ndelete: delete existing record with given content, or delete all records if no content is given') + parser.add_argument('--update-only-changes', action='store_false', required=False, help='Do not update entry if content has changed. Default is aktive') parser.add_argument('-p', '--public-ip', action='store_true', required=False, help='insert public ip. Use -r A for ip4 an -r AAAA for ipv6') parser.add_argument('-c', '--config_file', metavar='path', default='./conf.cfg', help='path to configuration file') parser.add_argument('-t', '--ttl', default=3600, type=int, help='TTL (time to live) of the nameserver record in seconds (default 3600)')