mirror of
https://codeberg.org/h3xx/you-dont-need-pihole.git
synced 2024-08-14 20:27:01 +00:00
Compare commits
No commits in common. "85d9a5feca07ede379ef69a06865f3e7a1d71970" and "dc38b1a3764030d5f8a02db46abeb7446cc4c7b0" have entirely different histories.
85d9a5feca
...
dc38b1a376
1 changed files with 17 additions and 25 deletions
|
@ -13,10 +13,10 @@
|
||||||
# You may NOT use this software for commercial purposes.
|
# You may NOT use this software for commercial purposes.
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
use 5.012;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Getopt::Long qw/ GetOptions :config bundling no_getopt_compat no_ignore_case /;
|
use Getopt::Long qw/ GetOptions :config no_ignore_case /;
|
||||||
use FindBin qw//;
|
use FindBin qw//;
|
||||||
|
|
||||||
my %domains;
|
my %domains;
|
||||||
|
@ -25,18 +25,16 @@ my $skip = 0;
|
||||||
my $removed_allowed = 0;
|
my $removed_allowed = 0;
|
||||||
sub add_domain_list {
|
sub add_domain_list {
|
||||||
my $file = shift;
|
my $file = shift;
|
||||||
foreach my $line (read_stripped($file)) {
|
foreach my $line (&read_stripped($file)) {
|
||||||
my $domain = lc $line;
|
my $domain = lc $line;
|
||||||
if (defined $domains{$domain}) {
|
++$dupes if defined $domains{$domain};
|
||||||
++$dupes;
|
|
||||||
}
|
|
||||||
$domains{$domain} = 1;
|
$domains{$domain} = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub add_host_file {
|
sub add_host_file {
|
||||||
my $file = shift;
|
my $file = shift;
|
||||||
foreach my $line (read_stripped($file)) {
|
foreach my $line (&read_stripped($file)) {
|
||||||
my @parts = split /\s+/, $line;
|
my @parts = split /\s+/, $line;
|
||||||
die "Malformed line in $file: $line; @parts"
|
die "Malformed line in $file: $line; @parts"
|
||||||
unless @parts > 1;
|
unless @parts > 1;
|
||||||
|
@ -49,9 +47,7 @@ sub add_host_file {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
my $domain = lc $parts[1];
|
my $domain = lc $parts[1];
|
||||||
if (defined $domains{$domain}) {
|
++$dupes if defined $domains{$domain};
|
||||||
++$dupes;
|
|
||||||
}
|
|
||||||
$domains{$domain} = 1;
|
$domains{$domain} = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,9 +71,11 @@ MAIN: {
|
||||||
my $block_ip = '0.0.0.0 ::';
|
my $block_ip = '0.0.0.0 ::';
|
||||||
my $workdir = $FindBin::RealBin;
|
my $workdir = $FindBin::RealBin;
|
||||||
|
|
||||||
unless (GetOptions(
|
unless (&GetOptions(
|
||||||
'out|O=s' => \$out,
|
'out=s' => \$out,
|
||||||
'block-ip|i=s' => \$block_ip,
|
'O=s' => \$out,
|
||||||
|
'i=s' => \$block_ip,
|
||||||
|
'block-ip=s' => \$block_ip,
|
||||||
)) {
|
)) {
|
||||||
exit 2;
|
exit 2;
|
||||||
}
|
}
|
||||||
|
@ -87,16 +85,16 @@ MAIN: {
|
||||||
my @allow_lists = glob "$workdir/allowlists/*.domains";
|
my @allow_lists = glob "$workdir/allowlists/*.domains";
|
||||||
|
|
||||||
foreach my $listfile (@domain_lists) {
|
foreach my $listfile (@domain_lists) {
|
||||||
add_domain_list($listfile);
|
&add_domain_list($listfile);
|
||||||
}
|
}
|
||||||
foreach my $hostfile (@hosts_lists) {
|
foreach my $hostfile (@hosts_lists) {
|
||||||
add_host_file($hostfile);
|
&add_host_file($hostfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Apply allowlists
|
# Apply allowlists
|
||||||
my @allow_domains;
|
my @allow_domains;
|
||||||
foreach my $allowlist (@allow_lists) {
|
foreach my $allowlist (@allow_lists) {
|
||||||
push @allow_domains, read_stripped($allowlist);
|
push @allow_domains, &read_stripped($allowlist);
|
||||||
}
|
}
|
||||||
my $before = %domains;
|
my $before = %domains;
|
||||||
delete %domains{@allow_domains};
|
delete %domains{@allow_domains};
|
||||||
|
@ -121,13 +119,7 @@ MAIN: {
|
||||||
printf STDERR "%d domains written to %s from\n", $written, $out // 'STDOUT';
|
printf STDERR "%d domains written to %s from\n", $written, $out // 'STDOUT';
|
||||||
printf STDERR " - %d .domains files\n", (scalar @domain_lists);
|
printf STDERR " - %d .domains files\n", (scalar @domain_lists);
|
||||||
printf STDERR " - %d .hosts files\n", (scalar @hosts_lists);
|
printf STDERR " - %d .hosts files\n", (scalar @hosts_lists);
|
||||||
if ($dupes) {
|
printf STDERR "(%d duplicates)\n", $dupes if $dupes;
|
||||||
say STDERR "($dupes duplicates)";
|
printf STDERR "(%d domains removed via allowlist)\n", $removed_allowed if $removed_allowed;
|
||||||
}
|
printf STDERR "(%d skipped)\n", $skip if $skip;
|
||||||
if ($removed_allowed) {
|
|
||||||
say STDERR "($removed_allowed domains removed via allowlist)";
|
|
||||||
}
|
|
||||||
if ($skip) {
|
|
||||||
say STDERR "($skip skipped)";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue