2021-02-19 16:41:43 +01:00
|
|
|
var recordsBuffer = [];
|
|
|
|
|
|
|
|
|
|
function addRecord(record) {
|
|
|
|
|
recordsBuffer.push(record);
|
|
|
|
|
refresh_records_list();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function delRecord(index) {
|
|
|
|
|
recordsBuffer.splice(index, 1);
|
|
|
|
|
refresh_records_list();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function refresh_records_list() {
|
|
|
|
|
var buf = "";
|
|
|
|
|
if (recordsBuffer.length > 0) {
|
|
|
|
|
buf = "<label class=\"label\">Records:</label>\n";
|
|
|
|
|
}
|
|
|
|
|
function getInput(text) {
|
2021-03-20 17:25:04 +01:00
|
|
|
if (typeof text === "string"){
|
|
|
|
|
// TODO sanitize
|
|
|
|
|
}
|
2021-02-19 16:41:43 +01:00
|
|
|
return '<input class="input" type="text" value="' + text + '" readonly>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function makeRecord(value, index, array) {
|
2021-03-20 17:25:04 +01:00
|
|
|
var data = value.addr;
|
2021-02-21 21:08:20 +01:00
|
|
|
if (value.type == "MX") {
|
|
|
|
|
data = value.priority + " " + value.host;
|
|
|
|
|
} else if (value.type == "CNAME") {
|
|
|
|
|
data = value.host;
|
|
|
|
|
} else if (value.type == "TXT") {
|
|
|
|
|
data = value.data;
|
|
|
|
|
} else if (value.type == "SRV") {
|
|
|
|
|
data = value.priority + " " + value.weight + " " + value.port + " " + value.host;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-24 19:06:22 +01:00
|
|
|
var text = "<div class=\"field is-grouped\">" +
|
|
|
|
|
"<input class=\"input\" type=\"text\" value=\"{1}\" readonly>" +
|
|
|
|
|
"<input class=\"input ml-3 has-text-centered\" type=\"text\" size=\"6\" style=\"width: 15%;\" value=\"{2}\" readonly>" +
|
|
|
|
|
"<input class=\"input ml-3 has-text-centered\" type=\"text\" size=\"6\" style=\"width: 15%;\" value=\"{3}\" readonly>" +
|
|
|
|
|
"<input class=\"input ml-3\" type=\"text\" value=\"{4}\" readonly>" +
|
|
|
|
|
"<button class=\"button is-danger is-outlined ml-3\" id=\"record_delete\" onclick=\"delRecord({5});\">" +
|
|
|
|
|
" <span class=\"icon is-small\"><i class=\"fas fa-times\"></i></span>" +
|
|
|
|
|
"</button>" +
|
|
|
|
|
"</div>";
|
|
|
|
|
buf += text.replace("{1}", value.domain)
|
|
|
|
|
.replace("{2}", value.type)
|
|
|
|
|
.replace("{3}", value.ttl)
|
|
|
|
|
.replace("{4}", data)
|
|
|
|
|
.replace("{5}", index);
|
2021-02-19 16:41:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
recordsBuffer.forEach(makeRecord);
|
|
|
|
|
document.getElementById("domain_records").innerHTML = buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function showNewRecordDialog() {
|
|
|
|
|
button_positive = document.getElementById("new_record_positive_button");
|
|
|
|
|
button_positive.onclick = function() {
|
2021-03-18 18:53:14 +01:00
|
|
|
checkRecord(get_record_from_dialog());
|
2021-02-19 16:41:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
button_negative = document.getElementById("new_record_negative_button");
|
|
|
|
|
button_negative.onclick = function() {
|
|
|
|
|
dialog = document.getElementById("new_record_dialog");
|
|
|
|
|
dialog.className = "modal";
|
|
|
|
|
refresh_records_list();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dialog = document.getElementById("new_record_dialog");
|
|
|
|
|
dialog.className = "modal is-active";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function get_record_from_dialog() {
|
2021-03-18 18:53:14 +01:00
|
|
|
record_name = document.getElementById("record_name").value.toLowerCase();
|
2021-02-19 16:41:43 +01:00
|
|
|
record_type = document.getElementById("record_type").value;
|
|
|
|
|
record_ttl = parseInt(document.getElementById("record_ttl").value);
|
|
|
|
|
record_data = document.getElementById("record_data").value;
|
2021-02-21 21:08:20 +01:00
|
|
|
if (record_type == "CNAME" || record_type == "NS") {
|
|
|
|
|
return { type: record_type, domain: record_name, ttl: record_ttl, host: record_data }
|
|
|
|
|
} else if (record_type == "MX") {
|
|
|
|
|
record_priority = parseInt(document.getElementById("record_priority").value);
|
|
|
|
|
return { type: record_type, domain: record_name, ttl: record_ttl, priority: record_priority, host: record_data }
|
|
|
|
|
} else if (record_type == "TXT") {
|
|
|
|
|
return { type: record_type, domain: record_name, ttl: record_ttl, data: record_data }
|
|
|
|
|
} else if (record_type == "SRV") {
|
|
|
|
|
record_priority = parseInt(document.getElementById("record_priority").value);
|
|
|
|
|
record_weight = parseInt(document.getElementById("record_weight").value);
|
|
|
|
|
record_port = parseInt(document.getElementById("record_port").value);
|
|
|
|
|
return { type: record_type, domain: record_name, ttl: record_ttl, priority: record_priority, weight: record_weight, port: record_port, host: record_data }
|
|
|
|
|
}
|
2021-02-19 16:41:43 +01:00
|
|
|
return { type: record_type, domain: record_name, ttl: record_ttl, addr: record_data }
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-30 14:18:37 +01:00
|
|
|
function onLoad() {
|
|
|
|
|
external.invoke(JSON.stringify({cmd: 'loaded'}));
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-18 21:31:40 +02:00
|
|
|
function loadKey() {
|
2021-02-15 23:09:30 +01:00
|
|
|
external.invoke(JSON.stringify({cmd: 'loadKey'}));
|
2020-04-18 21:31:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createKey() {
|
2021-02-15 23:09:30 +01:00
|
|
|
external.invoke(JSON.stringify({cmd: 'createKey'}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function saveKey() {
|
|
|
|
|
external.invoke(JSON.stringify({cmd: 'saveKey'}));
|
2020-04-18 21:31:40 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-18 18:53:14 +01:00
|
|
|
function checkRecord(data) {
|
|
|
|
|
external.invoke(JSON.stringify({cmd: 'checkRecord', data: JSON.stringify(data)}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function recordOkay(okay) {
|
|
|
|
|
if (okay) {
|
|
|
|
|
addRecord(get_record_from_dialog()); // It will refresh list
|
|
|
|
|
dialog = document.getElementById("new_record_dialog");
|
|
|
|
|
dialog.className = "modal";
|
|
|
|
|
} else {
|
|
|
|
|
showWarning('Record is not valid!');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-18 21:31:40 +02:00
|
|
|
function createDomain() {
|
2021-03-18 18:53:14 +01:00
|
|
|
new_domain = document.getElementById("new_domain").value.toLowerCase();
|
2021-02-19 16:41:43 +01:00
|
|
|
new_dom_records = JSON.stringify(recordsBuffer);
|
2021-03-24 19:06:22 +01:00
|
|
|
external.invoke(JSON.stringify({cmd: 'mineDomain', name: new_domain, records: new_dom_records}));
|
2021-03-18 18:53:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function domainMiningStarted() {
|
2021-02-22 17:45:18 +01:00
|
|
|
recordsBuffer = [];
|
2020-04-18 21:31:40 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-22 21:45:32 +01:00
|
|
|
function createZone() {
|
|
|
|
|
new_zone = document.getElementById("new_zone").value;
|
|
|
|
|
difficulty = document.getElementById("new_zone_difficulty").value;
|
|
|
|
|
obj = {};
|
|
|
|
|
obj.name = new_zone;
|
2021-03-17 20:05:05 +01:00
|
|
|
obj.difficulty = parseInt(difficulty);
|
2021-02-22 21:45:32 +01:00
|
|
|
data = JSON.stringify(obj);
|
2021-03-18 00:16:17 +01:00
|
|
|
external.invoke(JSON.stringify({cmd: 'mineZone', name: new_zone, data: data}));
|
2021-02-22 21:45:32 +01:00
|
|
|
}
|
|
|
|
|
|
2020-04-18 21:31:40 +02:00
|
|
|
function sendAction(param) {
|
|
|
|
|
external.invoke(JSON.stringify(param));
|
2021-01-30 14:18:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onDomainChange(element) {
|
|
|
|
|
external.invoke(JSON.stringify({cmd: 'checkDomain', name: element.value}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function domainAvailable(available) {
|
|
|
|
|
input = document.getElementById("new_domain");
|
|
|
|
|
button = document.getElementById("new_domain_button");
|
2021-03-23 18:55:11 +01:00
|
|
|
button2 = document.getElementById("add_record_button");
|
2021-01-30 14:18:37 +01:00
|
|
|
if (available) {
|
|
|
|
|
input.className = "input";
|
|
|
|
|
button.disabled = false
|
2021-03-23 18:55:11 +01:00
|
|
|
button2.disabled = false
|
2021-01-30 14:18:37 +01:00
|
|
|
} else {
|
|
|
|
|
input.className = "input is-danger";
|
|
|
|
|
button.disabled = true
|
2021-03-23 18:55:11 +01:00
|
|
|
button2.disabled = true
|
2021-01-30 14:18:37 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-22 21:45:32 +01:00
|
|
|
function onZoneChange() {
|
|
|
|
|
button = document.getElementById("new_zone_button");
|
|
|
|
|
diff = document.getElementById("new_zone_difficulty");
|
|
|
|
|
d = parseInt(diff.value);
|
|
|
|
|
// Checking for NaN first
|
|
|
|
|
if (d != d || d < 20 || d > 50) {
|
|
|
|
|
button.disabled = true;
|
|
|
|
|
diff.className = "input is-danger";
|
|
|
|
|
} else {
|
|
|
|
|
diff.className = "input";
|
|
|
|
|
input = document.getElementById("new_zone");
|
|
|
|
|
external.invoke(JSON.stringify({cmd: 'checkZone', name: input.value}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function zoneAvailable(available) {
|
|
|
|
|
input = document.getElementById("new_zone");
|
|
|
|
|
button = document.getElementById("new_zone_button");
|
|
|
|
|
if (available) {
|
|
|
|
|
input.className = "input";
|
|
|
|
|
button.disabled = false;
|
|
|
|
|
diff = document.getElementById("new_zone_difficulty");
|
|
|
|
|
d = parseInt(diff.value);
|
|
|
|
|
// Checking for NaN first
|
|
|
|
|
if (d != d || d < 20 || d > 50) {
|
|
|
|
|
button.disabled = true;
|
|
|
|
|
diff.className = "input is-danger";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
input.className = "input is-danger";
|
|
|
|
|
button.disabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-30 14:18:37 +01:00
|
|
|
function showModalDialog(text, callback) {
|
|
|
|
|
message = document.getElementById("modal_text");
|
|
|
|
|
message.textContent = text;
|
|
|
|
|
|
|
|
|
|
button_positive = document.getElementById("modal_positive_button");
|
|
|
|
|
button_positive.onclick = function() {
|
|
|
|
|
callback();
|
|
|
|
|
dialog = document.getElementById("modal_dialog");
|
|
|
|
|
dialog.className = "modal";
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
button_negative = document.getElementById("modal_negative_button");
|
|
|
|
|
button_negative.onclick = function() {
|
|
|
|
|
dialog = document.getElementById("modal_dialog");
|
|
|
|
|
dialog.className = "modal";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dialog = document.getElementById("modal_dialog");
|
|
|
|
|
dialog.className = "modal is-active";
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-19 16:41:43 +01:00
|
|
|
function showWarning(text) {
|
|
|
|
|
warning = document.getElementById("notification_warning");
|
|
|
|
|
message = document.getElementById("warning_text");
|
|
|
|
|
message.innerHTML = text;
|
|
|
|
|
|
|
|
|
|
warning.className = "notification is-warning";
|
|
|
|
|
button = document.getElementById("close");
|
|
|
|
|
button.onclick = function() {
|
|
|
|
|
message.value = "";
|
|
|
|
|
warning.className = "notification is-warning is-hidden";
|
|
|
|
|
}
|
|
|
|
|
setTimeout(button.onclick, 5000);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-27 18:57:15 +01:00
|
|
|
function showMiningIndicator(visible, blue) {
|
|
|
|
|
var indicator = document.getElementById("busy_indicator");
|
|
|
|
|
var parent = document.getElementById("indicator_parent");
|
|
|
|
|
var add = "";
|
|
|
|
|
if (blue) {
|
|
|
|
|
add = " busy_blue";
|
|
|
|
|
}
|
2021-01-30 14:18:37 +01:00
|
|
|
if (visible) {
|
2021-02-27 18:57:15 +01:00
|
|
|
indicator.className = 'busy_indicator' + add;
|
|
|
|
|
parent.style.display = 'flex';
|
2021-01-30 14:18:37 +01:00
|
|
|
} else {
|
2021-02-27 18:57:15 +01:00
|
|
|
indicator.className = 'busy_indicator is-hidden';
|
|
|
|
|
parent.style.display = 'none';
|
2021-01-30 14:18:37 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function miningIndicatorClick(element) {
|
|
|
|
|
showModalDialog("Do you really want to stop mining?", function() {
|
|
|
|
|
external.invoke(JSON.stringify({cmd: 'stopMining'}));
|
|
|
|
|
});
|
2021-02-15 23:09:30 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-27 18:57:15 +01:00
|
|
|
function setLeftStatusBarText(text) {
|
|
|
|
|
var bar = document.getElementById("status_bar_left");
|
|
|
|
|
bar.innerHTML = text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function setRightStatusBarText(text) {
|
|
|
|
|
var bar = document.getElementById("status_bar_right");
|
|
|
|
|
bar.innerHTML = text;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-10 22:21:50 +01:00
|
|
|
function keystoreChanged(path, pub_key, hash) {
|
2021-02-15 23:09:30 +01:00
|
|
|
if (path == '') {
|
|
|
|
|
path = "In memory";
|
|
|
|
|
}
|
2021-03-24 19:06:22 +01:00
|
|
|
var public_key_hash = document.getElementById("public_key_hash");
|
|
|
|
|
public_key_hash.value = hash;
|
|
|
|
|
|
2021-03-23 18:55:11 +01:00
|
|
|
var save_key = document.getElementById("save_key");
|
|
|
|
|
save_key.disabled = false;
|
|
|
|
|
|
|
|
|
|
var new_domain = document.getElementById("new_domain");
|
|
|
|
|
new_domain.disabled = false;
|
2021-03-24 19:06:22 +01:00
|
|
|
|
2021-03-23 18:55:11 +01:00
|
|
|
var new_zone = document.getElementById("new_zone");
|
|
|
|
|
new_zone.disabled = false;
|
|
|
|
|
var new_zone_difficulty = document.getElementById("new_zone_difficulty");
|
|
|
|
|
new_zone_difficulty.disabled = false;
|
2020-04-18 21:31:40 +02:00
|
|
|
}
|