Add maintenance mode
This commit is contained in:
parent
d5dce5216c
commit
62fde1e85a
1 changed files with 22 additions and 10 deletions
|
@ -99,6 +99,13 @@ class CloudflareAction(argparse.Action):
|
|||
key = config.get('Cloudflare', 'api_key')
|
||||
self.zone_id = config.get('Cloudflare', 'zone_id')
|
||||
self.domain = config.get('General', 'domain')
|
||||
self.device = config.get('General', 'device')
|
||||
|
||||
self.a_id = config.get('Cloudflare', 'a_record_id')
|
||||
self.a_proxied = config.getboolean('Cloudflare', 'a_proxied')
|
||||
|
||||
self.aaaa_id = config.get('Cloudflare', 'aaaa_record_id')
|
||||
self.aaaa_proxied = config.getboolean('Cloudflare', 'aaaa_proxied')
|
||||
|
||||
self.cloudflare = Cloudflare(self.domain, mail, key)
|
||||
|
||||
|
@ -115,21 +122,15 @@ class CloudflareAction(argparse.Action):
|
|||
print(json.dumps(dns_list, indent=4))
|
||||
|
||||
if option_string == '--update-dns':
|
||||
aaaa_record_id = config.get('Cloudflare', 'aaaa_record_id')
|
||||
a_record_id = config.get('Cloudflare', 'a_record_id')
|
||||
aaaa_proxied = config.getboolean('Cloudflare', 'aaaa_proxied')
|
||||
a_proxied = config.getboolean('Cloudflare', 'a_proxied')
|
||||
device = config.get('General', 'device')
|
||||
|
||||
local_a_address = get_local_address(device, (socket.AF_INET, 0))
|
||||
local_aaaa_address = get_local_address(device, (socket.AF_INET6, 1))
|
||||
local_a_address = get_local_address(self.device, (socket.AF_INET, 0))
|
||||
local_aaaa_address = get_local_address(self.device, (socket.AF_INET6, 1))
|
||||
|
||||
remote_a_address = self.cloudflare.get_remote_address(self.zone_id, 'A')
|
||||
remote_aaaa_address = self.cloudflare.get_remote_address(self.zone_id, 'AAAA')
|
||||
|
||||
if local_a_address != remote_a_address:
|
||||
response = self.cloudflare.update_dns(
|
||||
self.domain, self.zone_id, a_record_id, 'A', local_a_address, a_proxied,
|
||||
self.domain, self.zone_id, self.a_id, 'A', local_a_address, self.a_proxied,
|
||||
)
|
||||
print(f'A record: {response.status_code}', end='')
|
||||
else:
|
||||
|
@ -139,7 +140,7 @@ class CloudflareAction(argparse.Action):
|
|||
|
||||
if local_aaaa_address != remote_aaaa_address:
|
||||
response = self.cloudflare.update_dns(
|
||||
self.domain, self.zone_id, aaaa_record_id, 'AAAA', local_aaaa_address, aaaa_proxied,
|
||||
self.domain, self.zone_id, self.aaaa_id, 'AAAA', local_aaaa_address, self.aaaa_proxied,
|
||||
)
|
||||
print(f'AAAA record: {response.status_code}', end='')
|
||||
else:
|
||||
|
@ -153,6 +154,16 @@ class CloudflareAction(argparse.Action):
|
|||
subdomains = config.get('General', 'subdomains').replace(' ', '').split(',')
|
||||
self.cloudflare.issue_cert(ssl_home, acme_directory, subdomains)
|
||||
|
||||
if option_string == '--maintenance':
|
||||
self.cloudflare.update_dns(
|
||||
self.domain, self.zone_id, self.a_id, 'A', '192.0.2.1', True
|
||||
)
|
||||
|
||||
self.cloudflare.update_dns(
|
||||
self.domain, self.zone_id, self.aaaa_id, 'AAAA', '2001:db8::', True
|
||||
)
|
||||
|
||||
print(f'Enabled')
|
||||
|
||||
def get_local_address(interface: str, type_: Tuple[socket.AddressFamily, int]):
|
||||
if type_[0] == socket.AF_INET:
|
||||
|
@ -179,4 +190,5 @@ if __name__ == '__main__':
|
|||
command_parser.add_argument('--list-dns', action=CloudflareAction, nargs=1)
|
||||
command_parser.add_argument('--update-dns', action=CloudflareAction, nargs=0)
|
||||
command_parser.add_argument('--issue-cert', action=CloudflareAction, nargs=0)
|
||||
command_parser.add_argument('--maintenance', action=CloudflareAction, nargs=0)
|
||||
command_parser.parse_args()
|
||||
|
|
Loading…
Add table
Reference in a new issue