Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add privacy mode #258

Merged
merged 7 commits into from
Dec 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions data.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
$blackListFile = checkfile("/etc/pihole/blacklist.txt");
$blacklist = new \SplFileObject($blackListFile);

if(isset($setupVars["API_PRIVACY_MODE"]))
{
$privacyMode = $setupVars["API_PRIVACY_MODE"];
}
else
{
$privacyMode = false;
}

/******* Public Members ********/
function getSummaryData() {
$domains_being_blocked = gravityCount();
Expand Down Expand Up @@ -67,12 +76,19 @@ function getOverTimeData10mins() {
}

function getTopItems() {
global $log;
global $log,$privacyMode;
$dns_queries = getDnsQueries($log);
$ads_blocked = getBlockedQueries($log);

$topAds = topItems($ads_blocked);
$topQueries = topItems($dns_queries, $topAds);
if(!$privacyMode)
{
$topQueries = topItems($dns_queries, $topAds);
}
else
{
$topQueries = [];
}

return Array(
'top_queries' => $topQueries,
Expand Down Expand Up @@ -245,21 +261,33 @@ function setShowBlockedPermitted()
}

function getAllQueries($orderBy) {
global $log,$showBlocked,$showPermitted;
global $log,$showBlocked,$showPermitted,$privacyMode;
$allQueries = array("data" => array());
$dns_queries = getDnsQueries($log);

// Create empty array for gravity
$gravity_domains = getGravity();

setShowBlockedPermitted();

// Privacy mode?
if($privacyMode)
{
$showPermitted = false;
}

if(!$showBlocked && !$showPermitted)
{
// Nothing to do for us here
return [];
}

foreach ($dns_queries as $query) {
$time = date_create(substr($query, 0, 16));
$exploded = explode(" ", trim($query));
$domain = $exploded[count($exploded)-3];
$tmp = $exploded[count($exploded)-4];

setShowBlockedPermitted();

$status = isset($gravity_domains[$domain]) ? "Pi-holed" : "OK";
if(($status === "Pi-holed" && $showBlocked) || ($status === "OK" && $showPermitted))
{
Expand Down
7 changes: 6 additions & 1 deletion js/pihole/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ function updateTopLists() {
var domaintable = $("#domain-frequency").find("tbody:last");
var adtable = $("#ad-frequency").find("tbody:last");
var url, domain, percentage;

for (domain in data.top_queries) {
if ({}.hasOwnProperty.call(data.top_queries,domain)){
// Sanitize domain
Expand All @@ -198,8 +197,14 @@ function updateTopLists() {
"</td> <td>" + data.top_queries[domain] + "</td> <td> <div class=\"progress progress-sm\" title=\""+percentage.toFixed(1)+"%\"> <div class=\"progress-bar progress-bar-green\" style=\"width: " +
percentage + "%\"></div> </div> </td> </tr> ");
}
}

// Remove table if there are no results (e.g. privacy mode enabled)
if(jQuery.isEmptyObject(data.top_queries))
{
$("#domain-frequency").parent().remove();
}

for (domain in data.top_ads) {
if ({}.hasOwnProperty.call(data.top_ads,domain)){
// Sanitize domain
Expand Down
29 changes: 27 additions & 2 deletions php/savesettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,26 @@ function validDomain($domain_name)
if(isset($_POST["querylog-permitted"]) && isset($_POST["querylog-blocked"]))
{
exec("sudo pihole -a setquerylog all");
$success .= "All entries will be shown in Query Log";
if(!isset($_POST["privacyMode"]))
{
$success .= "All entries will be shown in Query Log";
}
else
{
$success .= "Only blocked entries will be shown in Query Log";
}
}
elseif(isset($_POST["querylog-permitted"]))
{
exec("sudo pihole -a setquerylog permittedonly");
$success .= "Only permitted will be shown in Query Log";
if(!isset($_POST["privacyMode"]))
{
$success .= "Only permitted will be shown in Query Log";
}
else
{
$success .= "No entries will be shown in Query Log";
}
}
elseif(isset($_POST["querylog-blocked"]))
{
Expand All @@ -230,6 +244,17 @@ function validDomain($domain_name)
$success .= "No entries will be shown in Query Log";
}


if(isset($_POST["privacyMode"]))
{
exec("sudo pihole -a privacymode true");
$success .= " (privacy mode enabled)";
}
else
{
exec("sudo pihole -a privacymode false");
}

if(isset($_POST["resolve-forward"]))
{
exec("sudo pihole -a resolve forward true");
Expand Down
8 changes: 8 additions & 0 deletions queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
}
}

if(isset($setupVars["API_PRIVACY_MODE"]))
{
if($setupVars["API_PRIVACY_MODE"])
{
// Overwrite string from above
$showing = "(privacy mode enabled)";
}
}
?>
<!-- Send PHP info to JS -->
<div id="token" hidden><?php echo $token ?></div>
Expand Down
12 changes: 12 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,14 @@
$queryLog = "all";
}

// Privacy Mode
if(isset($setupVars["API_PRIVACY_MODE"]))
{
$privacyMode = $setupVars["API_PRIVACY_MODE"];
} else {
$privacyMode = false;
}

if(istrue($setupVars["API_GET_UPSTREAM_DNS_HOSTNAME"]))
{
$resolveForward = true;
Expand Down Expand Up @@ -449,6 +457,10 @@
<div class="checkbox"><label><input type="checkbox" name="querylog-blocked" <?php if($queryLog === "blockedonly" || $queryLog === "all"){ ?>checked<?php } ?>> Show blocked queries</label></div>
</div>
</div>
<h4>Privacy mode</h4>
<div class="form-group">
<div class="checkbox"><label><input type="checkbox" name="privacyMode" <?php if($privacyMode){ ?>checked<?php } ?>> Don't show query results for permitted requests</label></div>
</div>
</div>
<div class="box-footer">
<input type="hidden" name="field" value="API">
Expand Down