From 990bbe5260c2e0dc972e8af7af5c18175bfc14dc Mon Sep 17 00:00:00 2001 From: Khanh Ngo Date: Thu, 24 Mar 2016 20:01:08 +0700 Subject: [PATCH] Add DNSSEC information into domain list. Adjustemnt in domain list table --- app/models.py | 26 ++++++++- .../admin/pages/scripts/table-managed.js | 54 +++++++++++++++++-- app/templates/dashboard.html | 13 ++++- app/views.py | 8 +++ 4 files changed, 95 insertions(+), 6 deletions(-) diff --git a/app/models.py b/app/models.py index b56487b..f9b4f23 100644 --- a/app/models.py +++ b/app/models.py @@ -357,8 +357,9 @@ class Domain(db.Model): serial = db.Column(db.Integer) notified_serial = db.Column(db.Integer) last_check = db.Column(db.Integer) + dnssec = db.Column(db.Integer) - def __int__(self, id=None, name=None, master=None, type='NATIVE', serial=None, notified_serial=None, last_check=None): + def __int__(self, id=None, name=None, master=None, type='NATIVE', serial=None, notified_serial=None, last_check=None, dnssec=None): self.id = id self.name = name self.master = master @@ -366,6 +367,7 @@ class Domain(db.Model): self.serial = serial self.notified_serial = notified_serial self.last_check = last_check + self.dnssec = dnssec def __repr__(self): return '' % (self.name) @@ -443,6 +445,7 @@ class Domain(db.Model): d.serial = data['serial'] d.notified_serial = data['notified_serial'] d.last_check = data['last_check'] + d.dnssec = data['dnssec'] else: # add new domain d = Domain() @@ -452,6 +455,7 @@ class Domain(db.Model): d.serial = data['serial'] d.notified_serial = data['notified_serial'] d.last_check = data['last_check'] + d.dnssec = data['dnssec'] db.session.add(d) try: db.session.commit() @@ -573,6 +577,26 @@ class Domain(db.Model): else: return {'status': 'error', 'msg': 'This domain doesnot exist'} + def get_domain_dnssec(self, domain_name): + """ + Get domain DNSSEC information + """ + domain = Domain.query.filter(Domain.name == domain_name).first() + if domain: + headers = {} + headers['X-API-Key'] = PDNS_API_KEY + try: + jdata = utils.fetch_json(urlparse.urljoin(PDNS_STATS_URL, '/servers/localhost/zones/%s/cryptokeys' % domain.name), headers=headers, method='GET') + if 'error' in jdata: + return {'status': 'error', 'msg': 'DNSSEC is not enabled for this domain'} + else: + return {'status': 'ok', 'dnssec': jdata} + except: + return {'status': 'error', 'msg': 'There was something wrong, please contact administrator'} + 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/static/admin/pages/scripts/table-managed.js b/app/static/admin/pages/scripts/table-managed.js index 82ebc67..cd6a581 100644 --- a/app/static/admin/pages/scripts/table-managed.js +++ b/app/static/admin/pages/scripts/table-managed.js @@ -42,6 +42,8 @@ var TableManaged = function () { "orderable": true }, { "orderable": true + }, { + "orderable": true }, { "orderable": false }], @@ -50,10 +52,10 @@ var TableManaged = function () { [5, 15, 20, "All"] // change per page values here ], // set the initial value - "pageLength": 5, + "pageLength": 10, "pagingType": "bootstrap_full_number", "language": { - "search": "My search: ", + "search": "Search: ", "lengthMenu": " _MENU_ records", "paginate": { "previous":"Prev", @@ -64,10 +66,10 @@ var TableManaged = function () { }, "columnDefs": [{ // set default column settings 'orderable': false, - 'targets': [0] + 'targets': [5] }, { "searchable": false, - "targets": [0] + "targets": [5] }], "order": [ [1, "asc"] @@ -96,6 +98,50 @@ var TableManaged = function () { }); tableWrapper.find('.dataTables_length select').addClass("form-control input-xsmall input-inline"); // modify table per page dropdown + + function getdnssec(url){ + $.getJSON(url, function(data) { + if (data['status'] == 'error'){ + bootbox.alert({ + title: 'DNSSEC', + message: 'DNSSEC is not enabled for this domain.' + }); + } + else { + var dnssec_msg = ''; + var dnssec = data['dnssec']; + for (var i = 0; i < dnssec.length; i++) { + if (dnssec[i]['active']){ + dnssec_msg += '
'+ + '

'+dnssec[i]['keytype']+'

'+ + 'DNSKEY'+ + ''+ + '
'+ + '
'; + if(dnssec[i]['ds']){ + var dsList = dnssec[i]['ds']; + dnssec_msg += 'DS'; + for (var j = 0; j < dsList.length; j++){ + dnssec_msg += ''; + } + } + } + } + bootbox.alert({ + title: 'DNSSEC', + message: dnssec_msg + }); + } + }); + } + + table.on('click', '.dnssec', function (e) { + e.preventDefault(); + var nRow = $(this).parents('tr')[0]; + var domain_name = nRow.cells[0].innerText; + getdnssec('/domain/'+ domain_name +'/dnssec'); + }); + } var initTableConfig = function () { diff --git a/app/templates/dashboard.html b/app/templates/dashboard.html index a7fde10..e86f4ce 100644 --- a/app/templates/dashboard.html +++ b/app/templates/dashboard.html @@ -69,12 +69,15 @@ {% endif %} - +
+ @@ -95,6 +98,13 @@ + @@ -135,6 +145,7 @@ + diff --git a/app/views.py b/app/views.py index 3a266ce..9969349 100644 --- a/app/views.py +++ b/app/views.py @@ -308,6 +308,14 @@ def record_delete(domain_name, record_name, record_type): return redirect(url_for('domain', domain_name=domain_name)) +@app.route('/domain//dnssec', methods=['GET']) +@login_required +def domain_dnssec(domain_name): + domain = Domain() + dnssec = domain.get_domain_dnssec(domain_name) + return make_response(jsonify(dnssec), 200) + + @app.route('/admin', methods=['GET', 'POST']) @login_required @admin_role_required
Name + DNSSEC + Kind {{ domain.name }} + {% if domain.dnssec %} + Enabled + {% else %} + Disabled + {% endif %} + {{ domain.type }}