Add ttl and update date

This commit is contained in:
Lain Iwakura 2025-01-25 21:54:52 -03:00
parent 62fde1e85a
commit 16f8f65a82
Signed by: lain
GPG key ID: 89686F4239E80508

View file

@ -9,6 +9,7 @@ import logging
import os import os
import socket import socket
import subprocess import subprocess
from datetime import datetime
from typing import Any, Dict, List, Tuple, Sequence from typing import Any, Dict, List, Tuple, Sequence
import ifaddr import ifaddr
@ -47,6 +48,7 @@ class Cloudflare:
record_type: str, record_type: str,
address: str, address: str,
proxied: bool = True, proxied: bool = True,
ttl: int = 1,
) -> requests.Response: ) -> requests.Response:
headers = { headers = {
'X-Auth-Email': self.mail, 'X-Auth-Email': self.mail,
@ -58,7 +60,9 @@ class Cloudflare:
'type': record_type, 'type': record_type,
'name': domain, 'name': domain,
'proxied': proxied, 'proxied': proxied,
'ttl': ttl,
'content': address, 'content': address,
'comment': f"Updated at {datetime.now().ctime()}"
} }
with requests.put( with requests.put(
@ -103,9 +107,11 @@ class CloudflareAction(argparse.Action):
self.a_id = config.get('Cloudflare', 'a_record_id') self.a_id = config.get('Cloudflare', 'a_record_id')
self.a_proxied = config.getboolean('Cloudflare', 'a_proxied') 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_id = config.get('Cloudflare', 'aaaa_record_id')
self.aaaa_proxied = config.getboolean('Cloudflare', 'aaaa_proxied') self.aaaa_proxied = config.getboolean('Cloudflare', 'aaaa_proxied')
self.aaaa_ttl = config.get('Cloudflare', 'aaaa_ttl')
self.cloudflare = Cloudflare(self.domain, mail, key) self.cloudflare = Cloudflare(self.domain, mail, key)
@ -130,7 +136,13 @@ class CloudflareAction(argparse.Action):
if local_a_address != remote_a_address: if local_a_address != remote_a_address:
response = self.cloudflare.update_dns( 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='') print(f'A record: {response.status_code}', end='')
else: else:
@ -140,7 +152,13 @@ class CloudflareAction(argparse.Action):
if local_aaaa_address != remote_aaaa_address: if local_aaaa_address != remote_aaaa_address:
response = self.cloudflare.update_dns( 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='') print(f'AAAA record: {response.status_code}', end='')
else: else: