mirror of
https://github.com/pragma-/pbot.git
synced 2025-01-09 11:32:34 +01:00
Updated mode +q list tracking to updated freenode syntax; added ban whitelist (for evasion allowing)
This commit is contained in:
parent
7ddf495f58
commit
44ba3001cb
@ -15,6 +15,7 @@ use feature 'switch';
|
||||
use vars qw($VERSION);
|
||||
$VERSION = $PBot::PBot::VERSION;
|
||||
|
||||
use PBot::DualIndexHashObject;
|
||||
use PBot::LagChecker;
|
||||
|
||||
use Time::HiRes qw(gettimeofday tv_interval);
|
||||
@ -48,9 +49,80 @@ sub initialize {
|
||||
|
||||
$self->{message_history} = {};
|
||||
|
||||
my $filename = delete $conf{filename} // $self->{pbot}->{data_dir} . '/ban_whitelist';
|
||||
$self->{ban_whitelist} = PBot::DualIndexHashObject->new(name => 'BanWhitelist', filename => $filename);
|
||||
$self->{ban_whitelist}->load;
|
||||
|
||||
$pbot->timer->register(sub { $self->prune_message_history }, 60 * 60 * 1);
|
||||
|
||||
$pbot->commands->register(sub { return $self->unbanme(@_) }, "unbanme", 0);
|
||||
$pbot->commands->register(sub { return $self->whitelist(@_) }, "whitelist", 10);
|
||||
}
|
||||
|
||||
sub ban_whitelisted {
|
||||
my ($self, $channel, $mask) = lc @_;
|
||||
|
||||
if($self->{ban_whitelist}->hash->{$channel}->{$mask}->{ban_whitelisted}) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
sub whitelist {
|
||||
my ($self, $from, $nick, $user, $host, $arguments) = @_;
|
||||
$arguments = lc $arguments;
|
||||
|
||||
my ($command, $args) = split / /, $arguments, 2;
|
||||
|
||||
return "Usage: whitelist <command>, where commands are: list/show, add, remove" if not defined $command;
|
||||
|
||||
given($command) {
|
||||
when($_ eq "list" or $_ eq "show") {
|
||||
my $text = "Ban whitelist:\n";
|
||||
my $entries = 0;
|
||||
foreach my $channel (keys %{ $self->{ban_whitelist}->hash }) {
|
||||
$text .= " $channel:\n";
|
||||
foreach my $mask (keys %{ $self->{ban_whitelist}->hash->{$channel} }) {
|
||||
$text .= " $mask,\n";
|
||||
$entries++;
|
||||
}
|
||||
}
|
||||
$text .= "none" if $entries == 0;
|
||||
return $text;
|
||||
}
|
||||
when("add") {
|
||||
my ($channel, $mask) = split / /, $args, 2;
|
||||
return "Usage: whitelist add <channel> <mask>" if not defined $channel or not defined $mask;
|
||||
|
||||
$self->{ban_whitelist}->hash->{$channel}->{$mask}->{ban_whitelisted} = 1;
|
||||
$self->{ban_whitelist}->hash->{$channel}->{$mask}->{owner} = "$nick!$user\@$host";
|
||||
$self->{ban_whitelist}->hash->{$channel}->{$mask}->{created_on} = gettimeofday;
|
||||
|
||||
$self->{ban_whitelist}->save;
|
||||
return "$mask whitelisted in channel $channel";
|
||||
}
|
||||
when("remove") {
|
||||
my ($channel, $mask) = split / /, $args, 2;
|
||||
return "Usage: whitelist remove <channel> <mask>" if not defined $channel or not defined $mask;
|
||||
|
||||
if(not defined $self->{ban_whitelist}->hash->{$channel}) {
|
||||
return "No whitelists for channel $channel";
|
||||
}
|
||||
|
||||
if(not defined $self->{ban_whitelist}->hash->{$channel}->{$mask}) {
|
||||
return "No such whitelist $mask for channel $channel";
|
||||
}
|
||||
|
||||
delete $self->{ban_whitelist}->hash->{$channel}->{$mask};
|
||||
delete $self->{ban_whitelist}->hash->{$channel} if keys %{ $self->{ban_whitelist}->hash->{$channel} } == 0;
|
||||
$self->{ban_whitelist}->save;
|
||||
return "$mask whitelist removed from channel $channel";
|
||||
}
|
||||
default {
|
||||
return "Unknown command '$command'; commands are: list/show, add, remove";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub get_flood_account {
|
||||
@ -395,7 +467,6 @@ sub check_nickserv_accounts {
|
||||
my @account_masks;
|
||||
|
||||
foreach my $mask (keys %{ $self->{message_history} }) {
|
||||
|
||||
if(exists $self->{message_history}->{$mask}->{nickserv_account}) {
|
||||
# has nickserv account
|
||||
if(lc $self->{message_history}->{$mask}->{nickserv_account} eq lc $account) {
|
||||
@ -404,12 +475,16 @@ sub check_nickserv_accounts {
|
||||
|
||||
my $baninfo = $self->{pbot}->bantracker->get_baninfo($mask);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if(defined $baninfo) {
|
||||
$self->{pbot}->logger->log("anti-flood: [check-bans] $mask evaded $baninfo->{banmask} banned in $baninfo->{channel} by $baninfo->{owner}\n");
|
||||
push @banned_channels, $baninfo->{channel};
|
||||
$self->{pbot}->conn->privmsg($nick, "You have been banned in $baninfo->{channel} for attempting to evade a ban on $baninfo->{banmask} set by $baninfo->{owner}");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -426,15 +501,13 @@ sub check_nickserv_accounts {
|
||||
|
||||
foreach my $banned_channel (@banned_channels) {
|
||||
foreach my $account_mask (@account_masks) {
|
||||
my $banmask;
|
||||
$account_mask =~ m/[^@]+\@(.*)/;
|
||||
$banmask = "*!*\@$1";
|
||||
my $banmask = "*!*\@$1";
|
||||
|
||||
$self->{pbot}->logger->log("anti-flood: [check-bans] Ban detected on account $account in $banned_channel, banning $banmask.\n");
|
||||
$self->{pbot}->chanops->ban_user_timed($banmask, $banned_channel, 60 * 60 * 5);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sub on_whoisaccount {
|
||||
@ -443,7 +516,6 @@ sub on_whoisaccount {
|
||||
my $account = $event->{args}[2];
|
||||
|
||||
$self->{pbot}->logger->log("$nick is using NickServ account [$account]\n");
|
||||
|
||||
$self->check_nickserv_accounts($nick, $account);
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,8 @@ sub get_banlist {
|
||||
delete $self->{banlist}->{$channel};
|
||||
|
||||
$self->{pbot}->logger->log("Retrieving banlist for $channel.\n");
|
||||
$conn->sl("mode $channel +bq");
|
||||
$conn->sl("mode $channel +b");
|
||||
$conn->sl("mode $channel +q");
|
||||
}
|
||||
|
||||
sub get_baninfo {
|
||||
@ -85,7 +86,20 @@ sub get_baninfo {
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub on_banlistentry {
|
||||
sub on_quietlist_entry {
|
||||
my ($self, $conn, $event) = @_;
|
||||
my $channel = lc $event->{args}[1];
|
||||
my $target = lc $event->{args}[3];
|
||||
my $source = lc $event->{args}[4];
|
||||
my $timestamp = $event->{args}[5];
|
||||
|
||||
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 ];
|
||||
}
|
||||
|
||||
sub on_banlist_entry {
|
||||
my ($self, $conn, $event) = @_;
|
||||
my $channel = lc $event->{args}[1];
|
||||
my $target = lc $event->{args}[2];
|
||||
|
@ -451,6 +451,7 @@ sub trans {
|
||||
640 => "rpl_dumping", # UnrealIrcd, Hendrik Frenzel
|
||||
641 => "rpl_dumprpl", # UnrealIrcd, Hendrik Frenzel
|
||||
642 => "rpl_eodump", # UnrealIrcd, Hendrik Frenzel
|
||||
728 => "quietlist", # freenode +q, pragma_ 12/12/2011
|
||||
|
||||
999 => "numericerror", # Bahamut IRCD
|
||||
|
||||
|
@ -194,7 +194,9 @@ sub connect {
|
||||
$self->conn->add_handler('quit' , sub { $self->irchandlers->on_departure(@_) });
|
||||
$self->conn->add_handler('pong' , sub { $self->lagchecker->on_pong(@_) });
|
||||
$self->conn->add_handler('whoisaccount' , sub { $self->antiflood->on_whoisaccount(@_) });
|
||||
$self->conn->add_handler('banlist' , sub { $self->bantracker->on_banlistentry(@_) });
|
||||
$self->conn->add_handler('banlist' , sub { $self->bantracker->on_banlist_entry(@_) });
|
||||
# freenode quietlist
|
||||
$self->conn->add_handler(728 , sub { $self->bantracker->on_quietlist_entry(@_) });
|
||||
$self->conn->add_handler('endofnames' , sub { $self->bantracker->get_banlist(@_) });
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ use warnings;
|
||||
# These are set automatically by the build/commit script
|
||||
use constant {
|
||||
BUILD_NAME => "PBot",
|
||||
BUILD_REVISION => 325,
|
||||
BUILD_REVISION => 326,
|
||||
BUILD_DATE => "2011-12-11",
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user