X-Git-Url: https://git.donarmstrong.com/?p=bin.git;a=blobdiff_plain;f=parse_banlist;h=9548f64e3fe72d666206666d2d9b1ef0423aa079;hp=a0774355f9a4f04743ddf275fea027b32c86e923;hb=4621d23526ccf936d1ad076ece0bc663510dfc52;hpb=ce0d3ef1d36d104e3f33bfdcea64b46a3a993384 diff --git a/parse_banlist b/parse_banlist index a077435..9548f64 100755 --- a/parse_banlist +++ b/parse_banlist @@ -5,50 +5,106 @@ use strict; use IO::File; -use Getopt::Std; +use Getopt::Long; +use Pod::Usage; -my $conf = {bans => 'bans.txt', - bans_to_remove => 'bans_to_remove.txt', - bans_to_keep => 'bans_to_keep.txt', - minimum_age => 1209600, # two weeks - max_ubans => 4, - }; +=head1 NAME -my $options = {}; -getopt('b:k:r:a:',$options); +parse_banlist -$conf->{bans} = $options->{b} || $conf->{bans}; -$conf->{bans_to_remove} = $options->{r} || $conf->{bans_to_remove}; -$conf->{bans_to_keep} = $options->{k} || $conf->{bans_to_keep}; -$conf->{minimum_age} = $options->{a} || $conf->{minimum_age}; +=head1 SYNOPSIS -my $bans_fh = new IO::File $conf->{bans}, 'r' or die "Unable to open file $conf->{bans} for reading: $!";; +parse_banlist [options] -my $bans_r_fh = new IO::File $conf->{bans_to_remove}, 'w' or - die "Unable to open file $conf->{bans_to_remove} for writing: $!"; + Options: + --bans, -b list of bans (bans.txt) + --remove, -r file to save bans to remove (bans_to_remove.txt) + --keep, -k file to save bans to keep (bans_to_keep.txt) + --debug, -d debugging level (Default 0) + --help, -h display this help + --man, -m display manual -my $bans_k_fh = new IO::File $conf->{bans_to_keep}, 'w' or - die "Unable to open file $conf->{bans_to_keep} for writing: $!"; +=head1 OPTIONS + +=over + +=item B<--debug, -d> + +Debug verbosity. (Default 0) + +=item B<--help, -h> + +Display brief useage information. + +=item B<--man, -m> + +Display this manual. + +=back + +=head1 EXAMPLES + + +=cut + + +use vars qw($DEBUG); + +# XXX parse config file + +my %options = (debug => 0, + help => 0, + man => 0, + age => 60*60*24*7, + unbans => 4, + bans => 'bans.txt', + remove => 'bans_to_remove.txt', + keep => 'bans_to_keep.txt', + pattern => 1, + user => 1, + wide => 1, + ); + +GetOptions(\%options,'age|a=i','unbans|u=i','bans|b=s','remove|r=s', + 'pattern|p!','keep|k=s','debug|d+','help|h|?','man|m', + 'user|specific-user|s!','wide|wide-bans|w!', + ); + +pod2usage() if $options{help}; +pod2usage({verbose=>2}) if $options{man}; + +$DEBUG = $options{debug}; + +my $bans_fh = new IO::File $options{bans}, 'r' or die "Unable to open file $options{bans} for reading: $!";; + +my $bans_r_fh = new IO::File $options{remove}, 'w' or + die "Unable to open file $options{remove} for writing: $!"; + +my $bans_k_fh = new IO::File $options{keep}, 'w' or + die "Unable to open file $options{keep} for writing: $!"; my @bans_to_remove; while (<$bans_fh>) { # pull the ban and the times. - print {$bans_k_fh} $_ and next unless my ($channel, $banmask, $time) = - $_ =~ /(\#\w+)\:\s+ban\s+([\w\d\*\@\%\!\-\_\.]+)\s+\[by\s*.*?\,\s+(\d+)\s+secs/; - print {$bans_k_fh} $_ and next unless $time > $conf->{minimum_age}; + print {$bans_k_fh} "nomatch: $_" and next unless my ($channel, $banmask, $time) = + $_ =~ /(\#\w+)\:\s+ban\s+([^\s]+)\s+\[by\s*.*?\,\s+(\d+)\s+secs/; + print {$bans_k_fh} "time: $_" and next unless $time > $options{age}; # Ignore bans against specific users. - print {$bans_k_fh} $_ and next if $banmask =~ /^\%?\w/; - + if ($options{user}) { + print {$bans_k_fh} "user: $_" and next if $banmask =~ /^\%?\w/ + } # Ignore wide bans - print {$bans_k_fh} $_ and next if $banmask =~ /\*\!.*?\@.*\*.*/; + if ($options{wide}) { + print {$bans_k_fh} "wide: $_" and next if $banmask =~ /\*\!.*?\@.*\*.*/; + } push @bans_to_remove, $banmask; } -while (my @unbans = splice(@bans_to_remove,0,$conf->{max_ubans})) { +while (my @unbans = splice(@bans_to_remove,0,$options{unbans})) { print {$bans_r_fh} q(/mode -), q(b) x ($#unbans+1), q( ), join(' ',@unbans); print {$bans_r_fh} qq(\n); }