Skip to content

Commit

Permalink
Merge pull request #287 from pi-hole/devel
Browse files Browse the repository at this point in the history
[RELEASE] Pi-hole WebAdmin 2.0.1
  • Loading branch information
PromoFaux authored Dec 23, 2016
2 parents 61cc6a0 + 0b21942 commit d4b0fd1
Show file tree
Hide file tree
Showing 9 changed files with 257 additions and 72 deletions.
32 changes: 29 additions & 3 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,33 @@
##### Expected Behaviour:
**In raising this issue, I confirm the following (please check boxes, eg [X] - no spaces) Failure to fill the template will close your issue:**

- [] I have read and understood the [contributors guide](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md).
- [] The issue I am reporting can be *replicated*
- [] The issue I'm reporting isn't a duplicate (see [FAQs](https://github.com/pi-hole/pi-hole/wiki/FAQs), [closed issues](https://github.com/pi-hole/pi-hole/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), and [open issues](https://github.com/pi-hole/pi-hole/issues)).

##### Actual Behaviour:
**How familiar are you with the codebase?:**

_{replace this text with a number from 1 to 10, with 1 being not familiar, and 10 being very familiar}_

##### Steps to reproduce this issue:
---
**[FEATURE REQUEST | QUESTION | OTHER]:**

Please [submit your feature request here](https://discourse.pi-hole.net/c/feature-requests), so it is votable by the community. It's also easier for us to track.

**[BUG | ISSUE] Expected Behaviour:**


**[BUG | ISSUE] Actual Behaviour:**


**[BUG | ISSUE] Steps to reproduce:**

-
-
-
-

**(Optional) Debug token generated by `pihole -d`:**

`<token>`

_This template was created based on the work of [`udemy-dl`](https://github.com/nishad/udemy-dl/blob/master/LICENSE)._
20 changes: 14 additions & 6 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
Fixes #[issue number] .
**By submitting this pull request, I confirm the following (please check boxes, eg [X] - no spaces) _Failure to fill the template will close your PR_:**

Changes proposed in this pull request:
***Please submit all pull requests against the `development` branch. Failure to do so will delay or deny your request***

-
- [] I have read and understood the [contributors guide](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md).
- [] I have checked that [another pull request](https://github.com/pi-hole/pi-hole/pulls) for this purpose does not exist.
- [] I have considered, and confirmed that this submission will be valuable to others.
- [] I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
- [] I give this submission freely, and claim no ownership to its content.

-
**How familiar are you with the codebase?:**

-
_{replace this text with a number from 1 to 10, with 1 being not familiar, and 10 being very familiar}_

@pi-hole/dashboard
---
_{replace this line with your pull request content}_


_This template was created based on the work of [`udemy-dl`](https://github.com/nishad/udemy-dl/blob/master/LICENSE)._
161 changes: 114 additions & 47 deletions data.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,36 @@ function getIpvType() {
return $queryTypes;
}

function resolveIPs(&$array) {
$hostarray = [];
foreach ($array as $key => $value)
{
$hostname = gethostbyaddr($key);
// If we found a hostname for the IP, replace it
if($hostname)
{
// Generate HOST entry
$hostarray[$hostname] = $value;
}
else
{
// Generate IP entry
$hostarray[$key] = $value;
}
}
$array = $hostarray;

// Sort new array
arsort($array);
}

function getForwardDestinations() {
global $log;
global $log, $setupVars;
$forwards = getForwards($log);
$destinations = array();
foreach ($forwards as $forward) {
$exploded = explode(" ", trim($forward));
$dest = hasHostName($exploded[count($exploded) - 1]);
$dest = $exploded[count($exploded) - 1];
if (isset($destinations[$dest])) {
$destinations[$dest]++;
}
Expand All @@ -122,17 +145,36 @@ function getForwardDestinations() {
}
}

if(istrue($setupVars["API_GET_UPSTREAM_DNS_HOSTNAME"]))
{
resolveIPs($destinations);
}

return $destinations;

}

// Check for existance of variable
// and test it only if it exists
function istrue(&$argument) {
$ret = false;
if(isset($argument))
{
if($argument)
{
$ret = true;
}
}
return $ret;
}

function getQuerySources() {
global $log;
global $log, $setupVars;
$dns_queries = getDnsQueries($log);
$sources = array();
foreach($dns_queries as $query) {
$exploded = explode(" ", $query);
$ip = hasHostName(trim($exploded[count($exploded)-1]));
$ip = trim($exploded[count($exploded)-1]);
if (isset($sources[$ip])) {
$sources[$ip]++;
}
Expand All @@ -149,6 +191,12 @@ function getQuerySources() {

arsort($sources);
$sources = array_slice($sources, 0, 10);

if(istrue($setupVars["API_GET_CLIENT_HOSTNAME"]))
{
resolveIPs($sources);
}

return Array(
'top_sources' => $sources
);
Expand Down Expand Up @@ -199,7 +247,7 @@ function setShowBlockedPermitted()
function getAllQueries($orderBy) {
global $log,$showBlocked,$showPermitted;
$allQueries = array("data" => array());
$dns_queries = getDnsQueriesAll($log);
$dns_queries = getDnsQueries($log);

// Create empty array for gravity
$gravity_domains = getGravity();
Expand All @@ -212,36 +260,33 @@ function getAllQueries($orderBy) {

setShowBlockedPermitted();

if (substr($tmp, 0, 5) == "query")
$status = isset($gravity_domains[$domain]) ? "Pi-holed" : "OK";
if(($status === "Pi-holed" && $showBlocked) || ($status === "OK" && $showPermitted))
{
$status = isset($gravity_domains[$domain]) ? "Pi-holed" : "OK";
if(($status === "Pi-holed" && $showBlocked) || ($status === "OK" && $showPermitted))
{
$type = substr($exploded[count($exploded)-4], 6, -1);
$client = $exploded[count($exploded)-1];

if($orderBy == "orderByClientDomainTime"){
$allQueries['data'][hasHostName($client)][$domain][$time->format('Y-m-d\TH:i:s')] = $status;
}elseif ($orderBy == "orderByClientTimeDomain"){
$allQueries['data'][hasHostName($client)][$time->format('Y-m-d\TH:i:s')][$domain] = $status;
}elseif ($orderBy == "orderByTimeClientDomain"){
$allQueries['data'][$time->format('Y-m-d\TH:i:s')][hasHostName($client)][$domain] = $status;
}elseif ($orderBy == "orderByTimeDomainClient"){
$allQueries['data'][$time->format('Y-m-d\TH:i:s')][$domain][hasHostName($client)] = $status;
}elseif ($orderBy == "orderByDomainClientTime"){
$allQueries['data'][$domain][hasHostName($client)][$time->format('Y-m-d\TH:i:s')] = $status;
}elseif ($orderBy == "orderByDomainTimeClient"){
$allQueries['data'][$domain][$time->format('Y-m-d\TH:i:s')][hasHostName($client)] = $status;
}else{
array_push($allQueries['data'], array(
$time->format('Y-m-d\TH:i:s'),
$type,
$domain,
hasHostName($client),
$status,
""
));
}
$type = substr($exploded[count($exploded)-4], 6, -1);
$client = $exploded[count($exploded)-1];

if($orderBy == "orderByClientDomainTime"){
$allQueries['data'][hasHostName($client)][$domain][$time->format('Y-m-d\TH:i:s')] = $status;
}elseif ($orderBy == "orderByClientTimeDomain"){
$allQueries['data'][hasHostName($client)][$time->format('Y-m-d\TH:i:s')][$domain] = $status;
}elseif ($orderBy == "orderByTimeClientDomain"){
$allQueries['data'][$time->format('Y-m-d\TH:i:s')][hasHostName($client)][$domain] = $status;
}elseif ($orderBy == "orderByTimeDomainClient"){
$allQueries['data'][$time->format('Y-m-d\TH:i:s')][$domain][hasHostName($client)] = $status;
}elseif ($orderBy == "orderByDomainClientTime"){
$allQueries['data'][$domain][hasHostName($client)][$time->format('Y-m-d\TH:i:s')] = $status;
}elseif ($orderBy == "orderByDomainTimeClient"){
$allQueries['data'][$domain][$time->format('Y-m-d\TH:i:s')][hasHostName($client)] = $status;
}else{
array_push($allQueries['data'], array(
$time->format('Y-m-d\TH:i:s'),
$type,
$domain,
hasHostName($client),
$status,
""
));
}
}
}
Expand All @@ -260,7 +305,7 @@ function getDnsQueries(\SplFileObject $log) {
$log->rewind();
$lines = [];
foreach ($log as $line) {
if(strpos($line, ": query[") !== false) {
if(strpos($line, ": query[A") !== false) {
$lines[] = $line;
}
}
Expand All @@ -269,14 +314,14 @@ function getDnsQueries(\SplFileObject $log) {

function countDnsQueries() {
global $logListName;
return exec("grep -c \": query\\[\" $logListName");
return exec("grep -c \": query\\[A\" $logListName");
}

function getDnsQueriesAll(\SplFileObject $log) {
$log->rewind();
$lines = [];
foreach ($log as $line) {
if(strpos($line, ": query[") || strpos($line, "gravity.list") || strpos($line, ": forwarded") !== false) {
if(strpos($line, ": query[A") || strpos($line, "gravity.list") || strpos($line, ": forwarded") !== false) {
$lines[] = $line;
}
}
Expand Down Expand Up @@ -323,16 +368,39 @@ function getGravity() {
function getBlockedQueries(\SplFileObject $log) {
$log->rewind();
$lines = [];
$hostname = trim(file_get_contents("/etc/hostname"), "\x00..\x1F");
foreach ($log as $line) {
$line = preg_replace('/ {2,}/', ' ', $line);
$exploded = explode(" ", $line);
if(count($exploded) == 8) {
$tmp = $exploded[count($exploded) - 4];
$tmp2 = $exploded[count($exploded) - 5];
$tmp3 = $exploded[count($exploded) - 3];
//filter out bad names and host file reloads:
if(substr($tmp, strlen($tmp) - 12, 12) == "gravity.list" && $tmp2 != "read" && $tmp3 != "pi.hole" && $tmp3 != $hostname) {
if(count($exploded) == 8 || count($exploded) == 10) {
// Structure of data is currently like:
// Array
// (
// [0] => Dec
// [1] => 19
// [2] => 11:21:51
// [3] => dnsmasq[2584]:
// [4] => /etc/pihole/gravity.list
// [5] => doubleclick.com
// [6] => is
// [7] => ip.of.pi.hole
// )
// with extra logging enabled
// Array
// (
// [0] => Dec
// [1] => 19
// [2] => 11:21:51
// [3] => dnsmasq[2584]:
// [4] => 1 (identifier)
// [5] => 1.2.3.4/12345
// [6] => /etc/pihole/gravity.list
// [7] => doubleclick.com
// [8] => is
// [9] => ip.of.pi.hole
// )
$list = $exploded[count($exploded)-4];
$is = $exploded[count($exploded)-2];
// Consider only gravity.list as DNS source (not e.g. hostname.list)
if(substr($list, strlen($list) - 12, 12) === "gravity.list" && $is === "is") {
$lines[] = $line;
};
}
Expand All @@ -342,8 +410,7 @@ function getBlockedQueries(\SplFileObject $log) {

function countBlockedQueries() {
global $logListName;
$hostname = trim(file_get_contents("/etc/hostname"), "\x00..\x1F");
return exec("grep \"gravity.list\" $logListName | grep -v \"pi.hole\" | grep -v \" read \" | grep -v -c \"".$hostname."\"");
return exec("grep \"gravity.list\" $logListName | grep -c \" is \"");
}

function getForwards(\SplFileObject $log) {
Expand Down
10 changes: 5 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
?>
<!-- Small boxes (Stat box) -->
<div class="row">
<div class="col-lg-3 col-xs-6">
<div class="col-lg-3 col-xs-12">
<!-- small box -->
<div class="small-box bg-aqua">
<div class="inner">
Expand All @@ -17,7 +17,7 @@
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-xs-6">
<div class="col-lg-3 col-xs-12">
<!-- small box -->
<div class="small-box bg-green">
<div class="inner">
Expand All @@ -30,7 +30,7 @@
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-xs-6">
<div class="col-lg-3 col-xs-12">
<!-- small box -->
<div class="small-box bg-yellow">
<div class="inner">
Expand All @@ -43,11 +43,11 @@
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-xs-6">
<div class="col-lg-3 col-xs-12">
<!-- small box -->
<div class="small-box bg-red">
<div class="inner">
<h3 class="statistic" id="domains_being_blocked"><sup style="font-size: 30px">---</sup></h3>
<h3 class="statistic" id="domains_being_blocked">---</h3>
<p>Domains Being Blocked</p>
</div>
<div class="icon">
Expand Down
2 changes: 1 addition & 1 deletion js/pihole/queryads.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function eventsource() {
}

var host = window.location.host;
var source = new EventSource("http://"+host+"/admin/php/queryads.php?domain="+domain.val()+"&"+exact);
var source = new EventSource("http://"+host+"/admin/php/queryads.php?domain="+domain.val().toLowerCase()+"&"+exact);

// Reset and show field
ta.empty();
Expand Down
12 changes: 10 additions & 2 deletions php/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,16 @@ function check_cors() {

// Since the Host header is easily manipulated, we can only check if it's wrong and can't use it
// to validate that the client is authorized, only unauthorized.
if(isset($_SERVER['HTTP_HOST']) && !in_array("http://".$_SERVER['HTTP_HOST'], $AUTHORIZED_HOSTNAMES)) {
log_and_die("Failed Host Check: " . $_SERVER['HTTP_HOST'] .' vs '. join(', ', $AUTHORIZED_HOSTNAMES));
$server_host = $_SERVER['HTTP_HOST'];

// If HTTP_HOST contains a non-standard port (!= 80) we have to strip the port
if(strpos($server_host,":"))
{
$server_host = parse_url($_SERVER['HTTP_HOST'], PHP_URL_HOST);
}

if(isset($_SERVER['HTTP_HOST']) && !in_array("http://".$server_host, $AUTHORIZED_HOSTNAMES)) {
log_and_die("Failed Host Check: " . $server_host .' vs '. join(', ', $AUTHORIZED_HOSTNAMES));
}

if(isset($_SERVER['HTTP_ORIGIN'])) {
Expand Down
2 changes: 1 addition & 1 deletion php/loginpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div class="panel-body">
<form action="" method="post">
<div class="form-group has-feedback <?php if ($wrongpassword) { ?>has-error<?php } ?> ">
<input type="password" name="pw" class="form-control" placeholder="Password">
<input type="password" name="pw" class="form-control" placeholder="Password" autofocus>
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">
Expand Down
Loading

0 comments on commit d4b0fd1

Please sign in to comment.