3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-20 02:49:49 +01:00

Improve ban evasion; show evaded ban in kick message

This commit is contained in:
Pragmatic Software 2015-06-05 22:26:55 -07:00
parent 62b8432be9
commit bf45c6cdde

View File

@ -146,7 +146,7 @@ sub whitelist {
} }
} }
sub check_join_watch { sub update_join_watch {
my ($self, $account, $channel, $text, $mode) = @_; my ($self, $account, $channel, $text, $mode) = @_;
return if $channel =~ /[@!]/; # ignore QUIT messages from nick!user@host channels return if $channel =~ /[@!]/; # ignore QUIT messages from nick!user@host channels
@ -217,7 +217,7 @@ sub check_flood {
my $channels = $self->{pbot}->{nicklist}->get_channels($nick); my $channels = $self->{pbot}->{nicklist}->get_channels($nick);
foreach my $chan (@$channels) { foreach my $chan (@$channels) {
next if $chan !~ m/^#/; next if $chan !~ m/^#/;
$self->check_join_watch($account, $chan, $text, $mode); $self->update_join_watch($account, $chan, $text, $mode);
} }
$self->{pbot}->{messagehistory}->{database}->devalidate_all_channels($account); $self->{pbot}->{messagehistory}->{database}->devalidate_all_channels($account);
@ -230,7 +230,7 @@ sub check_flood {
if($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) { if($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) {
$channels = $self->{pbot}->{nicklist}->get_channels($nick); $channels = $self->{pbot}->{nicklist}->get_channels($nick);
} else { } else {
$self->check_join_watch($account, $channel, $text, $mode); $self->update_join_watch($account, $channel, $text, $mode);
push @$channels, $channel; push @$channels, $channel;
} }
@ -254,7 +254,10 @@ sub check_flood {
} }
# check for ban evasion if channel begins with # (not private message) and hasn't yet been validated against ban evasion # check for ban evasion if channel begins with # (not private message) and hasn't yet been validated against ban evasion
if($channel =~ m/^#/ and not $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'validated')->{'validated'} & $self->{NICKSERV_VALIDATED}) { if($channel =~ m/^#/) {
my $validated = $self->{pbot}->{messagehistory}->{database}->get_channel_data($account, $channel, 'validated')->{'validated'};
if($validated & $self->{NEEDS_CHECKBAN} or not $validated & $self->{NICKSERV_VALIDATED}) {
if($mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) { if($mode == $self->{pbot}->{messagehistory}->{MSG_DEPARTURE}) {
# don't check for evasion on PART/KICK # don't check for evasion on PART/KICK
} elsif ($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) { } elsif ($mode == $self->{pbot}->{messagehistory}->{MSG_NICKCHANGE}) {
@ -266,6 +269,7 @@ sub check_flood {
$self->check_bans($account, $mask, $channel); $self->check_bans($account, $mask, $channel);
} }
} }
}
# do not do flood enforcement for this event if bot is lagging # do not do flood enforcement for this event if bot is lagging
if($self->{pbot}->{lagchecker}->lagging) { if($self->{pbot}->{lagchecker}->lagging) {
@ -540,7 +544,7 @@ sub check_bans {
my $debug_checkban = $self->{pbot}->{registry}->get_value('antiflood', 'debug_checkban'); my $debug_checkban = $self->{pbot}->{registry}->get_value('antiflood', 'debug_checkban');
$self->{pbot}->{logger}->log("anti-flood: [check-bans] checking for bans on $mask in $channel\n") if $debug_checkban >= 3; $self->{pbot}->{logger}->log("anti-flood: [check-bans] checking for bans on $mask in $channel\n") if $debug_checkban >= 1;
my $current_nickserv_account = $self->{pbot}->{messagehistory}->{database}->get_current_nickserv_account($message_account); my $current_nickserv_account = $self->{pbot}->{messagehistory}->{database}->get_current_nickserv_account($message_account);
@ -558,7 +562,7 @@ sub check_bans {
$channel_data->{validated} |= $self->{NEEDS_CHECKBAN}; $channel_data->{validated} |= $self->{NEEDS_CHECKBAN};
$self->{pbot}->{messagehistory}->{database}->update_channel_data($message_account, $channel, $channel_data); $self->{pbot}->{messagehistory}->{database}->update_channel_data($message_account, $channel, $channel_data);
} }
$self->{pbot}->{logger}->log("anti-flood: [check-bans] no account for $mask; marking for later validation\n") if $debug_checkban >= 2; $self->{pbot}->{logger}->log("anti-flood: [check-bans] no account for $mask; marking for later validation\n") if $debug_checkban >= 1;
} }
my ($nick) = $mask =~ m/^([^!]+)/; my ($nick) = $mask =~ m/^([^!]+)/;
@ -589,7 +593,7 @@ sub check_bans {
} }
foreach my $nickserv (@nickservs) { foreach my $nickserv (@nickservs) {
$self->{pbot}->{logger}->log("anti-flood: [check-bans] checking for bans in $channel on $alias using nickserv " . (defined $nickserv ? $nickserv : "[undefined]") . "\n") if $debug_checkban >= 4; $self->{pbot}->{logger}->log("anti-flood: [check-bans] checking for bans in $channel on $alias using nickserv " . (defined $nickserv ? $nickserv : "[undefined]") . "\n") if $debug_checkban >= 2;
my $baninfos = $self->{pbot}->{bantracker}->get_baninfo($alias, $channel, $nickserv); my $baninfos = $self->{pbot}->{bantracker}->get_baninfo($alias, $channel, $nickserv);
if(defined $baninfos) { if(defined $baninfos) {
@ -610,10 +614,12 @@ sub check_bans {
next; next;
} }
=cut
if($baninfo->{type} eq '+b' and $baninfo->{banmask} =~ m/!\*@\*$/) { if($baninfo->{type} eq '+b' and $baninfo->{banmask} =~ m/!\*@\*$/) {
$self->{pbot}->{logger}->log("anti-flood: [check-bans] Disregarding generic nick ban\n"); $self->{pbot}->{logger}->log("anti-flood: [check-bans] Disregarding generic nick ban\n");
next; next;
} }
=cut
my $banmask_regex = quotemeta $baninfo->{banmask}; my $banmask_regex = quotemeta $baninfo->{banmask};
$banmask_regex =~ s/\\\*/.*/g; $banmask_regex =~ s/\\\*/.*/g;
@ -652,9 +658,11 @@ sub check_bans {
if ($baninfo->{type} eq 'blacklist') { if ($baninfo->{type} eq 'blacklist') {
$self->{pbot}->{chanops}->add_op_command($baninfo->{channel}, "kick $baninfo->{channel} $bannick I don't think so"); $self->{pbot}->{chanops}->add_op_command($baninfo->{channel}, "kick $baninfo->{channel} $bannick I don't think so");
} else { } else {
$self->{pbot}->{chanops}->add_op_command($baninfo->{channel}, "kick $baninfo->{channel} $bannick Ban evasion"); my $owner = $baninfo->{owner};
$owner =~ s/!.*$//;
$self->{pbot}->{chanops}->add_op_command($baninfo->{channel}, "kick $baninfo->{channel} $bannick Evaded $baninfo->{banmask} set by $owner");
} }
$self->{pbot}->{chanops}->ban_user_timed($banmask, $baninfo->{channel}, 60 * 60 * 12); $self->{pbot}->{chanops}->ban_user_timed($banmask, $baninfo->{channel}, 60 * 60 * 24 * 7);
} }
my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($message_account, $channel, 'validated'); my $channel_data = $self->{pbot}->{messagehistory}->{database}->get_channel_data($message_account, $channel, 'validated');
if($channel_data->{validated} & $self->{NICKSERV_VALIDATED}) { if($channel_data->{validated} & $self->{NICKSERV_VALIDATED}) {