Skip to content

Commit

Permalink
Merge pull request #62 from pi-hole/fixQueryLog
Browse files Browse the repository at this point in the history
Actually fixed query log this time
  • Loading branch information
AzureMarker committed Mar 22, 2016
2 parents 6df1260 + 5394118 commit d4dc0f5
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions data.php
Expand Up @@ -121,37 +121,36 @@ function getAllQueries() {
$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]])){
if (isset($new_lines[$exploded[count($exploded)-3]])){
$extra = "Pi-holed";
}
else
{
$extra = "OK";
}
}
array_push($allQueries['data'], array(
$time->format('Y-m-d\TH:i:s'),
substr($exploded[5], 6, -1),
$exploded[6],
$exploded[8],
substr($exploded[count($exploded)-4], 6, -1),
$exploded[count($exploded)-3],
$exploded[count($exploded)-1],
$extra,
));
}

return $allQueries;
}

Expand Down

0 comments on commit d4dc0f5

Please sign in to comment.