sub _builtin_throttle { my ($eh, $app, $tb) = @_; my $user_ip = $app->remote_ip; use MT::Util qw(offset_time_list); my $throttle_period = $app->{cfg}->ThrottleSeconds; return 1 if ($throttle_period <= 0); # Disabled by ThrottleSeconds 0 my $eh = shift; my $app = shift; my ($entry) = @_; require MT::Util; my @ts = offset_time_list(time - $throttle_period, $tb->blog_id); my $from = sprintf("%04d%02d%02d%02d%02d%02d", $ts[5]+1900, $ts[4]+1, @ts[3,2,1,0]); #if Existed TB Ping , Goto Error if (MT::TBPing->count({ ip => $user_ip, blog_id => $tb->blog_id, created_on => [$from] }, {range => {created_on => 1} })) { return 0; } @ts = offset_time_list(time - $throttle_period * 10 - 1, $tb->blog_id); $from = sprintf("%04d%02d%02d%02d%02d%02d", $ts[5]+1900, $ts[4]+1, @ts[3,2,1,0]); my $count = MT::TBPing->count({ ip => $user_ip, created_on => [$from], blog_id => $entry->blog_id }, { range => {created_on => 1} }); if ($count >= 8) { require MT::IPBanList; my $ipban = MT::IPBanList->new(); $ipban->blog_id($entry->blog_id); $ipban->ip($user_ip); $ipban->save(); $ipban->commit(); $app->log({ message => $app->translate("IP [_1] banned because comment rate exceeded 8 comments in [_2] seconds.", $user_ip, 10 * $throttle_period ), class => 'comment', category => 'ip_ban', blog_id => $entry->blog_id, level => MT::Log::INFO(), metadata => $user_ip, }); require MT::Mail; my $author = $entry->author; $app->set_language($author->preferred_language) if $author && $author->preferred_language; my $blog = MT::Blog->load($entry->blog_id); if ($author && $author->email) { my %head = ( To => $author->email, From => $app->{cfg}->EmailAddressMain, Subject => '[' . $blog->name . '] ' . $app->translate("IP Banned Due to Excessive Comments")); my $charset = $app->{cfg}->MailEncoding || $app->{cfg}->PublishCharset; $head{'Content-Type'} = qq(text/plain; charset="$charset"); my $body = $app->translate('_THROTTLED_COMMENT_EMAIL', $blog->name, 10 * $throttle_period, $user_ip, $user_ip); $body = wrap_text($body, 72); MT::Mail->send(\%head, $body); } return 0; } return 1; }