2018-03-05 14:26:45 +00:00
|
|
|
var dnssecKeyList = []
|
|
|
|
|
2016-08-21 14:46:23 +00:00
|
|
|
function applyChanges(data, url, showResult, refreshPage) {
|
|
|
|
$.ajax({
|
|
|
|
type : "POST",
|
|
|
|
url : url,
|
|
|
|
data : JSON.stringify(data),// now data come in this function
|
|
|
|
contentType : "application/json; charset=utf-8",
|
|
|
|
crossDomain : true,
|
|
|
|
dataType : "json",
|
|
|
|
success : function(data, status, jqXHR) {
|
2019-12-11 06:45:27 +00:00
|
|
|
console.log("Applied changes successfully.");
|
|
|
|
console.log(data);
|
2016-08-21 14:46:23 +00:00
|
|
|
if (showResult) {
|
2022-05-18 22:53:20 +00:00
|
|
|
showSuccessModal(data['msg'] || "Applied changes successfully");
|
2016-08-21 14:46:23 +00:00
|
|
|
}
|
|
|
|
if (refreshPage) {
|
|
|
|
location.reload(true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
error : function(jqXHR, status) {
|
|
|
|
console.log(jqXHR);
|
2018-08-31 04:57:06 +00:00
|
|
|
var responseJson = jQuery.parseJSON(jqXHR.responseText);
|
2022-05-18 22:53:20 +00:00
|
|
|
showErrorModal(responseJson['msg']);
|
2016-08-21 14:46:23 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-12 04:18:44 +00:00
|
|
|
function applyRecordChanges(data, domain) {
|
|
|
|
$.ajax({
|
|
|
|
type : "POST",
|
|
|
|
url : $SCRIPT_ROOT + '/domain/' + domain + '/apply',
|
|
|
|
data : JSON.stringify(data),// now data come in this function
|
|
|
|
contentType : "application/json; charset=utf-8",
|
|
|
|
crossDomain : true,
|
|
|
|
dataType : "json",
|
|
|
|
success : function(data, status, jqXHR) {
|
|
|
|
// update Apply button value
|
|
|
|
$.getJSON($SCRIPT_ROOT + '/domain/' + domain + '/info', function(data) {
|
|
|
|
$(".button_apply_changes").val(data['serial']);
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log("Applied changes successfully.")
|
2022-05-18 22:53:20 +00:00
|
|
|
showSuccessModal("Applied changes successfully");
|
2021-11-30 09:02:37 +00:00
|
|
|
setTimeout(() => {window.location.reload()}, 2000);
|
2018-04-12 04:18:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
error : function(jqXHR, status) {
|
|
|
|
console.log(jqXHR);
|
|
|
|
var responseJson = jQuery.parseJSON(jqXHR.responseText);
|
2022-05-18 22:53:20 +00:00
|
|
|
showErrorModal(responseJson['msg']);
|
2018-04-12 04:18:44 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-08-21 14:46:23 +00:00
|
|
|
function getTableData(table) {
|
|
|
|
// reformat - pretty format
|
|
|
|
var records = []
|
|
|
|
table.rows().every(function() {
|
|
|
|
var r = this.data();
|
|
|
|
var record = {}
|
|
|
|
record["record_name"] = r[0].trim();
|
|
|
|
record["record_type"] = r[1].trim();
|
|
|
|
record["record_status"] = r[2].trim();
|
|
|
|
record["record_ttl"] = r[3].trim();
|
2022-04-04 12:43:02 +00:00
|
|
|
record["record_data"] = convertHTMLEntityToText(r[4].trim());
|
|
|
|
record["record_comment"] = convertHTMLEntityToText(r[5].trim());
|
2016-08-21 14:46:23 +00:00
|
|
|
records.push(record);
|
|
|
|
});
|
|
|
|
return records
|
|
|
|
}
|
|
|
|
|
2022-04-04 12:43:02 +00:00
|
|
|
function convertHTMLEntityToText(htmlEntity) {
|
|
|
|
return $('<textarea />').html(htmlEntity).text();
|
|
|
|
}
|
|
|
|
|
2016-08-21 14:46:23 +00:00
|
|
|
function saveRow(oTable, nRow) {
|
|
|
|
|
2018-08-31 14:57:52 +00:00
|
|
|
var status = 'Disabled';
|
2016-08-21 14:46:23 +00:00
|
|
|
var jqInputs = $(oTable.row(nRow).node()).find("input");
|
|
|
|
var jqSelect = $(oTable.row(nRow).node()).find("select");
|
|
|
|
|
|
|
|
if (jqSelect[1].value == 'false') {
|
|
|
|
status = 'Active';
|
|
|
|
}
|
|
|
|
|
|
|
|
oTable.cell(nRow,0).data(jqInputs[0].value);
|
|
|
|
oTable.cell(nRow,1).data(jqSelect[0].value);
|
|
|
|
oTable.cell(nRow,2).data(status);
|
|
|
|
oTable.cell(nRow,3).data(jqSelect[2].value);
|
|
|
|
oTable.cell(nRow,4).data(jqInputs[1].value);
|
2019-12-09 10:50:48 +00:00
|
|
|
oTable.cell(nRow,5).data(jqInputs[2].value);
|
2016-08-21 14:46:23 +00:00
|
|
|
|
|
|
|
var record = jqInputs[0].value;
|
|
|
|
var button_edit = "<button type=\"button\" class=\"btn btn-flat btn-warning button_edit\" id=\"" + record + "\">Edit <i class=\"fa fa-edit\"></i></button>"
|
|
|
|
var button_delete = "<button type=\"button\" class=\"btn btn-flat btn-danger button_delete\" id=\"" + record + "\">Delete <i class=\"fa fa-trash\"></i></button>"
|
|
|
|
|
2019-12-09 10:50:48 +00:00
|
|
|
oTable.cell(nRow,6).data(button_edit);
|
|
|
|
oTable.cell(nRow,7).data(button_delete);
|
2016-08-21 14:46:23 +00:00
|
|
|
|
|
|
|
oTable.draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
function restoreRow(oTable, nRow) {
|
|
|
|
var aData = oTable.row(nRow).data();
|
|
|
|
oTable.row(nRow).data(aData);
|
|
|
|
oTable.draw();
|
|
|
|
}
|
|
|
|
|
2018-11-28 21:19:38 +00:00
|
|
|
function sec2str(t){
|
|
|
|
var d = Math.floor(t/86400),
|
|
|
|
h = Math.floor(t/3600) % 24,
|
|
|
|
m = Math.floor(t/60) % 60,
|
|
|
|
s = t % 60;
|
|
|
|
return (d>0?d+' days ':'')+(h>0?h+' hours ':'')+(m>0?m+' minutes ':'')+(s>0?s+' seconds':'');
|
|
|
|
}
|
|
|
|
|
2016-08-21 14:46:23 +00:00
|
|
|
function editRow(oTable, nRow) {
|
2018-08-31 14:57:52 +00:00
|
|
|
var isDisabled = 'true';
|
2016-08-21 14:46:23 +00:00
|
|
|
var aData = oTable.row(nRow).data();
|
|
|
|
var jqTds = oTable.cells(nRow,'').nodes();
|
|
|
|
var record_types = "";
|
2018-11-24 12:45:14 +00:00
|
|
|
var ttl_opts = "";
|
2018-11-28 21:19:38 +00:00
|
|
|
var ttl_not_found = true;
|
2016-08-21 14:46:23 +00:00
|
|
|
for(var i = 0; i < records_allow_edit.length; i++) {
|
|
|
|
var record_type = records_allow_edit[i];
|
|
|
|
record_types += "<option value=\"" + record_type + "\">" + record_type + "</option>";
|
|
|
|
}
|
2018-11-24 12:45:14 +00:00
|
|
|
for(var i = 0; i < ttl_options.length; i++) {
|
|
|
|
ttl_opts += "<option value=\"" + ttl_options[i][0] + "\">" + ttl_options[i][1] + "</option>";
|
2018-11-28 21:19:38 +00:00
|
|
|
if (ttl_options[i][0] == aData[3]) {
|
|
|
|
ttl_not_found = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ttl_not_found) {
|
|
|
|
ttl_opts += "<option value=\"" + aData[3] + "\">" + sec2str(aData[3]) + "</option>";
|
2018-11-24 12:45:14 +00:00
|
|
|
}
|
2016-08-21 14:46:23 +00:00
|
|
|
jqTds[0].innerHTML = '<input type="text" id="edit-row-focus" class="form-control input-small" value="' + aData[0] + '">';
|
2018-11-24 12:45:14 +00:00
|
|
|
jqTds[1].innerHTML = '<select class="form-control" id="record_type" name="record_type" value="' + aData[1] + '">' + record_types + '</select>';
|
|
|
|
jqTds[2].innerHTML = '<select class="form-control" id="record_status" name="record_status" value="' + aData[2] + '"><option value="false">Active</option><option value="true">Disabled</option></select>';
|
|
|
|
jqTds[3].innerHTML = '<select class="form-control" id="record_ttl" name="record_ttl" value="' + aData[3] + '">' + ttl_opts + '</select>';
|
2016-08-21 14:46:23 +00:00
|
|
|
jqTds[4].innerHTML = '<input type="text" style="display:table-cell; width:100% !important" id="current_edit_record_data" name="current_edit_record_data" class="form-control input-small advance-data" value="' + aData[4].replace(/\"/g,""") + '">';
|
2019-12-09 10:50:48 +00:00
|
|
|
jqTds[5].innerHTML = '<input type="text" style="display:table-cell; width:100% !important" id="record_comment" name="record_comment" class="form-control input-small advance-data" value="' + aData[5].replace(/\"/g, """) + '">';
|
|
|
|
jqTds[6].innerHTML = '<button type="button" class="btn btn-flat btn-primary button_save">Save</button>';
|
|
|
|
jqTds[7].innerHTML = '<button type="button" class="btn btn-flat btn-primary button_cancel">Cancel</button>';
|
2016-08-21 14:46:23 +00:00
|
|
|
|
2018-10-02 07:13:08 +00:00
|
|
|
// set current value of dropdown column
|
2016-08-21 14:46:23 +00:00
|
|
|
if (aData[2] == 'Active'){
|
|
|
|
isDisabled = 'false';
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectElement('record_type', aData[1]);
|
|
|
|
SelectElement('record_status', isDisabled);
|
|
|
|
SelectElement('record_ttl', aData[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function SelectElement(elementID, valueToSelect)
|
|
|
|
{
|
|
|
|
var element = document.getElementById(elementID);
|
|
|
|
element.value = valueToSelect;
|
|
|
|
}
|
|
|
|
|
2018-11-21 03:24:33 +00:00
|
|
|
function enable_dns_sec(url, csrf_token) {
|
|
|
|
$.post(url, {'_csrf_token': csrf_token}, function(data) {
|
2018-03-05 10:18:29 +00:00
|
|
|
var modal = $("#modal_dnssec_info");
|
|
|
|
|
|
|
|
if (data['status'] == 'error'){
|
|
|
|
modal.find('.modal-body p').text(data['msg']);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
modal.modal('hide');
|
|
|
|
//location.reload();
|
|
|
|
window.location.reload(true);
|
|
|
|
}
|
2018-11-21 03:24:33 +00:00
|
|
|
}, 'json')
|
2018-03-05 10:18:29 +00:00
|
|
|
}
|
|
|
|
|
2018-04-02 06:38:53 +00:00
|
|
|
function getdnssec(url, domain){
|
2016-08-21 14:46:23 +00:00
|
|
|
|
|
|
|
$.getJSON(url, function(data) {
|
2018-08-31 14:57:52 +00:00
|
|
|
var dnssec_footer = '';
|
2016-08-21 14:46:23 +00:00
|
|
|
var modal = $("#modal_dnssec_info");
|
|
|
|
|
|
|
|
if (data['status'] == 'error'){
|
|
|
|
modal.find('.modal-body p').text(data['msg']);
|
|
|
|
}
|
|
|
|
else {
|
2018-08-31 14:57:52 +00:00
|
|
|
var dnssec_msg = '';
|
2016-08-21 14:46:23 +00:00
|
|
|
var dnssec = data['dnssec'];
|
2018-03-05 10:18:29 +00:00
|
|
|
|
2018-04-02 06:38:53 +00:00
|
|
|
if (dnssec.length == 0 && parseFloat(PDNS_VERSION) >= 4.1) {
|
|
|
|
dnssec_msg = '<h3>DNSSEC is disabled. Click on Enable to activate it.';
|
2018-02-28 13:47:10 +00:00
|
|
|
modal.find('.modal-body p').html(dnssec_msg);
|
2018-03-05 14:26:45 +00:00
|
|
|
dnssec_footer = '<button type="button" class="btn btn-flat btn-success button_dnssec_enable pull-left" id="'+domain+'">Enable</button><button type="button" class="btn btn-flat btn-default pull-right" data-dismiss="modal">Cancel</button>';
|
2018-02-28 13:47:10 +00:00
|
|
|
modal.find('.modal-footer ').html(dnssec_footer);
|
|
|
|
}
|
2018-03-05 14:26:45 +00:00
|
|
|
else {
|
2018-04-02 06:38:53 +00:00
|
|
|
if (parseFloat(PDNS_VERSION) >= 4.1) {
|
2018-03-05 14:26:45 +00:00
|
|
|
dnssec_footer = '<button type="button" class="btn btn-flat btn-danger button_dnssec_disable pull-left" id="'+domain+'">Disable DNSSEC</button><button type="button" class="btn btn-flat btn-default pull-right" data-dismiss="modal">Close</button>';
|
|
|
|
modal.find('.modal-footer ').html(dnssec_footer);
|
2016-08-21 14:46:23 +00:00
|
|
|
}
|
2018-03-05 14:26:45 +00:00
|
|
|
for (var i = 0; i < dnssec.length; i++) {
|
|
|
|
if (dnssec[i]['active']){
|
|
|
|
dnssec_msg += '<form>'+
|
|
|
|
'<h3><strong>'+dnssec[i]['keytype']+'</strong></h3>'+
|
|
|
|
'<strong>DNSKEY</strong>'+
|
|
|
|
'<input class="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="form-control" autocomplete="off" type="text" readonly="true" value="'+dsList[j]+'">';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dnssec_msg += '</form>';
|
|
|
|
}
|
|
|
|
}
|
2016-08-21 14:46:23 +00:00
|
|
|
}
|
|
|
|
modal.find('.modal-body p').html(dnssec_msg);
|
|
|
|
}
|
|
|
|
modal.modal('show');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-08 11:26:06 +00:00
|
|
|
function reload_domains(url) {
|
|
|
|
$.getJSON(url, function(data) {
|
|
|
|
$('#modal_bg_reload_content').html("<i class=\"fa fa-check\"></i> Finished: " + data['result']['msg']);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-21 14:46:23 +00:00
|
|
|
// pretty JSON
|
|
|
|
json_library = {
|
2019-12-15 14:42:08 +00:00
|
|
|
replacer: function (match, pIndent, pKey, pVal, pEnd) {
|
2016-08-21 14:46:23 +00:00
|
|
|
var key = '<span class=json-key>';
|
|
|
|
var val = '<span class=json-value>';
|
|
|
|
var str = '<span class=json-string>';
|
|
|
|
var r = pIndent || '';
|
2019-12-15 14:42:08 +00:00
|
|
|
if (pKey) {
|
|
|
|
// r = r + key + pKey.replace(/[": ]/g, '') + '</span>: ';
|
|
|
|
// Keep the quote in the key
|
|
|
|
r = r + key + pKey.replace(/":/, '"') + '</span>: ';
|
2016-08-21 14:46:23 +00:00
|
|
|
}
|
2019-12-15 14:42:08 +00:00
|
|
|
if (pVal) {
|
2016-08-21 14:46:23 +00:00
|
|
|
r = r + (pVal[0] == '"' ? str : val) + pVal + '</span>';
|
|
|
|
}
|
|
|
|
return r + (pEnd || '');
|
|
|
|
},
|
2019-12-15 14:42:08 +00:00
|
|
|
prettyPrint: function (obj) {
|
2018-09-06 04:35:54 +00:00
|
|
|
obj = obj.replace(/u'/g, "\'").replace(/'/g, "\"").replace(/(False|None)/g, "\"$1\"");
|
2016-08-21 14:46:23 +00:00
|
|
|
var jsonData = JSON.parse(obj);
|
2019-12-15 14:42:08 +00:00
|
|
|
// var jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?$/mg;
|
|
|
|
// The new regex to handle case value is an empty list [] or dict {}
|
|
|
|
var jsonLine = /^( *)("[\w]+": )?("[^"]*"|[\w.+-]*)?([,[{])?/mg;
|
|
|
|
return JSON.stringify(jsonData, null, 3)
|
2016-08-21 14:46:23 +00:00
|
|
|
.replace(/&/g, '&').replace(/\\"/g, '"')
|
|
|
|
.replace(/</g, '<').replace(/>/g, '>')
|
|
|
|
.replace(jsonLine, json_library.replacer);
|
2019-12-15 14:42:08 +00:00
|
|
|
}
|
|
|
|
};
|
2019-12-17 16:46:34 +00:00
|
|
|
|
|
|
|
// set count down in second on an element
|
|
|
|
function timer(elToUpdate, maxTime) {
|
|
|
|
elToUpdate.text(maxTime + "s");
|
|
|
|
|
|
|
|
var interval = setInterval(function () {
|
|
|
|
if (maxTime > 0) {
|
|
|
|
maxTime--;
|
|
|
|
elToUpdate.text(maxTime + "s");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
clearInterval(interval);
|
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
return interval;
|
2021-12-17 10:41:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// copy otp secret code to clipboard
|
|
|
|
function copy_otp_secret_to_clipboard() {
|
|
|
|
var copyBox = document.getElementById("otp_secret");
|
|
|
|
copyBox.select();
|
|
|
|
copyBox.setSelectionRange(0, 99999); /* For mobile devices */
|
|
|
|
navigator.clipboard.writeText(copyBox.value);
|
|
|
|
$("#copy_tooltip").css("visibility", "visible");
|
|
|
|
setTimeout(function(){ $("#copy_tooltip").css("visibility", "collapse"); }, 2000);
|
2023-02-02 21:19:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Side menu nav bar active selection
|
|
|
|
/** add active class and stay opened when selected */
|
|
|
|
var url = window.location;
|
|
|
|
|
|
|
|
// for sidebar menu entirely but not cover treeview
|
|
|
|
$('ul.nav-sidebar a').filter(function() {
|
|
|
|
return this.href == url;
|
|
|
|
}).addClass('active');
|
|
|
|
|
|
|
|
// for treeview
|
|
|
|
$('ul.nav-treeview a').filter(function() {
|
|
|
|
return this.href == url;
|
|
|
|
}).parentsUntil(".nav-sidebar > .nav-treeview").addClass('menu-open').prev('a').addClass('active');
|