#!/usr/bin/perl -w

# Dominik Heeg @ 29.10.2010 | rewrite for use of the new sqlite db which came with Plesk 9
# a simple script to realize POP Before SMTP Auth with Plesk and spamdyke

$table_file = "/var/qmail/spamdyke/pop-before-smtp";

# Optional lines for making the script quite
#open STDIN, '/dev/null' or die ERROR("Can't find /dev/null: $!");
#open STDOUT, '>/dev/null';
#open STDERR, '>/dev/null';

#
## Main ##
#
@sqlout = `sqlite3 /var/lib/plesk/mail/poplock/poplock.db "SELECT DISTINCT ip_address from smtp_poplocks"`;
chomp(@sqlout);

system("rm $table_file");
open(FILE,">> $table_file");

foreach(@sqlout) {
  print FILE "$_\n";
}

close(FILE);

exit();
