From 16f8f65a824e80cd53dbdfa6d2ee7def6512406b Mon Sep 17 00:00:00 2001 From: Lain Date: Sat, 25 Jan 2025 21:54:52 -0300 Subject: [PATCH] Add ttl and update date --- cloudflare.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/cloudflare.py b/cloudflare.py index 793de01..52d749b 100755 --- a/cloudflare.py +++ b/cloudflare.py @@ -9,6 +9,7 @@ import logging import os import socket import subprocess +from datetime import datetime from typing import Any, Dict, List, Tuple, Sequence import ifaddr @@ -47,6 +48,7 @@ class Cloudflare: record_type: str, address: str, proxied: bool = True, + ttl: int = 1, ) -> requests.Response: headers = { 'X-Auth-Email': self.mail, @@ -58,7 +60,9 @@ class Cloudflare: 'type': record_type, 'name': domain, 'proxied': proxied, + 'ttl': ttl, 'content': address, + 'comment': f"Updated at {datetime.now().ctime()}" } with requests.put( @@ -103,9 +107,11 @@ class CloudflareAction(argparse.Action): self.a_id = config.get('Cloudflare', 'a_record_id') self.a_proxied = config.getboolean('Cloudflare', 'a_proxied') + self.a_ttl = config.get('Cloudflare', 'a_ttl') self.aaaa_id = config.get('Cloudflare', 'aaaa_record_id') self.aaaa_proxied = config.getboolean('Cloudflare', 'aaaa_proxied') + self.aaaa_ttl = config.get('Cloudflare', 'aaaa_ttl') self.cloudflare = Cloudflare(self.domain, mail, key) @@ -130,7 +136,13 @@ class CloudflareAction(argparse.Action): if local_a_address != remote_a_address: response = self.cloudflare.update_dns( - self.domain, self.zone_id, self.a_id, 'A', local_a_address, self.a_proxied, + self.domain, + self.zone_id, + self.a_id, + 'A', + local_a_address, + self.a_proxied, + self.a_ttl, ) print(f'A record: {response.status_code}', end='') else: @@ -140,7 +152,13 @@ class CloudflareAction(argparse.Action): if local_aaaa_address != remote_aaaa_address: response = self.cloudflare.update_dns( - self.domain, self.zone_id, self.aaaa_id, 'AAAA', local_aaaa_address, self.aaaa_proxied, + self.domain, + self.zone_id, + self.aaaa_id, + 'AAAA', + local_aaaa_address, + self.aaaa_proxied, + self.aaaa_ttl, ) print(f'AAAA record: {response.status_code}', end='') else: