2016-01-18 20:45:07 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Lukas Metzger <developer@lukas-metzger.com>.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-01-20 19:46:14 +00:00
|
|
|
var sort = {
|
|
|
|
field: "",
|
|
|
|
order: 1
|
2016-01-23 16:05:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var domainName = "";
|
|
|
|
|
|
|
|
var recordTypes = [
|
|
|
|
"A","AAAA","AFSDB","CERT","CNAME","DHCID",
|
|
|
|
"DLV","DNSKEY","DS","EUI48","EUI64","HINFO",
|
|
|
|
"IPSECKEY","KEY","KX","LOC","MINFO","MR",
|
|
|
|
"MX","NAPTR","NS","NSEC","NSEC3","NSEC3PARAM",
|
|
|
|
"OPT","PTR","RKEY","RP","RRSIG","SOA","SPF",
|
|
|
|
"SRV","SSHFP","TLSA","TSIG","TXT","WKS"
|
|
|
|
];
|
2016-01-20 19:46:14 +00:00
|
|
|
|
2016-01-18 20:45:07 +00:00
|
|
|
$(document).ready(function() {
|
|
|
|
|
|
|
|
$('#soa button[type=submit]').click(function(){
|
|
|
|
if(validateSoaData()) {
|
2016-01-20 20:48:17 +00:00
|
|
|
saveSoaData();
|
|
|
|
$('#soa button[type=submit]').prop("disabled", true);
|
2016-01-18 20:45:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-01-20 20:48:17 +00:00
|
|
|
$('#soa input').bind("paste keyup change", function() {
|
|
|
|
$('#soa button[type=submit]').prop("disabled", false);
|
|
|
|
});
|
|
|
|
|
2016-01-23 16:29:53 +00:00
|
|
|
$('#soa form input').bind("paste keyup change", regexValidate);
|
|
|
|
$('#table-records>tfoot input').bind("paste keyup change", regexValidate);
|
2016-01-20 19:46:14 +00:00
|
|
|
|
|
|
|
$('#searchType').select2({
|
2016-01-23 16:05:13 +00:00
|
|
|
placeholder: "Filter...",
|
|
|
|
data: recordTypes
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#addType').select2({
|
|
|
|
data: recordTypes
|
2016-01-20 19:46:14 +00:00
|
|
|
});
|
2016-01-18 20:45:07 +00:00
|
|
|
|
2016-01-20 19:46:14 +00:00
|
|
|
$('#table-records>thead>tr>td span.glyphicon').click(function() {
|
|
|
|
var field = $(this).siblings('strong').text().toLowerCase();
|
|
|
|
if(sort.field == field) {
|
|
|
|
if(sort.order == 1) sort.order = 0;
|
|
|
|
else sort.field = "";
|
|
|
|
} else {
|
|
|
|
sort.field = field;
|
|
|
|
sort.order = 1;
|
|
|
|
}
|
|
|
|
$('#table-records>thead>tr>td span').removeClass("glyphicon-sort-by-attributes glyphicon-sort-by-attributes-alt");
|
|
|
|
|
|
|
|
if(sort.field == field) {
|
|
|
|
if(sort.order == 1) $(this).addClass("glyphicon-sort-by-attributes");
|
|
|
|
else $(this).addClass("glyphicon-sort-by-attributes-alt");
|
|
|
|
}
|
|
|
|
requestRecordData();
|
|
|
|
});
|
2016-01-18 20:45:07 +00:00
|
|
|
|
2016-01-20 19:46:14 +00:00
|
|
|
$('#searchName, #searchContent').bind("paste keyup", function() {
|
|
|
|
requestRecordData();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#searchType').change(function() {
|
|
|
|
requestRecordData();
|
|
|
|
});
|
2016-01-23 16:05:13 +00:00
|
|
|
|
|
|
|
$('#addButton').click(addRecord);
|
|
|
|
|
2016-01-20 19:46:14 +00:00
|
|
|
requestRecordData();
|
2016-01-20 20:48:17 +00:00
|
|
|
requestSoaData();
|
2016-01-23 16:05:13 +00:00
|
|
|
requestSerial();
|
|
|
|
requestDomainName();
|
2016-01-18 20:45:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function validateSoaData() {
|
|
|
|
|
|
|
|
var error = 0;
|
|
|
|
|
|
|
|
$('#soa form input:not(#soa-serial)').each(function() {
|
|
|
|
if($(this).val().length <= 0 || $(this).parent().hasClass('has-error')) {
|
|
|
|
error++;
|
|
|
|
$(this).parent().addClass('has-error');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return error<=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function recreateTable(data) {
|
2016-01-20 19:46:14 +00:00
|
|
|
$('#table-records>tbody').empty();
|
2016-01-18 20:45:07 +00:00
|
|
|
|
|
|
|
$.each(data, function(index,item) {
|
2016-01-20 19:46:14 +00:00
|
|
|
$('<tr></tr>').appendTo('#table-records>tbody')
|
2016-01-18 20:45:07 +00:00
|
|
|
.append('<td>' + item.id + '</td>')
|
|
|
|
.append('<td>' + item.name + '</td>')
|
|
|
|
.append('<td>' + item.type + '</td>')
|
2016-01-20 19:46:14 +00:00
|
|
|
.append('<td>' + item.content + '</td>')
|
|
|
|
.append('<td>' + item.priority + '</td>')
|
|
|
|
.append('<td>' + item.ttl + '</td>')
|
2016-01-23 16:05:13 +00:00
|
|
|
.append('<td><span class="glyphicon glyphicon-pencil cursor-pointer"></span></td>')
|
2016-02-05 16:14:49 +00:00
|
|
|
.append('<td><span class="glyphicon glyphicon-trash cursor-pointer"></span></td>')
|
|
|
|
.append('<td><span class="glyphicon glyphicon-share cursor-pointer"></span></td>');
|
2016-01-18 20:45:07 +00:00
|
|
|
|
|
|
|
});
|
2016-01-23 16:05:13 +00:00
|
|
|
|
|
|
|
$('#table-records>tbody>tr>td>span.glyphicon-trash').click(trashClicked);
|
|
|
|
$('#table-records>tbody>tr>td>span.glyphicon-pencil').click(editClicked);
|
2016-02-05 16:14:49 +00:00
|
|
|
$('#table-records>tbody>tr>td>span.glyphicon-share').click(remoteClicked);
|
2016-01-20 19:46:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function requestRecordData() {
|
2016-01-29 15:52:23 +00:00
|
|
|
var restrictions = {
|
|
|
|
csrfToken: $('#csrfToken').text()
|
|
|
|
};
|
2016-01-18 20:45:07 +00:00
|
|
|
|
2016-01-20 19:46:14 +00:00
|
|
|
restrictions.sort = sort;
|
|
|
|
|
|
|
|
var searchName = $('#searchName').val();
|
|
|
|
if(searchName.length > 0) {
|
|
|
|
restrictions.name = searchName;
|
|
|
|
}
|
|
|
|
|
|
|
|
var searchType = $('#searchType').val();
|
|
|
|
if(searchType != null && searchType.length > 0) {
|
|
|
|
restrictions.type = searchType;
|
|
|
|
}
|
|
|
|
|
|
|
|
var searchContent = $('#searchContent').val();
|
|
|
|
if(searchContent.length > 0) {
|
|
|
|
restrictions.content = searchContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
restrictions.action = "getRecords";
|
|
|
|
|
|
|
|
restrictions.domain = location.hash.substring(1);
|
|
|
|
|
|
|
|
$.post(
|
|
|
|
"api/edit-master.php",
|
|
|
|
JSON.stringify(restrictions),
|
|
|
|
function(data) {
|
|
|
|
recreateTable(data);
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
2016-01-20 20:48:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function requestSoaData() {
|
|
|
|
var data = {
|
2016-01-29 15:52:23 +00:00
|
|
|
action: "getSoa",
|
|
|
|
csrfToken: $('#csrfToken').text()
|
2016-01-20 20:48:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
data.domain = location.hash.substring(1);
|
|
|
|
|
|
|
|
$.post(
|
|
|
|
"api/edit-master.php",
|
|
|
|
JSON.stringify(data),
|
|
|
|
function(data) {
|
|
|
|
$('#soa-primary').val(data.primary);
|
|
|
|
$('#soa-mail').val(data.email);
|
|
|
|
$('#soa-refresh').val(data.refresh);
|
|
|
|
$('#soa-retry').val(data.retry);
|
|
|
|
$('#soa-expire').val(data.expire);
|
|
|
|
$('#soa-ttl').val(data.ttl);
|
2016-01-23 16:05:13 +00:00
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function requestSerial() {
|
|
|
|
var data = {
|
2016-01-29 15:52:23 +00:00
|
|
|
action: "getSerial",
|
|
|
|
csrfToken: $('#csrfToken').text()
|
2016-01-23 16:05:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
data.domain = location.hash.substring(1);
|
|
|
|
|
|
|
|
$.post(
|
|
|
|
"api/edit-master.php",
|
|
|
|
JSON.stringify(data),
|
|
|
|
function(data) {
|
2016-01-20 20:48:17 +00:00
|
|
|
$('#soa-serial').val(data.serial);
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveSoaData() {
|
2016-01-23 16:05:13 +00:00
|
|
|
var data = {
|
2016-01-29 15:52:23 +00:00
|
|
|
action: "saveSoa",
|
|
|
|
csrfToken: $('#csrfToken').text()
|
2016-01-23 16:05:13 +00:00
|
|
|
};
|
2016-01-20 20:48:17 +00:00
|
|
|
|
2016-01-23 16:05:13 +00:00
|
|
|
data.domain = location.hash.substring(1);
|
|
|
|
|
|
|
|
data.primary = $('#soa-primary').val();
|
|
|
|
data.email = $('#soa-mail').val();
|
|
|
|
data.refresh = $('#soa-refresh').val();
|
|
|
|
data.retry = $('#soa-retry').val();
|
|
|
|
data.expire = $('#soa-expire').val();
|
|
|
|
data.ttl = $('#soa-ttl').val();
|
|
|
|
|
|
|
|
$.post(
|
|
|
|
"api/edit-master.php",
|
|
|
|
JSON.stringify(data),
|
|
|
|
function() {
|
|
|
|
requestSerial();
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function editClicked() {
|
|
|
|
var tableCells = $(this).parent().parent().children('td');
|
|
|
|
var tableRow = $(this).parent().parent();
|
|
|
|
|
|
|
|
var valueName = tableCells.eq(1).text();
|
|
|
|
tableCells.eq(1).empty();
|
|
|
|
$('<input type="text" class="form-control input-sm">').appendTo(tableCells.eq(1)).val(valueName);
|
|
|
|
|
|
|
|
var valueType = tableCells.eq(2).text();
|
|
|
|
tableCells.eq(2).empty();
|
2016-01-29 14:52:57 +00:00
|
|
|
$('<select class="form-control select-narrow-70"></select>').appendTo(tableCells.eq(2)).select2({
|
2016-01-23 16:05:13 +00:00
|
|
|
data: recordTypes
|
|
|
|
}).val(valueType).trigger("change");
|
|
|
|
|
|
|
|
var valueContent = tableCells.eq(3).text();
|
|
|
|
tableCells.eq(3).empty();
|
|
|
|
$('<input type="text" class="form-control input-sm">').appendTo(tableCells.eq(3)).val(valueContent);
|
|
|
|
|
|
|
|
var valuePrio = tableCells.eq(4).text();
|
|
|
|
tableCells.eq(4).empty();
|
|
|
|
$('<input type="text" class="form-control input-sm" size="1">').appendTo(tableCells.eq(4)).val(valuePrio);
|
|
|
|
|
|
|
|
var valueTtl = tableCells.eq(5).text();
|
|
|
|
tableCells.eq(5).empty();
|
|
|
|
$('<input type="text" class="form-control input-sm" size="3">').appendTo(tableCells.eq(5)).val(valueTtl);
|
|
|
|
|
|
|
|
tableCells.eq(6).remove();
|
|
|
|
tableCells.eq(7).remove();
|
2016-02-05 16:14:49 +00:00
|
|
|
tableCells.eq(8).remove();
|
2016-01-23 16:05:13 +00:00
|
|
|
|
2016-02-05 16:14:49 +00:00
|
|
|
$(tableRow).append('<td colspan="3"><button class="btn btn-primary btn-sm">Save</button></td>');
|
2016-01-23 16:05:13 +00:00
|
|
|
|
|
|
|
$(tableRow).find('button').click(saveRecord);
|
|
|
|
|
|
|
|
enableFilter(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveRecord() {
|
|
|
|
|
|
|
|
var tableRow = $(this).parent().parent();
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
id: tableRow.children('td').eq(0).text(),
|
|
|
|
name: tableRow.children('td').eq(1).children('input').val(),
|
|
|
|
type: tableRow.children('td').eq(2).children('select').val(),
|
|
|
|
content: tableRow.children('td').eq(3).children('input').val(),
|
|
|
|
prio: tableRow.children('td').eq(4).children('input').val(),
|
|
|
|
ttl: tableRow.children('td').eq(5).children('input').val(),
|
|
|
|
action: "saveRecord",
|
2016-01-29 15:52:23 +00:00
|
|
|
domain: location.hash.substring(1),
|
|
|
|
csrfToken: $('#csrfToken').text()
|
2016-01-23 16:05:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
tableRow.children('td').eq(0).empty().text(data.id);
|
|
|
|
tableRow.children('td').eq(1).empty().text(data.name);
|
|
|
|
tableRow.children('td').eq(2).empty().text(data.type);
|
|
|
|
tableRow.children('td').eq(3).empty().text(data.content);
|
|
|
|
tableRow.children('td').eq(4).empty().text(data.prio);
|
|
|
|
tableRow.children('td').eq(5).empty().text(data.ttl);
|
|
|
|
|
|
|
|
tableRow.children('td').eq(6).remove();
|
|
|
|
|
|
|
|
tableRow.append('<td><span class="glyphicon glyphicon-pencil cursor-pointer"></span></td>')
|
2016-02-05 16:14:49 +00:00
|
|
|
.append('<td><span class="glyphicon glyphicon-trash cursor-pointer"></span></td>')
|
|
|
|
.append('<td><span class="glyphicon glyphicon-share cursor-pointer"></span></td>');
|
2016-01-23 16:05:13 +00:00
|
|
|
tableRow.find('span.glyphicon-trash').click(trashClicked);
|
2016-02-05 16:14:49 +00:00
|
|
|
tableRow.find('span.glyphicon-pencil').click(editClicked);
|
|
|
|
tableRow.find('span.glyphicon-share').click(remoteClicked);
|
2016-01-23 16:05:13 +00:00
|
|
|
|
|
|
|
enableFilter(true);
|
|
|
|
|
|
|
|
$.post(
|
|
|
|
"api/edit-master.php",
|
|
|
|
JSON.stringify(data),
|
|
|
|
function() {
|
|
|
|
requestSerial();
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function addRecord() {
|
2016-01-23 16:29:53 +00:00
|
|
|
if(!validateLine.call(this)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-23 16:05:13 +00:00
|
|
|
var data = {
|
|
|
|
name: $('#addName').val(),
|
|
|
|
type: $('#addType').val(),
|
|
|
|
content: $('#addContent').val(),
|
|
|
|
prio: $('#addPrio').val(),
|
|
|
|
ttl: $('#addTtl').val(),
|
|
|
|
action: "addRecord",
|
2016-01-29 15:52:23 +00:00
|
|
|
domain: location.hash.substring(1),
|
|
|
|
csrfToken: $('#csrfToken').text()
|
2016-01-23 16:05:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$.post(
|
|
|
|
"api/edit-master.php",
|
|
|
|
JSON.stringify(data),
|
|
|
|
function(dataRecv) {
|
|
|
|
$('<tr></tr>').appendTo('#table-records>tbody')
|
|
|
|
.append('<td>' + dataRecv.newId + '</td>')
|
|
|
|
.append('<td>' + data.name + '</td>')
|
|
|
|
.append('<td>' + data.type + '</td>')
|
|
|
|
.append('<td>' + data.content + '</td>')
|
|
|
|
.append('<td>' + data.prio + '</td>')
|
|
|
|
.append('<td>' + data.ttl + '</td>')
|
|
|
|
.append('<td><span class="glyphicon glyphicon-pencil cursor-pointer"></span></td>')
|
2016-02-05 16:14:49 +00:00
|
|
|
.append('<td><span class="glyphicon glyphicon-trash cursor-pointer"></span></td>')
|
|
|
|
.append('<td><span class="glyphicon glyphicon-share cursor-pointer"></span></td>');
|
2016-01-23 18:35:16 +00:00
|
|
|
|
|
|
|
$('#table-records>tbody>tr').last().find('span.glyphicon-pencil').click(editClicked);
|
|
|
|
$('#table-records>tbody>tr').last().find('span.glyphicon-trash').click(trashClicked);
|
2016-02-05 16:14:49 +00:00
|
|
|
$('#table-records>tbody>tr').last().find('span.glyphicon-share').click(remoteClicked);
|
2016-01-23 16:05:13 +00:00
|
|
|
requestSerial();
|
2016-01-23 18:35:16 +00:00
|
|
|
|
|
|
|
$('#addName').val("");
|
|
|
|
$('#addType').val("A").change();
|
|
|
|
$('#addContent').val("");
|
|
|
|
$('#addPrio').val("");
|
|
|
|
$('#addTtl').val("");
|
2016-01-23 16:05:13 +00:00
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function trashClicked() {
|
|
|
|
var data = {
|
|
|
|
id: $(this).parent().parent().children().eq(0).text(),
|
|
|
|
domain: location.hash.substring(1),
|
2016-01-29 15:52:23 +00:00
|
|
|
action: "removeRecord",
|
|
|
|
csrfToken: $('#csrfToken').text()
|
2016-01-23 16:05:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var lineAffected = $(this).parent().parent();
|
|
|
|
|
|
|
|
$.post(
|
|
|
|
"api/edit-master.php",
|
|
|
|
JSON.stringify(data),
|
|
|
|
function() {
|
|
|
|
lineAffected.remove();
|
|
|
|
requestSerial();
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function requestDomainName() {
|
|
|
|
var data = {
|
|
|
|
action: "getDomainName",
|
2016-01-29 15:52:23 +00:00
|
|
|
domain: location.hash.substring(1),
|
|
|
|
csrfToken: $('#csrfToken').text()
|
2016-01-23 16:05:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$.post(
|
|
|
|
"api/edit-master.php",
|
|
|
|
JSON.stringify(data),
|
|
|
|
function(data) {
|
|
|
|
$('#domain-name').text(data.name);
|
|
|
|
domainName = data.name;
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function enableFilter(enable) {
|
|
|
|
if(enable) {
|
|
|
|
$('#searchName').prop("disabled", false);
|
|
|
|
$('#searchType').prop("disabled", false);
|
|
|
|
$('#searchContent').prop("disabled", false);
|
|
|
|
} else {
|
|
|
|
$('#searchName').prop("disabled", true);
|
|
|
|
$('#searchType').prop("disabled", true);
|
|
|
|
$('#searchContent').prop("disabled", true);
|
|
|
|
}
|
2016-01-23 16:29:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function regexValidate() {
|
|
|
|
var regex = new RegExp($(this).attr('data-regex'));
|
|
|
|
if(!regex.test($(this).val())) {
|
|
|
|
$(this).parent().addClass("has-error");
|
|
|
|
} else {
|
|
|
|
$(this).parent().removeClass("has-error");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function validateLine() {
|
|
|
|
$(this).parent().parent().find('input[data-regex]').change();
|
|
|
|
var errors = 0;
|
|
|
|
$(this).parent().parent().find('input[data-regex]').each(function() {
|
|
|
|
if($(this).parent().hasClass('has-error')) {
|
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return errors <= 0;
|
2016-02-05 16:14:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function remoteClicked() {
|
|
|
|
var recordId = $(this).parent().siblings().eq(0).text();
|
|
|
|
location.assign("edit-remote.php#" + recordId);
|
2016-01-18 20:45:07 +00:00
|
|
|
}
|