Skip to content

Commit

Permalink
[#529 state:resolved] Removed IPBan functionality since there are far…
Browse files Browse the repository at this point in the history
… more effective ways of handling this.
  • Loading branch information
MikeThomsen committed Nov 25, 2010
1 parent c133564 commit 0a662de
Show file tree
Hide file tree
Showing 41 changed files with 36 additions and 761 deletions.
16 changes: 3 additions & 13 deletions build/sample.pm
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,9 @@ sub encoding {"iso-8859-1"} # Latin-1

## Blog Config: Navigation
'Configuration' => '',
'Core Setup' => '',
'Preferences' => '',
'Archiving' => '',
'IP Banning' => '',
'Core Setup' => '',
'Preferences' => '',
'Archiving' => '',

## Add a Category screen (category_add.tmpl)
'Add a Category' => '',
Expand All @@ -212,15 +211,6 @@ sub encoding {"iso-8859-1"} # Latin-1
'Del' => '',
'_USAGE_ARCHIVING_3' => '',

## Blog Config | IP Banning (cfg_banlist.tmpl)
'You did not select any IP addresses to delete.' => '',
'_USAGE_BANLIST' => '',
'You have added [_1] to your list of banned IP addresses.' => '',
'You have successfully deleted the selected IP addresses from the list.'
=> '',
'IP Ban List' => '',
'You have [quant,_1,user] in your list of banned IP addresses.' => '',

## Blog Config | Preferences (cfg_prefs.tmpl)
'_USAGE_PREFS' => '',
'General Settings' => '',
Expand Down
11 changes: 1 addition & 10 deletions lib/MT/App.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2260,23 +2260,14 @@ sub _send_comment_notification {
id => $comment->id
}
);
my $ban_link = $base
. $app->uri_params(
'mode' => 'save',
args => {
'_type' => 'banlist',
blog_id => $blog->id,
ip => $comment->ip
}
);

