3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-23 11:12:42 +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}) {
# 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}{last_offense_timestamp} = gettimeofday;
@ -416,26 +416,23 @@ sub prune_message_history {
sub unbanme {
my ($self, $from, $nick, $user, $host, $arguments) = @_;
my $channel = lc $arguments;
$host = lc $host;
$nick = lc $nick;
$user = lc $user;
$host = lc $host;
if(not defined $arguments or not defined $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.";
}
if(not $self->{pbot}->chanops->{unban_timeout}->hash->{$mask}{channel} eq $channel) {
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");
my $baninfo = $self->{pbot}->bantracker->get_baninfo("$nick!$user\@$host");
if(defined $baninfo) {
if($self->ban_whitelisted($baninfo->{channel}, $baninfo->{banmask})) {
@ -455,8 +452,6 @@ sub unbanme {
}
$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.";
}
@ -484,6 +479,8 @@ sub address_to_mask {
sub check_bans {
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);
if(defined $baninfo) {
@ -502,7 +499,7 @@ sub check_bans {
$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");
$self->{pbot}->logger->log("anti-flood: [check-bans] Hostmask ($mask) matches quiet banmask ($banmask_regex), disregarding\n");
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");
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();
if($self->{pbot}->chanops->{unban_timeout}->find_index($channel, $target)) {
$self->{pbot}->chanops->{unban_timeout}->remove($channel, $target);
}
} else {
$self->{pbot}->logger->log("BanTracker: Unknown mode '$mode'\n");
}

View File

@ -35,7 +35,7 @@ sub initialize {
}
$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->{is_opped} = {};
@ -91,8 +91,10 @@ sub unban_user {
my $self = shift;
my ($mask, $channel) = @_;
$self->{pbot}->logger->log("Unbanning $mask\n");
delete $self->{unban_timeout}->hash->{$mask};
$self->{unban_timeout}->save_hash();
if($self->{unban_timeout}->find_index($channel, $mask)) {
$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";
$self->gain_ops($channel);
}
@ -102,9 +104,8 @@ sub ban_user_timed {
my ($mask, $channel, $length) = @_;
$self->ban_user($mask, $channel);
$self->{unban_timeout}->hash->{$mask}{timeout} = gettimeofday + $length;
$self->{unban_timeout}->hash->{$mask}{channel} = $channel;
$self->{unban_timeout}->save_hash();
$self->{unban_timeout}->hash->{$channel}->{$mask}{timeout} = gettimeofday + $length;
$self->{unban_timeout}->save;
}
sub check_unban_timeouts {
@ -114,12 +115,11 @@ sub check_unban_timeouts {
my $now = gettimeofday();
foreach my $mask (keys %{ $self->{unban_timeout}->hash }) {
if($self->{unban_timeout}->hash->{$mask}{timeout} < $now) {
$self->unban_user($mask, $self->{unban_timeout}->hash->{$mask}{channel});
} else {
# my $timediff = $self->{unban_timeout}->hash->{$mask}{timeout} - $now;
# $self->{pbot}->logger->log("ban: $mask has $timediff seconds remaining\n");
foreach my $channel (keys %{ $self->{unban_timeout}->hash }) {
foreach my $mask (keys %{ $self->{unban_timeout}->hash->{$channel} }) {
if($self->{unban_timeout}->hash->{$channel}->{$mask}{timeout} < $now) {
$self->unban_user($mask, $channel);
}
}
}
}

View File

@ -341,6 +341,12 @@ sub remove {
}
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();
return "'$secondary' removed from $primary group [$self->{name}].";
}

View File

@ -161,9 +161,8 @@ sub on_mode {
else { # bot not targeted
if($mode eq "+b") {
if($nick eq "ChanServ") {
$self->{pbot}->chanops->{unban_timeout}->hash->{$target}{timeout} = gettimeofday + 3600 * 2; # 2 hours
$self->{pbot}->chanops->{unban_timeout}->hash->{$target}{channel} = $channel;
$self->{pbot}->chanops->{unban_timeout}->save_hash();
$self->{pbot}->chanops->{unban_timeout}->hash->{$channel}->{$target}{timeout} = gettimeofday + 3600 * 2; # 2 hours
$self->{pbot}->chanops->{unban_timeout}->save;
}
}
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->{chanopcmds} = PBot::ChanOpCommands->new(pbot => $self);
$self->{chanops}->{unban_timeout}->load_hash();
$self->{chanops}->{unban_timeout}->load;
$self->{quotegrabs} = PBot::Quotegrabs->new(
pbot => $self,

View File

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