2012-06-30 21:40:24 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Data::Dumper;
|
|
|
|
|
2012-06-30 21:40:24 +02:00
|
|
|
my $QPDIR = '/usr/home/qpsmtpd/smtpd';
|
2012-06-30 21:40:24 +02:00
|
|
|
my $logfile = "$QPDIR/log/main/current";
|
|
|
|
|
|
|
|
my $is_ip = 0;
|
|
|
|
my $search = $ARGV[0];
|
|
|
|
|
|
|
|
if ( ! $search ) {
|
|
|
|
die "\nusage: $0 [ ip_address | PID ]\n\n";
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( $search =~ /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/ ) {
|
|
|
|
#print "it's an IP\n";
|
|
|
|
$is_ip++;
|
|
|
|
};
|
|
|
|
|
2012-06-30 21:40:24 +02:00
|
|
|
open my $LOG, '<', $logfile;
|
2012-06-30 21:40:24 +02:00
|
|
|
|
|
|
|
if ( $is_ip ) { # look for the connection start message for the IP
|
|
|
|
my $ip_matches;
|
|
|
|
while ( defined (my $line = <$LOG>) ) {
|
|
|
|
next if ! $line;
|
|
|
|
my ( $tai, $pid, $mess ) = split /\s/, $line, 3;
|
|
|
|
if ( 'Connection from ' eq substr( $mess, 0, 16 ) ) {
|
|
|
|
my ( $ip ) = (split /\s+/, $mess)[-1]; # IP is last word
|
|
|
|
$ip = substr $ip, 1, -1; # trim off brackets
|
|
|
|
if ( $ip eq $search ) {
|
|
|
|
$ip_matches++;
|
|
|
|
$search = $pid;
|
|
|
|
$is_ip = 0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
seek $LOG, 0, 0;
|
|
|
|
die "no pid found for ip $search\n" if $is_ip;
|
|
|
|
print "showing the last of $ip_matches connnections from $ARGV[0]\n";
|
|
|
|
};
|
|
|
|
|
|
|
|
print "showing QP message PID $search\n";
|
|
|
|
|
|
|
|
while ( defined (my $line = <$LOG>) ) {
|
|
|
|
next if ! $line;
|
|
|
|
my ( $tai, $pid, $mess ) = split /\s/, $line, 3;
|
|
|
|
next if ! $pid;
|
|
|
|
print $mess if ( $pid eq $search );
|
|
|
|
};
|
|
|
|
close $LOG;
|
|
|
|
|
|
|
|
|
|
|
|
sub get_qp_dir {
|
|
|
|
foreach my $user ( qw/ qpsmtpd smtpd / ) {
|
|
|
|
my ($homedir) = (getpwnam( $user ))[7] or next;
|
|
|
|
|
|
|
|
if ( -d "$homedir/plugins" ) {
|
|
|
|
return "$homedir";
|
|
|
|
};
|
|
|
|
foreach my $s ( qw/ smtpd qpsmtpd qpsmtpd-dev / ) {
|
|
|
|
if ( -d "$homedir/$s/plugins" ) {
|
|
|
|
return "$homedir/$s";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if ( -d "./plugins" ) {
|
|
|
|
return Cwd::getcwd();
|
|
|
|
};
|
|
|
|
};
|