Add DNSSEC information into domain list. Adjustemnt in domain list table

This commit is contained in:
Khanh Ngo 2016-03-24 20:01:08 +07:00
parent 7c46c149f8
commit 990bbe5260
4 changed files with 95 additions and 6 deletions

View File

@ -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 '<Domain %r>' % (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)

View File

@ -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 += '<form class="bootbox-form">'+
'<h3><strong>'+dnssec[i]['keytype']+'</strong></h3>'+
'<strong>DNSKEY</strong>'+
'<input class="bootbox-input bootbox-input-text form-control" autocomplete="off" type="text" readonly="true" value="'+dnssec[i]['dnskey']+'">'+
'</form>'+
'<br/>';
if(dnssec[i]['ds']){
var dsList = dnssec[i]['ds'];
dnssec_msg += '<strong>DS</strong>';
for (var j = 0; j < dsList.length; j++){
dnssec_msg += '<input class="bootbox-input bootbox-input-text form-control" autocomplete="off" type="text" readonly="true" value="'+dsList[j]+'">';
}
}
}
}
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 () {

View File

@ -69,12 +69,15 @@
</div>
</div>
{% endif %}
<table class="table table-striped table-bordered table-hover" id="tb_vps_list">
<table class="table table-striped table-bordered table-hover" id="tb_domain_list">
<thead>
<tr>
<th>
Name
</th>
<th>
DNSSEC
</th>
<th>
Kind
</th>
@ -95,6 +98,13 @@
<td>
<a href="{{ url_for('domain', domain_name=domain.name) }}"><strong>{{ domain.name }}</strong></a>
</td>
<td>
{% if domain.dnssec %}
<a href="javascript:;" class="btn default btn-xs blue dnssec"><i class="fa fa-lock"></i>Enabled</a>
{% else %}
<a href="javascript:;" class="btn default btn-xs gray dnssec"><i class="fa fa-unlock-alt"></i>Disabled</a>
{% endif %}
</td>
<td>
{{ domain.type }}
</td>
@ -135,6 +145,7 @@
<!-- BEGIN PAGE LEVEL SCRIPTS -->
<script src="{{ url_for('static', filename='global/scripts/metronic.js') }}" type="text/javascript"></script>
<script src="{{ url_for('static', filename='admin/layout2/scripts/layout.js') }}" type="text/javascript"></script>
<script src="{{ url_for('static', filename='global/plugins/bootbox/bootbox.min.js') }}" type="text/javascript"></script>
<!-- END PAGE LEVEL SCRIPTS -->
<!-- TABLE PLUGINS -->
<script type="text/javascript" src="{{ url_for('static', filename='global/plugins/select2/select2.min.js') }}"></script>

View File

@ -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/<string:domain_name>/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