Skip to content

Commit

Permalink
Merge pull request #59 from pi-hole/apiChanges
Browse files Browse the repository at this point in the history
Vastly improve checking for domain in gravity.list
  • Loading branch information
PromoFaux committed Mar 8, 2016
2 parents 951a28c + e61c189 commit 6df1260
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions data.php
Expand Up @@ -123,21 +123,26 @@ function getAllQueries() {
$dns_queries = getDnsQueries($log);

$fileName = '/etc/pihole/gravity.list';
$file = file_get_contents($fileName);

//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));

$searchString = " {$exploded[6]}\n";

if (strpos($file,$searchString)) {
$extra="Pi-holed";
}
else {
$extra="OK";
};

//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[5], 6, -1),
Expand Down

0 comments on commit 6df1260

Please sign in to comment.