From 5ea70023ffbb79bdfbc578ec08b6ad3d65d27d6f Mon Sep 17 00:00:00 2001 From: Jeroen Boonstra Date: Mon, 5 Mar 2018 15:06:40 +0100 Subject: [PATCH] remove dnssec keys --- app/models.py | 21 +++++++++++++++++++++ app/views.py | 8 +++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/models.py b/app/models.py index ca35d70..d7de8c4 100644 --- a/app/models.py +++ b/app/models.py @@ -846,6 +846,27 @@ class Domain(db.Model): else: return {'status': 'error', 'msg': 'This domain doesnot exist'} + def delete_dnssec_key(self, domain_name, key_id): + """ + Remove keys DNSSEC + """ + domain = Domain.query.filter(Domain.name == domain_name).first() + if domain: + headers = {} + headers['X-API-Key'] = PDNS_API_KEY + url = '/servers/localhost/zones/%s/cryptokeys/%s' % (domain.name, key_id) + + try: + jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, API_EXTENDED_URL + url), headers=headers, method='DELETE') + if 'error' in jdata: + return {'status': 'error', 'msg': 'DNSSEC is not disabled for this domain', 'jdata' : jdata} + else: + return {'status': 'ok'} + except: + return {'status': 'error', 'msg': 'There was something wrong, please contact administrator','id': key_id, 'url': url} + else: + return {'status': 'error', 'msg': 'This domain doesnot exist'} + class DomainUser(db.Model): __tablename__ = 'domain_user' id = db.Column(db.Integer, primary_key = True) diff --git a/app/views.py b/app/views.py index 5a2d7df..2963354 100644 --- a/app/views.py +++ b/app/views.py @@ -662,7 +662,13 @@ def domain_dnssec_disable(domain_name): domain = Domain() dnssec = domain.get_domain_dnssec(domain_name) - return make_response(jsonify({'status': 'error', 'msg': 'Function not implemented'}), 400) + + for key in dnssec['dnssec']: + response = domain.delete_dnssec_key(domain_name,key['id']); + + return make_response(jsonify( { 'status': 'ok', 'msg': 'Setting updated.', 'response': response } )) + + #return make_response(jsonify({'status': 'error', 'msg': 'Function not implemented'}), 400) #return make_response(jsonify(dnssec), 200) @app.route('/domain//managesetting', methods=['GET', 'POST'])