3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-26 22:09:26 +01:00

Ban timeouts hash converted to DualIndexHashObject to properly group masks by channels

This commit is contained in:
Pragmatic Software 2013-07-24 12:35:40 +00:00
parent 58d45480a5
commit 416115f12f
7 changed files with 35 additions and 32 deletions

View File

@ -326,7 +326,7 @@ sub check_flood {
} }
} elsif($mode == $self->{FLOOD_CHAT}) { } elsif($mode == $self->{FLOOD_CHAT}) {
# don't increment offenses again if already banned # don't increment offenses again if already banned
return if exists $self->{pbot}->chanops->{unban_timeout}->hash->{"*!$user\@$host"}; return if $self->{pbot}->chanops->{unban_timeout}->find_index($channel, "*!$user\@$host");
$self->message_history->{$account}->{channels}->{$channel}{offenses}++; $self->message_history->{$account}->{channels}->{$channel}{offenses}++;
$self->message_history->{$account}->{channels}->{$channel}{last_offense_timestamp} = gettimeofday; $self->message_history->{$account}->{channels}->{$channel}{last_offense_timestamp} = gettimeofday;
@ -416,26 +416,23 @@ sub prune_message_history {
sub unbanme { sub unbanme {
my ($self, $from, $nick, $user, $host, $arguments) = @_; my ($self, $from, $nick, $user, $host, $arguments) = @_;
my $channel = lc $arguments; my $channel = lc $arguments;
$host = lc $host; $nick = lc $nick;
$user = lc $user; $user = lc $user;
$host = lc $host;
if(not defined $arguments or not defined $channel) { if(not defined $arguments or not defined $channel) {
return "/msg $nick Usage: unbanme <channel>"; return "/msg $nick Usage: unbanme <channel>";
} }
my $banmask = address_to_mask($host); my $banmask = lc address_to_mask($host);
my $mask = lc "*!$user\@$banmask\$##stop_join_flood"; my $mask = "*!$user\@$banmask\$##stop_join_flood";
if(not exists $self->{pbot}->{chanops}->{unban_timeout}->hash->{$mask}) { if(not $self->{pbot}->{chanops}->{unban_timeout}->find_index($channel, $mask)) {
return "/msg $nick There is no temporary ban set for $mask in channel $channel."; return "/msg $nick There is no temporary ban set for $mask in channel $channel.";
} }
if(not $self->{pbot}->chanops->{unban_timeout}->hash->{$mask}{channel} eq $channel) { my $baninfo = $self->{pbot}->bantracker->get_baninfo("$nick!$user\@$host");
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(defined $baninfo) {
if($self->ban_whitelisted($baninfo->{channel}, $baninfo->{banmask})) { if($self->ban_whitelisted($baninfo->{channel}, $baninfo->{banmask})) {
@ -455,8 +452,6 @@ sub unbanme {
} }
$self->{pbot}->chanops->unban_user($mask, $channel); $self->{pbot}->chanops->unban_user($mask, $channel);
delete $self->{pbot}->chanops->{unban_timeout}->hash->{$mask};
$self->{pbot}->chanops->{unban_timeout}->save_hash();
return "/msg $nick You have been unbanned from $channel."; return "/msg $nick You have been unbanned from $channel.";
} }
@ -484,6 +479,8 @@ sub address_to_mask {
sub check_bans { sub check_bans {
my ($self, $bans, $mask) = @_; my ($self, $bans, $mask) = @_;
$self->{pbot}->logger->log("anti-flood: [check-bans] checking for bans on ($mask)\n");
my $baninfo = $self->{pbot}->bantracker->get_baninfo($mask); my $baninfo = $self->{pbot}->bantracker->get_baninfo($mask);
if(defined $baninfo) { if(defined $baninfo) {
@ -502,7 +499,7 @@ sub check_bans {
$banmask_regex =~ s/\\\?/./g; $banmask_regex =~ s/\\\?/./g;
if($baninfo->{type} eq '+q' and $mask =~ /^$banmask_regex$/i) { if($baninfo->{type} eq '+q' and $mask =~ /^$banmask_regex$/i) {
$self->{pbot}->logger->log("anti-flood: [check-bans] Hostmask matches quiet banmask, disregarding\n"); $self->{pbot}->logger->log("anti-flood: [check-bans] Hostmask ($mask) matches quiet banmask ($banmask_regex), disregarding\n");
return undef; return undef;
} }

View File

@ -128,8 +128,9 @@ sub track_mode {
$self->{pbot}->logger->log("ban-tracker: $target " . ($mode eq '-b' ? 'unbanned' : 'unquieted') . " by $source in $channel.\n"); $self->{pbot}->logger->log("ban-tracker: $target " . ($mode eq '-b' ? 'unbanned' : 'unquieted') . " by $source in $channel.\n");
delete $self->{banlist}->{$channel}->{$mode eq "-b" ? "+b" : "+q"}->{$target}; delete $self->{banlist}->{$channel}->{$mode eq "-b" ? "+b" : "+q"}->{$target};
delete $self->{pbot}->chanops->{unban_timeout}->hash->{$target}; if($self->{pbot}->chanops->{unban_timeout}->find_index($channel, $target)) {
$self->{pbot}->chanops->{unban_timeout}->save_hash(); $self->{pbot}->chanops->{unban_timeout}->remove($channel, $target);
}
} else { } else {
$self->{pbot}->logger->log("BanTracker: Unknown mode '$mode'\n"); $self->{pbot}->logger->log("BanTracker: Unknown mode '$mode'\n");
} }

View File

@ -35,7 +35,7 @@ sub initialize {
} }
$self->{pbot} = $pbot; $self->{pbot} = $pbot;
$self->{unban_timeout} = PBot::HashObject->new(pbot => $pbot, name => 'Unban Timeouts', filename => "$pbot->{data_dir}/unban_timeouts"); $self->{unban_timeout} = PBot::DualIndexHashObject->new(pbot => $pbot, name => 'Unban Timeouts', filename => "$pbot->{data_dir}/unban_timeouts");
$self->{op_commands} = {}; $self->{op_commands} = {};
$self->{is_opped} = {}; $self->{is_opped} = {};
@ -91,8 +91,10 @@ sub unban_user {
my $self = shift; my $self = shift;
my ($mask, $channel) = @_; my ($mask, $channel) = @_;
$self->{pbot}->logger->log("Unbanning $mask\n"); $self->{pbot}->logger->log("Unbanning $mask\n");
delete $self->{unban_timeout}->hash->{$mask}; if($self->{unban_timeout}->find_index($channel, $mask)) {
$self->{unban_timeout}->save_hash(); $self->{unban_timeout}->hash->{$channel}->{$mask}{timeout} = gettimeofday + 7200; # try again in 2 hours if unban doesn't immediately succeed
$self->{unban_timeout}->save;
}
unshift @{ $self->{op_commands}->{$channel} }, "mode $channel -b $mask"; unshift @{ $self->{op_commands}->{$channel} }, "mode $channel -b $mask";
$self->gain_ops($channel); $self->gain_ops($channel);
} }
@ -102,9 +104,8 @@ sub ban_user_timed {
my ($mask, $channel, $length) = @_; my ($mask, $channel, $length) = @_;
$self->ban_user($mask, $channel); $self->ban_user($mask, $channel);
$self->{unban_timeout}->hash->{$mask}{timeout} = gettimeofday + $length; $self->{unban_timeout}->hash->{$channel}->{$mask}{timeout} = gettimeofday + $length;
$self->{unban_timeout}->hash->{$mask}{channel} = $channel; $self->{unban_timeout}->save;
$self->{unban_timeout}->save_hash();
} }
sub check_unban_timeouts { sub check_unban_timeouts {
@ -114,12 +115,11 @@ sub check_unban_timeouts {
my $now = gettimeofday(); my $now = gettimeofday();
foreach my $mask (keys %{ $self->{unban_timeout}->hash }) { foreach my $channel (keys %{ $self->{unban_timeout}->hash }) {
if($self->{unban_timeout}->hash->{$mask}{timeout} < $now) { foreach my $mask (keys %{ $self->{unban_timeout}->hash->{$channel} }) {
$self->unban_user($mask, $self->{unban_timeout}->hash->{$mask}{channel}); if($self->{unban_timeout}->hash->{$channel}->{$mask}{timeout} < $now) {
} else { $self->unban_user($mask, $channel);
# my $timediff = $self->{unban_timeout}->hash->{$mask}{timeout} - $now; }
# $self->{pbot}->logger->log("ban: $mask has $timediff seconds remaining\n");
} }
} }
} }

View File

@ -341,6 +341,12 @@ sub remove {
} }
delete $self->hash->{$primary}->{$secondary}; delete $self->hash->{$primary}->{$secondary};
# remove primary group if no more secondaries
if(scalar keys $self->hash->{$primary} == 0) {
delete $self->hash->{$primary};
}
$self->save(); $self->save();
return "'$secondary' removed from $primary group [$self->{name}]."; return "'$secondary' removed from $primary group [$self->{name}].";
} }

View File

@ -161,9 +161,8 @@ sub on_mode {
else { # bot not targeted else { # bot not targeted
if($mode eq "+b") { if($mode eq "+b") {
if($nick eq "ChanServ") { if($nick eq "ChanServ") {
$self->{pbot}->chanops->{unban_timeout}->hash->{$target}{timeout} = gettimeofday + 3600 * 2; # 2 hours $self->{pbot}->chanops->{unban_timeout}->hash->{$channel}->{$target}{timeout} = gettimeofday + 3600 * 2; # 2 hours
$self->{pbot}->chanops->{unban_timeout}->hash->{$target}{channel} = $channel; $self->{pbot}->chanops->{unban_timeout}->save;
$self->{pbot}->chanops->{unban_timeout}->save_hash();
} }
} }
elsif($mode eq "+e" && $channel eq $self->{pbot}->botnick) { elsif($mode eq "+e" && $channel eq $self->{pbot}->botnick) {

View File

@ -146,7 +146,7 @@ sub initialize {
$self->{chanops} = PBot::ChanOps->new(pbot => $self); $self->{chanops} = PBot::ChanOps->new(pbot => $self);
$self->{chanopcmds} = PBot::ChanOpCommands->new(pbot => $self); $self->{chanopcmds} = PBot::ChanOpCommands->new(pbot => $self);
$self->{chanops}->{unban_timeout}->load_hash(); $self->{chanops}->{unban_timeout}->load;
$self->{quotegrabs} = PBot::Quotegrabs->new( $self->{quotegrabs} = PBot::Quotegrabs->new(
pbot => $self, pbot => $self,

View File

@ -13,7 +13,7 @@ use warnings;
# These are set automatically by the build/commit script # These are set automatically by the build/commit script
use constant { use constant {
BUILD_NAME => "PBot", BUILD_NAME => "PBot",
BUILD_REVISION => 411, BUILD_REVISION => 412,
BUILD_DATE => "2013-07-24", BUILD_DATE => "2013-07-24",
}; };