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 2 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
24 changes: 20 additions & 4 deletions data.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
$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 +74,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 @@ -197,7 +211,7 @@ function setShowBlockedPermitted()
}

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

Expand All @@ -215,7 +229,9 @@ function getAllQueries($orderBy) {
if (substr($tmp, 0, 5) == "query")
{
$status = isset($gravity_domains[$domain]) ? "Pi-holed" : "OK";
if(($status === "Pi-holed" && $showBlocked) || ($status === "OK" && $showPermitted))
// Display blocked queries if $showBlocked is set
// Display permitted queries if $showPermitted is set and $privacyMode is disabled
if(($status === "Pi-holed" && $showBlocked) || ($status === "OK" && $showPermitted && !$privacyMode))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're not showing any queries, it would be faster to immediately return an empty array than to parse through all the queries.

{
$type = substr($exploded[count($exploded)-4], 6, -1);
$client = $exploded[count($exploded)-1];
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
9 changes: 9 additions & 0 deletions php/savesettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ function validDomain($domain_name)
$success .= "No entries will be shown in Query Log";
}

if(isset($_POST["privacyMode"]))
{
exec("sudo pihole -a privacymode true");
}
else
{
exec("sudo pihole -a privacymode false");
}

break;

case "webUI":
Expand Down
13 changes: 13 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,15 @@
} else {
$queryLog = "all";
}

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

?>
<div class="box box-success">
<div class="box-header with-border">
Expand All @@ -412,6 +421,10 @@
<div class="checkbox"><label><input type="checkbox" name="querylog-permitted" <?php if($queryLog === "permittedonly" || $queryLog === "all"){ ?>checked<?php } ?>> Show permitted queries</label></div>
<div class="checkbox"><label><input type="checkbox" name="querylog-blocked" <?php if($queryLog === "blockedonly" || $queryLog === "all"){ ?>checked<?php } ?>> Show blocked queries</label></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