2010-03-22 08:33:44 +01:00
# File: AntiFlood.pm
2010-03-24 07:47:40 +01:00
# Author: pragma_
2010-03-17 07:36:54 +01:00
#
2014-05-13 12:15:52 +02:00
# Purpose: Tracks message and nickserv statistics to enforce anti-flooding and
# ban-evasion detection.
2013-10-26 04:39:54 +02:00
#
2014-05-13 12:15:52 +02:00
# The nickserv/ban-evasion stuff probably ought to be in BanTracker or some
# such suitable class.
2010-03-17 07:36:54 +01:00
2017-03-05 22:33:31 +01:00
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
2010-03-17 07:36:54 +01:00
package PBot::AntiFlood ;
use warnings ;
use strict ;
2019-07-11 03:40:53 +02:00
use feature 'unicode_strings' ;
2010-06-18 06:17:30 +02:00
use feature 'switch' ;
2014-07-11 14:54:56 +02:00
no if $] >= 5.018 , warnings = > "experimental::smartmatch" ;
2010-06-18 06:17:30 +02:00
2011-12-11 23:56:57 +01:00
use PBot::DualIndexHashObject ;
2011-01-25 00:56:55 +01:00
2011-01-22 10:26:04 +01:00
use Time::HiRes qw( gettimeofday tv_interval ) ;
2010-06-27 07:36:58 +02:00
use Time::Duration ;
2016-01-26 18:04:03 +01:00
use POSIX qw/strftime/ ;
2016-02-10 16:10:37 +01:00
use Text::CSV ;
2010-03-22 08:33:44 +01:00
use Carp ( ) ;
sub new {
2020-02-02 07:15:06 +01:00
Carp:: croak ( "Options to " . __FILE__ . " should be key/value pairs, not hash reference" ) if ref ( $ _ [ 1 ] ) eq 'HASH' ;
2010-03-22 08:33:44 +01:00
my ( $ class , % conf ) = @ _ ;
my $ self = bless { } , $ class ;
$ self - > initialize ( % conf ) ;
return $ self ;
}
2010-03-17 07:36:54 +01:00
2010-03-22 08:33:44 +01:00
sub initialize {
my ( $ self , % conf ) = @ _ ;
2014-05-13 12:15:52 +02:00
$ self - > { pbot } = delete $ conf { pbot } // Carp:: croak ( "Missing pbot reference to " . __FILE__ ) ;
2010-03-22 08:33:44 +01:00
2014-05-13 12:15:52 +02:00
# flags for 'validated' field
2019-06-26 18:34:19 +02:00
$ self - > { NICKSERV_VALIDATED } = ( 1 << 0 ) ;
$ self - > { NEEDS_CHECKBAN } = ( 1 << 1 ) ;
2010-03-22 08:33:44 +01:00
2015-05-10 21:36:47 +02:00
$ self - > { channels } = { } ; # per-channel statistics, e.g. for optimized tracking of last spoken nick for enter-abuse detection, etc
$ self - > { nickflood } = { } ; # statistics to track nickchange flooding
$ self - > { whois_pending } = { } ; # prevents multiple whois for nick joining multiple channels at once
2016-08-18 05:34:45 +02:00
$ self - > { changinghost } = { } ; # tracks nicks changing hosts/identifying to strongly link them
2010-03-23 19:24:02 +01:00
2019-12-24 23:28:57 +01:00
my $ filename = $ self - > { pbot } - > { registry } - > get_value ( 'general' , 'data_dir' ) . '/whitelist' ;
2019-06-28 09:22:57 +02:00
$ self - > { whitelist } = PBot::DualIndexHashObject - > new ( name = > 'Whitelist' , filename = > $ filename , pbot = > $ self - > { pbot } ) ;
2016-01-27 04:23:03 +01:00
$ self - > { whitelist } - > load ;
2011-12-11 23:56:57 +01:00
2014-05-18 22:09:05 +02:00
$ self - > { pbot } - > { timer } - > register ( sub { $ self - > adjust_offenses } , 60 * 60 * 1 ) ;
2014-05-20 12:14:09 +02:00
$ self - > { pbot } - > { registry } - > add_default ( 'text' , 'antiflood' , 'enforce' , $ conf { enforce_antiflood } // 1 ) ;
2014-05-19 04:42:18 +02:00
$ self - > { pbot } - > { registry } - > add_default ( 'text' , 'antiflood' , 'join_flood_threshold' , $ conf { join_flood_threshold } // 4 ) ;
$ self - > { pbot } - > { registry } - > add_default ( 'text' , 'antiflood' , 'join_flood_time_threshold' , $ conf { join_flood_time_threshold } // 60 * 30 ) ;
2015-05-16 02:51:50 +02:00
$ self - > { pbot } - > { registry } - > add_default ( 'array' , 'antiflood' , 'join_flood_punishment' , $ conf { join_flood_punishment } // '28800,3600,86400,604800,2419200,14515200' ) ;
2014-05-19 04:42:18 +02:00
$ self - > { pbot } - > { registry } - > add_default ( 'text' , 'antiflood' , 'chat_flood_threshold' , $ conf { chat_flood_threshold } // 4 ) ;
$ self - > { pbot } - > { registry } - > add_default ( 'text' , 'antiflood' , 'chat_flood_time_threshold' , $ conf { chat_flood_time_threshold } // 10 ) ;
$ self - > { pbot } - > { registry } - > add_default ( 'array' , 'antiflood' , 'chat_flood_punishment' , $ conf { chat_flood_punishment } // '60,300,3600,86400,604800,2419200' ) ;
$ self - > { pbot } - > { registry } - > add_default ( 'text' , 'antiflood' , 'nick_flood_threshold' , $ conf { nick_flood_threshold } // 3 ) ;
$ self - > { pbot } - > { registry } - > add_default ( 'text' , 'antiflood' , 'nick_flood_time_threshold' , $ conf { nick_flood_time_threshold } // 60 * 30 ) ;
$ self - > { pbot } - > { registry } - > add_default ( 'array' , 'antiflood' , 'nick_flood_punishment' , $ conf { nick_flood_punishment } // '60,300,3600,86400,604800,2419200' ) ;
$ self - > { pbot } - > { registry } - > add_default ( 'text' , 'antiflood' , 'enter_abuse_threshold' , $ conf { enter_abuse_threshold } // 4 ) ;
$ self - > { pbot } - > { registry } - > add_default ( 'text' , 'antiflood' , 'enter_abuse_time_threshold' , $ conf { enter_abuse_time_threshold } // 20 ) ;
2014-05-19 06:30:36 +02:00
$ self - > { pbot } - > { registry } - > add_default ( 'array' , 'antiflood' , 'enter_abuse_punishment' , $ conf { enter_abuse_punishment } // '60,300,3600,86400,604800,2419200' ) ;
2014-05-19 04:42:18 +02:00
$ self - > { pbot } - > { registry } - > add_default ( 'text' , 'antiflood' , 'enter_abuse_max_offenses' , $ conf { enter_abuse_max_offenses } // 3 ) ;
2014-05-18 22:09:05 +02:00
2014-05-21 06:52:17 +02:00
$ self - > { pbot } - > { registry } - > add_default ( 'text' , 'antiflood' , 'debug_checkban' , $ conf { debug_checkban } // 0 ) ;
2014-05-18 22:09:05 +02:00
$ self - > { pbot } - > { commands } - > register ( sub { return $ self - > unbanme ( @ _ ) } , "unbanme" , 0 ) ;
$ self - > { pbot } - > { commands } - > register ( sub { return $ self - > whitelist ( @ _ ) } , "whitelist" , 10 ) ;
2014-11-01 01:15:21 +01:00
2016-08-28 12:49:27 +02:00
$ self - > { pbot } - > { event_dispatcher } - > register_handler ( 'irc.whoisaccount' , sub { $ self - > on_whoisaccount ( @ _ ) } ) ;
$ self - > { pbot } - > { event_dispatcher } - > register_handler ( 'irc.whoisuser' , sub { $ self - > on_whoisuser ( @ _ ) } ) ;
$ self - > { pbot } - > { event_dispatcher } - > register_handler ( 'irc.endofwhois' , sub { $ self - > on_endofwhois ( @ _ ) } ) ;
$ self - > { pbot } - > { event_dispatcher } - > register_handler ( 'irc.account' , sub { $ self - > on_accountnotify ( @ _ ) } ) ;
2011-12-11 23:56:57 +01:00
}
2016-01-27 04:23:03 +01:00
sub whitelisted {
my ( $ self , $ channel , $ hostmask , $ mode ) = @ _ ;
$ channel = lc $ channel ;
$ hostmask = lc $ hostmask ;
$ mode = 'user' if not defined $ mode ;
given ( $ mode ) {
when ( 'ban' ) {
2020-01-15 03:10:53 +01:00
return 1 if exists $ self - > { whitelist } - > { hash } - > { $ channel }
and exists $ self - > { whitelist } - > { hash } - > { $ channel } - > { $ hostmask }
and $ self - > { whitelist } - > { hash } - > { $ channel } - > { $ hostmask } - > { ban } ;
2016-01-27 04:23:03 +01:00
return 0 ;
}
default {
my $ ret = eval {
2020-01-15 03:10:53 +01:00
foreach my $ chan ( keys % { $ self - > { whitelist } - > { hash } } ) {
next unless $ channel eq $ chan ;
foreach my $ mask ( keys % { $ self - > { whitelist } - > { hash } - > { $ chan } } ) {
next if $ mask eq '_name' ;
next if $ self - > { whitelist } - > { hash } - > { $ chan } - > { $ mask } - > { ban } ;
return 1 if $ hostmask eq $ mask and $ self - > { whitelist } - > { hash } - > { $ chan } - > { $ mask } - > { $ mode } ;
2016-01-27 04:23:03 +01:00
}
2016-01-23 15:03:47 +01:00
}
2016-01-27 04:23:03 +01:00
return 0 ;
} ;
if ( $@ ) {
$ self - > { pbot } - > { logger } - > log ( "Error in whitelist: $@" ) ;
return 0 ;
2016-01-23 15:03:47 +01:00
}
2016-01-27 04:23:03 +01:00
return $ ret ;
2016-01-23 15:03:47 +01:00
}
2016-01-27 04:23:03 +01:00
}
2011-12-11 23:56:57 +01:00
}
sub whitelist {
2018-08-09 02:38:57 +02:00
my ( $ self , $ from , $ nick , $ user , $ host , $ arguments , $ stuff ) = @ _ ;
2016-01-27 04:23:03 +01:00
2018-08-09 02:38:57 +02:00
my $ arglist = $ stuff - > { arglist } ;
$ self - > { pbot } - > { interpreter } - > lc_args ( $ arglist ) ;
my $ command = $ self - > { pbot } - > { interpreter } - > shift_arg ( $ arglist ) ;
2016-01-27 04:23:03 +01:00
return "Usage: whitelist <command>, where commands are: list/show, add, remove, set, unset" if not defined $ command ;
2016-08-18 05:34:45 +02:00
given ( $ command ) {
when ( $ _ eq "list" or $ _ eq "show" ) {
2016-01-27 04:23:03 +01:00
my $ text = "Whitelist:\n" ;
my $ entries = 0 ;
2020-01-15 03:10:53 +01:00
foreach my $ channel ( keys % { $ self - > { whitelist } - > { hash } } ) {
$ text . = " $self->{whitelist}->{hash}->{$channel}->{_name}:\n" ;
foreach my $ mask ( keys % { $ self - > { whitelist } - > { hash } - > { $ channel } } ) {
next if $ mask eq '_name' ;
2016-01-27 04:23:03 +01:00
my $ mode = '' ;
2020-01-15 03:10:53 +01:00
$ mode . = 'u' if $ self - > { whitelist } - > { hash } - > { $ channel } - > { $ mask } - > { user } ;
$ mode . = 'b' if $ self - > { whitelist } - > { hash } - > { $ channel } - > { $ mask } - > { ban } ;
$ mode . = 'a' if $ self - > { whitelist } - > { hash } - > { $ channel } - > { $ mask } - > { antiflood } ;
2016-01-27 04:23:03 +01:00
$ mode = '?' if not length $ mode ;
$ text . = " $mask [$mode],\n" ;
$ entries + + ;
2011-12-11 23:56:57 +01:00
}
2016-01-27 04:23:03 +01:00
}
$ text . = "none" if $ entries == 0 ;
return $ text ;
}
2016-08-18 05:34:45 +02:00
when ( "set" ) {
2018-08-09 02:38:57 +02:00
my ( $ channel , $ mask , $ flag , $ value ) = $ self - > { pbot } - > { interpreter } - > split_args ( $ arglist , 4 ) ;
2020-01-29 22:35:56 +01:00
return "Usage: whitelist set <channel> <mask> [flag [value]]" if not defined $ channel or not defined $ mask ;
2016-01-26 18:04:03 +01:00
2020-01-15 03:10:53 +01:00
if ( not exists $ self - > { whitelist } - > { hash } - > { lc $ channel } ) {
2016-01-27 04:23:03 +01:00
return "There is no such channel `$channel` in the whitelist." ;
}
2016-01-26 18:04:03 +01:00
2020-01-15 03:10:53 +01:00
if ( not exists $ self - > { whitelist } - > { hash } - > { lc $ channel } - > { lc $ mask } ) {
2016-01-27 04:23:03 +01:00
return "There is no such mask `$mask` for channel `$channel` in the whitelist." ;
}
2016-01-26 18:04:03 +01:00
2016-01-27 04:23:03 +01:00
if ( not defined $ flag ) {
my $ text = "Flags:\n" ;
my $ comma = '' ;
2020-01-15 03:10:53 +01:00
foreach $ flag ( keys % { $ self - > { whitelist } - > { hash } - > { lc $ channel } - > { lc $ mask } } ) {
2016-01-27 04:23:03 +01:00
if ( $ flag eq 'created_on' ) {
2020-01-15 03:10:53 +01:00
my $ timestamp = strftime "%a %b %e %H:%M:%S %Z %Y" , localtime $ self - > { whitelist } - > { hash } - > { lc $ channel } - > { lc $ mask } - > { $ flag } ;
2016-01-27 04:23:03 +01:00
$ text . = $ comma . "created_on: $timestamp" ;
} else {
2020-01-15 03:10:53 +01:00
$ value = $ self - > { whitelist } - > { hash } - > { lc $ channel } - > { lc $ mask } - > { $ flag } ;
2016-01-27 04:23:03 +01:00
$ text . = $ comma . "$flag: $value" ;
}
$ comma = ",\n " ;
}
return $ text ;
}
2016-01-26 18:04:03 +01:00
2016-01-27 04:23:03 +01:00
if ( not defined $ value ) {
2020-01-15 03:10:53 +01:00
$ value = $ self - > { whitelist } - > { hash } - > { lc $ channel } - > { lc $ mask } - > { $ flag } ;
2016-01-27 04:23:03 +01:00
if ( not defined $ value ) {
2017-09-02 09:14:13 +02:00
return "/say $flag is not set." ;
2016-01-27 04:23:03 +01:00
} else {
2017-09-02 09:14:13 +02:00
return "/say $flag is set to $value" ;
2016-01-26 18:04:03 +01:00
}
2016-01-27 04:23:03 +01:00
}
2016-01-26 18:04:03 +01:00
2020-01-15 03:10:53 +01:00
$ self - > { whitelist } - > { hash } - > { lc $ channel } - > { lc $ mask } - > { $ flag } = $ value ;
2016-01-27 04:23:03 +01:00
$ self - > { whitelist } - > save ;
return "Flag set." ;
}
2016-08-18 05:34:45 +02:00
when ( "unset" ) {
2018-08-09 02:38:57 +02:00
my ( $ channel , $ mask , $ flag ) = $ self - > { pbot } - > { interpreter } - > split_args ( $ arglist , 3 ) ;
2016-01-27 04:23:03 +01:00
return "Usage: whitelist unset <channel> <mask> <flag>" if not defined $ channel or not defined $ mask or not defined $ flag ;
2016-01-26 18:04:03 +01:00
2020-01-15 03:10:53 +01:00
if ( not exists $ self - > { whitelist } - > { hash } - > { lc $ channel } ) {
2016-01-27 04:23:03 +01:00
return "There is no such channel `$channel` in the whitelist." ;
}
2016-01-26 18:04:03 +01:00
2020-01-15 03:10:53 +01:00
if ( not exists $ self - > { whitelist } - > { hash } - > { lc $ channel } - > { lc $ mask } ) {
2016-01-27 04:23:03 +01:00
return "There is no such mask `$mask` for channel `$channel` in the whitelist." ;
}
2016-01-26 18:04:03 +01:00
2020-01-15 03:10:53 +01:00
if ( not exists $ self - > { whitelist } - > { hash } - > { lc $ channel } - > { lc $ mask } - > { $ flag } ) {
2016-01-27 04:23:03 +01:00
return "There is no such flag `$flag` for mask `$mask` for channel `$channel` in the whitelist." ;
}
2016-01-23 15:03:47 +01:00
2020-01-15 03:10:53 +01:00
delete $ self - > { whitelist } - > { hash } - > { lc $ channel } - > { lc $ mask } - > { $ flag } ;
2016-01-27 04:23:03 +01:00
$ self - > { whitelist } - > save ;
return "Flag unset." ;
}
2016-08-18 05:34:45 +02:00
when ( "add" ) {
2018-08-09 02:38:57 +02:00
my ( $ channel , $ mask , $ mode ) = $ self - > { pbot } - > { interpreter } - > split_args ( $ arglist , 3 ) ;
2016-01-27 04:23:03 +01:00
return "Usage: whitelist add <channel> <mask> [mode (user or ban, default: user)]" if not defined $ channel or not defined $ mask ;
$ mode = 'user' if not defined $ mode ;
2011-12-11 23:56:57 +01:00
2020-01-15 03:10:53 +01:00
my $ data = {
owner = > "$nick!$user\@$host" ,
created_on = > scalar gettimeofday
} ;
2016-01-27 04:23:03 +01:00
if ( $ mode eq 'user' ) {
2020-01-15 03:10:53 +01:00
$ data - > { user } = 1 ;
2016-01-27 04:23:03 +01:00
} else {
2020-01-15 03:10:53 +01:00
$ data - > { ban } = 1 ;
2016-01-27 04:23:03 +01:00
}
2011-12-11 23:56:57 +01:00
2020-01-15 03:10:53 +01:00
$ self - > { whitelist } - > add ( $ channel , $ mask , $ data ) ;
2017-09-02 09:14:13 +02:00
return "/say $mask whitelisted in channel $channel" ;
2016-01-27 04:23:03 +01:00
}
2016-08-18 05:34:45 +02:00
when ( "remove" ) {
2018-08-09 02:38:57 +02:00
my ( $ channel , $ mask ) = $ self - > { pbot } - > { interpreter } - > split_args ( $ arglist , 2 ) ;
2016-01-27 04:23:03 +01:00
return "Usage: whitelist remove <channel> <mask>" if not defined $ channel or not defined $ mask ;
2020-01-15 03:10:53 +01:00
return $ self - > { whitelist } - > remove ( $ channel , $ mask ) ;
2016-01-27 04:23:03 +01:00
}
default {
return "Unknown command '$command'; commands are: list/show, add, remove" ;
2011-12-11 23:56:57 +01:00
}
2016-01-27 04:23:03 +01:00
}
2010-03-22 08:33:44 +01:00
}
2010-03-17 07:36:54 +01:00
2015-06-06 07:26:55 +02:00
sub update_join_watch {
2010-06-19 21:19:56 +02:00
my ( $ self , $ account , $ channel , $ text , $ mode ) = @ _ ;
2010-06-21 05:18:39 +02:00
2014-05-13 12:15:52 +02:00
return if $ channel =~ /[@!]/ ; # ignore QUIT messages from nick!user@host channels
2010-06-19 21:19:56 +02:00
2014-05-13 12:15:52 +02:00
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ account , $ channel , 'join_watch' ) ;
2010-06-21 05:18:39 +02:00
2019-05-28 18:19:42 +02:00
if ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_JOIN } ) {
2014-05-15 03:39:33 +02:00
$ channel_data - > { join_watch } + + ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
2019-05-28 18:19:42 +02:00
} elsif ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_DEPARTURE } ) {
2014-05-15 03:39:33 +02:00
# PART or QUIT
# check QUIT message for netsplits, and decrement joinwatch to allow a free rejoin
2019-05-28 18:19:42 +02:00
if ( $ text =~ /^QUIT .*\.net .*\.split/ ) {
if ( $ channel_data - > { join_watch } > 0 ) {
2019-06-26 18:34:19 +02:00
$ channel_data - > { join_watch } - - ;
2014-05-15 03:39:33 +02:00
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
2010-06-21 05:18:39 +02:00
}
}
2014-05-15 03:39:33 +02:00
# check QUIT message for Ping timeout or Excess Flood
2019-05-28 18:19:42 +02:00
elsif ( $ text =~ /^QUIT Excess Flood/ or $ text =~ /^QUIT Max SendQ exceeded/ or $ text =~ /^QUIT Ping timeout/ ) {
2016-08-28 12:49:27 +02:00
# treat these as an extra join so they're snagged more quickly since these usually will keep flooding
$ channel_data - > { join_watch } + + ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
2014-05-15 03:39:33 +02:00
} else {
# some other type of QUIT or PART
}
2019-05-28 18:19:42 +02:00
} elsif ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_CHAT } ) {
2010-06-21 05:18:39 +02:00
# reset joinwatch if they send a message
2019-05-28 18:19:42 +02:00
if ( $ channel_data - > { join_watch } > 0 ) {
2014-05-13 12:15:52 +02:00
$ channel_data - > { join_watch } = 0 ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
}
2010-06-19 21:19:56 +02:00
}
}
2010-03-17 07:36:54 +01:00
sub check_flood {
2018-08-13 23:25:35 +02:00
my ( $ self , $ channel , $ nick , $ user , $ host , $ text , $ max_messages , $ max_time , $ mode , $ stuff ) = @ _ ;
2012-10-27 23:03:10 +02:00
$ channel = lc $ channel ;
2010-03-17 07:36:54 +01:00
2014-05-13 12:15:52 +02:00
my $ mask = "$nick!$user\@$host" ;
2015-02-14 13:03:18 +01:00
my $ oldnick = $ nick ;
2016-08-18 05:34:45 +02:00
my $ account ;
if ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_JOIN } and exists $ self - > { changinghost } - > { $ nick } ) {
$ self - > { pbot } - > { logger } - > log ( "Finalizing changinghost for $nick!\n" ) ;
$ account = delete $ self - > { changinghost } - > { $ nick } ;
my $ id = $ self - > { pbot } - > { messagehistory } - > { database } - > get_message_account_id ( $ mask ) ;
if ( defined $ id ) {
if ( $ id != $ account ) {
$ self - > { pbot } - > { logger } - > log ( "Linking $mask [$id] to account $account\n" ) ;
2016-08-25 10:41:32 +02:00
$ self - > { pbot } - > { messagehistory } - > { database } - > link_alias ( $ account , $ id , $ self - > { pbot } - > { messagehistory } - > { database } - > { alias_type } - > { STRONG } , 1 ) ;
2016-08-18 05:34:45 +02:00
} else {
$ self - > { pbot } - > { logger } - > log ( "New hostmask already belongs to original account.\n" ) ;
}
$ account = $ id ;
} else {
$ self - > { pbot } - > { logger } - > log ( "Adding $mask to account $account\n" ) ;
$ self - > { pbot } - > { messagehistory } - > { database } - > add_message_account ( $ mask , $ account , $ self - > { pbot } - > { messagehistory } - > { database } - > { alias_type } - > { STRONG } ) ;
}
$ self - > { pbot } - > { messagehistory } - > { database } - > devalidate_all_channels ( $ account ) ;
my @ nickserv_accounts = $ self - > { pbot } - > { messagehistory } - > { database } - > get_nickserv_accounts ( $ account ) ;
foreach my $ nickserv_account ( @ nickserv_accounts ) {
$ self - > { pbot } - > { logger } - > log ( "$nick!$user\@$host [$account] seen with nickserv account [$nickserv_account]\n" ) ;
$ self - > check_nickserv_accounts ( $ nick , $ nickserv_account , "$nick!$user\@$host" ) ;
}
} else {
$ account = $ self - > { pbot } - > { messagehistory } - > get_message_account ( $ nick , $ user , $ host ) ;
}
$ self - > { pbot } - > { messagehistory } - > { database } - > update_hostmask_data ( $ mask , { last_seen = > scalar gettimeofday } ) ;
2010-06-05 08:07:15 +02:00
2019-05-28 18:19:42 +02:00
if ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_NICKCHANGE } ) {
2014-09-09 09:19:10 +02:00
$ self - > { pbot } - > { logger } - > log ( sprintf ( "%-18s | %-65s | %s\n" , "NICKCHANGE" , $ mask , $ text ) ) ;
2014-05-16 07:58:21 +02:00
my ( $ newnick ) = $ text =~ m/NICKCHANGE (.*)/ ;
2015-08-08 21:40:06 +02:00
$ mask = "$newnick!$user\@$host" ;
$ account = $ self - > { pbot } - > { messagehistory } - > get_message_account ( $ newnick , $ user , $ host ) ;
$ nick = $ newnick ;
2014-05-16 02:48:46 +02:00
} else {
2014-09-09 09:19:10 +02:00
$ self - > { pbot } - > { logger } - > log ( sprintf ( "%-18s | %-65s | %s\n" , lc $ channel eq lc $ mask ? "QUIT" : $ channel , $ mask , $ text ) ) ;
2014-05-16 02:48:46 +02:00
}
2015-03-15 21:52:30 +01:00
# do not do flood processing for bot messages
2019-05-28 18:19:42 +02:00
if ( $ nick eq $ self - > { pbot } - > { registry } - > get_value ( 'irc' , 'botnick' ) ) {
2015-05-07 06:10:55 +02:00
$ self - > { channels } - > { $ channel } - > { last_spoken_nick } = $ nick ;
2015-03-15 21:52:30 +01:00
return ;
}
2018-08-13 23:25:35 +02:00
# don't do flood processing for unidentified or banned users in +z channels
if ( defined $ stuff and $ stuff - > { 'chan-z' } and ( $ stuff - > { 'unidentified' } or $ stuff - > { 'banned' } ) ) {
return ;
}
2016-11-29 10:50:49 +01:00
my $ ancestor = $ self - > { pbot } - > { messagehistory } - > { database } - > get_ancestor_id ( $ account ) ;
2016-11-30 18:28:19 +01:00
$ self - > { pbot } - > { logger } - > log ( "Processing anti-flood account $account " . ( $ ancestor != $ account ? "[ancestor $ancestor] " : '' ) . "for mask $mask\n" ) if $ self - > { pbot } - > { registry } - > get_value ( 'antiflood' , 'debug_account' ) ;
2016-11-29 10:50:49 +01:00
if ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_NICKCHANGE } ) {
2016-11-30 18:28:19 +01:00
$ self - > { nickflood } - > { $ ancestor } - > { changes } + + ;
$ self - > { pbot } - > { logger } - > log ( "account $ancestor has $self->{nickflood}->{$ancestor}->{changes} nickchanges\n" ) ;
2016-11-29 10:50:49 +01:00
}
2010-06-21 05:18:39 +02:00
# handle QUIT events
# (these events come from $channel nick!user@host, not a specific channel or nick,
2014-03-09 07:56:48 +01:00
# so they need to be dispatched to all channels the nick has been seen on)
2019-05-28 18:19:42 +02:00
if ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_DEPARTURE } and $ text =~ /^QUIT/ ) {
2015-02-14 13:03:18 +01:00
my $ channels = $ self - > { pbot } - > { nicklist } - > get_channels ( $ nick ) ;
foreach my $ chan ( @$ channels ) {
2014-05-16 02:48:46 +02:00
next if $ chan !~ m/^#/ ;
2015-06-06 07:26:55 +02:00
$ self - > update_join_watch ( $ account , $ chan , $ text , $ mode ) ;
2010-06-10 22:26:09 +02:00
}
2010-06-21 05:18:39 +02:00
2014-05-13 12:15:52 +02:00
$ self - > { pbot } - > { messagehistory } - > { database } - > devalidate_all_channels ( $ account ) ;
2016-08-18 05:34:45 +02:00
if ( $ text eq 'QUIT Changing host' ) {
$ self - > { pbot } - > { logger } - > log ( "$mask [$account] changing host!\n" ) ;
$ self - > { changinghost } - > { $ nick } = $ account ;
}
2011-02-11 03:46:35 +01:00
# don't do flood processing for QUIT events
2010-06-21 05:18:39 +02:00
return ;
2010-06-12 06:27:58 +02:00
}
2010-06-10 22:26:09 +02:00
2015-03-11 10:00:10 +01:00
my $ channels ;
2019-05-28 18:19:42 +02:00
if ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_NICKCHANGE } ) {
2016-12-05 07:00:50 +01:00
$ channels = $ self - > { pbot } - > { nicklist } - > get_channels ( $ oldnick ) ;
2014-05-16 02:48:46 +02:00
} else {
2015-06-06 07:26:55 +02:00
$ self - > update_join_watch ( $ account , $ channel , $ text , $ mode ) ;
2015-03-11 10:00:10 +01:00
push @$ channels , $ channel ;
2014-05-16 02:48:46 +02:00
}
2013-10-22 20:57:08 +02:00
2015-03-11 10:00:10 +01:00
foreach my $ channel ( @$ channels ) {
2016-12-01 13:57:25 +01:00
$ channel = lc $ channel ;
2015-03-11 10:00:10 +01:00
# do not do flood processing if channel is not in bot's channel list or bot is not set as chanop for the channel
2015-06-26 05:55:42 +02:00
next if $ channel =~ /^#/ and not $ self - > { pbot } - > { chanops } - > can_gain_ops ( $ channel ) ;
2010-06-21 05:18:39 +02:00
2019-05-28 18:19:42 +02:00
if ( $ channel =~ /^#/ and $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_DEPARTURE } ) {
2015-03-11 10:00:10 +01:00
# remove validation on PART or KICK so we check for ban-evasion when user returns at a later time
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ account , $ channel , 'validated' ) ;
2019-05-28 18:19:42 +02:00
if ( $ channel_data - > { validated } & $ self - > { NICKSERV_VALIDATED } ) {
2015-03-11 10:00:10 +01:00
$ channel_data - > { validated } & = ~ $ self - > { NICKSERV_VALIDATED } ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
}
next ;
2014-05-13 12:15:52 +02:00
}
2013-09-14 03:56:00 +02:00
2019-05-28 18:19:42 +02:00
if ( $ self - > whitelisted ( $ channel , "$nick!$user\@$host" , 'antiflood' ) ) {
2019-07-11 03:40:53 +02:00
$ self - > { pbot } - > { logger } - > log ( "$nick!$user\@$host anti-flood whitelisted, skipping anti-flood checking\n" ) ;
2016-01-26 18:04:03 +01:00
next ;
}
2019-05-28 18:19:42 +02:00
if ( $ max_messages > $ self - > { pbot } - > { registry } - > get_value ( 'messagehistory' , 'max_messages' ) ) {
2015-03-11 10:00:10 +01:00
$ self - > { pbot } - > { logger } - > log ( "Warning: max_messages greater than max_messages limit; truncating.\n" ) ;
$ max_messages = $ self - > { pbot } - > { registry } - > get_value ( 'messagehistory' , 'max_messages' ) ;
2013-07-28 16:12:57 +02:00
}
2013-07-28 12:31:12 +02:00
2015-03-11 10:00:10 +01:00
# check for ban evasion if channel begins with # (not private message) and hasn't yet been validated against ban evasion
2019-05-28 18:19:42 +02:00
if ( $ channel =~ m/^#/ ) {
2015-06-06 07:26:55 +02:00
my $ validated = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ account , $ channel , 'validated' ) - > { 'validated' } ;
2016-11-29 10:50:49 +01:00
if ( $ validated & $ self - > { NEEDS_CHECKBAN } or not $ validated & $ self - > { NICKSERV_VALIDATED } ) {
2019-05-28 18:19:42 +02:00
if ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_DEPARTURE } ) {
2015-06-06 07:26:55 +02:00
# don't check for evasion on PART/KICK
} elsif ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_NICKCHANGE } ) {
2015-06-20 09:20:23 +02:00
if ( not exists $ self - > { whois_pending } - > { $ nick } ) {
$ self - > { pbot } - > { messagehistory } - > { database } - > set_current_nickserv_account ( $ account , '' ) ;
$ self - > { pbot } - > { conn } - > whois ( $ nick ) ;
$ self - > { whois_pending } - > { $ nick } = gettimeofday ;
}
2015-06-06 07:26:55 +02:00
} else {
2020-02-03 18:50:38 +01:00
if ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_JOIN } && exists $ self - > { pbot } - > { irc_capabilities } - > { 'extended-join' } ) {
2016-08-30 05:47:46 +02:00
# don't WHOIS joins if extended-join capability is active
2020-02-03 18:50:38 +01:00
} elsif ( not exists $ self - > { pbot } - > { irc_capabilities } - > { 'account-notify' } ) {
2016-08-30 05:47:46 +02:00
if ( not exists $ self - > { whois_pending } - > { $ nick } ) {
$ self - > { pbot } - > { messagehistory } - > { database } - > set_current_nickserv_account ( $ account , '' ) ;
$ self - > { pbot } - > { conn } - > whois ( $ nick ) ;
$ self - > { whois_pending } - > { $ nick } = gettimeofday ;
}
2016-11-29 10:50:49 +01:00
} else {
$ self - > { pbot } - > { logger } - > log ( "Not validated; checking bans...\n" ) ;
$ self - > check_bans ( $ account , "$nick!$user\@$host" , $ channel ) ;
2015-06-20 09:20:23 +02:00
}
2015-06-06 07:26:55 +02:00
}
2015-03-11 10:00:10 +01:00
}
}
2014-05-13 12:15:52 +02:00
2015-03-11 10:00:10 +01:00
# do not do flood enforcement for this event if bot is lagging
2019-05-28 18:19:42 +02:00
if ( $ self - > { pbot } - > { lagchecker } - > lagging ) {
2015-03-11 10:00:10 +01:00
$ self - > { pbot } - > { logger } - > log ( "Disregarding enforcement of anti-flood due to lag: " . $ self - > { pbot } - > { lagchecker } - > lagstring . "\n" ) ;
2015-05-07 06:10:55 +02:00
$ self - > { channels } - > { $ channel } - > { last_spoken_nick } = $ nick ;
2015-03-11 10:00:10 +01:00
return ;
}
2014-05-17 22:08:19 +02:00
2015-03-11 10:00:10 +01:00
# do not do flood enforcement for logged in bot admins
2020-01-25 21:28:05 +01:00
if ( $ self - > { pbot } - > { registry } - > get_value ( 'antiflood' , 'dont_enforce_admins' ) and $ self - > { pbot } - > { users } - > loggedin_admin ( $ channel , "$nick!$user\@$host" ) ) {
2015-06-14 01:08:06 +02:00
$ self - > { channels } - > { $ channel } - > { last_spoken_nick } = $ nick ;
next ;
}
# do not do flood enforcement for channels that do not want it
if ( $ self - > { pbot } - > { registry } - > get_value ( $ channel , 'dont_enforce_antiflood' ) ) {
2015-05-07 06:10:55 +02:00
$ self - > { channels } - > { $ channel } - > { last_spoken_nick } = $ nick ;
next ;
}
2015-03-11 10:00:10 +01:00
# check for chat/join/private message flooding
2019-05-28 18:19:42 +02:00
if ( $ max_messages > 0 and $ self - > { pbot } - > { messagehistory } - > { database } - > get_max_messages ( $ account , $ channel , $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_NICKCHANGE } ? $ nick : undef ) >= $ max_messages ) {
2015-03-11 10:00:10 +01:00
my $ msg ;
2019-05-28 18:19:42 +02:00
if ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_CHAT } ) {
2015-03-11 10:00:10 +01:00
$ msg = $ self - > { pbot } - > { messagehistory } - > { database } - > recall_message_by_count ( $ account , $ channel , $ max_messages - 1 )
}
2019-05-28 18:19:42 +02:00
elsif ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_JOIN } ) {
2015-03-11 10:00:10 +01:00
my $ joins = $ self - > { pbot } - > { messagehistory } - > { database } - > get_recent_messages ( $ account , $ channel , $ max_messages , $ self - > { pbot } - > { messagehistory } - > { MSG_JOIN } ) ;
$ msg = $ joins - > [ 0 ] ;
}
2019-05-28 18:19:42 +02:00
elsif ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_NICKCHANGE } ) {
2016-12-01 13:57:25 +01:00
my $ nickchanges = $ self - > { pbot } - > { messagehistory } - > { database } - > get_recent_messages ( $ ancestor , $ channel , $ max_messages , $ self - > { pbot } - > { messagehistory } - > { MSG_NICKCHANGE } , $ nick ) ;
2015-03-11 10:00:10 +01:00
$ msg = $ nickchanges - > [ 0 ] ;
}
2019-05-28 18:19:42 +02:00
elsif ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_DEPARTURE } ) {
2015-03-11 10:00:10 +01:00
# no flood checks to be done for departure events
next ;
}
else {
$ self - > { pbot } - > { logger } - > log ( "Unknown flood mode [$mode] ... aborting flood enforcement.\n" ) ;
return ;
}
2010-06-19 21:19:56 +02:00
2016-12-05 07:00:50 +01:00
my $ last ;
if ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_NICKCHANGE } ) {
$ last = $ self - > { pbot } - > { messagehistory } - > { database } - > recall_message_by_count ( $ ancestor , $ channel , 0 , undef , $ nick ) ;
} else {
$ last = $ self - > { pbot } - > { messagehistory } - > { database } - > recall_message_by_count ( $ account , $ channel , 0 ) ;
}
2010-06-05 08:07:15 +02:00
2015-03-11 10:00:10 +01:00
if ( $ last - > { timestamp } - $ msg - > { timestamp } <= $ max_time ) {
2019-05-28 18:19:42 +02:00
if ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_JOIN } ) {
2015-03-11 10:00:10 +01:00
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ account , $ channel , 'offenses' , 'last_offense' , 'join_watch' ) ;
#$self->{pbot}->{logger}->log("$account offenses $channel_data->{offenses}, join watch $channel_data->{join_watch}, max messages $max_messages\n");
2019-05-28 18:19:42 +02:00
if ( $ channel_data - > { join_watch } >= $ max_messages ) {
2015-03-11 10:00:10 +01:00
$ channel_data - > { offenses } + + ;
$ channel_data - > { last_offense } = gettimeofday ;
2010-06-18 06:15:28 +02:00
2019-05-28 18:19:42 +02:00
if ( $ self - > { pbot } - > { registry } - > get_value ( 'antiflood' , 'enforce' ) ) {
2015-03-11 10:00:10 +01:00
my $ timeout = $ self - > { pbot } - > { registry } - > get_array_value ( 'antiflood' , 'join_flood_punishment' , $ channel_data - > { offenses } - 1 ) ;
my $ duration = duration ( $ timeout ) ;
2020-01-26 06:09:17 +01:00
my $ banmask = $ self - > address_to_mask ( $ host ) ;
2014-05-20 12:14:09 +02:00
2016-11-29 10:50:49 +01:00
if ( $ self - > { pbot } - > { channels } - > is_active_op ( "${channel}-floodbans" ) ) {
2019-07-26 23:17:06 +02:00
$ self - > { pbot } - > { chanops } - > ban_user_timed ( $ self - > { pbot } - > { registry } - > get_value ( 'irc' , 'botnick' ) , 'join flooding' , "*!$user\@$banmask\$##stop_join_flood" , $ channel . '-floodbans' , $ timeout ) ;
2016-11-29 10:50:49 +01:00
$ self - > { pbot } - > { logger } - > log ( "$nick!$user\@$banmask banned for $duration due to join flooding (offense #" . $ channel_data - > { offenses } . ").\n" ) ;
2017-08-05 14:31:46 +02:00
$ self - > { pbot } - > { conn } - > privmsg ( $ nick , "You have been banned from $channel due to join flooding. If your connection issues have been fixed, or this was an accident, you may request an unban at any time by responding to this message with `unbanme`, otherwise you will be automatically unbanned in $duration." ) ;
2016-11-29 10:50:49 +01:00
} else {
$ self - > { pbot } - > { logger } - > log ( "[anti-flood] I am not an op for ${channel}-floodbans, disregarding join-flood.\n" ) ;
}
2015-03-11 10:00:10 +01:00
}
2019-06-26 18:34:19 +02:00
$ channel_data - > { join_watch } = $ max_messages - 2 ; # give them a chance to rejoin
2015-03-11 10:00:10 +01:00
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
2019-06-26 18:34:19 +02:00
}
2019-05-28 18:19:42 +02:00
} elsif ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_CHAT } ) {
if ( $ channel =~ /^#/ ) { #channel flood (opposed to private message or otherwise)
2015-03-11 10:00:10 +01:00
# don't increment offenses again if already banned
2020-01-26 06:09:17 +01:00
if ( $ self - > { pbot } - > { chanops } - > has_ban_timeout ( $ channel , "*!$user\@" . $ self - > address_to_mask ( $ host ) ) ) {
2015-06-26 05:55:42 +02:00
$ self - > { pbot } - > { logger } - > log ( "$nick $channel flood offense disregarded due to existing ban\n" ) ;
next ;
}
2014-05-13 12:15:52 +02:00
2015-03-11 10:00:10 +01:00
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ account , $ channel , 'offenses' , 'last_offense' ) ;
$ channel_data - > { offenses } + + ;
$ channel_data - > { last_offense } = gettimeofday ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
2011-02-11 03:46:35 +01:00
2019-05-28 18:19:42 +02:00
if ( $ self - > { pbot } - > { registry } - > get_value ( 'antiflood' , 'enforce' ) ) {
2015-03-11 10:00:10 +01:00
my $ length = $ self - > { pbot } - > { registry } - > get_array_value ( 'antiflood' , 'chat_flood_punishment' , $ channel_data - > { offenses } - 1 ) ;
2014-05-13 12:15:52 +02:00
2020-01-26 06:09:17 +01:00
$ self - > { pbot } - > { chanops } - > ban_user_timed ( $ self - > { pbot } - > { registry } - > get_value ( 'irc' , 'botnick' ) , 'chat flooding' , "*!$user\@" . $ self - > address_to_mask ( $ host ) , $ channel , $ length ) ;
2015-03-11 10:00:10 +01:00
$ length = duration ( $ length ) ;
$ self - > { pbot } - > { logger } - > log ( "$nick $channel flood offense " . $ channel_data - > { offenses } . " earned $length ban\n" ) ;
2017-05-21 11:18:44 +02:00
$ self - > { pbot } - > { conn } - > privmsg ( $ nick , "You have been muted due to flooding. Please use a web paste service such as http://codepad.org for lengthy pastes. You will be allowed to speak again in approximately $length." ) ;
2015-03-11 10:00:10 +01:00
}
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
}
else { # private message flood
2020-01-26 06:09:17 +01:00
my $ hostmask = $ self - > address_to_mask ( $ host ) ;
2015-06-26 05:55:42 +02:00
$ hostmask =~ s/\*/.*/g ;
next if exists $ self - > { pbot } - > { ignorelist } - > { ignore_list } - > { ".*!$user\@$hostmask" } - > { $ channel } ;
2014-05-13 12:15:52 +02:00
2015-03-11 10:00:10 +01:00
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ account , $ channel , 'offenses' , 'last_offense' ) ;
$ channel_data - > { offenses } + + ;
$ channel_data - > { last_offense } = gettimeofday ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
2014-05-13 12:15:52 +02:00
2015-03-11 10:00:10 +01:00
my $ length = $ self - > { pbot } - > { registry } - > get_array_value ( 'antiflood' , 'chat_flood_punishment' , $ channel_data - > { offenses } - 1 ) ;
2014-05-16 07:53:39 +02:00
2015-06-26 05:55:42 +02:00
$ self - > { pbot } - > { ignorelist } - > add ( ".*!$user\@$hostmask" , $ channel , $ length ) ;
2015-03-11 10:00:10 +01:00
$ length = duration ( $ length ) ;
$ self - > { pbot } - > { logger } - > log ( "$nick msg flood offense " . $ channel_data - > { offenses } . " earned $length ignore\n" ) ;
$ self - > { pbot } - > { conn } - > privmsg ( $ nick , "You have used too many commands in too short a time period, you have been ignored for $length." ) ;
}
2015-09-14 18:06:43 +02:00
next ;
2019-05-28 18:19:42 +02:00
} elsif ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_NICKCHANGE } and $ self - > { nickflood } - > { $ ancestor } - > { changes } >= $ max_messages ) {
2015-03-15 21:52:30 +01:00
next if $ channel !~ /^#/ ;
2015-03-11 10:00:10 +01:00
( $ nick ) = $ text =~ m/NICKCHANGE (.*)/ ;
2014-05-16 02:48:46 +02:00
2016-11-30 18:28:19 +01:00
$ self - > { nickflood } - > { $ ancestor } - > { offenses } + + ;
$ self - > { nickflood } - > { $ ancestor } - > { changes } = $ max_messages - 2 ; # allow 1 more change (to go back to original nick)
$ self - > { nickflood } - > { $ ancestor } - > { timestamp } = gettimeofday ;
2014-05-16 02:48:46 +02:00
2019-05-28 18:19:42 +02:00
if ( $ self - > { pbot } - > { registry } - > get_value ( 'antiflood' , 'enforce' ) ) {
2016-11-30 18:28:19 +01:00
my $ length = $ self - > { pbot } - > { registry } - > get_array_value ( 'antiflood' , 'nick_flood_punishment' , $ self - > { nickflood } - > { $ ancestor } - > { offenses } - 1 ) ;
2020-01-26 06:09:17 +01:00
$ self - > { pbot } - > { chanops } - > ban_user_timed ( $ self - > { pbot } - > { registry } - > get_value ( 'irc' , 'botnick' ) , 'nick flooding' , "*!$user\@" . $ self - > address_to_mask ( $ host ) , $ channel , $ length ) ;
2015-03-11 10:00:10 +01:00
$ length = duration ( $ length ) ;
2016-11-30 18:28:19 +01:00
$ self - > { pbot } - > { logger } - > log ( "$nick nickchange flood offense " . $ self - > { nickflood } - > { $ ancestor } - > { offenses } . " earned $length ban\n" ) ;
2015-03-11 10:00:10 +01:00
$ self - > { pbot } - > { conn } - > privmsg ( $ nick , "You have been temporarily banned due to nick-change flooding. You will be unbanned in $length." ) ;
2014-05-20 12:14:09 +02:00
}
}
2010-03-17 07:36:54 +01:00
}
}
2015-09-14 18:06:43 +02:00
# check for enter abuse
2019-05-28 18:19:42 +02:00
if ( $ mode == $ self - > { pbot } - > { messagehistory } - > { MSG_CHAT } and $ channel =~ m/^#/ ) {
2015-09-14 18:06:43 +02:00
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ account , $ channel , 'enter_abuse' , 'enter_abuses' , 'offenses' ) ;
my $ other_offenses = delete $ channel_data - > { offenses } ;
my $ debug_enter_abuse = $ self - > { pbot } - > { registry } - > get_value ( 'antiflood' , 'debug_enter_abuse' ) ;
2019-05-28 18:19:42 +02:00
if ( defined $ self - > { channels } - > { $ channel } - > { last_spoken_nick } and $ nick eq $ self - > { channels } - > { $ channel } - > { last_spoken_nick } ) {
2015-09-14 18:06:43 +02:00
my $ messages = $ self - > { pbot } - > { messagehistory } - > { database } - > get_recent_messages ( $ account , $ channel , 2 , $ self - > { pbot } - > { messagehistory } - > { MSG_CHAT } ) ;
my $ enter_abuse_threshold = $ self - > { pbot } - > { registry } - > get_value ( $ channel , 'enter_abuse_threshold' ) ;
my $ enter_abuse_time_threshold = $ self - > { pbot } - > { registry } - > get_value ( $ channel , 'enter_abuse_time_threshold' ) ;
my $ enter_abuse_max_offenses = $ self - > { pbot } - > { registry } - > get_value ( $ channel , 'enter_abuse_max_offenses' ) ;
$ enter_abuse_threshold = $ self - > { pbot } - > { registry } - > get_value ( 'antiflood' , 'enter_abuse_threshold' ) if not defined $ enter_abuse_threshold ;
$ enter_abuse_time_threshold = $ self - > { pbot } - > { registry } - > get_value ( 'antiflood' , 'enter_abuse_time_threshold' ) if not defined $ enter_abuse_time_threshold ;
$ enter_abuse_max_offenses = $ self - > { pbot } - > { registry } - > get_value ( 'antiflood' , 'enter_abuse_max_offenses' ) if not defined $ enter_abuse_max_offenses ;
2019-05-28 18:19:42 +02:00
if ( $ messages - > [ 1 ] - > { timestamp } - $ messages - > [ 0 ] - > { timestamp } <= $ enter_abuse_time_threshold ) {
if ( + + $ channel_data - > { enter_abuse } >= $ enter_abuse_threshold - 1 ) {
2015-09-14 18:06:43 +02:00
$ channel_data - > { enter_abuse } = $ enter_abuse_threshold / 2 - 1 ;
$ channel_data - > { enter_abuses } + + ;
2019-05-28 18:19:42 +02:00
if ( $ channel_data - > { enter_abuses } >= $ enter_abuse_max_offenses ) {
if ( $ self - > { pbot } - > { registry } - > get_value ( 'antiflood' , 'enforce' ) ) {
2020-01-26 06:09:17 +01:00
if ( $ self - > { pbot } - > { chanops } - > has_ban_timeout ( $ channel , "*!$user\@" . $ self - > address_to_mask ( $ host ) ) ) {
2015-09-14 18:06:43 +02:00
$ self - > { pbot } - > { logger } - > log ( "$nick $channel enter abuse offense disregarded due to existing ban\n" ) ;
next ;
}
my $ offenses = $ channel_data - > { enter_abuses } - $ enter_abuse_max_offenses + 1 + $ other_offenses ;
my $ ban_length = $ self - > { pbot } - > { registry } - > get_array_value ( 'antiflood' , 'enter_abuse_punishment' , $ offenses - 1 ) ;
2020-01-26 06:09:17 +01:00
$ self - > { pbot } - > { chanops } - > ban_user_timed ( $ self - > { pbot } - > { registry } - > get_value ( 'irc' , 'botnick' ) , 'enter abuse' , "*!$user\@" . $ self - > address_to_mask ( $ host ) , $ channel , $ ban_length ) ;
2015-09-14 18:06:43 +02:00
$ ban_length = duration ( $ ban_length ) ;
$ self - > { pbot } - > { logger } - > log ( "$nick $channel enter abuse offense " . $ channel_data - > { enter_abuses } . " earned $ban_length ban\n" ) ;
2017-05-21 11:18:44 +02:00
$ self - > { pbot } - > { conn } - > privmsg ( $ nick , "You have been muted due to abusing the enter key. Please do not split your sentences over multiple messages. You will be allowed to speak again in approximately $ban_length." ) ;
2015-09-14 18:06:43 +02:00
$ channel_data - > { last_offense } = gettimeofday ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
next ;
}
} else {
$ self - > { pbot } - > { logger } - > log ( "$nick $channel enter abuses counter incremented to " . $ channel_data - > { enter_abuses } . "\n" ) if $ debug_enter_abuse ;
if ( $ channel_data - > { enter_abuses } == $ enter_abuse_max_offenses - 1 && $ channel_data - > { enter_abuse } == $ enter_abuse_threshold / 2 - 1 ) {
2019-05-28 18:19:42 +02:00
if ( $ self - > { pbot } - > { registry } - > get_value ( 'antiflood' , 'enforce' ) ) {
2015-09-14 18:06:43 +02:00
$ self - > { pbot } - > { conn } - > privmsg ( $ channel , "$nick: Please stop abusing the enter key. Feel free to type longer messages and to take a moment to think of anything else to say before you hit that enter key." ) ;
}
}
}
} else {
$ self - > { pbot } - > { logger } - > log ( "$nick $channel enter abuse counter incremented to " . $ channel_data - > { enter_abuse } . "\n" ) if $ debug_enter_abuse ;
}
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
} else {
2019-05-28 18:19:42 +02:00
if ( $ channel_data - > { enter_abuse } > 0 ) {
2015-09-14 18:06:43 +02:00
$ self - > { pbot } - > { logger } - > log ( "$nick $channel more than $enter_abuse_time_threshold seconds since last message, enter abuse counter reset\n" ) if $ debug_enter_abuse ;
$ channel_data - > { enter_abuse } = 0 ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
}
}
} else {
$ self - > { channels } - > { $ channel } - > { last_spoken_nick } = $ nick ;
$ self - > { pbot } - > { logger } - > log ( "last spoken nick set to $nick\n" ) if $ debug_enter_abuse ;
2019-05-28 18:19:42 +02:00
if ( $ channel_data - > { enter_abuse } > 0 ) {
2015-09-14 18:06:43 +02:00
$ self - > { pbot } - > { logger } - > log ( "$nick $channel enter abuse counter reset\n" ) if $ debug_enter_abuse ;
$ channel_data - > { enter_abuse } = 0 ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
}
}
}
2010-03-17 07:36:54 +01:00
}
}
2010-06-16 03:55:29 +02:00
sub unbanme {
my ( $ self , $ from , $ nick , $ user , $ host , $ arguments ) = @ _ ;
2017-08-05 14:31:46 +02:00
my $ unbanned ;
2010-06-18 06:15:28 +02:00
2015-11-21 06:08:30 +01:00
my % aliases = $ self - > { pbot } - > { messagehistory } - > { database } - > get_also_known_as ( $ nick ) ;
2010-06-16 03:55:29 +02:00
2015-11-21 06:08:30 +01:00
foreach my $ alias ( keys % aliases ) {
next if $ aliases { $ alias } - > { type } == $ self - > { pbot } - > { messagehistory } - > { database } - > { alias_type } - > { WEAK } ;
2016-08-18 05:34:45 +02:00
next if $ aliases { $ alias } - > { nickchange } == 1 ;
2010-06-16 03:55:29 +02:00
2015-11-21 06:08:30 +01:00
my ( $ anick , $ auser , $ ahost ) = $ alias =~ m/([^!]+)!([^@]+)@(.*)/ ;
2020-01-26 06:09:17 +01:00
my $ banmask = $ self - > address_to_mask ( $ ahost ) ;
2015-11-21 06:08:30 +01:00
my $ mask = "*!$auser\@$banmask\$##stop_join_flood" ;
2015-03-27 12:08:47 +01:00
2017-08-05 14:31:46 +02:00
my @ channels = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channels ( $ aliases { $ alias } - > { id } ) ;
2014-03-10 04:50:02 +01:00
2017-08-05 14:31:46 +02:00
foreach my $ channel ( @ channels ) {
next if exists $ unbanned - > { $ channel } and exists $ unbanned - > { $ channel } - > { $ mask } ;
2020-01-15 03:10:53 +01:00
next if not $ self - > { pbot } - > { chanops } - > { unban_timeout } - > exists ( $ channel . '-floodbans' , $ mask ) ;
2015-11-21 06:08:30 +01:00
2017-08-05 14:31:46 +02:00
my $ message_account = $ self - > { pbot } - > { messagehistory } - > { database } - > get_message_account ( $ anick , $ auser , $ ahost ) ;
my @ nickserv_accounts = $ self - > { pbot } - > { messagehistory } - > { database } - > get_nickserv_accounts ( $ message_account ) ;
2015-11-21 06:08:30 +01:00
2017-08-05 14:31:46 +02:00
push @ nickserv_accounts , undef ;
foreach my $ nickserv_account ( @ nickserv_accounts ) {
my $ baninfos = $ self - > { pbot } - > { bantracker } - > get_baninfo ( "$anick!$auser\@$ahost" , $ channel , $ nickserv_account ) ;
2019-05-28 18:19:42 +02:00
if ( defined $ baninfos ) {
2017-08-05 14:31:46 +02:00
foreach my $ baninfo ( @$ baninfos ) {
2019-05-28 18:19:42 +02:00
if ( $ self - > whitelisted ( $ baninfo - > { channel } , $ baninfo - > { banmask } , 'ban' ) || $ self - > whitelisted ( $ baninfo - > { channel } , "$nick!$user\@$host" , 'user' ) ) {
2017-08-05 14:31:46 +02:00
$ self - > { pbot } - > { logger } - > log ( "anti-flood: [unbanme] $anick!$auser\@$ahost banned as $baninfo->{banmask} in $baninfo->{channel}, but allowed through whitelist\n" ) ;
} else {
2019-05-28 18:19:42 +02:00
if ( $ channel eq lc $ baninfo - > { channel } ) {
2017-08-05 14:31:46 +02:00
my $ mode = $ baninfo - > { type } eq "+b" ? "banned" : "quieted" ;
$ self - > { pbot } - > { logger } - > log ( "anti-flood: [unbanme] $anick!$auser\@$ahost $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." ;
}
2015-11-21 06:08:30 +01:00
}
2014-03-10 04:50:02 +01:00
}
2013-07-28 12:31:12 +02:00
}
2011-12-17 12:43:21 +01:00
}
2017-08-05 14:31:46 +02:00
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ message_account , $ channel , 'unbanmes' ) ;
2017-08-05 14:58:45 +02:00
if ( $ channel_data - > { unbanmes } <= 2 ) {
2017-08-05 14:31:46 +02:00
$ channel_data - > { unbanmes } + + ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ message_account , $ channel , $ channel_data ) ;
}
$ unbanned - > { $ channel } - > { $ mask } = $ channel_data - > { unbanmes } ;
2011-12-17 12:43:21 +01:00
}
2017-08-05 14:31:46 +02:00
}
2012-09-06 12:09:44 +02:00
2017-08-05 14:31:46 +02:00
if ( keys %$ unbanned ) {
my $ channels = '' ;
my $ sep = '' ;
my $ channels_warning = '' ;
my $ sep_warning = '' ;
my $ channels_disabled = '' ;
my $ sep_disabled = '' ;
foreach my $ channel ( keys %$ unbanned ) {
2017-08-06 05:10:54 +02:00
foreach my $ mask ( keys % { $ unbanned - > { $ channel } } ) {
2017-08-05 14:31:46 +02:00
if ( $ self - > { pbot } - > { channels } - > is_active_op ( "${channel}-floodbans" ) ) {
if ( $ unbanned - > { $ channel } - > { $ mask } <= 2 ) {
$ self - > { pbot } - > { chanops } - > unban_user ( $ mask , $ channel . '-floodbans' ) ;
$ channels . = "$sep$channel" ;
$ sep = ", " ;
}
if ( $ unbanned - > { $ channel } - > { $ mask } == 1 ) {
$ channels_warning . = "$sep_warning$channel" ;
$ sep_warning = ", " ;
} else {
$ channels_disabled . = "$sep_disabled$channel" ;
$ sep_disabled = ", " ;
}
}
}
2016-01-17 01:55:48 +01:00
}
2017-08-05 14:31:46 +02:00
$ self - > { pbot } - > { chanops } - > check_unban_queue ( ) ;
2016-01-17 01:55:48 +01:00
2017-08-05 14:31:46 +02:00
$ channels =~ s/(.*), /$1 and / ;
$ channels_warning =~ s/(.*), /$1 and / ;
$ channels_disabled =~ s/(.*), /$1 and / ;
2016-01-17 01:55:48 +01:00
2017-08-05 14:31:46 +02:00
my $ warning = '' ;
if ( length $ channels_warning ) {
2019-06-21 21:36:43 +02:00
$ warning = " You may use `unbanme` one more time today for $channels_warning; please ensure that your client or connection issues are resolved before using your final `unbanme` of the day." ;
2015-11-21 06:08:30 +01:00
}
2012-09-06 12:09:44 +02:00
2017-08-05 14:31:46 +02:00
if ( length $ channels_disabled ) {
$ warning . = " You may not use `unbanme` again for several hours for $channels_disabled; ensure that your client or connection issues are resolved, otherwise leave the channel until they are or you will be temporarily banned for several hours if you join-flood again during this period." ;
2016-11-29 10:50:49 +01:00
}
2010-06-16 03:55:29 +02:00
2017-08-05 14:58:45 +02:00
if ( length $ channels ) {
return "/msg $nick You have been unbanned from $channels.$warning" ;
} else {
return "/msg $nick You were not unbanned at this time.$warning" ;
}
2015-11-21 06:08:30 +01:00
} else {
2019-06-21 21:36:43 +02:00
return "/msg $nick There is no join-flooding ban set for you." ;
2015-11-21 06:08:30 +01:00
}
2010-06-16 03:55:29 +02:00
}
2010-06-18 06:15:28 +02:00
sub address_to_mask {
2020-01-26 06:09:17 +01:00
my ( $ self , $ address ) = @ _ ;
2010-06-18 06:15:28 +02:00
my $ banmask ;
2019-05-28 18:19:42 +02:00
if ( $ address =~ m/^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)$/ ) {
2010-06-18 06:15:28 +02:00
my ( $ a , $ b , $ c , $ d ) = ( $ 1 , $ 2 , $ 3 , $ 4 ) ;
2016-08-18 05:34:45 +02:00
given ( $ a ) {
when ( $ _ <= 127 ) { $ banmask = "$a.*" ; }
when ( $ _ <= 191 ) { $ banmask = "$a.$b.*" ; }
2010-06-18 06:15:28 +02:00
default { $ banmask = "$a.$b.$c.*" ; }
}
2019-05-28 18:19:42 +02:00
} elsif ( $ address =~ m {^gateway/([^/]+)/([^/]+)/} ) {
2014-08-18 16:57:12 +02:00
$ banmask = "gateway/$1/$2/*" ;
2019-05-28 18:19:42 +02:00
} elsif ( $ address =~ m {^nat/([^/]+)/} ) {
2015-07-14 16:29:27 +02:00
$ banmask = "nat/$1/*" ;
2019-05-28 18:19:42 +02:00
} elsif ( $ address =~ m/^([^:]+):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*):([^:]*)$/ ) {
2015-03-23 12:18:33 +01:00
$ banmask = "$1:$2:*" ;
2019-05-28 18:19:42 +02:00
} elsif ( $ address =~ m/[^.]+\.([^.]+\.[a-zA-Z]+)$/ ) {
2015-07-21 22:44:42 +02:00
$ banmask = "*.$1" ;
2010-06-18 06:15:28 +02:00
} else {
$ banmask = $ address ;
}
return $ banmask ;
}
2013-09-13 23:48:19 +02:00
sub devalidate_accounts {
# remove validation on accounts in $channel that match a ban/quiet $mask
my ( $ self , $ mask , $ channel ) = @ _ ;
2014-05-13 12:15:52 +02:00
my @ message_accounts ;
2014-05-18 22:09:05 +02:00
#$self->{pbot}->{logger}->log("Devalidating accounts for $mask in $channel\n");
2013-09-13 23:48:19 +02:00
2019-05-28 18:19:42 +02:00
if ( $ mask =~ m/^\$a:(.*)/ ) {
2014-05-13 12:15:52 +02:00
my $ ban_account = lc $ 1 ;
@ message_accounts = $ self - > { pbot } - > { messagehistory } - > { database } - > find_message_accounts_by_nickserv ( $ ban_account ) ;
2013-09-13 23:48:19 +02:00
} else {
2014-05-13 12:15:52 +02:00
@ message_accounts = $ self - > { pbot } - > { messagehistory } - > { database } - > find_message_accounts_by_mask ( $ mask ) ;
2013-09-13 23:48:19 +02:00
}
2014-05-13 12:15:52 +02:00
foreach my $ account ( @ message_accounts ) {
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ account , $ channel , 'validated' ) ;
2019-05-28 18:19:42 +02:00
if ( defined $ channel_data and $ channel_data - > { validated } & $ self - > { NICKSERV_VALIDATED } ) {
2014-05-13 12:15:52 +02:00
$ channel_data - > { validated } & = ~ $ self - > { NICKSERV_VALIDATED } ;
2014-05-18 22:09:05 +02:00
#$self->{pbot}->{logger}->log("Devalidating account $account\n");
2014-05-13 12:15:52 +02:00
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ account , $ channel , $ channel_data ) ;
2013-09-13 23:48:19 +02:00
}
}
}
2011-12-17 12:43:21 +01:00
sub check_bans {
2016-09-02 11:12:20 +02:00
my ( $ self , $ message_account , $ mask , $ channel , $ dry_run ) = @ _ ;
2014-05-13 12:15:52 +02:00
2016-11-29 10:50:49 +01:00
$ channel = lc $ channel ;
if ( not $ self - > { pbot } - > { chanops } - > can_gain_ops ( $ channel ) ) {
2017-08-05 14:31:46 +02:00
$ self - > { pbot } - > { logger } - > log ( "anti-flood: [check-ban] I do not have ops for $channel, ignoring possible ban evasions.\n" ) ;
2016-11-29 10:50:49 +01:00
return ;
}
2015-06-20 09:20:23 +02:00
2014-05-21 06:52:17 +02:00
my $ debug_checkban = $ self - > { pbot } - > { registry } - > get_value ( 'antiflood' , 'debug_checkban' ) ;
2015-06-20 09:20:23 +02:00
my $ current_nickserv_account = $ self - > { pbot } - > { messagehistory } - > { database } - > get_current_nickserv_account ( $ message_account ) ;
2011-12-17 12:43:21 +01:00
2016-08-30 05:47:46 +02:00
$ self - > { pbot } - > { logger } - > log ( "anti-flood: [check-bans] checking for bans on $mask " . ( defined $ current_nickserv_account and length $ current_nickserv_account ? "[$current_nickserv_account] " : "" ) . "in $channel\n" ) ;
2016-11-29 10:50:49 +01:00
my ( $ do_not_validate , $ bans ) ;
2016-08-18 05:34:45 +02:00
if ( defined $ current_nickserv_account and length $ current_nickserv_account ) {
2015-06-20 09:20:23 +02:00
$ self - > { pbot } - > { logger } - > log ( "anti-flood: [check-bans] current nickserv [$current_nickserv_account] found for $mask\n" ) if $ debug_checkban >= 2 ;
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ message_account , $ channel , 'validated' ) ;
if ( $ channel_data - > { validated } & $ self - > { NEEDS_CHECKBAN } ) {
$ channel_data - > { validated } & = ~ $ self - > { NEEDS_CHECKBAN } ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ message_account , $ channel , $ channel_data ) ;
2014-05-13 12:15:52 +02:00
}
2015-06-20 09:20:23 +02:00
} else {
2020-02-03 18:50:38 +01:00
if ( not exists $ self - > { pbot } - > { irc_capabilities } - > { 'account-notify' } ) {
2016-11-29 10:50:49 +01:00
# mark this account as needing check-bans when nickserv account is identified
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ message_account , $ channel , 'validated' ) ;
2019-05-28 18:19:42 +02:00
if ( not $ channel_data - > { validated } & $ self - > { NEEDS_CHECKBAN } ) {
2016-11-29 10:50:49 +01:00
$ channel_data - > { validated } |= $ self - > { NEEDS_CHECKBAN } ;
$ 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 >= 1 ;
} else {
$ do_not_validate = 1 ;
2015-06-20 09:20:23 +02:00
}
}
2013-07-24 14:35:40 +02:00
2015-06-20 09:20:23 +02:00
my ( $ nick ) = $ mask =~ m/^([^!]+)/ ;
my % aliases = $ self - > { pbot } - > { messagehistory } - > { database } - > get_also_known_as ( $ nick ) ;
2016-02-10 19:14:12 +01:00
my $ csv = Text::CSV - > new ( { binary = > 1 } ) ;
2016-02-10 16:10:37 +01:00
2015-06-20 09:20:23 +02:00
foreach my $ alias ( keys % aliases ) {
next if $ alias =~ /^Guest\d+(?:!.*)?$/ ;
2017-08-05 14:31:46 +02:00
$ self - > { pbot } - > { logger } - > log ( "[after aka] processing $alias\n" ) if $ debug_checkban >= 1 ;
2015-07-29 02:50:06 +02:00
if ( $ aliases { $ alias } - > { type } == $ self - > { pbot } - > { messagehistory } - > { database } - > { alias_type } - > { WEAK } ) {
2015-07-15 09:18:57 +02:00
$ self - > { pbot } - > { logger } - > log ( "anti-flood: [check-bans] skipping WEAK alias $alias in channel $channel\n" ) if $ debug_checkban >= 2 ;
next ;
}
2015-06-20 09:20:23 +02:00
my @ nickservs ;
2013-07-28 12:31:12 +02:00
2015-06-20 09:20:23 +02:00
if ( exists $ aliases { $ alias } - > { nickserv } ) {
@ nickservs = split /,/ , $ aliases { $ alias } - > { nickserv } ;
} else {
@ nickservs = ( undef ) ;
}
2014-05-13 12:15:52 +02:00
2015-06-20 09:20:23 +02:00
foreach my $ nickserv ( @ nickservs ) {
2016-02-10 12:42:42 +01:00
my @ gecoses ;
if ( exists $ aliases { $ alias } - > { gecos } ) {
2016-02-10 16:10:37 +01:00
$ csv - > parse ( $ aliases { $ alias } - > { gecos } ) ;
@ gecoses = $ csv - > fields ;
2016-02-10 12:42:42 +01:00
} else {
@ gecoses = ( undef ) ;
}
foreach my $ gecos ( @ gecoses ) {
my $ tgecos = defined $ gecos ? $ gecos : "[undefined]" ;
my $ tnickserv = defined $ nickserv ? $ nickserv : "[undefined]" ;
$ self - > { pbot } - > { logger } - > log ( "anti-flood: [check-bans] checking blacklist for $alias in channel $channel using gecos '$tgecos' and nickserv '$tnickserv'\n" ) if $ debug_checkban >= 5 ;
if ( $ self - > { pbot } - > { blacklist } - > check_blacklist ( $ alias , $ channel , $ nickserv , $ gecos ) ) {
2019-05-28 18:19:42 +02:00
if ( $ self - > whitelisted ( $ channel , $ mask , 'user' ) ) {
2016-02-10 12:42:42 +01:00
$ self - > { pbot } - > { logger } - > log ( "anti-flood: [check-bans] $mask [$alias] blacklisted in $channel, but allowed through whitelist\n" ) ;
next ;
}
my $ baninfo = { } ;
$ baninfo - > { banmask } = $ alias ;
$ baninfo - > { channel } = $ channel ;
$ baninfo - > { owner } = 'blacklist' ;
$ baninfo - > { when } = 0 ;
$ baninfo - > { type } = 'blacklist' ;
push @$ bans , $ baninfo ;
next ;
}
}
2015-06-20 09:20:23 +02:00
$ 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 ) ;
2014-05-21 06:52:17 +02:00
2019-05-28 18:19:42 +02:00
if ( defined $ baninfos ) {
2015-06-20 09:20:23 +02:00
foreach my $ baninfo ( @$ baninfos ) {
2019-05-28 18:19:42 +02:00
if ( time - $ baninfo - > { when } < 5 ) {
2015-06-20 09:20:23 +02:00
$ self - > { pbot } - > { logger } - > log ( "anti-flood: [check-bans] $mask [$alias] evaded $baninfo->{banmask} in $baninfo->{channel}, but within 5 seconds of establishing ban; giving another chance\n" ) ;
2014-05-21 06:52:17 +02:00
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ message_account , $ channel , 'validated' ) ;
2019-05-28 18:19:42 +02:00
if ( $ channel_data - > { validated } & $ self - > { NICKSERV_VALIDATED } ) {
2014-05-21 06:52:17 +02:00
$ channel_data - > { validated } & = ~ $ self - > { NICKSERV_VALIDATED } ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ message_account , $ channel , $ channel_data ) ;
2014-05-13 12:15:52 +02:00
}
2014-05-21 06:52:17 +02:00
$ do_not_validate = 1 ;
next ;
}
2014-03-10 04:50:02 +01:00
2019-05-28 18:19:42 +02:00
if ( $ self - > whitelisted ( $ baninfo - > { channel } , $ baninfo - > { banmask } , 'ban' ) || $ self - > whitelisted ( $ baninfo - > { channel } , $ mask , 'user' ) ) {
2018-08-01 02:21:15 +02:00
#$self->{pbot}->{logger}->log("anti-flood: [check-bans] $mask [$alias] evaded $baninfo->{banmask} in $baninfo->{channel}, but allowed through whitelist\n");
2014-05-21 06:52:17 +02:00
next ;
2019-06-26 18:34:19 +02:00
}
2014-03-10 04:50:02 +01:00
2016-07-01 21:55:52 +02:00
# special case for twkm clone bans
if ( $ baninfo - > { banmask } =~ m/\?\*!\*@\*$/ ) {
$ self - > { pbot } - > { logger } - > log ( "anti-flood: [check-bans] $mask [$alias] evaded $baninfo->{banmask} in $baninfo->{channel}, but disregarded due to clone ban\n" ) ;
next ;
}
2014-05-21 06:52:17 +02:00
my $ banmask_regex = quotemeta $ baninfo - > { banmask } ;
$ banmask_regex =~ s/\\\*/.*/g ;
$ banmask_regex =~ s/\\\?/./g ;
2013-07-28 12:31:12 +02:00
2019-05-28 18:19:42 +02:00
if ( $ mask =~ /^$banmask_regex$/i ) {
2016-02-25 09:51:52 +01:00
$ self - > { pbot } - > { logger } - > log ( "anti-flood: [check-bans] Hostmask ($mask) matches $baninfo->{type} banmask ($banmask_regex), disregarding\n" ) ;
2014-05-21 06:52:17 +02:00
next ;
}
2013-07-28 12:31:12 +02:00
2019-05-28 18:19:42 +02:00
if ( defined $ nickserv and $ baninfo - > { type } eq '+q' and $ baninfo - > { banmask } =~ /^\$a:(.*)/ and lc $ 1 eq $ nickserv and $ nickserv eq $ current_nickserv_account ) {
2015-05-12 06:27:22 +02:00
$ self - > { pbot } - > { logger } - > log ( "anti-flood: [check-bans] Hostmask ($mask) matches quiet on account ($nickserv), disregarding\n" ) ;
next ;
2014-05-21 06:52:17 +02:00
}
2014-05-13 12:15:52 +02:00
2019-05-28 18:19:42 +02:00
if ( not defined $ bans ) {
2014-05-21 06:52:17 +02:00
$ bans = [] ;
2013-07-28 12:31:12 +02:00
}
2014-05-21 06:52:17 +02:00
2015-06-20 09:20:23 +02:00
$ self - > { pbot } - > { logger } - > log ( "anti-flood: [check-bans] Hostmask ($mask [$alias" . ( defined $ nickserv ? "/$nickserv" : "" ) . "]) matches $baninfo->{type} $baninfo->{banmask}, adding ban\n" ) ;
2014-05-21 06:52:17 +02:00
push @$ bans , $ baninfo ;
2015-06-21 02:48:42 +02:00
goto GOT_BAN ;
2013-07-28 12:31:12 +02:00
}
}
2011-12-17 12:43:21 +01:00
}
2013-07-28 12:31:12 +02:00
}
2011-12-17 12:43:21 +01:00
2015-06-21 02:48:42 +02:00
GOT_BAN:
2019-05-28 18:19:42 +02:00
if ( defined $ bans ) {
2013-07-28 12:31:12 +02:00
foreach my $ baninfo ( @$ bans ) {
2015-06-20 09:20:23 +02:00
my $ banmask ;
my ( $ user , $ host ) = $ mask =~ m/[^!]+!([^@]+)@(.*)/ ;
if ( $ host =~ m {^([^/]+)/.+} and $ 1 ne 'gateway' and $ 1 ne 'nat' ) {
$ banmask = "*!*\@$host" ;
2016-11-29 10:50:49 +01:00
} elsif ( $ current_nickserv_account and $ baninfo - > { banmask } !~ m/^\$a:/i and not exists $ self - > { pbot } - > { bantracker } - > { banlist } - > { $ baninfo - > { channel } } - > { '+b' } - > { "\$a:$current_nickserv_account" } ) {
2015-06-20 09:20:23 +02:00
$ banmask = "\$a:$current_nickserv_account" ;
} else {
2016-07-01 21:55:52 +02:00
if ( $ host =~ m {^gateway/web/irccloud.com/} ) {
$ banmask = "*!$user\@gateway/web/irccloud.com/*" ;
} elsif ( $ host =~ m {^nat/([^/]+)/} ) {
$ banmask = "*!$user\@nat/$1/*" ;
} else {
$ banmask = "*!*\@$host" ;
2020-01-26 06:09:17 +01:00
#$banmask = "*!$user@" . $self->address_to_mask($host);
2016-07-01 21:55:52 +02:00
}
2015-06-20 09:20:23 +02:00
}
2014-05-18 22:09:05 +02:00
$ self - > { pbot } - > { logger } - > log ( "anti-flood: [check-bans] $mask evaded $baninfo->{banmask} banned in $baninfo->{channel} by $baninfo->{owner}, banning $banmask\n" ) ;
2014-04-21 09:26:06 +02:00
my ( $ bannick ) = $ mask =~ m/^([^!]+)/ ;
2019-05-28 18:19:42 +02:00
if ( $ self - > { pbot } - > { registry } - > get_value ( 'antiflood' , 'enforce' ) ) {
2015-06-26 07:55:06 +02:00
if ( $ self - > { pbot } - > { chanops } - > has_ban_timeout ( $ baninfo - > { channel } , $ banmask ) ) {
2015-06-26 05:55:42 +02:00
$ self - > { pbot } - > { logger } - > log ( "anti-flood: [check-bans] $banmask already banned in $channel, disregarding\n" ) ;
return ;
}
2016-11-30 18:28:19 +01:00
my $ ancestor = $ self - > { pbot } - > { messagehistory } - > { database } - > get_ancestor_id ( $ message_account ) ;
if ( exists $ self - > { nickflood } - > { $ ancestor } and $ self - > { nickflood } - > { $ ancestor } - > { offenses } > 0 and $ baninfo - > { type } ne 'blacklist' ) {
if ( gettimeofday - $ self - > { nickflood } - > { $ ancestor } - > { timestamp } < 60 * 15 ) {
2016-07-15 23:09:29 +02:00
$ self - > { pbot } - > { logger } - > log ( "anti-flood: [check-bans] $mask evading nick-flood ban, disregarding\n" ) ;
return ;
}
2016-01-23 15:03:47 +01:00
}
2016-09-02 11:12:20 +02:00
if ( defined $ dry_run && $ dry_run != 0 ) {
$ self - > { pbot } - > { logger } - > log ( "Skipping ban due to dry-run.\n" ) ;
return ;
}
2015-03-17 05:08:25 +01:00
if ( $ baninfo - > { type } eq 'blacklist' ) {
2015-03-15 21:52:30 +01:00
$ self - > { pbot } - > { chanops } - > add_op_command ( $ baninfo - > { channel } , "kick $baninfo->{channel} $bannick I don't think so" ) ;
} else {
2015-06-06 07:26:55 +02:00
my $ owner = $ baninfo - > { owner } ;
$ owner =~ s/!.*$// ;
$ self - > { pbot } - > { chanops } - > add_op_command ( $ baninfo - > { channel } , "kick $baninfo->{channel} $bannick Evaded $baninfo->{banmask} set by $owner" ) ;
2015-03-15 21:52:30 +01:00
}
2019-07-26 23:17:06 +02:00
$ self - > { pbot } - > { chanops } - > ban_user_timed ( $ self - > { pbot } - > { registry } - > get_value ( 'irc' , 'botnick' ) , 'ban evasion' , $ banmask , $ baninfo - > { channel } , 60 * 60 * 24 * 14 ) ;
2014-05-20 12:14:09 +02:00
}
2014-05-13 12:15:52 +02:00
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ message_account , $ channel , 'validated' ) ;
2019-05-28 18:19:42 +02:00
if ( $ channel_data - > { validated } & $ self - > { NICKSERV_VALIDATED } ) {
2014-05-13 12:15:52 +02:00
$ channel_data - > { validated } & = ~ $ self - > { NICKSERV_VALIDATED } ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ message_account , $ channel , $ channel_data ) ;
}
2013-07-28 12:31:12 +02:00
return ;
}
2011-12-17 12:43:21 +01:00
}
2013-07-28 12:31:12 +02:00
2016-11-29 10:50:49 +01:00
unless ( $ do_not_validate ) {
2014-05-13 12:15:52 +02:00
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ message_account , $ channel , 'validated' ) ;
2019-05-28 18:19:42 +02:00
if ( not $ channel_data - > { validated } & $ self - > { NICKSERV_VALIDATED } ) {
2014-05-13 12:15:52 +02:00
$ channel_data - > { validated } |= $ self - > { NICKSERV_VALIDATED } ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ message_account , $ channel , $ channel_data ) ;
}
}
2011-12-17 12:43:21 +01:00
}
2011-02-11 03:46:35 +01:00
sub check_nickserv_accounts {
2014-03-10 07:28:56 +01:00
my ( $ self , $ nick , $ account , $ hostmask ) = @ _ ;
2014-05-13 12:15:52 +02:00
my $ message_account ;
2014-05-18 22:09:05 +02:00
#$self->{pbot}->{logger}->log("Checking nickserv accounts for nick $nick with account $account and hostmask " . (defined $hostmask ? $hostmask : 'undef') . "\n");
2011-02-11 03:46:35 +01:00
2014-03-10 04:50:02 +01:00
$ account = lc $ account ;
2019-05-28 18:19:42 +02:00
if ( not defined $ hostmask ) {
2014-05-13 12:15:52 +02:00
( $ message_account , $ hostmask ) = $ self - > { pbot } - > { messagehistory } - > { database } - > find_message_account_by_nick ( $ nick ) ;
2019-05-28 18:19:42 +02:00
if ( not defined $ message_account ) {
2014-05-18 22:09:05 +02:00
$ self - > { pbot } - > { logger } - > log ( "No message account found for nick $nick.\n" ) ;
2014-05-13 12:15:52 +02:00
( $ message_account ) = $ self - > { pbot } - > { messagehistory } - > { database } - > find_message_accounts_by_nickserv ( $ account ) ;
2019-05-28 18:19:42 +02:00
if ( not $ message_account ) {
2014-05-18 22:09:05 +02:00
$ self - > { pbot } - > { logger } - > log ( "No message account found for nickserv $account.\n" ) ;
2014-05-13 12:15:52 +02:00
return ;
2011-02-11 03:46:35 +01:00
}
}
2014-03-10 07:28:56 +01:00
} else {
2014-05-13 12:15:52 +02:00
( $ message_account ) = $ self - > { pbot } - > { messagehistory } - > { database } - > find_message_accounts_by_mask ( $ hostmask ) ;
2019-05-28 18:19:42 +02:00
if ( not $ message_account ) {
2014-05-18 22:09:05 +02:00
$ self - > { pbot } - > { logger } - > log ( "No message account found for hostmask $hostmask.\n" ) ;
2014-05-13 12:15:52 +02:00
return ;
}
2014-03-10 07:28:56 +01:00
}
2014-05-18 22:09:05 +02:00
#$self->{pbot}->{logger}->log("anti-flood: $message_account: setting nickserv account to [$account]\n");
2014-05-13 12:15:52 +02:00
$ self - > { pbot } - > { messagehistory } - > { database } - > update_nickserv_account ( $ message_account , $ account , scalar gettimeofday ) ;
$ self - > { pbot } - > { messagehistory } - > { database } - > set_current_nickserv_account ( $ message_account , $ account ) ;
2011-02-11 03:46:35 +01:00
}
2015-05-10 21:36:47 +02:00
sub on_endofwhois {
my ( $ self , $ event_type , $ event ) = @ _ ;
my $ nick = $ event - > { event } - > { args } [ 1 ] ;
2015-06-20 09:20:23 +02:00
2015-05-10 21:36:47 +02:00
delete $ self - > { whois_pending } - > { $ nick } ;
2015-05-12 06:27:22 +02:00
my ( $ id , $ hostmask ) = $ self - > { pbot } - > { messagehistory } - > { database } - > find_message_account_by_nick ( $ nick ) ;
2015-05-12 21:59:22 +02:00
# $self->{pbot}->{logger}->log("endofwhois: Found [$id][$hostmask] for [$nick]\n");
2015-05-12 06:27:22 +02:00
$ self - > { pbot } - > { messagehistory } - > { database } - > link_aliases ( $ id , $ hostmask ) if $ id ;
2015-06-20 09:20:23 +02:00
# check to see if any channels need check-ban validation
my $ channels = $ self - > { pbot } - > { nicklist } - > get_channels ( $ nick ) ;
foreach my $ channel ( @$ channels ) {
next unless $ channel =~ /^#/ ;
my $ channel_data = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_data ( $ id , $ channel , 'validated' ) ;
if ( $ channel_data - > { validated } & $ self - > { NEEDS_CHECKBAN } or not $ channel_data - > { validated } & $ self - > { NICKSERV_VALIDATED } ) {
$ self - > check_bans ( $ id , $ hostmask , $ channel ) ;
}
}
2015-05-10 21:36:47 +02:00
return 0 ;
}
2016-02-10 12:42:42 +01:00
sub on_whoisuser {
my ( $ self , $ event_type , $ event ) = @ _ ;
my $ nick = $ event - > { event } - > { args } [ 1 ] ;
my $ gecos = lc $ event - > { event } - > { args } [ 5 ] ;
my ( $ id ) = $ self - > { pbot } - > { messagehistory } - > { database } - > find_message_account_by_nick ( $ nick ) ;
2016-02-25 09:51:52 +01:00
if ( $ self - > { pbot } - > { registry } - > get_value ( 'antiflood' , 'debug_checkban' ) >= 2 ) {
2016-02-10 12:42:42 +01:00
$ self - > { pbot } - > { logger } - > log ( "Got gecos for $nick ($id): '$gecos'\n" ) ;
}
$ self - > { pbot } - > { messagehistory } - > { database } - > update_gecos ( $ id , $ gecos , scalar gettimeofday ) ;
}
2011-02-11 03:46:35 +01:00
sub on_whoisaccount {
2014-11-01 01:15:21 +01:00
my ( $ self , $ event_type , $ event ) = @ _ ;
my $ nick = $ event - > { event } - > { args } [ 1 ] ;
my $ account = lc $ event - > { event } - > { args } [ 2 ] ;
2011-02-11 03:46:35 +01:00
2015-06-21 02:48:42 +02:00
if ( $ self - > { pbot } - > { registry } - > get_value ( 'antiflood' , 'debug_checkban' ) ) {
$ self - > { pbot } - > { logger } - > log ( "$nick is using NickServ account [$account]\n" ) ;
}
2015-05-12 06:27:22 +02:00
my ( $ id , $ hostmask ) = $ self - > { pbot } - > { messagehistory } - > { database } - > find_message_account_by_nick ( $ nick ) ;
2015-05-12 21:59:22 +02:00
# $self->{pbot}->{logger}->log("whoisaccount: Found [$id][$hostmask][$account] for [$nick]\n");
2015-05-12 06:27:22 +02:00
$ self - > { pbot } - > { messagehistory } - > { database } - > link_aliases ( $ id , undef , $ account ) if $ id ;
2015-06-20 09:20:23 +02:00
$ self - > check_nickserv_accounts ( $ nick , $ account ) ;
2014-11-01 01:15:21 +01:00
return 0 ;
2011-02-11 03:46:35 +01:00
}
2016-08-28 12:49:27 +02:00
sub on_accountnotify {
my ( $ self , $ event_type , $ event ) = @ _ ;
2016-11-29 10:50:49 +01:00
$ self - > { pbot } - > { messagehistory } - > { database } - > update_hostmask_data ( $ event - > { event } - > { from } , { last_seen = > scalar gettimeofday } ) ;
2016-08-28 12:49:27 +02:00
if ( $ event - > { event } - > { args } [ 0 ] eq '*' ) {
$ self - > { pbot } - > { logger } - > log ( "$event->{event}->{from} logged out of NickServ\n" ) ;
2018-08-01 02:21:15 +02:00
my ( $ nick , $ user , $ host ) = $ event - > { event } - > { from } =~ m/^([^!]+)!([^@]+)@(.*)/ ;
my $ message_account = $ self - > { pbot } - > { messagehistory } - > { database } - > get_message_account ( $ nick , $ user , $ host ) ;
$ self - > { pbot } - > { messagehistory } - > { database } - > set_current_nickserv_account ( $ message_account , '' ) ;
2016-08-28 12:49:27 +02:00
} else {
$ self - > { pbot } - > { logger } - > log ( "$event->{event}->{from} logged into NickServ account $event->{event}->{args}[0]\n" ) ;
my $ nick = $ event - > { event } - > nick ;
my ( $ id , $ hostmask ) = $ self - > { pbot } - > { messagehistory } - > { database } - > find_message_account_by_nick ( $ nick ) ;
$ self - > { pbot } - > { messagehistory } - > { database } - > link_aliases ( $ id , undef , $ event - > { event } - > { args } [ 0 ] ) if $ id ;
$ self - > check_nickserv_accounts ( $ nick , $ event - > { event } - > { args } [ 0 ] ) ;
$ self - > { pbot } - > { messagehistory } - > { database } - > devalidate_all_channels ( $ id ) ;
my $ channels = $ self - > { pbot } - > { nicklist } - > get_channels ( $ nick ) ;
foreach my $ channel ( @$ channels ) {
next unless $ channel =~ /^#/ ;
2016-09-02 11:12:20 +02:00
$ self - > check_bans ( $ id , $ hostmask , $ channel ) ;
2016-08-28 12:49:27 +02:00
}
}
2016-12-17 04:22:42 +01:00
return 0 ;
2016-08-28 12:49:27 +02:00
}
2014-05-13 12:15:52 +02:00
sub adjust_offenses {
2014-02-05 02:10:56 +01:00
my $ self = shift ;
2014-05-18 22:09:05 +02:00
#$self->{pbot}->{logger}->log("Adjusting offenses . . .\n");
2014-05-13 12:15:52 +02:00
# decrease offenses counter if 24 hours have elapsed since latest offense
my $ channel_datas = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_datas_where_last_offense_older_than ( gettimeofday - 60 * 60 * 24 ) ;
foreach my $ channel_data ( @$ channel_datas ) {
2016-01-17 01:55:48 +01:00
my $ id = delete $ channel_data - > { id } ;
my $ channel = delete $ channel_data - > { channel } ;
my $ update = 0 ;
if ( $ channel_data - > { offenses } > 0 ) {
2014-05-13 12:15:52 +02:00
$ channel_data - > { offenses } - - ;
2016-01-17 01:55:48 +01:00
$ update = 1 ;
}
2016-01-23 15:03:47 +01:00
if ( defined $ channel_data - > { unbanmes } and $ channel_data - > { unbanmes } > 0 ) {
2016-01-17 01:55:48 +01:00
$ channel_data - > { unbanmes } - - ;
$ update = 1 ;
}
if ( $ update ) {
2014-05-13 12:15:52 +02:00
$ channel_data - > { last_offense } = gettimeofday ;
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ id , $ channel , $ channel_data ) ;
}
2014-02-05 02:10:56 +01:00
}
2014-05-13 12:15:52 +02:00
$ channel_datas = $ self - > { pbot } - > { messagehistory } - > { database } - > get_channel_datas_with_enter_abuses ( ) ;
foreach my $ channel_data ( @$ channel_datas ) {
my $ id = delete $ channel_data - > { id } ;
my $ channel = delete $ channel_data - > { channel } ;
2014-07-11 14:54:56 +02:00
my $ last_offense = delete $ channel_data - > { last_offense } ;
2019-05-28 18:19:42 +02:00
if ( gettimeofday - $ last_offense >= 60 * 60 * 3 ) {
2014-07-11 14:54:56 +02:00
$ channel_data - > { enter_abuses } - - ;
2015-03-11 10:00:10 +01:00
#$self->{pbot}->{logger}->log("[adjust-offenses] [$id][$channel] decreasing enter abuse offenses to $channel_data->{enter_abuses}\n");
2014-07-11 14:54:56 +02:00
$ self - > { pbot } - > { messagehistory } - > { database } - > update_channel_data ( $ id , $ channel , $ channel_data ) ;
}
2014-05-13 12:15:52 +02:00
}
2014-05-16 02:48:46 +02:00
foreach my $ account ( keys % { $ self - > { nickflood } } ) {
2019-05-28 18:19:42 +02:00
if ( $ self - > { nickflood } - > { $ account } - > { offenses } and gettimeofday - $ self - > { nickflood } - > { $ account } - > { timestamp } >= 60 * 60 ) {
2014-05-16 02:48:46 +02:00
$ self - > { nickflood } - > { $ account } - > { offenses } - - ;
2019-05-28 18:19:42 +02:00
if ( $ self - > { nickflood } - > { $ account } - > { offenses } <= 0 ) {
2014-05-16 02:48:46 +02:00
delete $ self - > { nickflood } - > { $ account } ;
} else {
$ self - > { nickflood } - > { $ account } - > { timestamp } = gettimeofday ;
}
}
}
2014-02-05 02:10:56 +01:00
}
2010-03-17 07:36:54 +01:00
1 ;