mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2025-01-07 19:05:39 +00:00
Adjustment to support new api url format in pdns 4.x.x
This commit is contained in:
parent
fdd00f543a
commit
382807fdd7
@ -4,6 +4,7 @@ import json
|
|||||||
import requests
|
import requests
|
||||||
import urlparse
|
import urlparse
|
||||||
from app import app
|
from app import app
|
||||||
|
from distutils.version import StrictVersion
|
||||||
|
|
||||||
if 'TIMEOUT' in app.config.keys():
|
if 'TIMEOUT' in app.config.keys():
|
||||||
TIMEOUT = app.config['TIMEOUT']
|
TIMEOUT = app.config['TIMEOUT']
|
||||||
@ -132,3 +133,12 @@ def display_time(amount, units='s', remove_seconds=True):
|
|||||||
return final_string[:final_string.rfind(' ')]
|
return final_string[:final_string.rfind(' ')]
|
||||||
|
|
||||||
return final_string
|
return final_string
|
||||||
|
|
||||||
|
def pdns_api_extended_uri(version):
|
||||||
|
"""
|
||||||
|
Check the pdns version
|
||||||
|
"""
|
||||||
|
if StrictVersion(version) >= StrictVersion('4.0.0'):
|
||||||
|
return "/api/v1"
|
||||||
|
else:
|
||||||
|
return ""
|
||||||
|
@ -27,6 +27,8 @@ else:
|
|||||||
|
|
||||||
PDNS_STATS_URL = app.config['PDNS_STATS_URL']
|
PDNS_STATS_URL = app.config['PDNS_STATS_URL']
|
||||||
PDNS_API_KEY = app.config['PDNS_API_KEY']
|
PDNS_API_KEY = app.config['PDNS_API_KEY']
|
||||||
|
PDNS_VERSION = app.config['PDNS_VERSION']
|
||||||
|
API_EXTENDED_URL = utils.pdns_api_extended_uri(PDNS_VERSION)
|
||||||
|
|
||||||
|
|
||||||
class Anonymous(AnonymousUserMixin):
|
class Anonymous(AnonymousUserMixin):
|
||||||
@ -410,7 +412,7 @@ class Domain(db.Model):
|
|||||||
"""
|
"""
|
||||||
headers = {}
|
headers = {}
|
||||||
headers['X-API-Key'] = PDNS_API_KEY
|
headers['X-API-Key'] = PDNS_API_KEY
|
||||||
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, '/servers/localhost/zones'), headers=headers)
|
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones'), headers=headers)
|
||||||
return jdata
|
return jdata
|
||||||
|
|
||||||
def get_id_by_name(self, name):
|
def get_id_by_name(self, name):
|
||||||
@ -430,7 +432,7 @@ class Domain(db.Model):
|
|||||||
headers = {}
|
headers = {}
|
||||||
headers['X-API-Key'] = PDNS_API_KEY
|
headers['X-API-Key'] = PDNS_API_KEY
|
||||||
try:
|
try:
|
||||||
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, '/servers/localhost/zones'), headers=headers)
|
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones'), headers=headers)
|
||||||
list_jdomain = [d['name'] for d in jdata]
|
list_jdomain = [d['name'] for d in jdata]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -507,7 +509,7 @@ class Domain(db.Model):
|
|||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, '/servers/localhost/zones'), headers=headers, method='POST', data=post_data)
|
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones'), headers=headers, method='POST', data=post_data)
|
||||||
if 'error' in jdata.keys():
|
if 'error' in jdata.keys():
|
||||||
logging.error(jdata['error'])
|
logging.error(jdata['error'])
|
||||||
return {'status': 'error', 'msg': jdata['error']}
|
return {'status': 'error', 'msg': jdata['error']}
|
||||||
@ -528,7 +530,7 @@ class Domain(db.Model):
|
|||||||
headers = {}
|
headers = {}
|
||||||
headers['X-API-Key'] = PDNS_API_KEY
|
headers['X-API-Key'] = PDNS_API_KEY
|
||||||
try:
|
try:
|
||||||
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, '/servers/localhost/zones/%s' % domain_name), headers=headers, method='DELETE')
|
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/%s' % domain_name), headers=headers, method='DELETE')
|
||||||
logging.info('Delete domain %s successfully' % domain_name)
|
logging.info('Delete domain %s successfully' % domain_name)
|
||||||
return {'status': 'ok', 'msg': 'Delete domain successfully'}
|
return {'status': 'ok', 'msg': 'Delete domain successfully'}
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
@ -587,7 +589,7 @@ class Domain(db.Model):
|
|||||||
headers = {}
|
headers = {}
|
||||||
headers['X-API-Key'] = PDNS_API_KEY
|
headers['X-API-Key'] = PDNS_API_KEY
|
||||||
try:
|
try:
|
||||||
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, '/servers/localhost/zones/%s/axfr-retrieve' % domain), headers=headers, method='PUT')
|
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/%s/axfr-retrieve' % domain), headers=headers, method='PUT')
|
||||||
return {'status': 'ok', 'msg': 'Update from Master successfully'}
|
return {'status': 'ok', 'msg': 'Update from Master successfully'}
|
||||||
except:
|
except:
|
||||||
return {'status': 'error', 'msg': 'There was something wrong, please contact administrator'}
|
return {'status': 'error', 'msg': 'There was something wrong, please contact administrator'}
|
||||||
@ -603,7 +605,7 @@ class Domain(db.Model):
|
|||||||
headers = {}
|
headers = {}
|
||||||
headers['X-API-Key'] = PDNS_API_KEY
|
headers['X-API-Key'] = PDNS_API_KEY
|
||||||
try:
|
try:
|
||||||
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, '/servers/localhost/zones/%s/cryptokeys' % domain.name), headers=headers, method='GET')
|
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/%s/cryptokeys' % domain.name), headers=headers, method='GET')
|
||||||
if 'error' in jdata:
|
if 'error' in jdata:
|
||||||
return {'status': 'error', 'msg': 'DNSSEC is not enabled for this domain'}
|
return {'status': 'error', 'msg': 'DNSSEC is not enabled for this domain'}
|
||||||
else:
|
else:
|
||||||
@ -648,7 +650,7 @@ class Record(object):
|
|||||||
headers = {}
|
headers = {}
|
||||||
headers['X-API-Key'] = PDNS_API_KEY
|
headers['X-API-Key'] = PDNS_API_KEY
|
||||||
try:
|
try:
|
||||||
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, '/servers/localhost/zones/%s' % domain), headers=headers)
|
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/%s' % domain), headers=headers)
|
||||||
except:
|
except:
|
||||||
logging.error("Cannot fetch domain's record data from remote powerdns api")
|
logging.error("Cannot fetch domain's record data from remote powerdns api")
|
||||||
return False
|
return False
|
||||||
@ -688,7 +690,7 @@ class Record(object):
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, '/servers/localhost/zones/%s' % domain), headers=headers, method='PATCH', data=data)
|
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/%s' % domain), headers=headers, method='PATCH', data=data)
|
||||||
logging.debug(jdata)
|
logging.debug(jdata)
|
||||||
return {'status': 'ok', 'msg': 'Record was added successfully'}
|
return {'status': 'ok', 'msg': 'Record was added successfully'}
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
@ -782,10 +784,10 @@ class Record(object):
|
|||||||
try:
|
try:
|
||||||
headers = {}
|
headers = {}
|
||||||
headers['X-API-Key'] = PDNS_API_KEY
|
headers['X-API-Key'] = PDNS_API_KEY
|
||||||
jdata1 = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, '/servers/localhost/zones/%s' % domain), headers=headers, method='PATCH', data=postdata_for_delete)
|
jdata1 = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/%s' % domain), headers=headers, method='PATCH', data=postdata_for_delete)
|
||||||
#logging.debug(jdata1)
|
#logging.debug(jdata1)
|
||||||
|
|
||||||
jdata2 = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, '/servers/localhost/zones/%s' % domain), headers=headers, method='PATCH', data=postdata_for_new)
|
jdata2 = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/%s' % domain), headers=headers, method='PATCH', data=postdata_for_new)
|
||||||
#logging.debug(jdata2)
|
#logging.debug(jdata2)
|
||||||
|
|
||||||
if 'error' in jdata2.keys():
|
if 'error' in jdata2.keys():
|
||||||
@ -821,7 +823,7 @@ class Record(object):
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, '/servers/localhost/zones/%s' % domain), headers=headers, method='PATCH', data=data)
|
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/localhost/zones/%s' % domain), headers=headers, method='PATCH', data=data)
|
||||||
logging.debug(jdata)
|
logging.debug(jdata)
|
||||||
return {'status': 'ok', 'msg': 'Record was removed successfully'}
|
return {'status': 'ok', 'msg': 'Record was removed successfully'}
|
||||||
except:
|
except:
|
||||||
@ -853,7 +855,7 @@ class Server(object):
|
|||||||
headers['X-API-Key'] = PDNS_API_KEY
|
headers['X-API-Key'] = PDNS_API_KEY
|
||||||
|
|
||||||
try:
|
try:
|
||||||
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, '/servers/%s/config' % self.server_id), headers=headers, method='GET')
|
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/%s/config' % self.server_id), headers=headers, method='GET')
|
||||||
return jdata
|
return jdata
|
||||||
except:
|
except:
|
||||||
logging.error("Can not get server configuration.")
|
logging.error("Can not get server configuration.")
|
||||||
@ -866,9 +868,9 @@ class Server(object):
|
|||||||
"""
|
"""
|
||||||
headers = {}
|
headers = {}
|
||||||
headers['X-API-Key'] = PDNS_API_KEY
|
headers['X-API-Key'] = PDNS_API_KEY
|
||||||
|
|
||||||
try:
|
try:
|
||||||
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, '/servers/%s/statistics' % self.server_id), headers=headers, method='GET')
|
jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, API_EXTENDED_URL + '/servers/%s/statistics' % self.server_id), headers=headers, method='GET')
|
||||||
return jdata
|
return jdata
|
||||||
except:
|
except:
|
||||||
logging.error("Can not get server statistics.")
|
logging.error("Can not get server statistics.")
|
||||||
|
@ -40,6 +40,7 @@ SIGNUP_ENABLED = True
|
|||||||
# POWERDNS CONFIG
|
# POWERDNS CONFIG
|
||||||
PDNS_STATS_URL = 'http://172.16.214.131:8081/'
|
PDNS_STATS_URL = 'http://172.16.214.131:8081/'
|
||||||
PDNS_API_KEY = 'you never know'
|
PDNS_API_KEY = 'you never know'
|
||||||
|
PDNS_VERSION = '3.4.7'
|
||||||
|
|
||||||
# RECORDS ALLOWED TO EDIT
|
# RECORDS ALLOWED TO EDIT
|
||||||
RECORDS_ALLOW_EDIT = ['A', 'AAAA', 'CNAME', 'SPF', 'PTR', 'MX', 'TXT']
|
RECORDS_ALLOW_EDIT = ['A', 'AAAA', 'CNAME', 'SPF', 'PTR', 'MX', 'TXT']
|
||||||
|
Loading…
Reference in New Issue
Block a user