danny 2006-11-19 18:29
安裝pop-before-smtp
1. install perl modules
[code]perl -MCPAN -e shell;
install Time::HiRes
install File::Tail
install Net::Netmask
install Date::Parse
install DB_File [/code]
2.安裝pop-before-smtp
wget http://www.ihao.org/download/pop-before-smtp-1.41.tar.gz
解壓縮:
[code]tar zxvf pop-before-smtp-1.41.tar.gz[/code]
進入該目錄:
[code]cd pop-before-smtp-1.41[/code]
修改檔案:
[code]vi pop-before-smtp-conf.pl [/code]
設定三個變數:
[code]$file_tail{'name'} = '/var/log/maillog';#設定mail的log檔
$grace = 30*60; #這項功能是有效時間,單位是秒
$dbfile = '/etc/postfix/pop-before-smtp'; [/code]
3. modify /etc/pop-before-smtp-conf.pl for vm-pop3d
在最底下那行 1; 之前...加上
[code]# For vm-pop3d -- needs to match 2 log entries (uncomment all 3 "my" lines).
my $PID_pat = '^(... .. ..:..:..) \S+ (?:vm-pop3d)\[(\d+)\]: ';
my $IP_pat = $PID_pat . 'Connect from (\d+\.\d+\.\d+\.\d+)$';
my $OK_pat = $PID_pat . 'User .+ logged in$';
############################## Support Routines ############################
# This section takes care of defining a multi-line-match custom_match()
# subroutine, but only if the user configured our 3 required patterns.
if (defined($PID_pat) && defined($IP_pat) && defined($OK_pat)) {
eval <<'EOT';
# Some pop services don't put the IP on the line that lets us know that a
# user was properly authenticated. For these programs, we scan the IP off
# an earlier line and the check the validation by comparing the PID values.
my %popIPs;
# The maillog line to match is in $_.
sub custom_match
{
if (/$PID_pat/o) {
my($ts, $pid) = ($1, $2);
if (/$IP_pat/o) {
$popIPs{$pid} = $3;
}
else {
foreach my $key (keys %popIPs) {
if ($pid == $key) {
my $ip = $popIPs{$pid};
delete $popIPs{$pid};
if (/$OK_pat/o) {
return ($ts, $ip);
}
last;
}
}
}
}
( );
}
EOT
} [/code]
測試是否可以使用:
./pop-before-smtp --config=./pop-before-smtp-conf.pl --debug --nowrite –reprocess
如果正確,會列出日期及ip等資料
安裝:
cp pop-before-smtp.init /etc/rc.d/init.d/pop-before-smtp
cp pop-before-smtp /usr/sbin/
cp pop-before-smtp-conf.pl /etc
背景執行:
/etc/rc.d/init.d/pop-before-smtp start
接著設定postfix的參數:
smtpd_recipient_restrictions = permit_mynetworks,reject_non_fqdn_recipient,
check_client_access hash:/etc/postfix/pop-before-smtp,#加入這行
check_relay_domains
測試:
請從遠端登入,請勿從同一網域登入(因為permit_mynetworks在最前面,會先檢查到此一條件而無法測試),再看看 /etc/postfix/pop-before-smtp.db的更新時間,是否是你剛從遠端入的時間,如果是,那就對了
參考來源 ADJ+鳥哥