mirror of
https://github.com/pi-hole/web.git
synced 2024-12-06 19:36:21 +01:00
Merge branch 'devel' into whitelist
Conflicts: list.php php/add.php php/sub.php
This commit is contained in:
@@ -8,4 +8,4 @@ Changes proposed in this pull request:
|
||||
|
||||
-
|
||||
|
||||
@pihole/dashboard
|
||||
@pi-hole/dashboard
|
||||
|
||||
@@ -47,6 +47,18 @@
|
||||
$data = array_merge($data, getAllQueries());
|
||||
}
|
||||
|
||||
|
||||
function filterArray(&$a) {
|
||||
$sanArray = array();
|
||||
foreach ($a as $k=>$v) {
|
||||
if (is_array($v)) {
|
||||
$sanArray[htmlspecialchars($k)] = filterArray($v);
|
||||
} else {
|
||||
$sanArray[htmlspecialchars($k)] = htmlspecialchars($v);
|
||||
}
|
||||
}
|
||||
return $sanArray;
|
||||
}
|
||||
|
||||
$data = filterArray($data);
|
||||
echo json_encode($data);
|
||||
?>
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
<?php
|
||||
$domains = Array();
|
||||
$log = Array();
|
||||
$log = array();
|
||||
$ipv6 = file_exists("/etc/pihole/.useIPv6");
|
||||
$hosts = file_exists("/etc/hosts") ? file("/etc/hosts") : array();
|
||||
|
||||
/******* Public Members ********/
|
||||
function getSummaryData() {
|
||||
global $ipv6;
|
||||
$domains = readInBlockList();
|
||||
$log = readInLog();
|
||||
$domains_being_blocked = count($domains) / ($ipv6 ? 2 : 1);
|
||||
$domains_being_blocked = gravityCount() / ($ipv6 ? 2 : 1);
|
||||
|
||||
$dns_queries_today = count(getDnsQueries($log));
|
||||
|
||||
@@ -25,7 +24,6 @@
|
||||
}
|
||||
|
||||
function getOverTimeData() {
|
||||
$domains = readInBlockList();
|
||||
$log = readInLog();
|
||||
$dns_queries = getDnsQueries($log);
|
||||
$ads_blocked = getBlockedQueries($log);
|
||||
@@ -40,7 +38,6 @@
|
||||
}
|
||||
|
||||
function getTopItems() {
|
||||
$domains = readInBlockList();
|
||||
$log = readInLog();
|
||||
$dns_queries = getDnsQueries($log);
|
||||
$ads_blocked = getBlockedQueries($log);
|
||||
@@ -106,7 +103,7 @@
|
||||
$sources = array();
|
||||
foreach($dns_queries as $query) {
|
||||
$exploded = explode(" ", $query);
|
||||
$ip = trim($exploded[count($exploded)-1]);
|
||||
$ip = hasHostName(trim($exploded[count($exploded)-1]));
|
||||
if (isset($sources[$ip])) {
|
||||
$sources[$ip]++;
|
||||
}
|
||||
@@ -114,47 +111,64 @@
|
||||
$sources[$ip] = 1;
|
||||
}
|
||||
}
|
||||
return $sources;
|
||||
arsort($sources);
|
||||
$sources = array_slice($sources, 0, 10);
|
||||
return Array(
|
||||
'top_sources' => $sources
|
||||
);
|
||||
}
|
||||
|
||||
function getAllQueries() {
|
||||
$allQueries = array("data" => array());
|
||||
$log = readInLog();
|
||||
$dns_queries = getDnsQueries($log);
|
||||
|
||||
$fileName = '/etc/pihole/gravity.list';
|
||||
$file = file_get_contents($fileName);
|
||||
|
||||
$dns_queries = getDnsQueriesAll($log);
|
||||
|
||||
foreach ($dns_queries as $query) {
|
||||
$time = date_create(substr($query, 0, 16));
|
||||
$exploded = explode(" ", trim($query));
|
||||
|
||||
$searchString = " {$exploded[6]}\n";
|
||||
|
||||
if (strpos($file,$searchString)) {
|
||||
$extra="Pi-holed";
|
||||
}
|
||||
else {
|
||||
$extra="OK";
|
||||
};
|
||||
|
||||
array_push($allQueries['data'], array(
|
||||
$tmp = $exploded[count($exploded)-4];
|
||||
|
||||
if (substr($tmp, 0, 5) == "query"){
|
||||
$type = substr($exploded[count($exploded)-4], 6, -1);
|
||||
$domain = $exploded[count($exploded)-3];
|
||||
$client = $exploded[count($exploded)-1];
|
||||
$status = "";
|
||||
}
|
||||
elseif (substr($tmp, 0, 9) == "forwarded" ){
|
||||
$status="OK";
|
||||
}
|
||||
elseif (substr($tmp, strlen($tmp) - 12, 12) == "gravity.list" && $exploded[count($exploded)-5] != "read"){
|
||||
$status="Pi-holed";
|
||||
}
|
||||
|
||||
if ( $status != ""){
|
||||
array_push($allQueries['data'], array(
|
||||
$time->format('Y-m-d\TH:i:s'),
|
||||
substr($exploded[5], 6, -1),
|
||||
$exploded[6],
|
||||
$exploded[8],
|
||||
$extra,
|
||||
));
|
||||
$type,
|
||||
$domain,
|
||||
hasHostName($client),
|
||||
$status,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $allQueries;
|
||||
}
|
||||
|
||||
/******** Private Members ********/
|
||||
function readInBlockList() {
|
||||
global $domains;
|
||||
return count($domains) > 1 ? $domains :
|
||||
file("/etc/pihole/gravity.list");
|
||||
function gravityCount() {
|
||||
//returns count of domains in blocklist.
|
||||
$gravity="/etc/pihole/gravity.list";
|
||||
$swallowed = 0;
|
||||
$NGC4889 = fopen($gravity, "r");
|
||||
while ($stars = fread($NGC4889, 1024000)) {
|
||||
$swallowed += substr_count($stars, "\n");
|
||||
}
|
||||
fclose($NGC4889);
|
||||
|
||||
return $swallowed;
|
||||
|
||||
}
|
||||
function readInLog() {
|
||||
global $log;
|
||||
@@ -164,6 +178,9 @@
|
||||
function getDnsQueries($log) {
|
||||
return array_filter($log, "findQueries");
|
||||
}
|
||||
function getDnsQueriesAll($log) {
|
||||
return array_filter($log, "findQueriesAll");
|
||||
}
|
||||
function getBlockedQueries($log) {
|
||||
return array_filter($log, "findAds");
|
||||
}
|
||||
@@ -209,7 +226,7 @@
|
||||
function alignTimeArrays(&$times1, &$times2) {
|
||||
$max = max(array(max(array_keys($times1)), max(array_keys($times2))));
|
||||
$min = min(array(min(array_keys($times1)), min(array_keys($times2))));
|
||||
|
||||
|
||||
for ($i = $min; $i <= $max; $i++) {
|
||||
if (!isset($times2[$i])) {
|
||||
$times2[$i] = 0;
|
||||
@@ -238,30 +255,34 @@
|
||||
return array_reverse($recent);
|
||||
}
|
||||
|
||||
function findQueriesAll($var) {
|
||||
return strpos($var, ": query[") || strpos($var, "gravity.list") || strpos($var, ": forwarded") !== false;
|
||||
}
|
||||
|
||||
function findQueries($var) {
|
||||
return strpos($var, ": query[") !== false;
|
||||
}
|
||||
|
||||
function findAds($var) {
|
||||
return strpos($var, "gravity.list") !== false;
|
||||
$exploded = explode(" ", $var);
|
||||
$tmp = $exploded[count($exploded)-4];
|
||||
$tmp2 = $exploded[count($exploded)-5];
|
||||
//filter out bad names and host file reloads:
|
||||
return (substr($tmp, strlen($tmp) - 12, 12) == "gravity.list" && $tmp2 != "read") ;
|
||||
}
|
||||
|
||||
function findForwards($var) {
|
||||
return strpos($var, ": forwarded") !== false;
|
||||
}
|
||||
|
||||
/*
|
||||
$data = array(
|
||||
'domains_being_blocked' => $domains_being_blocked,
|
||||
'dns_queries_today' => $dns_queries_today,
|
||||
'ads_blocked_today' => $ads_blocked_today,
|
||||
'ads_percentage_today' => $ads_percentage_today,
|
||||
'top_queries' => $topQueries,
|
||||
'top_ads' => $topAds,
|
||||
'domains_over_time' => $domains_over_time,
|
||||
'ads_over_time' => $ads_over_time,
|
||||
'recent_queries' => getRecent($dns_queries, 20),
|
||||
);
|
||||
|
||||
*/
|
||||
function hasHostName($var){
|
||||
global $hosts;
|
||||
foreach ($hosts as $host){
|
||||
$x = preg_split('/\s+/', $host);
|
||||
if ( $var == $x[0] ){
|
||||
$var = $x[1] . "($var)";
|
||||
}
|
||||
}
|
||||
return $var;
|
||||
}
|
||||
?>
|
||||
|
||||
+12
-1
@@ -104,7 +104,14 @@
|
||||
</div>
|
||||
<div class="pull-left info">
|
||||
<p>Status</p>
|
||||
<a href="#"><i class="fa fa-circle text-success"></i> Nominal</a>
|
||||
<?php
|
||||
$pistatus = exec('pgrep dnsmasq | wc -l');
|
||||
if ($pistatus > "0") {
|
||||
echo '<a href="#"><i class="fa fa-circle" style="color:#7FFF00"></i> Active</a>';
|
||||
} else {
|
||||
echo '<a href="#"><i class="fa fa-circle" style="color:#FF0000"></i> Offline</a>';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<!-- sidebar menu: : style can be found in sidebar.less -->
|
||||
@@ -123,17 +130,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">
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<div class="col-md-6">
|
||||
<div class="box" id="query-types">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">Query Types</h3>
|
||||
@@ -102,23 +102,7 @@
|
||||
<!-- /.box-body -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="box" id="top-clients">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">Top Clients</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
<div class="chart">
|
||||
<canvas id="topClientsChart" style="height: 247px; width: 466px;" width="932" height="494"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
<div class="overlay">
|
||||
<i class="fa fa-refresh fa-spin"></i>
|
||||
</div>
|
||||
<!-- /.box-body -->
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="col-md-6">
|
||||
<div class="box" id="forward-destinations">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">Forward Destinations</h3>
|
||||
@@ -137,7 +121,7 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-4">
|
||||
<div class="box" id="domain-frequency">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">Top Domains</h3>
|
||||
@@ -160,7 +144,7 @@
|
||||
<!-- /.box -->
|
||||
</div>
|
||||
<!-- /.col -->
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-4">
|
||||
<div class="box" id="ad-frequency">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">Top Advertisers</h3>
|
||||
@@ -185,6 +169,29 @@
|
||||
<!-- /.box -->
|
||||
</div>
|
||||
<!-- /.col -->
|
||||
<div class="col-md-4">
|
||||
<div class="box" id="client-frequency">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">Top Clients</h3>
|
||||
</div>
|
||||
<!-- /.box-header -->
|
||||
<div class="box-body">
|
||||
<table class="table table-bordered">
|
||||
<tbody><tr>
|
||||
<th>Client</th>
|
||||
<th>Requests</th>
|
||||
<th>Frequency</th>
|
||||
</tr>
|
||||
</tbody></table>
|
||||
</div>
|
||||
<div class="overlay">
|
||||
<i class="fa fa-refresh fa-spin"></i>
|
||||
</div>
|
||||
<!-- /.box-body -->
|
||||
</div>
|
||||
<!-- /.box -->
|
||||
</div>
|
||||
<!-- /.col -->
|
||||
</div>
|
||||
<!-- /.row -->
|
||||
|
||||
@@ -243,7 +250,7 @@
|
||||
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows());
|
||||
}
|
||||
};
|
||||
var animate = !isMobile.any();
|
||||
var animate = false;
|
||||
var ctx = document.getElementById("queryOverTimeChart").getContext("2d");
|
||||
timeLineChart = new Chart(ctx).Line(chartData,
|
||||
{
|
||||
@@ -268,20 +275,6 @@
|
||||
animation : animate
|
||||
}
|
||||
);
|
||||
|
||||
var radarChartData = {
|
||||
labels: [],
|
||||
datasets: [
|
||||
{
|
||||
label: "Top Clients",
|
||||
fillColor: "rgba(220,220,220,0.5)",
|
||||
strokeColor: "rgba(0, 166, 90,.8)",
|
||||
data: []
|
||||
}
|
||||
]
|
||||
};
|
||||
ctx = document.getElementById("topClientsChart").getContext("2d");
|
||||
topClientsChart = new Chart(ctx).Radar(radarChartData, {animation : animate});
|
||||
});
|
||||
|
||||
// Functions to oupdate data in page
|
||||
@@ -328,14 +321,15 @@
|
||||
}
|
||||
|
||||
function updateTopClientsChart() {
|
||||
$.getJSON("api.php?getQuerySources", function(data) {
|
||||
console.log(data);
|
||||
$.each(data, function(key, value) {
|
||||
topClientsChart.addData([value], key);
|
||||
});
|
||||
|
||||
$('#top-clients .overlay').remove();
|
||||
//$('#queries-over-time').append(timeLineChart.generateLegend());
|
||||
$.getJSON("api.php?summaryRaw&getQuerySources", function(data) {
|
||||
var clienttable = $('#client-frequency').find('tbody:last');
|
||||
for (domain in data.top_sources) {
|
||||
clienttable.append('<tr> <td>' + domain +
|
||||
'</td> <td>' + data.top_sources[domain] + '</td> <td> <div class="progress progress-sm"> <div class="progress-bar progress-bar-blue" style="width: ' +
|
||||
data.top_sources[domain] / data.dns_queries_today * 100 + '%"></div> </div> </td> </tr> ');
|
||||
}
|
||||
|
||||
$('#client-frequency .overlay').remove();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -375,6 +369,7 @@
|
||||
$.getJSON("api.php?summaryRaw&topItems", function(data) {
|
||||
var domaintable = $('#domain-frequency').find('tbody:last');
|
||||
var adtable = $('#ad-frequency').find('tbody:last');
|
||||
|
||||
for (domain in data.top_queries) {
|
||||
domaintable.append('<tr> <td>' + domain +
|
||||
'</td> <td>' + data.top_queries[domain] + '</td> <td> <div class="progress progress-sm"> <div class="progress-bar progress-bar-green" style="width: ' +
|
||||
|
||||
+1
-1
@@ -77,4 +77,4 @@
|
||||
function refreshData() {
|
||||
tableApi.ajax.url("api.php?getAllQueries").load();
|
||||
}
|
||||
</script>
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user