getAllDNS, deleteARecord and some main file logics
This commit is contained in:
parent
790a38a970
commit
48cfb3ee87
32
apicalls.py
32
apicalls.py
@ -30,22 +30,44 @@ curl -X GET "https://api.cloudflare.com/client/v4/zones \
|
|||||||
-H "Content-Type: application/json"
|
-H "Content-Type: application/json"
|
||||||
"""
|
"""
|
||||||
headers = getHeaders(credentials)
|
headers = getHeaders(credentials)
|
||||||
zones = requests.get('https://api.cloudflare.com/client/v4/zones', headers= headers)
|
zones = requests.get(
|
||||||
|
'https://api.cloudflare.com/client/v4/zones',
|
||||||
|
headers= getHeaders(credentials)
|
||||||
|
)
|
||||||
return zones
|
return zones
|
||||||
|
|
||||||
|
|
||||||
def getAllDNS(credentials):
|
def getAllDNS(credentials, id):
|
||||||
"""
|
"""
|
||||||
curl -X GET "https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/ \
|
curl -X GET "https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records" \
|
||||||
-H "X-Auth-Email: user@example.com" \
|
-H "X-Auth-Email: user@example.com" \
|
||||||
-H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
|
-H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
|
||||||
-H "Content-Type: application/json"
|
-H "Content-Type: application/json"
|
||||||
"""
|
"""
|
||||||
|
dns_records = requests.get(
|
||||||
|
f'https://api.cloudflare.com/client/v4/zones/{id}/dns_records',
|
||||||
|
headers=getHeaders(credentials)
|
||||||
|
)
|
||||||
|
return dns_records
|
||||||
|
|
||||||
def deleteARecord(credentials):
|
def exportBindDNS(credentials, id):
|
||||||
|
"""
|
||||||
|
curl -X GET "https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/export" \
|
||||||
|
-H "X-Auth-Email: user@example.com" \
|
||||||
|
-H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
|
||||||
|
-H "Content-Type: application/json"
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def deleteARecord(credentials, zone_id, dns_id):
|
||||||
"""
|
"""
|
||||||
curl -X DELETE "https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59" \
|
curl -X DELETE "https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59" \
|
||||||
-H "X-Auth-Email: user@example.com" \
|
-H "X-Auth-Email: user@example.com" \
|
||||||
-H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
|
-H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
|
||||||
-H "Content-Type: application/json"
|
-H "Content-Type: application/json"
|
||||||
"""
|
"""
|
||||||
|
delete_response = requests.delete(
|
||||||
|
f'https://api.cloudflare.com/client/v4/zones/{zone_id}/dns_records/{dns_id}',
|
||||||
|
headers=getHeaders(credentials)
|
||||||
|
)
|
||||||
|
return delete_response
|
||||||
|
|||||||
39
app.py
39
app.py
@ -1,7 +1,10 @@
|
|||||||
import json
|
import json
|
||||||
from sys import argv
|
from sys import argv
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import requests
|
from unittest import result
|
||||||
|
|
||||||
|
import dns
|
||||||
|
# import requests
|
||||||
from apicalls import *
|
from apicalls import *
|
||||||
|
|
||||||
|
|
||||||
@ -25,7 +28,37 @@ if len(argv) > 1 and 'loadconfig' in argv:
|
|||||||
else:
|
else:
|
||||||
credentials = getCredentials()
|
credentials = getCredentials()
|
||||||
|
|
||||||
# print(credentials)
|
|
||||||
|
|
||||||
zones = listAllZones(credentials).json()["result"]
|
zones = listAllZones(credentials).json()["result"]
|
||||||
# print(f"{zones.status_code}\n{zones.json()}")
|
|
||||||
|
|
||||||
|
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.')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user