mirror of
https://github.com/pragma-/pbot.git
synced 2025-01-22 10:04:36 +01:00
bantracker: track +q and +b separately to prevent loss of information
bantracker: do not ban someone if their hostmask matches their +q mask bantracker: remove ban timeouts on -q/-b antiflood: unbanme will not work if manual ban/quiet set in place
This commit is contained in:
parent
1d691caeb9
commit
dd7f84ceff
@ -421,7 +421,7 @@ sub unbanme {
|
||||
$host = lc $host;
|
||||
$user = lc $user;
|
||||
|
||||
if(not defined $channel) {
|
||||
if(not defined $arguments or not defined $channel) {
|
||||
return "/msg $nick Usage: unbanme <channel>";
|
||||
}
|
||||
|
||||
@ -437,6 +437,20 @@ sub unbanme {
|
||||
return "/msg $nick There is no temporary ban set for $mask in channel $channel.";
|
||||
}
|
||||
|
||||
my $baninfo = $self->{pbot}->bantracker->get_baninfo(lc "$nick!$user\@$host");
|
||||
|
||||
if(defined $baninfo) {
|
||||
if($self->ban_whitelisted($baninfo->{channel}, $baninfo->{banmask})) {
|
||||
$self->{pbot}->logger->log("anti-flood: [unbanme] $nick!$user\@$host banned as $baninfo->{banmask} in $baninfo->{channel}, but allowed through whitelist\n");
|
||||
} else {
|
||||
if($channel eq lc $baninfo->{channel}) {
|
||||
my $mode = $baninfo->{type} eq "+b" ? "banned" : "quieted";
|
||||
$self->{pbot}->logger->log("anti-flood: [unbanme] $nick!$user\@$host $mode as $baninfo->{banmask} in $baninfo->{channel} by $baninfo->{owner}, unbanme rejected\n");
|
||||
return "/msg $nick You have been $mode as $baninfo->{banmask} by $baninfo->{owner}, unbanme will not work until it is removed.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$self->{pbot}->chanops->unban_user($mask, $channel);
|
||||
delete $self->{pbot}->chanops->{unban_timeout}->hash->{$mask};
|
||||
$self->{pbot}->chanops->{unban_timeout}->save_hash();
|
||||
@ -464,6 +478,37 @@ sub address_to_mask {
|
||||
return $banmask;
|
||||
}
|
||||
|
||||
sub check_bans {
|
||||
my ($self, $bans, $mask) = @_;
|
||||
|
||||
my $baninfo = $self->{pbot}->bantracker->get_baninfo($mask);
|
||||
|
||||
if(defined $baninfo) {
|
||||
if($self->ban_whitelisted($baninfo->{channel}, $baninfo->{banmask})) {
|
||||
$self->{pbot}->logger->log("anti-flood: [check-bans] $mask evaded $baninfo->{banmask} in $baninfo->{channel}, but allowed through whitelist\n");
|
||||
return undef;
|
||||
}
|
||||
|
||||
if($baninfo->{type} eq '+b' and $baninfo->{banmask} =~ m/!\*@\*$/) {
|
||||
$self->{pbot}->logger->log("anti-flood: [check-bans] Disregarding generic nick ban\n");
|
||||
return undef;
|
||||
}
|
||||
|
||||
my $banmask_regex = quotemeta $baninfo->{banmask};
|
||||
$banmask_regex =~ s/\\\*/.*/g;
|
||||
$banmask_regex =~ s/\\\?/./g;
|
||||
|
||||
if($baninfo->{type} eq '+q' and $mask =~ /^$banmask_regex$/i) {
|
||||
$self->{pbot}->logger->log("anti-flood: [check-bans] Hostmask matches quiet banmask, disregarding\n");
|
||||
return undef;
|
||||
}
|
||||
|
||||
push @$bans, $baninfo;
|
||||
return $baninfo;
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub check_nickserv_accounts {
|
||||
my ($self, $nick, $account) = @_;
|
||||
|
||||
@ -475,17 +520,7 @@ sub check_nickserv_accounts {
|
||||
if(lc $self->{message_history}->{$mask}->{nickserv_account} eq lc $account) {
|
||||
# pre-existing mask found using this account previously, check for bans
|
||||
$self->{pbot}->logger->log("anti-flood: [check-account] $nick [nickserv: $account] seen previously as $mask.\n");
|
||||
|
||||
my $baninfo = $self->{pbot}->bantracker->get_baninfo($mask);
|
||||
|
||||
if(defined $baninfo) {
|
||||
if($self->ban_whitelisted($baninfo->{channel}, $baninfo->{banmask})) {
|
||||
$self->{pbot}->logger->log("anti-flood: [check-bans] $mask evaded $baninfo->{banmask} in $baninfo->{channel}, but allowed through whitelist\n");
|
||||
next;
|
||||
} else {
|
||||
push @bans, $baninfo;
|
||||
}
|
||||
}
|
||||
$self->check_bans(\@bans, $mask);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -496,17 +531,7 @@ sub check_nickserv_accounts {
|
||||
$self->message_history->{$mask}->{nickserv_account} = $account;
|
||||
|
||||
$account_mask = $mask;
|
||||
|
||||
my $baninfo = $self->{pbot}->bantracker->get_baninfo($mask);
|
||||
|
||||
if(defined $baninfo) {
|
||||
if($self->ban_whitelisted($baninfo->{channel}, $baninfo->{banmask})) {
|
||||
$self->{pbot}->logger->log("anti-flood: [check-bans] $mask evaded $baninfo->{banmask} in $baninfo->{channel}, but allowed through whitelist\n");
|
||||
next;
|
||||
} else {
|
||||
push @bans, $baninfo;
|
||||
}
|
||||
}
|
||||
$self->check_bans(\@bans, $mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,8 @@ sub get_baninfo {
|
||||
my ($self, $mask) = @_;
|
||||
|
||||
foreach my $channel (keys %{ $self->{banlist} }) {
|
||||
foreach my $banmask (keys %{ $self->{banlist}{$channel} }) {
|
||||
foreach my $mode (keys %{ $self->{banlist}{$channel} }) {
|
||||
foreach my $banmask (keys %{ $self->{banlist}{$channel}{$mode} }) {
|
||||
my $banmask_key = $banmask;
|
||||
$banmask = quotemeta $banmask;
|
||||
|
||||
@ -75,20 +76,16 @@ sub get_baninfo {
|
||||
my $baninfo = {};
|
||||
$baninfo->{banmask} = $banmask_key;
|
||||
$baninfo->{channel} = $channel;
|
||||
$baninfo->{owner} = $self->{banlist}{$channel}{$banmask_key}[0];
|
||||
$baninfo->{when} = $self->{banlist}{$channel}{$banmask_key}[1];
|
||||
$baninfo->{type} = $self->{banlist}{$channel}{$banmask_key}[2];
|
||||
$baninfo->{owner} = $self->{banlist}{$channel}{$mode}{$banmask_key}[0];
|
||||
$baninfo->{when} = $self->{banlist}{$channel}{$mode}{$banmask_key}[1];
|
||||
$baninfo->{type} = $mode;
|
||||
$self->{pbot}->logger->log("get-baninfo: dump: " . Dumper($baninfo) . "\n");
|
||||
|
||||
if($baninfo->{type} eq '+b' and $banmask_key =~ m/!\*@\*$/) {
|
||||
$self->{pbot}->logger->log("get-baninfo: Disregarding generic nick ban\n");
|
||||
return undef;
|
||||
}
|
||||
|
||||
return $baninfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return undef;
|
||||
}
|
||||
@ -103,7 +100,7 @@ sub on_quietlist_entry {
|
||||
my $ago = ago(gettimeofday - $timestamp);
|
||||
|
||||
$self->{pbot}->logger->log("ban-tracker: [quietlist entry] $channel: $target quieted by $source $ago.\n");
|
||||
$self->{banlist}->{$channel}->{$target} = [ $source, $timestamp, '+q' ];
|
||||
$self->{banlist}->{$channel}->{'+q'}->{$target} = [ $source, $timestamp ];
|
||||
}
|
||||
|
||||
sub on_banlist_entry {
|
||||
@ -116,7 +113,7 @@ sub on_banlist_entry {
|
||||
my $ago = ago(gettimeofday - $timestamp);
|
||||
|
||||
$self->{pbot}->logger->log("ban-tracker: [banlist entry] $channel: $target banned by $source $ago.\n");
|
||||
$self->{banlist}->{$channel}->{$target} = [ $source, $timestamp, '+b' ];
|
||||
$self->{banlist}->{$channel}->{'+b'}->{$target} = [ $source, $timestamp ];
|
||||
}
|
||||
|
||||
sub track_mode {
|
||||
@ -125,11 +122,14 @@ sub track_mode {
|
||||
|
||||
if($mode eq "+b" or $mode eq "+q") {
|
||||
$self->{pbot}->logger->log("ban-tracker: $target " . ($mode eq '+b' ? 'banned' : 'quieted') . " by $source in $channel.\n");
|
||||
$self->{banlist}->{$channel}->{$target} = [ $source, gettimeofday, $mode ];
|
||||
$self->{banlist}->{$channel}->{$mode}->{$target} = [ $source, gettimeofday ];
|
||||
}
|
||||
elsif($mode eq "-b" or $mode eq "-q") {
|
||||
$self->{pbot}->logger->log("ban-tracker: $target " . ($mode eq '-b' ? 'unbanned' : 'unquieted') . " by $source in $channel.\n");
|
||||
delete $self->{banlist}->{$channel}->{$target};
|
||||
delete $self->{banlist}->{$channel}->{$mode eq "-b" ? "+b" : "+q"}->{$target};
|
||||
|
||||
delete $self->{pbot}->chanops->{unban_timeout}->hash->{$target};
|
||||
$self->{pbot}->chanops->{unban_timeout}->save_hash();
|
||||
} else {
|
||||
$self->{pbot}->logger->log("BanTracker: Unknown mode '$mode'\n");
|
||||
}
|
||||
|
@ -13,8 +13,8 @@ use warnings;
|
||||
# These are set automatically by the build/commit script
|
||||
use constant {
|
||||
BUILD_NAME => "PBot",
|
||||
BUILD_REVISION => 341,
|
||||
BUILD_DATE => "2011-12-16",
|
||||
BUILD_REVISION => 342,
|
||||
BUILD_DATE => "2011-12-17",
|
||||
};
|
||||
|
||||
1;
|
||||
|
Loading…
Reference in New Issue
Block a user