Implemented also actions for audit log

This commit is contained in:
DL6ER
2017-04-22 16:09:56 +02:00
parent b2a8ea7fee
commit 349faac048
4 changed files with 86 additions and 40 deletions

View File

@@ -92,7 +92,11 @@ if (isset($_GET['topItems']) && $auth)
$top_queries[$tmp[2]] = intval($tmp[1]);
}
if(is_numeric($_GET['topItems']))
if($_GET['topItems'] === "audit")
{
sendRequestFTL("top-ads for audit");
}
else if(is_numeric($_GET['topItems']))
{
sendRequestFTL("top-ads (".$_GET['topItems'].")");
}
@@ -106,6 +110,9 @@ if (isset($_GET['topItems']) && $auth)
foreach($return as $line)
{
$tmp = explode(" ",$line);
if(count($tmp) === 4)
$top_ads[$tmp[2]." (".$tmp[3].")"] = intval($tmp[1]);
else
$top_ads[$tmp[2]] = intval($tmp[1]);
}

View File

@@ -11,7 +11,7 @@
<div id="token" hidden><?php echo $token ?></div>
<!-- Title -->
<div class="page-header">
<h1>Audit log</h1>
<h1>Audit log (showing live data)</h1>
</div>
<div class="row">
@@ -28,7 +28,7 @@
<tr>
<th>Domain</th>
<th>Hits</th>
<th>Action</th>
<th>Actions</th>
</tr>
</tbody>
</table>
@@ -55,7 +55,7 @@
<tr>
<th>Domain</th>
<th>Hits</th>
<th>Action</th>
<th>Actions</th>
</tr>
</tbody>
</table>
@@ -68,6 +68,9 @@
</div>
<!-- /.box -->
</div>
<div class="col-md-12">
<p><strong>Important:</strong> Note that black- and whitelisted domains are not automatically applied on this page to avoid restarting the DNS service too often. Instead, go to <a href="http://pi.hole/admin/gravity.php">Update Lists</a> and run the update, to have the new settings become effective.</p>
</div>
<!-- /.col -->
</div>
<!-- /.row -->

View File

@@ -7,30 +7,6 @@
// Define global variables
var timeLineChart, queryTypeChart, forwardDestinationChart;
function padNumber(num) {
return ("00" + num).substr(-2,2);
}
// Helper function needed for converting the Objects to Arrays
function objectToArray(p){
var keys = Object.keys(p);
keys.sort(function(a, b) {
return a - b;
});
var arr = [], idx = [];
for (var i = 0; i < keys.length; i++) {
arr.push(p[keys[i]]);
idx.push(keys[i]);
}
return [idx,arr];
}
// Functions to update data in page
var failures = 0;
// Credit: http://stackoverflow.com/questions/1787322/htmlspecialchars-equivalent-in-javascript/4835406#4835406
function escapeHtml(text) {
var map = {
@@ -65,18 +41,29 @@ function updateTopLists() {
url = "<a href=\"queries.php?domain="+domain+"\">"+domain+"</a>";
percentage = data.top_queries[domain] / data.dns_queries_today * 100;
domaintable.append("<tr> <td>" + url +
"</td> <td>" + data.top_queries[domain] + "</td> <td> Buttons ... </td> </tr> ");
"</td> <td>" + data.top_queries[domain] + "</td> <td> <button style=\"color:red; white-space: nowrap;\"><i class=\"fa fa-ban\"></i> Blacklist</button> <button style=\"color:orange; white-space: nowrap;\"><i class=\"fa fa-balance-scale\"></i> Audit</button> </td> </tr> ");
}
}
for (domain in data.top_ads) {
if ({}.hasOwnProperty.call(data.top_ads,domain)){
// Sanitize domain
domain = escapeHtml(domain);
url = "<a href=\"queries.php?domain="+domain+"\">"+domain+"</a>";
percentage = data.top_ads[domain] / data.ads_blocked_today * 100;
console.log(domain);
console.log();
var input = domain.split(" ");
var printdomain = escapeHtml(input[0]);
if(input.length > 1)
{
url = "<a href=\"queries.php?domain="+printdomain+"\">"+printdomain+"</a> (wildcard blocked)";
adtable.append("<tr> <td>" + url +
"</td> <td>" + data.top_ads[domain] + "</td> <td> Buttons ... </td> </tr> ");
"</td> <td>" + data.top_ads[domain] + "</td> <td> <button style=\"color:orange; white-space: nowrap;\"><i class=\"fa fa-balance-scale\"></i> Audit</button> </td> </tr> ");
}
else
{
url = "<a href=\"queries.php?domain="+printdomain+"\">"+printdomain+"</a>";
adtable.append("<tr> <td>" + url +
"</td> <td>" + data.top_ads[domain] + "</td> <td> <button style=\"color:green; white-space: nowrap;\"><i class=\"fa fa-pencil-square-o\"></i> Whitelist</button> <button style=\"color:orange; white-space: nowrap;\"><i class=\"fa fa-balance-scale\"></i> Audit</button> </td> </tr> ");
}
}
}
@@ -87,8 +74,37 @@ function updateTopLists() {
});
}
function add(domain,list) {
var token = $("#token").html();
$.ajax({
url: "scripts/pi-hole/php/add.php",
method: "post",
data: {"domain":domain, "list":list, "token":token, "auditlog":1},
success: function(response) {
setTimeout(updateTopLists, 300);
}
});
}
$(document).ready(function() {
// Pull in data via AJAX
updateTopLists();
$("#domain-frequency tbody").on( "click", "button", function () {
var url = ($(this).parents("tr"))[0].innerText.split(" ")[0];
if($(this).context.innerText === "Blacklist")
add(url,"black");
else
add(url,"audit");
});
$("#ad-frequency tbody").on( "click", "button", function () {
var url = ($(this).parents("tr"))[0].innerText.split(" ")[0].split(" ")[0];
if($(this).context.innerText === "Whitelist")
add(url,"white");
else
add(url,"audit");
});
});

View File

@@ -16,13 +16,33 @@ list_verify($type);
switch($type) {
case "white":
if(!isset($_POST["auditlog"]))
echo exec("sudo pihole -w -q ${_POST['domain']}");
else
{
echo exec("sudo pihole -w -q -n ${_POST['domain']}");
echo exec("sudo pihole -a audit ${_POST['domain']}");
}
break;
case "black":
if(!isset($_POST["auditlog"]))
echo exec("sudo pihole -b -q ${_POST['domain']}");
else
{
echo exec("sudo pihole -b -q -n ${_POST['domain']}");
echo exec("sudo pihole -a audit ${_POST['domain']}");
}
break;
case "wild":
if(!isset($_POST["auditlog"]))
echo exec("sudo pihole -wild -q ${_POST['domain']}");
else
{
echo exec("sudo pihole -wild -q -n ${_POST['domain']}");
echo exec("sudo pihole -a audit ${_POST['domain']}");
}
case "audit":
echo exec("sudo pihole -a audit ${_POST['domain']}");
break;
}