Add ttl and update date
This commit is contained in:
parent
62fde1e85a
commit
4b2621fb96
1 changed files with 20 additions and 2 deletions
|
@ -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:
|
||||||
|
|
Loading…
Add table
Reference in a new issue