use perl DNS methods instead of shell cmds

This commit is contained in:
Matt Simerson 2015-01-28 10:23:03 -08:00
parent 45bc5cfffc
commit 31dbe00514
2 changed files with 8 additions and 9 deletions

View File

@ -9,8 +9,10 @@ use Net::IP qw(:PROC);
use POSIX qw(strftime); use POSIX qw(strftime);
use lib 'lib'; use lib 'lib';
use Qpsmtpd::Base;
use Qpsmtpd::DB; use Qpsmtpd::DB;
my $base = Qpsmtpd::Base->new();
my $self = bless({args => {db_dir => 'config'},}, 'Karma'); my $self = bless({args => {db_dir => 'config'},}, 'Karma');
my $command = $ARGV[0]; my $command = $ARGV[0];
@ -119,8 +121,7 @@ sub show_ip {
if ($penalty_start_ts) { if ($penalty_start_ts) {
$time_human = strftime "%a %b %e %H:%M", localtime $penalty_start_ts; $time_human = strftime "%a %b %e %H:%M", localtime $penalty_start_ts;
} }
my $hostname = `dig +short -x $ip` || ''; my $hostname = $base->resolve_ptr($ip);
chomp $hostname;
print print
" IP Address Penalty Naughty Nice Connects Hostname\n"; " IP Address Penalty Naughty Nice Connects Hostname\n";
printf(" %-18s %24s %3s %3s %3s %-30s\n", printf(" %-18s %24s %3s %3s %3s %-30s\n",
@ -164,8 +165,8 @@ sub main {
} }
my $hostname = ''; my $hostname = '';
if ($naughty && $nice) { if ($naughty && $nice) {
# this can be slow, waiting for each IP to resolve
#$hostname = `dig +short -x $ip`; chomp $hostname; #$hostname = $base->resolve_ptr($ip);
} }
printf(" %-18s %24s %3s %3s %3s %30s\n", printf(" %-18s %24s %3s %3s %3s %30s\n",
$ip, $time_human, $naughty, $nice, $connects, $hostname); $ip, $time_human, $naughty, $nice, $connects, $hostname);

View File

@ -3,15 +3,13 @@
use strict; use strict;
use warnings; use warnings;
# Very basic script to create TLS certificates for qpsmtpd # create TLS certificates for qpsmtpd
use File::Temp qw/ tempfile tempdir /; use File::Temp qw/ tempfile tempdir /;
use Getopt::Long; use Getopt::Long;
use Sys::Hostname;
my %opts = (); my %opts = ();
chomp (my $hostname = `hostname --fqdn`); my $hostname = hostname();
if ($?) {
chomp($hostname = `hostname`);
}
print "Using hostname: $hostname\n"; print "Using hostname: $hostname\n";
my %defaults = ( my %defaults = (
C => 'XY', C => 'XY',