Merge pull request #99 from msimerson/earlytalker
Cleanups and style changes.
This commit is contained in:
commit
43eb6381fe
@ -26,6 +26,12 @@ greeting timeouts -- these are known to range as low as 30 seconds, and may
|
||||
in some cases be configured lower by mailserver admins. Network transit time
|
||||
must also be allowed for.
|
||||
|
||||
=head3 overriding wait
|
||||
|
||||
Other plugins can set specify a per-connection delay by setting
|
||||
connection->notes->('relayclient_wait'). This is ideally used in conjunction with
|
||||
a reputation database.
|
||||
|
||||
=head2 reject <boolean>
|
||||
|
||||
Do we reject/deny connections to early talkers?
|
||||
@ -88,7 +94,7 @@ sub register {
|
||||
$check_at{CONNECT} = 1;
|
||||
}
|
||||
$self->{_args} = {
|
||||
'wait' => 1,
|
||||
wait => 1,
|
||||
@args,
|
||||
'check-at' => \%check_at,
|
||||
};
|
||||
@ -106,8 +112,8 @@ sub register {
|
||||
if (!defined $self->{_args}{reject_type}) {
|
||||
$self->{_args}{reject_type} = 'perm';
|
||||
}
|
||||
|
||||
# /end compat
|
||||
|
||||
if ($qp->{conn} && $qp->{conn}->isa('Apache2::Connection')) {
|
||||
require APR::Const;
|
||||
APR::Const->import(qw(POLLIN SUCCESS));
|
||||
@ -118,11 +124,22 @@ sub register {
|
||||
$self->register_hook('connect', 'connect_handler');
|
||||
$self->register_hook('data', 'data_handler');
|
||||
}
|
||||
if ($self->{_args}{'defer-reject'}) {
|
||||
$self->register_hook('mail', 'mail_handler')
|
||||
if $self->{_args}{'defer-reject'};
|
||||
$self->{_args}{reject} = 1 if !defined $self->{_args}{reject};
|
||||
};
|
||||
if (!defined $self->{_args}{reject}) {
|
||||
$self->{_args}{reject} = 1;
|
||||
};
|
||||
}
|
||||
|
||||
sub wait_length {
|
||||
my ($self) = @_;
|
||||
if ($self->connection->notes('earlytalker_wait')) {
|
||||
return $self->connection->notes('earlytalker_wait');
|
||||
}
|
||||
return $self->{_args}{wait};
|
||||
};
|
||||
|
||||
sub apr_connect_handler {
|
||||
my ($self, $transaction) = @_;
|
||||
|
||||
@ -131,7 +148,7 @@ sub apr_connect_handler {
|
||||
|
||||
my $c = $self->qp->{conn} or return DECLINED;
|
||||
my $socket = $c->client_socket or return DECLINED;
|
||||
my $timeout = $self->{_args}{'wait'} * 1_000_000;
|
||||
my $timeout = $self->wait_length() * 1_000_000;
|
||||
|
||||
my $rc = $socket->poll($c->pool, $timeout, APR::Const::POLLIN());
|
||||
if ($rc == APR::Const::SUCCESS()) {
|
||||
@ -152,7 +169,7 @@ sub apr_data_handler {
|
||||
|
||||
my $c = $self->qp->{conn} or return DECLINED;
|
||||
my $socket = $c->client_socket or return DECLINED;
|
||||
my $timeout = $self->{_args}{'wait'} * 1_000_000;
|
||||
my $timeout = $self->wait_length() * 1_000_000;
|
||||
|
||||
my $rc = $socket->poll($c->pool, $timeout, APR::Const::POLLIN());
|
||||
if ($rc == APR::Const::SUCCESS()) {
|
||||
@ -163,7 +180,6 @@ sub apr_data_handler {
|
||||
|
||||
sub connect_handler {
|
||||
my ($self, $transaction) = @_;
|
||||
my $in = new IO::Select;
|
||||
|
||||
return DECLINED unless $self->{_args}{'check-at'}{CONNECT};
|
||||
return DECLINED if $self->is_immune();
|
||||
@ -175,8 +191,9 @@ sub connect_handler {
|
||||
return DECLINED;
|
||||
}
|
||||
|
||||
my $in = new IO::Select;
|
||||
$in->add(\*STDIN) or return DECLINED;
|
||||
if (!$in->can_read($self->{_args}{'wait'})) {
|
||||
if (!$in->can_read($self->wait_length())) {
|
||||
return $self->log_and_pass();
|
||||
}
|
||||
|
||||
@ -197,7 +214,7 @@ sub data_handler {
|
||||
return DECLINED if $self->is_immune();
|
||||
|
||||
$in->add(\*STDIN) or return DECLINED;
|
||||
if (!$in->can_read($self->{_args}{'wait'})) {
|
||||
if (!$in->can_read($self->wait_length())) {
|
||||
return $self->log_and_pass();
|
||||
}
|
||||
|
||||
@ -206,7 +223,6 @@ sub data_handler {
|
||||
|
||||
sub log_and_pass {
|
||||
my $self = shift;
|
||||
my $ip = $self->qp->connection->remote_ip || 'remote host';
|
||||
$self->log(LOGINFO, "pass, not spontaneous");
|
||||
return DECLINED;
|
||||
}
|
||||
@ -214,8 +230,6 @@ sub log_and_pass {
|
||||
sub log_and_deny {
|
||||
my $self = shift;
|
||||
|
||||
my $ip = $self->qp->connection->remote_ip || 'remote host';
|
||||
|
||||
$self->connection->notes('earlytalker', 1);
|
||||
$self->adjust_karma(-1);
|
||||
|
||||
|
@ -144,4 +144,3 @@ sub test_reject_type {
|
||||
$self->{_args}{reject_type} = 'disconnect';
|
||||
cmp_ok( $self->get_reject_type(), '==', DENY_DISCONNECT, "disconnect");
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user