Skip to content

Commit

Permalink
Merge pull request pi-hole#85 from pi-hole/new/black.list
Browse files Browse the repository at this point in the history
Parse black.list blocking
  • Loading branch information
DL6ER authored Jun 18, 2017
2 parents 63dd395 + 9a51c12 commit 9625ebc
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 15 deletions.
8 changes: 8 additions & 0 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ void *GC_thread(void *val)
validate_access("domains", queries[i].domainID, true, __LINE__, __FUNCTION__, __FILE__);
domains[queries[i].domainID].blockedcount--;
break;
case 5:
// Blocked by user's black list
counters.blocked--;
validate_access("overTime", queries[i].timeidx, true, __LINE__, __FUNCTION__, __FILE__);
overTime[queries[i].timeidx].blocked--;
validate_access("domains", queries[i].domainID, true, __LINE__, __FUNCTION__, __FILE__);
domains[queries[i].domainID].blockedcount--;
break;
default:
/* That cannot happen */
break;
Expand Down
16 changes: 16 additions & 0 deletions parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ void process_pihole_log(int file)
// - "gravity.list" + domain
// - "forwarded" + domain
// - "cached" + domain
// - "black.list" + domain
// in the following up to 200 lines
bool firsttime = true;
int forwardID = -1;
Expand Down Expand Up @@ -374,6 +375,12 @@ void process_pihole_log(int file)
status = detectStatus(domain);
break;
}
// Blocked by black.list ?
else if(strstr(readbuffer2,"black.list ") != NULL)
{
status = 5;
break;
}
}
}
else
Expand Down Expand Up @@ -520,8 +527,17 @@ void process_pihole_log(int file)
domains[domainID].blockedcount++;
domains[domainID].wildcard = true;
break;
case 5:
// Blocked by user's black list
counters.blocked++;
validate_access("overTime", timeidx, true, __LINE__, __FUNCTION__, __FILE__);
overTime[timeidx].blocked++;
validate_access("domains", domainID, true, __LINE__, __FUNCTION__, __FILE__);
domains[domainID].blockedcount++;
break;
default:
/* That cannot happen */
logg("Found unexpected status %i",status);
break;
}

Expand Down
4 changes: 4 additions & 0 deletions test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ ${ts} reply play.google.com is <CNAME>
${ts} query[AAAA] play.google.com from 192.168.2.208
${ts} forwarded play.google.com to 2620:0:ccd::2
${ts} reply play.l.google.com is 2a00:1450:4017:802::200e
${ts} query[A] blacklisted.com from 192.168.2.208
${ts} /etc/pihole/black.list blacklisted.com is 1.2.3.4
${ts} query[A] addomain.com from 192.168.2.208
${ts} /etc/pihole/gravity.list addomain.com is 1.2.3.4
EOT
touch "pihole-FTL.log"

Expand Down
35 changes: 20 additions & 15 deletions test/test_suite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ load 'libs/bats-support/load'
echo "output: ${lines[@]}"
[[ ${lines[0]} == "Connection to 127.0.0.1 4711 port [tcp/*] succeeded!" ]]
[[ ${lines[1]} =~ "domains_being_blocked -1" ]]
[[ ${lines[2]} =~ "dns_queries_today 5" ]]
[[ ${lines[3]} =~ "ads_blocked_today 0" ]]
[[ ${lines[4]} =~ "ads_percentage_today 0.000000" ]]
[[ ${lines[5]} =~ "unique_domains 4" ]]
[[ ${lines[2]} =~ "dns_queries_today 7" ]]
[[ ${lines[3]} =~ "ads_blocked_today 2" ]]
[[ ${lines[4]} =~ "ads_percentage_today 28.571428" ]]
[[ ${lines[5]} =~ "unique_domains 6" ]]
[[ ${lines[6]} =~ "queries_forwarded 3" ]]
[[ ${lines[7]} =~ "queries_cached 2" ]]
[[ ${lines[8]} == "---EOM---" ]]
Expand All @@ -32,7 +32,7 @@ load 'libs/bats-support/load'
run bash -c 'echo ">top-clients" | nc -v 127.0.0.1 4711'
echo "output: ${lines[@]}"
[[ ${lines[0]} == "Connection to 127.0.0.1 4711 port [tcp/*] succeeded!" ]]
[[ ${lines[1]} =~ "0 2 192.168.2.208" ]]
[[ ${lines[1]} =~ "0 4 192.168.2.208" ]]
[[ ${lines[2]} == "1 2 127.0.0.1 localhost" ]]
[[ ${lines[3]} =~ "2 1 10.8.0.2" ]]
[[ ${lines[4]} == "---EOM---" ]]
Expand All @@ -53,14 +53,16 @@ load 'libs/bats-support/load'
run bash -c 'echo ">top-ads" | nc -v 127.0.0.1 4711'
echo "output: ${lines[@]}"
[[ ${lines[0]} == "Connection to 127.0.0.1 4711 port [tcp/*] succeeded!" ]]
[[ ${lines[1]} == "---EOM---" ]]
[[ ${lines[1]} == "0 1 addomain.com" ]]
[[ ${lines[2]} == "1 1 blacklisted.com" ]]
[[ ${lines[3]} == "---EOM---" ]]
}

