#! /usr/bin/perl use warnings; use strict; use IO::File; use Getopt::Long; use Pod::Usage; =head1 NAME parse_banlist =head1 SYNOPSIS parse_banlist [options] 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 =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} "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. if ($options{user}) { print {$bans_k_fh} "user: $_" and next if $banmask =~ /^\%?\w/ } # Ignore wide bans 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,$options{unbans})) { print {$bans_r_fh} q(/mode -), q(b) x ($#unbans+1), q( ), join(' ',@unbans); print {$bans_r_fh} qq(\n); }