-
-
Notifications
You must be signed in to change notification settings - Fork 562
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
Added support for CNAME records add/remove #1278
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4e07ae2
Added support for CNAME records add/remove
marank e380d92
Removed already defined functions
marank 212da94
Added token verification
marank b597a0f
Merge branch 'devel' into devel
marank 773fed0
Incorporate upstream changes
marank File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?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"; | ||
|
||
?> | ||
|
||
<!-- Title --> | ||
<div class="page-header"> | ||
<h1>Local CNAME Records</h1> | ||
<small>On this page, you can add CNAME records.</small> | ||
</div> | ||
|
||
<!-- Domain Input --> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<div class="box"> | ||
<!-- /.box-header --> | ||
<div class="box-header with-border"> | ||
<h3 class="box-title"> | ||
Add a new CNAME record | ||
</h3> | ||
</div> | ||
<!-- /.box-header --> | ||
<div class="box-body"> | ||
<div class="row"> | ||
<div class="form-group col-md-6"> | ||
<label for="domain">Domain:</label> | ||
<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" autocomplete="off" spellcheck="false" autocapitalize="none" autocorrect="off"> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="box-footer clearfix"> | ||
<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> | ||
<button type="button" class="close" data-hide="alert" aria-label="Close"><span aria-hidden="true">×</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">×</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">×</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">×</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"> | ||
<div class="box-header with-border"> | ||
<h3 class="box-title"> | ||
List of local CNAME records | ||
</h3> | ||
</div> | ||
<!-- /.box-header --> | ||
<div class="box-body"> | ||
<table id="customCNAMETable" class="table table-striped table-bordered" width="100%"> | ||
<thead> | ||
<tr> | ||
<th>Domain</th> | ||
<th>Target</th> | ||
<th>Action</th> | ||
</tr> | ||
</thead> | ||
</table> | ||
<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 | ||
require "scripts/pi-hole/php/footer.php"; | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* 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. */ | ||
|
||
/* global utils:false */ | ||
|
||
var table; | ||
var token = $("#token").text(); | ||
|
||
function showAlert(type, message) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why duplicate stuff here? |
||
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); | ||
|
||
table = $("#customCNAMETable").DataTable({ | ||
ajax: { | ||
url: "scripts/pi-hole/php/customcname.php", | ||
data: { action: "get", token: token }, | ||
type: "POST" | ||
}, | ||
columns: [{}, {}, { orderable: false, searchable: false }], | ||
columnDefs: [ | ||
{ | ||
targets: 2, | ||
render: function (data, type, row) { | ||
return ( | ||
'<button type="button" class="btn btn-danger btn-xs deleteCustomCNAME" data-domain=\'' + | ||
row[0] + | ||
"' data-target='" + | ||
row[1] + | ||
"'>" + | ||
'<span class="far fa-trash-alt"></span>' + | ||
"</button>" | ||
); | ||
} | ||
} | ||
], | ||
drawCallback: function () { | ||
$(".deleteCustomCNAME").on("click", deleteCustomCNAME); | ||
} | ||
}); | ||
// Disable autocorrect in the search box | ||
var input = document.querySelector("input[type=search]"); | ||
input.setAttribute("autocomplete", "off"); | ||
input.setAttribute("autocorrect", "off"); | ||
input.setAttribute("autocapitalize", "off"); | ||
input.setAttribute("spellcheck", false); | ||
}); | ||
|
||
function addCustomCNAME() { | ||
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", domain: domain, target: target, token: token }, | ||
success: function (response) { | ||
if (response.success) { | ||
showAlert("success"); | ||
table.ajax.reload(); | ||
} else showAlert("error", response.message); | ||
}, | ||
error: function () { | ||
showAlert("error", "Error while adding this custom CNAME record"); | ||
} | ||
}); | ||
} | ||
|
||
function deleteCustomCNAME() { | ||
var domain = $(this).attr("data-domain"); | ||
var target = $(this).attr("data-target"); | ||
|
||
showAlert("info"); | ||
$.ajax({ | ||
url: "scripts/pi-hole/php/customcname.php", | ||
method: "post", | ||
dataType: "json", | ||
data: { action: "delete", domain: domain, target: target, token: token }, | ||
success: function (response) { | ||
if (response.success) { | ||
showAlert("success"); | ||
table.ajax.reload(); | ||
} else showAlert("error", response.message); | ||
}, | ||
error: function (jqXHR, exception) { | ||
showAlert("error", "Error while deleting this custom CNAME record"); | ||
console.log(exception); // eslint-disable-line no-console | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
require_once "func.php"; | ||
|
||
require_once('auth.php'); | ||
|
||
// Authentication checks | ||
if (isset($_POST['token'])) { | ||
check_cors(); | ||
check_csrf($_POST['token']); | ||
} else { | ||
log_and_die('Not allowed (login session invalid or expired, please relogin on the Pi-hole dashboard)!'); | ||
} | ||
|
||
|
||
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"); | ||
} | ||
|
||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid global variables