function getTopItems() { global $log; $dns_queries = getDnsQueries($log); $ads_blocked = getBlockedQueries($log); $topAds = topItems($ads_blocked); $topQueries = topItems($dns_queries, $topAds); return array('top_queries' => $topQueries, 'top_ads' => $topAds); }
function getTopItems() { $domains = readInBlockList(); $log = readInLog(); $dns_queries = getDnsQueries($log); $ads_blocked = getBlockedQueries($log); $topAds = topItems($ads_blocked); $topQueries = topItems($dns_queries, $topAds); return array('top_queries' => $topQueries, 'top_ads' => $topAds); }
function defHP() { findItems(); echo "\n <div class='col-sm-4'>\n <div class='panel-group'>\n <div class='panel panel-primary'>\n <div class='panel-heading basecolours'>\n <h1>Search for an item</h1>\n </div>\n <div class='panel-body basecolours' align='center'>\n <form class='input-group' role='form' method='get' action='search.php' >\n <input type='text' name='search' class='form-control' id='search' placeholder='Search...' >\n <span class='input-group-btn''>\n <button class='btn btn-primary' type='submit' value='Submit'>\n <span class='glyphicon glyphicon-search'></span>\n </button>\n </span>\n </form>\n </div>\n </div>\n </div>\n </div>\n </div>\n\n "; topItems(); }
<?php $domains = file("/etc/pihole/gravity.list"); $log = file("/var/log/pihole.log"); $domains_being_blocked = count($domains); $dns_queries = array_filter($log, "findQueries"); $dns_queries_today = count($dns_queries); $ads_blocked = array_filter($log, "findAds"); $ads_blocked_today = count($ads_blocked); $ads_percentage_today = $ads_blocked_today / $dns_queries_today * 100; $domains_over_time = overTime($dns_queries); $ads_over_time = overTime($ads_blocked); alignTimeArrays($ads_over_time, $domains_over_time); $topAds = topItems($ads_blocked); $topQueries = topItems($dns_queries, $topAds); function topItems($queries, $exclude = array()) { $splitQueries = array(); foreach ($queries as $query) { $exploded = explode(" ", $query); $domain = trim($exploded[5]); if (!isset($exclude[$domain])) { if (isset($splitQueries[$domain])) { $splitQueries[$domain]++; } else { $splitQueries[$domain] = 1; } } } arsort($splitQueries); return array_slice($splitQueries, 0, 10);