65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
import json
|
|
from sys import argv
|
|
from pathlib import Path
|
|
from unittest import result
|
|
|
|
import dns
|
|
# import requests
|
|
from apicalls import *
|
|
|
|
|
|
# Get API key and Email address
|
|
def getCredentials():
|
|
api_key = input("Enter the Cloudflare API key: ")
|
|
email_address = input("Enter the Cloudflare Email address: ")
|
|
return {"api_key": api_key, "email": email_address}
|
|
|
|
|
|
# Get credentials
|
|
|
|
if len(argv) > 1 and 'loadconfig' in argv:
|
|
if Path("config.json").exists():
|
|
configfile = open("config.json")
|
|
config = json.load(configfile)
|
|
credentials = {'api_key': config['API_Key'], 'email': config['Email']}
|
|
else:
|
|
print('config.json was not found. Please enter the credentials manually')
|
|
credentials = getCredentials()
|
|
else:
|
|
credentials = getCredentials()
|
|
|
|
|
|
zones = listAllZones(credentials).json()["result"]
|
|
|
|
|
|
print('Here are the domains in your account')
|
|
zone_index = 0
|
|
zone_list = {}
|
|
for zone in zones:
|
|
print(f'{zone_index + 1}: {zone["name"]}')
|
|
zone_list[zone['name']] = {'id': zone['id'], 'name': zone['name'], 'owner': zone['owner']['email'], 'account_of': zone['account']['name']}
|
|
|
|
domainToDelete = input('Please enter the domain name to delete the DNS records from:\n')
|
|
|
|
if domainToDelete in zone_list:
|
|
zone_id = zone_list[domainToDelete]['id']
|
|
zone_owner = zone_list[domainToDelete]['owner']
|
|
confirmation = input(f'Are you sure to delete all the DNS records from the domain {domainToDelete}, owned by {zone_owner}?\nEnter YES to continue: ')
|
|
if confirmation == 'YES':
|
|
# get DNS Records
|
|
dns_records = getAllDNS(credentials, zone_id).json()["result"]
|
|
# Delete DNS Records
|
|
for record in dns_records:
|
|
dns_id = record['id']
|
|
dns_type = record['type']
|
|
dns_name = record['name']
|
|
dns_content = record['content']
|
|
print(f'Deleting:\n{dns_type}\t{dns_name}\t{dns_content}...')
|
|
# deleteARecord(credentials, zone_id, dns_id)
|
|
print(f'Deleted {dns_id}')
|
|
pass
|
|
else:
|
|
print('Aborted, bye...')
|
|
else:
|
|
print('We don\'t have access to the domain name you have entered. Please make sure the API key you have provided has access to the domain name you have entereed.')
|