Skip to content

Commit

Permalink
Incorporate upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
marank committed Jun 21, 2020
1 parent b597a0f commit 94f7f51
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
19 changes: 10 additions & 9 deletions cname_records.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,35 @@
<div class="row">
<div class="form-group col-md-6">
<label for="domain">Domain:</label>
<input id="domain" type="text" class="form-control" placeholder="Add a domain (example.com or sub.example.com)">
<input id="domain" type="url" class="form-control" placeholder="Add a domain (example.com or sub.example.com)" autocomplete="off" spellcheck="false" autocapitalize="none" autocorrect="off">
</div>
<div class="form-group col-md-6">
<label for="target">Target Domain:</label>
<input id="target" type="url" class="form-control" placeholder="Associated Target Domain Record">
<input id="target" type="url" class="form-control" placeholder="Associated Target Domain" autocomplete="off" spellcheck="false" autocapitalize="none" autocorrect="off">
</div>
</div>
</div>
<div class="box-footer clearfix">
<button id="btnAdd" class="btn btn-primary pull-right">Add</button>
<button type="button" id="btnAdd" class="btn btn-primary pull-right">Add</button>
</div>
</div>
</div>
</div>

<!-- Alerts -->
<div id="alInfo" class="alert alert-info alert-dismissible fade in" role="alert" hidden="true">
<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="true">
<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="true">
<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="true">
<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>
Expand All @@ -72,7 +72,7 @@
</div>
<!-- /.box-header -->
<div class="box-body">
<table id="customCNAMETable" class="display table table-striped table-bordered" cellspacing="0" width="100%">
<table id="customCNAMETable" class="table table-striped table-bordered" width="100%">
<thead>
<tr>
<th>Domain</th>
Expand All @@ -81,14 +81,15 @@
</tr>
</thead>
</table>
<button type="button" id="resetButton" hidden="true" class="btn btn-default btn-sm text-red">Clear Filters</button>
<button type="button" id="resetButton" class="btn btn-default btn-sm text-red hidden">Clear Filters</button>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
</div>

<script src="scripts/pi-hole/js/utils.js"></script>
<script src="scripts/pi-hole/js/customcname.js"></script>

<?php
Expand Down
16 changes: 9 additions & 7 deletions scripts/pi-hole/js/customcname.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */

/* global utils:false */

var table;
var token = $("#token").text();

Expand Down Expand Up @@ -37,7 +39,7 @@ function showAlert(type, message) {
alertElement.delay(8000).fadeOut(2000);
}

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

table = $("#customCNAMETable").DataTable({
Expand All @@ -52,7 +54,7 @@ $(document).ready(function () {
targets: 2,
render: function (data, type, row) {
return (
'<button class="btn btn-danger btn-xs deleteCustomCNAME" type="button" data-domain=\'' +
'<button type="button" class="btn btn-danger btn-xs deleteCustomCNAME" data-domain=\'' +
row[0] +
"' data-target='" +
row[1] +
Expand All @@ -76,15 +78,15 @@ $(document).ready(function () {
});

function addCustomCNAME() {
var target = $("#target").val();
var domain = $("#domain").val();
var domain = utils.escapeHtml($("#domain").val());
var target = utils.escapeHtml($("#target").val());

showAlert("info");
$.ajax({
url: "scripts/pi-hole/php/customcname.php",
method: "post",
dataType: "json",
data: { action: "add", target: target, domain: domain, token: token },
data: { action: "add", domain: domain, target: target, token: token },
success: function (response) {
if (response.success) {
showAlert("success");
Expand All @@ -98,8 +100,8 @@ function addCustomCNAME() {
}

function deleteCustomCNAME() {
var target = $(this).attr("data-target");
var domain = $(this).attr("data-domain");
var target = $(this).attr("data-target");

showAlert("info");
$.ajax({
Expand All @@ -115,7 +117,7 @@ function deleteCustomCNAME() {
},
error: function (jqXHR, exception) {
showAlert("error", "Error while deleting this custom CNAME record");
console.log(exception);
console.log(exception); // eslint-disable-line no-console
}
});
}
5 changes: 4 additions & 1 deletion scripts/pi-hole/php/customcname.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
log_and_die('Not allowed (login session invalid or expired, please relogin on the Pi-hole dashboard)!');
}

switch ($_REQUEST['action'])

switch ($_POST['action'])
{
case 'get': echo json_encode(echoCustomCNAMEEntries()); break;
case 'add': echo json_encode(addCustomCNAMEEntry()); break;
case 'delete': echo json_encode(deleteCustomCNAMEEntry()); break;
default:
die("Wrong action");
}


?>
2 changes: 0 additions & 2 deletions scripts/pi-hole/php/customdns.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

require_once "func.php";

$customDNSFile = "/etc/pihole/custom.list";

require_once('auth.php');

// Authentication checks
Expand Down

0 comments on commit 94f7f51

Please sign in to comment.