mirror of
https://github.com/pi-hole/web.git
synced 2024-12-06 19:36:21 +01:00
Merge branch 'devel' into fixQueryLog
Conflicts: data.php
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
|
||||
$ads_blocked_today = count(getBlockedQueries($log));
|
||||
|
||||
$ads_percentage_today = $ads_blocked_today / $dns_queries_today * 100;
|
||||
$ads_percentage_today = $dns_queries_today > 0 ? ($ads_blocked_today / $dns_queries_today * 100) : 0;
|
||||
|
||||
return array(
|
||||
'domains_being_blocked' => $domains_being_blocked,
|
||||
@@ -121,19 +121,38 @@
|
||||
$allQueries = array("data" => array());
|
||||
$log = readInLog();
|
||||
$dns_queries = getDnsQueries($log);
|
||||
|
||||
|
||||
$fileName = '/etc/pihole/gravity.list';
|
||||
//Turn gravity.list into an array
|
||||
$lines = explode("\n", file_get_contents($fileName));
|
||||
|
||||
//Create a new array and set domain name as index instead of value, with value as 1
|
||||
foreach(array_values($lines) as $v){
|
||||
$new_lines[trim(strstr($v, ' '))] = 1;
|
||||
}
|
||||
|
||||
foreach ($dns_queries as $query) {
|
||||
$time = date_create(substr($query, 0, 16));
|
||||
|
||||
$exploded = explode(" ", trim($query));
|
||||
|
||||
//Is index of the domain name set?
|
||||
if (isset($new_lines[$exploded[6]])){
|
||||
$extra = "Pi-holed";
|
||||
}
|
||||
else
|
||||
{
|
||||
$extra = "OK";
|
||||
}
|
||||
array_push($allQueries['data'], array(
|
||||
$time->format('Y-m-d\TH:i:s'),
|
||||
substr($exploded[count($exploded)-4], 6, -1),
|
||||
$exploded[count($exploded)-3],
|
||||
$exploded[count($exploded)-1],
|
||||
$extra,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
return $allQueries;
|
||||
}
|
||||
|
||||
|
||||
@@ -123,17 +123,21 @@
|
||||
</a>
|
||||
</li>
|
||||
<!-- Whitelist -->
|
||||
<!--
|
||||
<li>
|
||||
<a href="list.php?l=white">
|
||||
<i class="fa fa-pencil-square-o"></i> <span>Whitelist</span>
|
||||
</a>
|
||||
</li>
|
||||
-->
|
||||
<!-- Blacklist -->
|
||||
<!--
|
||||
<li>
|
||||
<a href="list.php?l=black">
|
||||
<i class="fa fa-pencil-square-o"></i> <span>Blacklist</span>
|
||||
</a>
|
||||
</li>
|
||||
-->
|
||||
<!-- Donate -->
|
||||
<li>
|
||||
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3J2L3Z4DHW9UY">
|
||||
|
||||
@@ -347,7 +347,7 @@
|
||||
queryTypeChart.addData({
|
||||
value: value,
|
||||
color: colors.shift(),
|
||||
label: key
|
||||
label: key.substr(6,key.length - 7)
|
||||
});
|
||||
});
|
||||
$('#query-types .overlay').remove();
|
||||
|
||||
@@ -1,212 +0,0 @@
|
||||
<?php
|
||||
require "header.html";
|
||||
|
||||
$list = $_GET['l'];
|
||||
|
||||
function getFullName() {
|
||||
global $list;
|
||||
if($list == "white")
|
||||
echo "Whitelist";
|
||||
else
|
||||
echo "Blacklist";
|
||||
}
|
||||
?>
|
||||
|
||||
<!-- Title -->
|
||||
<div class="page-header">
|
||||
<h1><?php getFullName(); ?></h1>
|
||||
</div>
|
||||
|
||||
<!-- Domain Input -->
|
||||
<div class="form-group input-group">
|
||||
<input id="domain" type="text" class="form-control" placeholder="Add a domain (example.com or sub.example.com)">
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-default" type="button" onclick="add()">Add</button>
|
||||
<button class="btn btn-default" type="button" onclick="refresh()">Refresh</button>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- Alerts -->
|
||||
<div id="alInfo" class="alert alert-info" role="alert" hidden="true">
|
||||
Adding to the <?php getFullName(); ?>...
|
||||
</div>
|
||||
<div id="alSuccess" class="alert alert-success" role="alert" hidden="true">
|
||||
Success! The list will refresh.
|
||||
</div>
|
||||
<div id="alFailure" class="alert alert-danger" role="alert" hidden="true">
|
||||
Failure! Something went wrong.
|
||||
</div>
|
||||
|
||||
<!-- Password Modal -->
|
||||
<div id="passModal" class="modal fade" role="dialog">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||
<h4 class="modal-title">Enter Your Pi-hole Password</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
Please enter your Pi-hole password to proceed.
|
||||
<div id="alPassword" class="alert alert-danger" role="alert" hidden="true">
|
||||
Wrong Password! Please try again.
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="passInput">Password:</label>
|
||||
<input id="passInput" type="password" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal" onclick="$('#alPassword').hide()">Cancel</button>
|
||||
<button id="passBtn" type="button" class="btn btn-primary">Enter</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Domain List -->
|
||||
<ul class="list-group" id="list"></ul>
|
||||
|
||||
<?php
|
||||
require "footer.php";
|
||||
?>
|
||||
|
||||
<script>
|
||||
window.onload = refresh;
|
||||
var password = "";
|
||||
$("#passModal").on("shown.bs.modal", function() {
|
||||
$("#passInput").focus();
|
||||
});
|
||||
|
||||
function refresh() {
|
||||
$.ajax({
|
||||
url: "php/get.php",
|
||||
method: "get",
|
||||
data: {"list":"<?php echo $list ?>"},
|
||||
success: function(response) {
|
||||
var list = document.getElementById("list");
|
||||
list.innerHTML = "";
|
||||
var data = JSON.parse(response);
|
||||
|
||||
if(data.length === 0) {
|
||||
list.innerHTML =
|
||||
'<div class="alert alert-info" role="alert">Your <?php getFullName(); ?> is empty!</div>';
|
||||
}
|
||||
else {
|
||||
data.forEach(function (entry, index) {
|
||||
list.innerHTML +=
|
||||
'<li id="' + index + '" class="list-group-item clearfix">' + entry +
|
||||
'<button class="btn btn-danger btn-xs pull-right" type="button" onclick="sub(\'' + index + '\', \'' + entry + '\')">' +
|
||||
'<span class="glyphicon glyphicon-trash"></span></button></li>';
|
||||
})
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, exception) {
|
||||
document.getElementById("alFailure").hidden = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function add() {
|
||||
var domain = document.getElementById("domain").value;
|
||||
if(domain.length === 0)
|
||||
return;
|
||||
|
||||
getPassword(function() {
|
||||
document.getElementById("alInfo").hidden = false;
|
||||
document.getElementById("alSuccess").hidden = true;
|
||||
document.getElementById("alFailure").hidden = true;
|
||||
$.ajax({
|
||||
url: "php/add.php",
|
||||
method: "get",
|
||||
data: {"domain":domain, "list":"<?php echo $list ?>", "pass":password},
|
||||
success: function(response) {
|
||||
if(response.length !== 0)
|
||||
return;
|
||||
document.getElementById("alSuccess").hidden = false;
|
||||
refresh();
|
||||
},
|
||||
error: function(jqXHR, exception) {
|
||||
document.getElementById("alFailure").hidden = false;
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
function sub(index, entry) {
|
||||
getPassword(function() {
|
||||
$("#"+index).hide("highlight");
|
||||
$.ajax({
|
||||
url: "php/sub.php",
|
||||
method: "get",
|
||||
data: {"domain":entry, "list":"<?php echo $list ?>", "pass":password},
|
||||
success: function(response) {
|
||||
if(response.length !== 0)
|
||||
return;
|
||||
document.getElementById("list").removeChild(document.getElementById(index));
|
||||
},
|
||||
error: function(jqXHR, exception) {
|
||||
alert("Failed to remove the domain!");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getPassword(callback) {
|
||||
// Check password and return
|
||||
if(password.length !== 0) {
|
||||
$.ajax({
|
||||
url: "php/checkPass.php",
|
||||
method: "get",
|
||||
data: {"pass":password},
|
||||
success: function(response) {
|
||||
if(response === "Correct")
|
||||
callback();
|
||||
},
|
||||
error: function(jqXHR, exception) {
|
||||
alert("Failed to check password!");
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Prompt the user for password
|
||||
var modal = $("#passModal");
|
||||
modal.modal();
|
||||
|
||||
// Handle enter button
|
||||
$("#passBtn").on("click", function() {
|
||||
var passInput = $("#passInput");
|
||||
var passAlert = $("#alPassword");
|
||||
password = passInput.val();
|
||||
|
||||
// Execute callback if entered
|
||||
if(password.length !== 0) {
|
||||
// Check if password is correct
|
||||
$.ajax({
|
||||
url: "php/checkPass.php",
|
||||
method: "get",
|
||||
data: {"pass":password},
|
||||
success: function(response) {
|
||||
if(response === "Correct") {
|
||||
passInput.html("");
|
||||
passAlert.hide();
|
||||
modal.modal("hide");
|
||||
callback();
|
||||
}
|
||||
else {
|
||||
passAlert.show();
|
||||
password = "";
|
||||
}
|
||||
},
|
||||
error: function(jqXHR, exception) {
|
||||
alert("Failed to check password!");
|
||||
password = "";
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
passAlert.show()
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
if(!isset($_GET['domain'], $_GET['list'], $_GET['pass']))
|
||||
die();
|
||||
|
||||
include "functions.php";
|
||||
|
||||
if(!checkPass($_GET['pass']))
|
||||
die("Wrong Password");
|
||||
|
||||
switch($_GET['list']) {
|
||||
case "white":
|
||||
exec("/usr/local/bin/whitelist.sh -q ${_GET['domain']}");
|
||||
break;
|
||||
case "black":
|
||||
exec("/usr/local/bin/blacklist.sh -q ${_GET['domain']}");
|
||||
break;
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<?php
|
||||
if(!isset($_GET['pass']))
|
||||
die("No password entered");
|
||||
|
||||
include "functions.php";
|
||||
|
||||
if(checkPass($_GET['pass']))
|
||||
echo "Correct";
|
||||
else
|
||||
echo "Wrong";
|
||||
@@ -1,5 +0,0 @@
|
||||
<?php
|
||||
function checkPass($pass) {
|
||||
// Check password
|
||||
return $pass == str_replace(array("\r", "\n"), '', file_get_contents("/etc/pihole/password.txt"));
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
<?php
|
||||
if(!isset($_GET['list']))
|
||||
die();
|
||||
|
||||
$type = $_GET['list'];
|
||||
$rawList = file_get_contents("/etc/pihole/${type}list.txt");
|
||||
$list = explode("\n", $rawList);
|
||||
|
||||
// Get rid of empty lines
|
||||
for($i = sizeof($list)-1; $i >= 0; $i--) {
|
||||
if($list[$i] == "")
|
||||
unset($list[$i]);
|
||||
}
|
||||
|
||||
echo json_encode(array_values($list));
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
if(!isset($_GET['domain'], $_GET['list'], $_GET['pass']))
|
||||
die();
|
||||
|
||||
include "functions.php";
|
||||
|
||||
if(!checkPass($_GET['pass']))
|
||||
die("Wrong Password");
|
||||
|
||||
switch($_GET['list']) {
|
||||
case "white":
|
||||
exec("/usr/local/bin/whitelist.sh -q -d ${_GET['domain']}");
|
||||
break;
|
||||
case "black":
|
||||
exec("/usr/local/bin/blacklist.sh -q -d ${_GET['domain']}");
|
||||
break;
|
||||
}
|
||||
+14
-4
@@ -24,6 +24,7 @@
|
||||
<th>Type</th>
|
||||
<th>Domain</th>
|
||||
<th>Client</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot>
|
||||
@@ -32,6 +33,7 @@
|
||||
<th>Type</th>
|
||||
<th>Domain</th>
|
||||
<th>Client</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
@@ -50,6 +52,15 @@
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
tableApi = $('#all-queries').DataTable( {
|
||||
"rowCallback": function( row, data, index ){
|
||||
if (data[4] == "Pi-holed") {
|
||||
$(row).css('color','red')
|
||||
}
|
||||
else{
|
||||
$(row).css('color','green')
|
||||
}
|
||||
|
||||
},
|
||||
"ajax": "api.php?getAllQueries",
|
||||
"autoWidth" : false,
|
||||
"order" : [[0, "desc"]],
|
||||
@@ -58,13 +69,12 @@
|
||||
{ "width" : "10%" },
|
||||
{ "width" : "40%" },
|
||||
{ "width" : "15%" },
|
||||
{ "width" : "15%" }
|
||||
]
|
||||
})
|
||||
} );
|
||||
|
||||
function refreshData() {
|
||||
tableApi.ajax.url("api.php?getAllQuerie").load();
|
||||
tableApi.ajax.url("api.php?getAllQueries").load();
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
</script>
|
||||
Reference in New Issue
Block a user