2002-07-03 15:10:44 +02:00
|
|
|
package Qpsmtpd::TcpServer;
|
2002-09-24 12:56:35 +02:00
|
|
|
use Qpsmtpd::SMTP;
|
2003-04-15 19:01:43 +02:00
|
|
|
use Qpsmtpd::Constants;
|
|
|
|
|
2002-09-24 12:56:35 +02:00
|
|
|
@ISA = qw(Qpsmtpd::SMTP);
|
2002-07-03 15:10:44 +02:00
|
|
|
use strict;
|
|
|
|
|
|
|
|
sub start_connection {
|
|
|
|
my $self = shift;
|
|
|
|
|
2002-08-06 14:34:03 +02:00
|
|
|
die "Qpsmtpd::TcpServer must be started by tcpserver\n"
|
|
|
|
unless $ENV{TCPREMOTEIP};
|
|
|
|
|
2002-07-04 03:45:19 +02:00
|
|
|
my $remote_host = $ENV{TCPREMOTEHOST} || ( $ENV{TCPREMOTEIP} ? "[$ENV{TCPREMOTEIP}]" : "[noip!]");
|
2002-07-03 15:10:44 +02:00
|
|
|
my $remote_info = $ENV{TCPREMOTEINFO} ? "$ENV{TCPREMOTEINFO}\@$remote_host" : $remote_host;
|
|
|
|
my $remote_ip = $ENV{TCPREMOTEIP};
|
|
|
|
|
2003-04-21 10:28:12 +02:00
|
|
|
# if the local dns resolver doesn't filter it out we might get
|
|
|
|
# ansi escape characters that could make a ps axw do "funny"
|
|
|
|
# things. So to be safe, cut them out.
|
|
|
|
$remote_host =~ tr/a-zA-Z\.\-0-9//cd;
|
|
|
|
|
2003-04-16 18:35:14 +02:00
|
|
|
$0 = "$0 [$remote_ip : $remote_host]";
|
|
|
|
|
2002-07-03 15:10:44 +02:00
|
|
|
$self->SUPER::connection->start(remote_info => $remote_info,
|
|
|
|
remote_ip => $remote_ip,
|
|
|
|
remote_host => $remote_host,
|
|
|
|
@_);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub run {
|
|
|
|
my $self = shift;
|
|
|
|
|
2002-07-06 09:16:23 +02:00
|
|
|
# should be somewhere in Qpsmtpd.pm and not here...
|
|
|
|
$self->load_plugins;
|
|
|
|
|
2003-04-15 19:01:43 +02:00
|
|
|
my $rc = $self->start_conversation;
|
|
|
|
return if $rc != DONE;
|
2002-07-03 15:10:44 +02:00
|
|
|
|
|
|
|
# this should really be the loop and read_input should just get one line; I think
|
2002-09-12 09:31:56 +02:00
|
|
|
|
2002-07-03 15:10:44 +02:00
|
|
|
$self->read_input;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub read_input {
|
|
|
|
my $self = shift;
|
2002-09-12 09:31:56 +02:00
|
|
|
|
2002-07-06 09:16:23 +02:00
|
|
|
my $timeout = $self->config('timeout');
|
|
|
|
alarm $timeout;
|
2002-07-03 15:10:44 +02:00
|
|
|
while (<STDIN>) {
|
|
|
|
alarm 0;
|
|
|
|
$_ =~ s/\r?\n$//s; # advanced chomp
|
2004-03-05 13:46:24 +01:00
|
|
|
$self->log(LOGDEBUG, "dispatching $_");
|
2002-07-03 15:10:44 +02:00
|
|
|
defined $self->dispatch(split / +/, $_)
|
|
|
|
or $self->respond(502, "command unrecognized: '$_'");
|
2002-07-06 09:16:23 +02:00
|
|
|
alarm $timeout;
|
2002-07-03 15:10:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub respond {
|
|
|
|
my ($self, $code, @messages) = @_;
|
|
|
|
while (my $msg = shift @messages) {
|
|
|
|
my $line = $code . (@messages?"-":" ").$msg;
|
2004-03-05 13:46:24 +01:00
|
|
|
$self->log(LOGDEBUG, "$line");
|
|
|
|
print "$line\r\n" or ($self->log(LOGERROR, "Could not print [$line]: $!"), return 0);
|
2002-07-03 15:10:44 +02:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-07-15 13:49:49 +02:00
|
|
|
sub disconnect {
|
|
|
|
my $self = shift;
|
|
|
|
$self->SUPER::disconnect(@_);
|
|
|
|
exit;
|
|
|
|
}
|
2002-07-03 15:10:44 +02:00
|
|
|
|
|
|
|
1;
|