From 41ba29d218415a817b083fae5e1deeaa7de1fc79 Mon Sep 17 00:00:00 2001 From: Dan Church Date: Mon, 4 Sep 2023 10:08:00 -0500 Subject: [PATCH 1/4] Remove Perl 4 sigils (PBP) --- make-block.pl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/make-block.pl b/make-block.pl index 315dfd8..64cebfb 100755 --- a/make-block.pl +++ b/make-block.pl @@ -25,7 +25,7 @@ my $skip = 0; my $removed_allowed = 0; sub add_domain_list { my $file = shift; - foreach my $line (&read_stripped($file)) { + foreach my $line (read_stripped($file)) { my $domain = lc $line; ++$dupes if defined $domains{$domain}; $domains{$domain} = 1; @@ -34,7 +34,7 @@ sub add_domain_list { sub add_host_file { my $file = shift; - foreach my $line (&read_stripped($file)) { + foreach my $line (read_stripped($file)) { my @parts = split /\s+/, $line; die "Malformed line in $file: $line; @parts" unless @parts > 1; @@ -71,7 +71,7 @@ MAIN: { my $block_ip = '0.0.0.0 ::'; my $workdir = $FindBin::RealBin; - unless (&GetOptions( + unless (GetOptions( 'out=s' => \$out, 'O=s' => \$out, 'i=s' => \$block_ip, @@ -85,16 +85,16 @@ MAIN: { my @allow_lists = glob "$workdir/allowlists/*.domains"; foreach my $listfile (@domain_lists) { - &add_domain_list($listfile); + add_domain_list($listfile); } foreach my $hostfile (@hosts_lists) { - &add_host_file($hostfile); + add_host_file($hostfile); } # Apply allowlists my @allow_domains; foreach my $allowlist (@allow_lists) { - push @allow_domains, &read_stripped($allowlist); + push @allow_domains, read_stripped($allowlist); } my $before = %domains; delete %domains{@allow_domains}; From 133b2712088b44b6f5cc5ee638dced77a727254e Mon Sep 17 00:00:00 2001 From: Dan Church Date: Mon, 4 Sep 2023 10:08:36 -0500 Subject: [PATCH 2/4] Combine GetOpt::Long options --- make-block.pl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/make-block.pl b/make-block.pl index 64cebfb..f778e4d 100755 --- a/make-block.pl +++ b/make-block.pl @@ -72,10 +72,8 @@ MAIN: { my $workdir = $FindBin::RealBin; unless (GetOptions( - 'out=s' => \$out, - 'O=s' => \$out, - 'i=s' => \$block_ip, - 'block-ip=s' => \$block_ip, + 'out|O=s' => \$out, + 'block-ip|i=s' => \$block_ip, )) { exit 2; } From 7d9188c6fa64c5f6c350ae1228395e03c531d6d0 Mon Sep 17 00:00:00 2001 From: Dan Church Date: Mon, 4 Sep 2023 10:50:30 -0500 Subject: [PATCH 3/4] Require Perl 5.12 Fix some postfix 'if' statements too. --- make-block.pl | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/make-block.pl b/make-block.pl index f778e4d..9c572d2 100755 --- a/make-block.pl +++ b/make-block.pl @@ -13,7 +13,7 @@ # You may NOT use this software for commercial purposes. ############################################################################### -use strict; +use 5.012; use warnings; use Getopt::Long qw/ GetOptions :config no_ignore_case /; @@ -27,7 +27,9 @@ sub add_domain_list { my $file = shift; foreach my $line (read_stripped($file)) { my $domain = lc $line; - ++$dupes if defined $domains{$domain}; + if (defined $domains{$domain}) { + ++$dupes; + } $domains{$domain} = 1; } } @@ -47,7 +49,9 @@ sub add_host_file { next; } my $domain = lc $parts[1]; - ++$dupes if defined $domains{$domain}; + if (defined $domains{$domain}) { + ++$dupes; + } $domains{$domain} = 1; } } @@ -117,7 +121,13 @@ MAIN: { printf STDERR "%d domains written to %s from\n", $written, $out // 'STDOUT'; printf STDERR " - %d .domains files\n", (scalar @domain_lists); printf STDERR " - %d .hosts files\n", (scalar @hosts_lists); - printf STDERR "(%d duplicates)\n", $dupes if $dupes; - printf STDERR "(%d domains removed via allowlist)\n", $removed_allowed if $removed_allowed; - printf STDERR "(%d skipped)\n", $skip if $skip; + if ($dupes) { + say STDERR "($dupes duplicates)"; + } + if ($removed_allowed) { + say STDERR "($removed_allowed domains removed via allowlist)"; + } + if ($skip) { + say STDERR "($skip skipped)"; + } } From 85d9a5feca07ede379ef69a06865f3e7a1d71970 Mon Sep 17 00:00:00 2001 From: Dan Church Date: Mon, 22 Apr 2024 10:17:45 -0500 Subject: [PATCH 4/4] Configure Getopt::Long with better options --- make-block.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make-block.pl b/make-block.pl index 9c572d2..c390910 100755 --- a/make-block.pl +++ b/make-block.pl @@ -16,7 +16,7 @@ use 5.012; use warnings; -use Getopt::Long qw/ GetOptions :config no_ignore_case /; +use Getopt::Long qw/ GetOptions :config bundling no_getopt_compat no_ignore_case /; use FindBin qw//; my %domains;