Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using utils.showAlert for Local DNS and Local CNAME pages. #2203

Merged
merged 5 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions cname_records.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php /*
<?php
/*
* Pi-hole: A black hole for Internet advertisements
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
require "scripts/pi-hole/php/header.php";

require "scripts/pi-hole/php/header.php";
?>

<!-- Title -->
Expand Down Expand Up @@ -50,23 +51,6 @@
</div>
</div>

<!-- Alerts -->
<div id="alInfo" class="alert alert-info alert-dismissible fade in" role="alert" hidden>
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
Updating CNAME records...
</div>
<div id="alSuccess" class="alert alert-success alert-dismissible fade in" role="alert" hidden>
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
Success! The list will refresh.
</div>
<div id="alFailure" class="alert alert-danger alert-dismissible fade in" role="alert" hidden>
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
Failure! Something went wrong, see output below:<br/><br/><pre><span id="err"></span></pre>
</div>
<div id="alWarning" class="alert alert-warning alert-dismissible fade in" role="alert" hidden>
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
At least one domain was already present, see output below:<br/><br/><pre><span id="warn"></span></pre>
</div>
<div class="row">
<div class="col-md-12">
<div class="box" id="recent-queries">
Expand Down
22 changes: 3 additions & 19 deletions dns_records.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php /*
<?php
/*
* Pi-hole: A black hole for Internet advertisements
* (c) 2017 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
require "scripts/pi-hole/php/header.php";

require "scripts/pi-hole/php/header.php";
?>

<!-- Title -->
Expand Down Expand Up @@ -54,23 +55,6 @@
</div>
</div>

<!-- Alerts -->
<div id="alInfo" class="alert alert-info alert-dismissible fade in" role="alert" hidden>
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
Updating the custom DNS entries...
</div>
<div id="alSuccess" class="alert alert-success alert-dismissible fade in" role="alert" hidden>
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
Success! The list will refresh.
</div>
<div id="alFailure" class="alert alert-danger alert-dismissible fade in" role="alert" hidden>
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
Failure! Something went wrong, see output below:<br/><br/><pre><span id="err"></span></pre>
</div>
<div id="alWarning" class="alert alert-warning alert-dismissible fade in" role="alert" hidden>
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
At least one domain was already present, see output below:<br/><br/><pre><span id="warn"></span></pre>
</div>
<div class="row">
<div class="col-md-12">
<div class="box" id="recent-queries">
Expand Down
71 changes: 34 additions & 37 deletions scripts/pi-hole/js/customcname.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,6 @@
var table;
var token = $("#token").text();

function showAlert(type, message) {
var alertElement = null;
var messageElement = null;

switch (type) {
case "info":
alertElement = $("#alInfo");
break;
case "success":
alertElement = $("#alSuccess");
break;
case "warning":
alertElement = $("#alWarning");
messageElement = $("#warn");
break;
case "error":
alertElement = $("#alFailure");
messageElement = $("#err");
break;
default:
return;
}

if (messageElement !== null) messageElement.html(message);

alertElement.fadeIn(200);
alertElement.delay(8000).fadeOut(2000);
}

$(function () {
$("#btnAdd").on("click", addCustomCNAME);

Expand Down Expand Up @@ -99,20 +70,35 @@ function addCustomCNAME() {
var domain = utils.escapeHtml($("#domain").val());
var target = utils.escapeHtml($("#target").val());

showAlert("info");
utils.disableAll();
utils.showAlert("info", "", "Adding custom CNAME record...", "");

$.ajax({
url: "scripts/pi-hole/php/customcname.php",
method: "post",
dataType: "json",
data: { action: "add", domain: domain, target: target, token: token },
success: function (response) {
utils.enableAll();
if (response.success) {
showAlert("success");
utils.showAlert(
"success",
"far fa-check-circle",
"Custom CNAME added",
domain + ": " + target
);

// Clean up field values and reload table data
$("#domain").val("");
$("#target").val("");
table.ajax.reload();
} else showAlert("error", response.message);
} else {
utils.showAlert("error", "fas fa-times", "Failure! Something went wrong", response.message);
}
},
error: function () {
showAlert("error", "Error while adding this custom CNAME record");
utils.enableAll();
utils.showAlert("error", "fas fa-times", "Error while adding custom CNAME record", "");
},
});
}
Expand All @@ -121,20 +107,31 @@ function deleteCustomCNAME() {
var domain = $(this).attr("data-domain");
var target = $(this).attr("data-target");

showAlert("info");
utils.disableAll();
utils.showAlert("info", "", "Deleting custom CNAME record...", "");

$.ajax({
url: "scripts/pi-hole/php/customcname.php",
method: "post",
dataType: "json",
data: { action: "delete", domain: domain, target: target, token: token },
success: function (response) {
utils.enableAll();
if (response.success) {
showAlert("success");
utils.showAlert(
"success",
"far fa-check-circle",
"Custom CNAME deleted",
domain + ": " + target
);
table.ajax.reload();
} else showAlert("error", response.message);
} else {
utils.showAlert("error", "fas fa-times", "Failure! Something went wrong", response.message);
}
},
error: function (jqXHR, exception) {
showAlert("error", "Error while deleting this custom CNAME record");
utils.enableAll();
utils.showAlert("error", "fas fa-times", "Error while deleting custom CNAME record", "");
console.log(exception); // eslint-disable-line no-console
},
});
Expand Down
61 changes: 24 additions & 37 deletions scripts/pi-hole/js/customdns.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,6 @@
var table;
var token = $("#token").text();

function showAlert(type, message) {
var alertElement = null;
var messageElement = null;

switch (type) {
case "info":
alertElement = $("#alInfo");
break;
case "success":
alertElement = $("#alSuccess");
break;
case "warning":
alertElement = $("#alWarning");
messageElement = $("#warn");
break;
case "error":
alertElement = $("#alFailure");
messageElement = $("#err");
break;
default:
return;
}

if (messageElement !== null) messageElement.html(message);

alertElement.fadeIn(200);
alertElement.delay(8000).fadeOut(2000);
}

$(function () {
$("#btnAdd").on("click", addCustomDNS);

Expand Down Expand Up @@ -98,20 +69,30 @@ function addCustomDNS() {
var ip = utils.escapeHtml($("#ip").val());
var domain = utils.escapeHtml($("#domain").val());

showAlert("info");
utils.disableAll();
utils.showAlert("info", "", "Adding custom DNS entry...", "");

$.ajax({
url: "scripts/pi-hole/php/customdns.php",
method: "post",
dataType: "json",
data: { action: "add", ip: ip, domain: domain, token: token },
success: function (response) {
utils.enableAll();
if (response.success) {
showAlert("success");
utils.showAlert("success", "far fa-check-circle", "Custom DNS added", domain + ": " + ip);

// Clean up field values and reload table data
$("#domain").val("");
$("#ip").val("");
table.ajax.reload();
} else showAlert("error", response.message);
} else {
utils.showAlert("error", "fas fa-times", "Failure! Something went wrong", response.message);
}
},
error: function () {
showAlert("error", "Error while adding this custom DNS entry");
utils.enableAll();
utils.showAlert("error", "fas fa-times", "Error while adding custom DNS entry", "");
},
});
}
Expand All @@ -120,20 +101,26 @@ function deleteCustomDNS() {
var ip = $(this).attr("data-ip");
var domain = $(this).attr("data-domain");

showAlert("info");
utils.disableAll();
utils.showAlert("info", "", "Deleting custom DNS entry...", "");

$.ajax({
url: "scripts/pi-hole/php/customdns.php",
method: "post",
dataType: "json",
data: { action: "delete", domain: domain, ip: ip, token: token },
success: function (response) {
utils.enableAll();
if (response.success) {
showAlert("success");
utils.showAlert("success", "far fa-check-circle", "Custom DNS deleted", domain + ": " + ip);
table.ajax.reload();
} else showAlert("error", response.message);
} else {
utils.showAlert("error", "fas fa-times", "Failure! Something went wrong", response.message);
}
},
error: function (jqXHR, exception) {
showAlert("error", "Error while deleting this custom DNS entry");
utils.enableAll();
utils.showAlert("error", "fas fa-times", "Error while deleting custom DNS entry", "");
console.log(exception); // eslint-disable-line no-console
},
});
Expand Down