my %param = (
blog => $blog,
entry => $entry,
view_url => $comment_link,
approve_url => $approve_link,
spam_url => $spam_link,
edit_url => $edit_link,
ban_url => $ban_link,
comment => $comment,
unapproved => !$comment->visible(),
state_editable => (
Expand Down
22 changes: 1 addition & 21 deletions lib/MT/App/CMS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1401,17 +1401,6 @@ sub core_menus {
mode => "cfg_plugins",
permission => "manage_plugins",
},
'prefs:ip_info' => {
label => "IP Banning",
mode => 'list',
args => { _type => 'banlist' },
order => 180,
permission => 'manage_feedback',
condition => sub {
$app->config->ShowIPInformation;
},
view => "blog",
},

'tools:activity_log' => {
label => "Activity Log",
Expand Down Expand Up @@ -1528,11 +1517,6 @@ sub init_core_callbacks {
. 'post_delete.notification' =>
"${pfx}AddressBook::post_delete",

# banlist callbacks
$pkg
. 'save_permission_filter.banlist' => "${pfx}BanList::can_save",
$pkg . 'save_filter.banlist' => "${pfx}BanList::save_filter",

# associations
$pkg
. 'delete_permission_filter.association' =>
Expand Down Expand Up @@ -1781,8 +1765,7 @@ sub set_default_tmpl_params {
|| $param->{can_edit_categories}
|| $param->{can_edit_config}
|| $param->{can_edit_tags}
|| $param->{can_set_publish_paths}
|| $param->{show_ip_info};
|| $param->{can_set_publish_paths};
$param->{has_posting_label}
= $param->{can_create_post}
|| $param->{can_edit_entries}
Expand All @@ -1796,14 +1779,11 @@ sub set_default_tmpl_params {
$param->{can_view_log} = $param->{can_view_blog_log};
$param->{can_publish_post} = $param->{can_publish_post}
|| $param->{can_edit_all_posts};
$param->{show_ip_info}
= $app->config->ShowIPInformation && $param->{can_manage_feedback};
} ## end if ( my $perms = $app->permissions)

my $static_app_url = $app->static_path;
$param->{help_url} = $app->help_url() || $static_app_url . 'docs/';

$param->{show_ip_info} ||= $app->config('ShowIPInformation');
my $type = $q->param('_type') || '';

$param->{ "mode_$mode" . ( $type ? "_$type" : '' ) } = 1;
Expand Down
81 changes: 0 additions & 81 deletions lib/MT/App/Comments.pm
Original file line number Diff line number Diff line change
Expand Up @@ -716,78 +716,6 @@ sub _builtin_throttle {
return 0; # Put a collar on that puppy.
}

return 1 unless $cfg->ShowIPInformation;

# If IP banning is enabled, check for lots of comments from
# the user's IP within the throttle period * 10; if they
# exceed 8 comments within that period, ban the IP.

@ts = MT::Util::offset_time_list( time - $throttle_period * 10 - 1,
$entry->blog_id );
$from = sprintf( "%04d%02d%02d%02d%02d%02d",
$ts[5] + 1900,
$ts[4] + 1,
@ts[ 3, 2, 1, 0 ] );
my $count = MT::Comment->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();
$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 )
or return $app->error(
$app->translate( 'Can\'t load blog #[_1].', $entry->blog_id ) );
if ( $author && $author->email ) {
my %head = (
id => 'comment_throttle',
To => $author->email,
From => $cfg->EmailAddressMain,
Subject => '['
. $blog->name . '] '
. $app->translate("IP Banned Due to Excessive Comments")
);
my $charset = $cfg->MailEncoding || $cfg->PublishCharset;
$head{'Content-Type'} = qq(text/plain; charset="$charset");
my $body =
$app->build_email(
'comment_throttle.tmpl',
{
blog => $blog,
throttled_ip => $user_ip,
throttle_seconds => 10 * $throttle_period,
}
);
$body = wrap_text( $body, 72 );
MT::Mail->send( \%head, $body );
} ## end if ( $author && $author...)
return 0;
} ## end if ( $count >= 8 )
return 1;
} ## end sub _builtin_throttle

Expand Down Expand Up @@ -817,15 +745,6 @@ sub post {
)
) if $entry->status != RELEASE;

require MT::IPBanList;
my $iter = MT::IPBanList->load_iter( { blog_id => $entry->blog_id } );
while ( my $ban = $iter->() ) {
my $banned_ip = $ban->ip;
if ( $app->remote_ip =~ /$banned_ip/ ) {
return $app->handle_error( $app->translate("Invalid request") );
}
}

my $blog = $app->model('blog')->load( $entry->blog_id )
or return $app->error(
$app->translate( 'Can\'t load blog #[_1].', $entry->blog_id ) );
Expand Down
25 changes: 1 addition & 24 deletions lib/MT/App/Trackback.pm
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,6 @@ sub ping {
or return $app->_response(
Error => $app->translate( "Invalid TrackBack ID '[_1]'", $tb_id ) );

my $user_ip = $app->remote_ip;

## Check if this user has been banned from sending TrackBack pings.
require MT::IPBanList;
my $iter = MT::IPBanList->load_iter( { blog_id => $tb->blog_id } );
while ( my $ban = $iter->() ) {
my $banned_ip = $ban->ip;
if ( $user_ip =~ /$banned_ip/ ) {
return
$app->_response(
Error =>
$app->translate(
"You are not allowed to send TrackBack pings.")
);
}
}

my ( $blog_id, $entry, $cat );
if ( $tb->entry_id ) {
require MT::Entry;
Expand Down Expand Up @@ -501,18 +484,12 @@ sub _send_ping_notification {
args =>
{ blog_id => $blog->id, '_type' => 'ping', id => $ping->id }
);
my $ban_link = $base
. $app->uri_params(
'mode' => 'save',
args =>
{ '_type' => 'banlist', blog_id => $blog->id, ip => $ping->ip }
);

my %param = (
blog => $blog,
approve_url => $approve_link,
spam_url => $spam_link,
edit_url => $edit_link,
ban_url => $ban_link,
ping => $ping,
unapproved => !$ping->visible(),
state_editable => (
Expand Down
7 changes: 0 additions & 7 deletions lib/MT/BackupRestore.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1426,13 +1426,6 @@ sub parents {
};
}

package MT::IPBanList;

sub parents {
my $obj = shift;
{ blog_id => MT->model('blog'), };
}

package MT::Blocklist;

sub parents {
Expand Down
1 change: 0 additions & 1 deletion lib/MT/Blog.pm
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,6 @@ sub clone_with_children {
# Placement records
# Template records
# Permission records
# IPBanList records???
# Notification records???

my $new_blog_id;
Expand Down
55 changes: 0 additions & 55 deletions lib/MT/CMS/BanList.pm

This file was deleted.

1 change: 0 additions & 1 deletion lib/MT/CMS/Blog.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ sub edit {
# my $output = $param->{output} ||= 'cfg_prefs.tmpl';
$param->{need_full_rebuild} = 1 if $q->param('need_full_rebuild');
$param->{need_index_rebuild} = 1 if $q->param('need_index_rebuild');
$param->{show_ip_info} = $cfg->ShowIPInformation;
$param->{use_plugins} = $cfg->UsePlugins;

my $entries_on_index = ( $obj->entries_on_index || 0 );
Expand Down
10 changes: 2 additions & 8 deletions lib/MT/CMS/Comment.pm
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,7 @@ sub edit_commenter {
sub list {
my $app = shift;
my $q = $app->query;
my $trim_length
= $app->config('ShowIPInformation')
? const('DISPLAY_LENGTH_EDIT_COMMENT_TEXT_SHORT')
: const('DISPLAY_LENGTH_EDIT_COMMENT_TEXT_LONG');
my $trim_length = const('DISPLAY_LENGTH_EDIT_COMMENT_TEXT_LONG');
my $author_max_len = const('DISPLAY_LENGTH_EDIT_COMMENT_AUTHOR');
my $comment_short_len
= const('DISPLAY_LENGTH_EDIT_COMMENT_TEXT_BREAK_UP_SHORT');
Expand Down Expand Up @@ -1767,10 +1764,7 @@ sub build_comment_table {
my $i;
$i = 1;
my ( %blogs, %entries, %perms, %cmntrs );
my $trim_length
= $app->config('ShowIPInformation')
? const('DISPLAY_LENGTH_EDIT_COMMENT_TEXT_SHORT')
: const('DISPLAY_LENGTH_EDIT_COMMENT_TEXT_LONG');
my $trim_length = const('DISPLAY_LENGTH_EDIT_COMMENT_TEXT_LONG');
my $author_max_len = const('DISPLAY_LENGTH_EDIT_COMMENT_AUTHOR');
my $comment_short_len
= const('DISPLAY_LENGTH_EDIT_COMMENT_TEXT_BREAK_UP_SHORT');
Expand Down
Loading

0 comments on commit 0a662de

Please sign in to comment.