]> TLD Linux GIT Repositories - packages/postgrey.git/blob - postgrey_clients_dump
- from PLD, migrated configuration to /etc/postfix
[packages/postgrey.git] / postgrey_clients_dump
1 #!/usr/bin/perl -w
2
3 # written by David Schweikert and adapted to Debian by Adrian von Bidder
4 # adapted to PLD Linux Distribution Micha³ Lipka
5 # this script is in the public domain
6 #
7 # This script will output all clients that were automatically whitelisted
8 # by postgrey's --auto-whitelist-clients option. 
9 # Set the default number of mails your to fit your needs (generally it 
10 # should be the same as N i --auto-whitelist-clients=N)
11
12 use BerkeleyDB;
13 use Socket;
14
15 my $dbdir = '/var/spool/postfix/postgrey/';
16 my $mails = 3;
17
18 sub resolv($) {
19     my $host = shift;
20     my $iaddr = inet_aton($host);
21     return gethostbyaddr($iaddr, AF_INET) || $host;
22 }
23
24 sub dbopen($)
25 {
26     my ($dbdir) = @_;
27     my %db;
28
29     my $dbenv = BerkeleyDB::Env->new(
30         -Home     => $dbdir,
31         -Flags    => DB_INIT_TXN|DB_INIT_MPOOL|DB_INIT_LOG,
32     ) or die "ERROR: can't open DB environment: $!\n";
33
34     tie(%db, 'BerkeleyDB::Btree',
35         -Filename => "postgrey_clients.db",
36         -Flags    => DB_RDONLY,
37         -Env      => $dbenv,
38     ) or die "ERROR: can't open database $dbdir/postgrey_clients.db: $!\n";
39
40     return \%db;
41 }
42
43 sub main()
44 {
45     # go through the database
46     my $db = dbopen($dbdir);
47     while (my ($key, $value) = each %$db) {
48         my ($c,$l) = split(/,/,$value);
49         $c >= $mails or next;
50         my $host = resolv($key);
51         print "$host [$key] ($c)\n";
52     }
53 }
54
55 main;
56
57 # vim: sw=4