Allow user to add in a comment next to domain entry

Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
Adam Warner
2019-10-14 21:55:29 +01:00
parent 34de877ccf
commit 07195fb4e7
4 changed files with 28 additions and 13 deletions
+11 -1
View File
@@ -32,14 +32,24 @@ function getFullName() {
</div>
<!-- Domain Input -->
<div class="form-group input-group">
<div class="form-group row">
<div class="col-xs-4">
<label for="ex1">Domain:</label>
<input id="domain" type="text" class="form-control" placeholder="Add a domain (example.com or sub.example.com)">
</div>
<div class="col-xs-4">
<label for="ex2">Comment:</label>
<input id="comment" type="text" class="form-control" placeholder="Include a comment (optional)">
</div>
<div class="col-xs-4">
<label for="ex2">&nbsp;</label>
<span class="input-group-btn">
<button id="btnAdd" class="btn btn-default" type="button">Add (exact)</button>
<button id="btnAddWildcard" class="btn btn-default" type="button">Add (wildcard)</button>
<button id="btnAddRegex" class="btn btn-default" type="button">Add (regex)</button>
<button id="btnRefresh" class="btn btn-default" type="button"><i class="fa fa-sync"></i></button>
</span>
</div>
</div>
<!-- Alerts -->
+6 -3
View File
@@ -173,6 +173,8 @@ function add(type) {
return;
}
var comment = $("#comment");
var alInfo = $("#alInfo");
var alSuccess = $("#alSuccess");
var alFailure = $("#alFailure");
@@ -187,7 +189,7 @@ function add(type) {
$.ajax({
url: "scripts/pi-hole/php/add.php",
method: "post",
data: {"domain":domain.val().trim(), "list":type, "token":token},
data: {"domain":domain.val().trim(),"comment":comment.val(), "list":type, "token":token},
success: function(response) {
if (response.indexOf("Success") === -1) {
alFailure.show();
@@ -208,6 +210,7 @@ function add(type) {
alInfo.hide();
});
domain.val("");
comment.val("");
refresh(true);
}
},
@@ -228,10 +231,10 @@ function add(type) {
// Handle enter button for adding domains
$(document).keypress(function(e) {
if(e.which === 13 && $("#domain").is(":focus")) {
if(e.which === 13 && $("#domain,#comment").is(":focus")) {
// Enter was pressed, and the input has focus
add(listType);
}
};
});
// Handle buttons
+8 -7
View File
@@ -25,6 +25,7 @@ if(in_array($list, $check_lists)) {
// Split individual domains into array
$domains = preg_split('/\s+/', trim($_POST['domain']));
$comment = trim($_POST['comment']);
require_once("func.php");
require_once("database.php");
@@ -33,31 +34,31 @@ $db = SQLite3_connect($GRAVITYDB, SQLITE3_OPEN_READWRITE);
switch($list) {
case "white":
echo add_to_table($db, "whitelist", $domains);
echo add_to_table($db, "whitelist", $domains, $comment);
break;
case "black":
echo add_to_table($db, "blacklist", $domains);
echo add_to_table($db, "blacklist", $domains, $comment);
break;
case "black_regex":
echo add_to_table($db, "regex_blacklist", $domains);
echo add_to_table($db, "regex_blacklist", $domains, $comment);
break;
case "white_regex":
echo add_to_table($db, "regex_whitelist", $domains);
echo add_to_table($db, "regex_whitelist", $domains, $comment);
break;
case "black_wild":
echo add_to_table($db, "regex_blacklist", $domains, true);
echo add_to_table($db, "regex_blacklist", $domains, $comment, true);
break;
case "white_wild":
echo add_to_table($db, "regex_whitelist", $domains, true);
echo add_to_table($db, "regex_whitelist", $domains, $comment, true);
break;
case "audit":
echo add_to_table($db, "domain_audit", $domains);
echo add_to_table($db, "domain_audit", $domains, $comment);
break;
default:
+3 -2
View File
@@ -76,7 +76,7 @@ function SQLite3_connect($filename, $mode=SQLITE3_OPEN_READONLY)
* @param $returnnum boolean Whether to return an integer or a string
* @return string Success/error and number of processed domains
*/
function add_to_table($db, $table, $domains, $wildcardstyle=false, $returnnum=false)
function add_to_table($db, $table, $domains, $comment, $wildcardstyle=false, $returnnum=false)
{
// Begin transaction
if(!$db->exec("BEGIN TRANSACTION;"))
@@ -89,7 +89,7 @@ function add_to_table($db, $table, $domains, $wildcardstyle=false, $returnnum=fa
$initialcount = intval($db->querySingle("SELECT COUNT(*) FROM ".$table.";"));
// Prepare SQLite statememt
$stmt = $db->prepare("INSERT OR IGNORE INTO ".$table." (domain) VALUES (:domain);");
$stmt = $db->prepare("INSERT OR IGNORE INTO ".$table." (domain,comment) VALUES (:domain, :comment);");
// Return early if we failed to prepare the SQLite statement
if(!$stmt)
@@ -112,6 +112,7 @@ function add_to_table($db, $table, $domains, $wildcardstyle=false, $returnnum=fa
$domain = "(\\.|^)".str_replace(".","\\.",$domain)."$";
$stmt->bindValue(":domain", $domain, SQLITE3_TEXT);
$stmt->bindValue(":comment", $comment, SQLITE3_TEXT);
if($stmt->execute() && $stmt->reset())
$num++;