@test "Over Time" {
run bash -c 'echo ">overTime" | nc -v 127.0.0.1 4711'
echo "output: ${lines[@]}"
[[ ${lines[0]} == "Connection to 127.0.0.1 4711 port [tcp/*] succeeded!" ]]
[[ ${lines[1]} =~ "5 0" ]]
[[ ${lines[1]} =~ "7 2" ]]
[[ ${lines[2]} == "---EOM---" ]]
}

Expand All @@ -70,17 +72,17 @@ load 'libs/bats-support/load'
[[ ${lines[0]} == "Connection to 127.0.0.1 4711 port [tcp/*] succeeded!" ]]
[[ ${lines[1]} =~ "0 4 2001:1608:10:25::9249:d69b" ]]
[[ ${lines[2]} =~ "1 4 2620:0:ccd::2 resolver2.ipv6-sandbox.opendns.com" ]]
[[ ${lines[3]} =~ "2 2 2001:1608:10:25::1c04:b12f" ]]
[[ ${lines[4]} =~ "3 2 2620:0:ccc::2 resolver1.ipv6-sandbox.opendns.com" ]]
[[ ${lines[5]} =~ "4 2 ::1 local" ]]
[[ ${lines[3]} =~ "2 4 ::1 local" ]]
[[ ${lines[4]} =~ "3 2 2001:1608:10:25::1c04:b12f" ]]
[[ ${lines[5]} =~ "4 2 2620:0:ccc::2 resolver1.ipv6-sandbox.opendns.com" ]]
[[ ${lines[6]} == "---EOM---" ]]
}

@test "Query Types" {
run bash -c 'echo ">querytypes" | nc -v 127.0.0.1 4711'
echo "output: ${lines[@]}"
[[ ${lines[0]} == "Connection to 127.0.0.1 4711 port [tcp/*] succeeded!" ]]
[[ ${lines[1]} == "A (IPv4): 3" ]]
[[ ${lines[1]} == "A (IPv4): 5" ]]
[[ ${lines[2]} == "AAAA (IPv6): 2" ]]
[[ ${lines[3]} == "---EOM---" ]]
}
Expand All @@ -94,7 +96,9 @@ load 'libs/bats-support/load'
[[ ${lines[3]} =~ "IPv4 pi.hole" ]]
[[ ${lines[4]} =~ "IPv4 play.google.com" ]]
[[ ${lines[5]} =~ "IPv6 play.google.com" ]]
[[ ${lines[6]} == "---EOM---" ]]
[[ ${lines[6]} =~ "IPv4 blacklisted.com" ]]
[[ ${lines[7]} =~ "IPv4 addomain.com" ]]
[[ ${lines[8]} == "---EOM---" ]]
}

@test "Get all queries (domain filtered)" {
Expand All @@ -107,7 +111,7 @@ load 'libs/bats-support/load'
}

@test "Get all queries (domain + number filtered)" {
run bash -c 'echo ">getallqueries-domain play.google.com (1)" | nc -v 127.0.0.1 4711'
run bash -c 'echo ">getallqueries-domain play.google.com (3)" | nc -v 127.0.0.1 4711'
echo "output: ${lines[@]}"
[[ ${lines[0]} == "Connection to 127.0.0.1 4711 port [tcp/*] succeeded!" ]]
[[ ${lines[1]} =~ "IPv6 play.google.com" ]]
Expand All @@ -124,7 +128,7 @@ load 'libs/bats-support/load'
}

@test "Get all queries (client + number filtered)" {
run bash -c 'echo ">getallqueries-client localhost (4)" | nc -v 127.0.0.1 4711'
run bash -c 'echo ">getallqueries-client localhost (6)" | nc -v 127.0.0.1 4711'
echo "output: ${lines[@]}"
[[ ${lines[0]} == "Connection to 127.0.0.1 4711 port [tcp/*] succeeded!" ]]
[[ ${lines[1]} =~ "IPv4 checkip.dyndns.org localhost 2" ]]
Expand Down Expand Up @@ -152,7 +156,8 @@ load 'libs/bats-support/load'
run bash -c 'echo ">recentBlocked" | nc -v 127.0.0.1 4711'
echo "output: ${lines[@]}"
[[ ${lines[0]} == "Connection to 127.0.0.1 4711 port [tcp/*] succeeded!" ]]
[[ ${lines[1]} == "---EOM---" ]]
[[ ${lines[1]} == "addomain.com" ]]
[[ ${lines[2]} == "---EOM---" ]]
}

@test "DB test: Tables created and populated?" {
Expand Down

0 comments on commit 9625ebc

Please sign in to comment.