File: postgrey_clients_dump

package info (click to toggle)
postgrey 1.35-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 520 kB
  • ctags: 94
  • sloc: perl: 1,141; sh: 231; makefile: 17
file content (54 lines) | stat: -rw-r--r-- 1,189 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/perl -w

# written by David Schweikert and adapted to Debian by Adrian von Bidder
# this script is in the public domain
#
# This script will output all clients that were automatically whitelisted
# by postgrey's --auto-whitelist-clients option. The default number of
# mails required (5) is hardcoded below!

use BerkeleyDB;
use Socket;

my $dbdir = '/var/lib/postgrey';

sub resolv($) {
    my $host = shift;
    my $iaddr = inet_aton($host);
    return gethostbyaddr($iaddr, AF_INET) || $host;
}

sub dbopen($)
{
    my ($dbdir) = @_;
    my %db;

    my $dbenv = BerkeleyDB::Env->new(
	-Home     => $dbdir,
	-Flags    => DB_INIT_TXN|DB_INIT_MPOOL|DB_INIT_LOG,
    ) or die "ERROR: can't open DB environment: $!\n";

    tie(%db, 'BerkeleyDB::Btree',
	-Filename => "postgrey_clients.db",
	-Flags    => DB_RDONLY,
	-Env      => $dbenv,
    ) or die "ERROR: can't open database $dbdir/postgrey_clients.db: $!\n";

    return \%db;
}

sub main()
{
    # go through the database
    my $db = dbopen($dbdir);
    while (my ($key, $value) = each %$db) {
	my ($c,$l) = split(/,/,$value);
	$c >= 5 or next;
	my $host = resolv($key);
	print "$host ($c)\n";
    }
}

main;

# vim: sw=4