mirror of
https://github.com/shmilylty/OneForAll.git
synced 2026-10-25 00:56:14 +08:00
Merge branch 'master' of https://github.com/shmilylty/OneForAll
This commit is contained in:
@@ -23,14 +23,14 @@ class CloudFlareAPI(Query):
|
|||||||
query from source
|
query from source
|
||||||
"""
|
"""
|
||||||
account_id_resp = self.get(self.addr + 'accounts')
|
account_id_resp = self.get(self.addr + 'accounts')
|
||||||
if not account_id_resp:
|
if account_id_resp.status_code != 200:
|
||||||
return
|
return
|
||||||
account_id = account_id_resp.json()['result'][0]['id']
|
account_id = account_id_resp.json()['result'][0]['id']
|
||||||
# query domain zone, if it not exist, create
|
# query domain zone, if it not exist, create
|
||||||
zones_resp = self.get(self.addr + 'zones',
|
zones_resp = self.get(self.addr + 'zones',
|
||||||
params={'name': self.domain}, check=False)
|
params={'name': self.domain}, check=False)
|
||||||
if not zones_resp:
|
|
||||||
return
|
if zones_resp.status_code == 200:
|
||||||
if zones_resp.json()['success'] and not zones_resp.json()['result']:
|
if zones_resp.json()['success'] and not zones_resp.json()['result']:
|
||||||
zone_id = self.create_zone(account_id)
|
zone_id = self.create_zone(account_id)
|
||||||
if zone_id:
|
if zone_id:
|
||||||
@@ -45,10 +45,14 @@ class CloudFlareAPI(Query):
|
|||||||
if zone_id:
|
if zone_id:
|
||||||
self.list_dns(zone_id)
|
self.list_dns(zone_id)
|
||||||
return
|
return
|
||||||
elif not zones_resp.json()['success']:
|
elif zones_resp.status_code == 403:
|
||||||
logger.log('DEBUG',
|
logger.log('DEBUG',
|
||||||
f'{self.domain} is banned or not a registered domain, so cannot be added to Cloudflare.')
|
f'{self.domain} is banned or not a registered domain, so cannot be added to Cloudflare.')
|
||||||
return
|
return
|
||||||
|
else:
|
||||||
|
logger.log('DEBUG',
|
||||||
|
f'{zones_resp.status_code} {zones_resp.text}')
|
||||||
|
return
|
||||||
|
|
||||||
def create_zone(self, account_id):
|
def create_zone(self, account_id):
|
||||||
data = {"name": self.domain, "account": {"id": account_id}, "jump_start": True,
|
data = {"name": self.domain, "account": {"id": account_id}, "jump_start": True,
|
||||||
@@ -56,6 +60,8 @@ class CloudFlareAPI(Query):
|
|||||||
create_zone_resp = self.post(
|
create_zone_resp = self.post(
|
||||||
self.addr + 'zones', json=data, check=False)
|
self.addr + 'zones', json=data, check=False)
|
||||||
if not create_zone_resp:
|
if not create_zone_resp:
|
||||||
|
logger.log('DEBUG',
|
||||||
|
f'{create_zone_resp.status_code} {create_zone_resp.text}')
|
||||||
return
|
return
|
||||||
if create_zone_resp.json()['success']:
|
if create_zone_resp.json()['success']:
|
||||||
return create_zone_resp.json()['result']['id']
|
return create_zone_resp.json()['result']['id']
|
||||||
@@ -67,6 +73,8 @@ class CloudFlareAPI(Query):
|
|||||||
page = 1
|
page = 1
|
||||||
list_dns_resp = self.get(self.addr + f'zones/{zone_id}/dns_records', params={'page': page, 'per_page': 10})
|
list_dns_resp = self.get(self.addr + f'zones/{zone_id}/dns_records', params={'page': page, 'per_page': 10})
|
||||||
if not list_dns_resp:
|
if not list_dns_resp:
|
||||||
|
logger.log('DEBUG',
|
||||||
|
f'{list_dns_resp.status_code} {list_dns_resp.text}')
|
||||||
return
|
return
|
||||||
subdomains = self.match_subdomains(self.domain, list_dns_resp.text)
|
subdomains = self.match_subdomains(self.domain, list_dns_resp.text)
|
||||||
self.subdomains = self.subdomains.union(subdomains)
|
self.subdomains = self.subdomains.union(subdomains)
|
||||||
@@ -79,6 +87,8 @@ class CloudFlareAPI(Query):
|
|||||||
list_dns_resp = self.get(self.addr + f'zones/{zone_id}/dns_records',
|
list_dns_resp = self.get(self.addr + f'zones/{zone_id}/dns_records',
|
||||||
params={'page': page, 'per_page': 10})
|
params={'page': page, 'per_page': 10})
|
||||||
if not list_dns_resp:
|
if not list_dns_resp:
|
||||||
|
logger.log('DEBUG',
|
||||||
|
f'{list_dns_resp.status_code} {list_dns_resp.text}')
|
||||||
return
|
return
|
||||||
total_pages = list_dns_resp.json()['result_info']['total_pages']
|
total_pages = list_dns_resp.json()['result_info']['total_pages']
|
||||||
subdomains = (self.match_subdomains(self.domain, list_dns_resp.text))
|
subdomains = (self.match_subdomains(self.domain, list_dns_resp.text))
|
||||||
|
|||||||
Reference in New Issue
Block a user