キーワード  
☆ カテゴリー ☆
  序章
  動作環境
  インストール
  設定
    ├システム
    ├SSHサーバー
    ├Webサーバー
    ├  Mailサーバー
    ├FTPサーバー
    ├ファイルサーバー
    ├PHP
    ├DBサーバー
    └その他
  Webminでの設定
  チューニング
  ウィンドウシステム
  ウィンドウマネージャー
  スクリプト言語
  システム管理
  デスクトップアプリケーション
  サーバーサイドアプリケーション
  コマンド
  印刷
  シェル・シェルスクリプト
  落書き
  備考
  HD-BSD
  基本操作
  自宅サーバー
  スパム ウィルス 撃退
   戻る



外国旅行に日本のテレビを連れて行こう。

ネット環境さえあれば、どこからでも テレビが見えます。

観るだけでなく 録る 操る 操作する

 新しい 生活が始まる!!

     ロケーションフリー



・・・管理モードON・・・

設定
Mailサーバー

スパム ウィルス 撃退

# cd /usr/ports/japanese/p5-Mail-SpamAssassin
# make install clean

mysqlを有効にする


# cd /usr/ports/security/clamav
# make install clean

iconbを有効にする。

===> Installing rc.d startup script(s)
===> Compressing manual pages for clamav-0.92.1_1
===> Running ldconfig
/sbin/ldconfig -m /usr/local/lib
===> Registering installation for clamav-0.92.1_1
===> SECURITY REPORT:
This port has installed the following files which may act as network
servers and may therefore pose a remote security risk to the system.
/usr/local/sbin/clamd

This port has installed the following startup scripts which may cause
these network services to be started at boot time.
/usr/local/etc/rc.d/clamav-freshclam
/usr/local/etc/rc.d/clamav-clamd

If there are vulnerabilities in these programs there may be a security
risk to the system. FreeBSD makes no guarantee about the security of
ports included in the Ports Collection. Please type 'make deinstall'
to deinstall the port if this is a concern.

For more information, and contact details about the security
status of this software, see the following webpage:
http://www.clamav.net/



# cd /usr/ports/security/amavisd-new
# make install clean


*******************************************************************
To use amavisd-new, you need to install at least one virus scanner.
The following virus scanners are available in the FreeBSD ports
collection:

/usr/ports/security/vscan McAfee VirusScan
/usr/ports/security/clamav Clam Antivirus
/usr/ports/security/f-prot F-Prot Antivirus
/usr/ports/security/drweb DrWeb antivirus suite

Enable amavisd-new in /etc/rc.conf with the following line:

amavisd_enable="YES"

Optionally enable amavisd tmp ram disk with: (example 512m)

amavisd_ram="512m"

If you have installed and want to use the amavis sendmail milter interface,
you need the following additional line in /etc/rc.conf:

amavis_milter_enable="YES"

If you have installed and want to use the p0fanalyzer interface,
you need the following additional lines in /etc/rc.conf
(with modifications according to your needs):

amavis_p0fanalyzer_enable="YES"
amavis_p0fanalyzer_p0f_filter="tcp dst port 25"

You can pass another command line options to p0f daemon by setting
amavis_p0f_daemon_flags and to p0f-analyzer.pl by setting
amavis_p0fanalyzer_flags.

Configuration templates are available in /usr/local/etc
as amavisd.conf-dist, amavisd.conf-sample, amavisd.conf-default
and amavisd-custom.conf-dist.
Documentation is available in /usr/local/share/doc/amavisd-new.
*******************************************************************


mysqlを有効にする


# /usr/ports/mail/procmail
# make install clean

途中止まるので Enter




SpamAssassin はスパムメールの判定を行うのみです。
Procmail は、振り分けをしてくれます。
ClamAV というのは、Clam Anti Virus のことで、ウィルスチェック用のものです。
Amavisd-new は、Postfix と SpamAssassinやClamAVなどとの受け渡しをやってくれるようです。




spamassassin の設定

# cd /usr/local/etc/mail/spamassassin
# cp local.cf.sample local.cf

# echo "allow_user_rules 1" >> local.cf

これは、ユーザの設定ファイルがあってもこの値が0だと解析に失敗してしまうためです。
次に、日本語に対応したSPAMの判定用の設定ファイルをダウンロードします。
spamassassin はもともと国外で作成されたため、そのままでは日本語のメールをほとんどSPAMだと判定してしまいます。
また、日本語SPAMは解析できません。
これを補うため、TLEC(Tokyo Linux Entertainment Community)の松田陽一さんが作成した
user_prefs を利用するのが定番です。
spamd のホームディレクトリに移動し、次のようにしてください。

# cd /root/.spamassassin/
# wget http://tlec.linux.or.jp/docs/user_prefs <= 定義ファイルのダウンロード

僕は、postfixadminな人なので

local.cf に http://tlec.linux.or.jp/docs/user_prefs の内容を使わせていただきました。


更に 一箇所 修正

config: failed to parse, now a plugin, skipping: ok_languages ja ←未修正時のエラー

# ee /usr/local/etc/mail/spamassassin/v310.pre

# TextCat - language guesser
#
loadplugin Mail::SpamAssassin::Plugin::TextCat
↑の行を有効にする。


ここまでで spamassassin の設定は完了です。

# echo spamd_enable="YES" >> /etc/rc.conf



これで起動する準備が整いましたので、次のようにして起動します。

# /usr/local/etc/rc.d/sa-spamd start

確認
# ps ax | grep spam
1897 ?? Ss 0:00.50 /usr/local/bin/spamd -c -Q -d -r /var/run/spamd/spamd.pid (perl
1898 ?? I 0:00.00 spamd child (perl5.8.8)
1899 ?? I 0:00.00 spamd child (perl5.8.8)
1904 p1 S+ 0:00.00 grep spam



Postfixとの連携
spamassassin の準備はできたので、今度は Postfix が spamd を経由してメールを配信するように設定します。


postfixadmin用にフィルタースクリプトを作成する。

# ee /usr/local/etc/sa_filter.sh


#!/bin/sh
# SpamAssassin filter with Postfix

# File path (MODIFY THIS PART TO MATCH YOUR SERVER)
RM=/bin/rm
INSPECT_DIR=/var/spool/filter
OUTPUTFILE=/tmp/out.$$
SENDMAIL=/usr/local/sbin/sendmail
SPAMASSASSIN=/usr/local/bin/spamc

# Exit codes from
# EX_USAGE 64 command line usage error
# EX_DATAERR 65 data format error
# EX_NOINPUT 66 cannot open input
# EX_NOUSER 67 addressee unknown
# EX_NOHOST 68 host name unknown
# EX_UNAVAILABLE 69 service unavailable
# EX_SOFTWARE 70 internal software error
# EX_OSERR 71 system error (e.g., can't fork)
# EX_OSFILE 72 critical OS file missing
# EX_CANTCREAT 73 can't create (user) output file
# EX_IOERR 74 input/output error
# EX_TEMPFAIL 75 temp failure; user is invited to retry
# EX_PROTOCOL 76 remote error in protocol
# EX_NOPERM 77 permission denied
# EX_CONFIG 78 configuration error

EX_TEMPFAIL=75
EX_UNAVAILABLE=69

# Move to work dir
cd $INSPECT_DIR || { echo $INSPECT_DIR does not exist; exit $EX_TEMPFAIL; }

# Clean up when done or when aborting.
trap "$RM -f $OUTPUTFILE" 0 1 2 3 15

cat | $SPAMASSASSIN -x > $OUTPUTFILE

$SENDMAIL "$@" < $OUTPUTFILE

exit $?


もしくは、(下記では、フラグ付のメールを指定されたメアドに送信している)


#!/bin/sh
# SpamAssassin filter with Postfix

# File path (MODIFY THIS PART TO MATCH YOUR SERVER)
RM=/bin/rm
INSPECT_DIR=/var/spool/filter
OUTPUTFILE=/tmp/out.$$
SENDMAIL=/usr/local/sbin/sendmail
SPAMASSASSIN=/usr/local/bin/spamc

# Exit codes from
# EX_USAGE 64 command line usage error
# EX_DATAERR 65 data format error
# EX_NOINPUT 66 cannot open input
# EX_NOUSER 67 addressee unknown
# EX_NOHOST 68 host name unknown
# EX_UNAVAILABLE 69 service unavailable
# EX_SOFTWARE 70 internal software error
# EX_OSERR 71 system error (e.g., can't fork)
# EX_OSFILE 72 critical OS file missing
# EX_CANTCREAT 73 can't create (user) output file
# EX_IOERR 74 input/output error
# EX_TEMPFAIL 75 temp failure; user is invited to retry
# EX_PROTOCOL 76 remote error in protocol
# EX_NOPERM 77 permission denied
# EX_CONFIG 78 configuration error

EX_TEMPFAIL=75
EX_UNAVAILABLE=69

# Move to work dir
cd $INSPECT_DIR || { echo $INSPECT_DIR does not exist; exit $EX_TEMPFAIL; }

# Clean up when done or when aborting.
trap "$RM -f $OUTPUTFILE" 0 1 2 3 15

#cat | $SPAMASSASSIN -x > $OUTPUTFILE
#$SENDMAIL "$@" < $OUTPUTFILE


cat | $SPAMASSASSIN -x > in.$$
grep -e "^X-Spam-Status:.Yes" in.$$
&& $SENDMAIL "spam@819.gr.jp" < in.$$
|| $SENDMAIL "$@" < in.$$


exit $?






User/Groupにfilterという名前で追加します。

# vipw (# ee /etc/passwd)

filter:*:127:127:SpamAssassin:/:/sbin/nologin


# ee /etc/group

filter:*:127:


設定したディレクトリを作り、パーミッションを変更します。
# mkdir /var/spool/filter
# chmod 770 /var/spool/filter
# chmod 500 /usr/local/etc/sa_filter.sh
# chown filter:filter /usr/local/etc/sa_filter.sh /var/spool/filter



Postfixの設定ファイル(master.cf)のsmtp行を下記のように書き換えます。(SMTP経由のみフィルター)

# ee /usr/local/etc/postfix/master.cf

smtp inet n - n - - smtpd
-o content_filter=filter:dummy
# SpamAssassin Filter
filter unix - n n - - pipe
user=filter argv=/usr/local/etc/sa_filter.sh -f ${sender} -- ${recipient}
↑の空白は、非常に意味がある。dummyは、いらないかも?


# ee /etc/rc.conf

spamd_enable="YES"
spamd_flags="-C /usr/local/etc/mail/spamassassin/local.cf -s /var/log/spamd.log"





ここまでで 迷惑メール対策終了









「Clam AV」の設定。

# chmod 644 /usr/local/etc/clamd.conf <= 設定ファイルに書き込み権限付加
# ee /usr/local/etc/clamd.conf <= 設定ファイルの編集
#LogTime

LogTime yes <= ログファイルに日付と時間を加える

LocalSocket /var/run/clamav/clamd

LocalSocket /var/run/clamav/clamd.sock <= 変更

AllowSupplementaryGroups

AllowSupplementaryGroups yes <= グループ権限も移行させる

ScanMail

ScanMail yes <= メールスキャナを有効にする





「freshclam」の設定

# chmod 644 /usr/local/etc/freshclam.conf <= 設定ファイルに書き込み権限付加

# ee /usr/local/etc/freshclam.conf <= 設定ファイルの編集

AllowSupplementaryGroups

AllowSupplementaryGroups yes <= グループ権限も移行させる

NotifyClamd

NotifyClamd /usr/local/etc/clamd.conf



#ee /etc/rc.conf
clamav_clamd_enable="YES"
clamav_freshclam_enable="YES"







「amavisd-new」の設定

# chmod 644 /usr/local/etc/amavisd.conf <= 設定ファイルに書き込み権限付加

# ee /usr/local/etc/amavisd.conf <= 設定ファイルの編集

# @bypass_spam_checks_maps = (1); # uncomment to DISABLE anti-spam code

@bypass_spam_checks_maps = (1); # uncomment to DISABLE anti-spam code

$QUARANTINEDIR = '/var/virusmails'; # -Q <= ウィルス等と判断したメールを隔離するディレクトリ

$mydomain = 'example.com'; # a convenient default for other settings

$mydomain = 'crimson-snow.net'; # a convenient default for other settings <= ドメインを指定

# $myhostname = 'host.example.com'; # must be a fully-qualified domain name!

$myhostname = 'FreeBSD.crimson-snow.net'; # must be a fully-qualified domain name! <= ホスト名を記述

$virus_admin = "virusalert@$mydomain"; # notifications recip.

$virus_admin = "root@$mydomain"; # notifications recip. <= ウィルス検出時の通知先アドレスを指定


# $notify_method = 'smtp:[127.0.0.1]:10025';
# $forward_method = 'smtp:[127.0.0.1]:10025'; # set to undef with milter!

$notify_method = 'smtp:[127.0.0.1]:10025'; <= コメント解除
$forward_method = 'smtp:[127.0.0.1]:10025'; # set to undef with milter! <= コメント解除

以下の設定を追加し、ウィルスやスパムメールの処理を決める(詳細は後述)
$final_virus_destiny = D_DISCARD; ウィルスメールの最終的な処理方法。
$final_banned_destiny = D_BOUNCE;(禁止された)メールの最終的な処理方法。
$final_spam_destiny = D_PASS;($sa_kill_level_deflt以上のスコア)の最終的な処理方法。
$final_bad_header_destiny = D_PASS;ヘッダにASCII以外の文字が含まれているメール(Bad Header)の最終的な処理方法。

D_DISCARD メールは受信者に配送せず、送信者にも通知しない。

$warnvirussender = 0;
$warnspamsender = 0;
$warnbannedsender = 0;
$warnbadhsender = 0;


「Clam AV」に関する部分のコメントを解除し、sockファイルを「Clam AV」の設定と合わせる

# ### http://www.clamav.net/
['ClamAV-clamd',
&ask_daemon, ["CONTSCAN {}n", "/var/run/clamav/clamd.sock"],
qr/bOK$/, qr/bFOUND$/,
qr/^.*?: (?!Infected Archive)(.*) FOUND$/ ],






「Clam AV」の再設定

「amavisd-new」と「Clam AV」の実行ユーザを同じにする必要がある為、
再び「Clam AV」を設定し、「Clam AV」の実行ユーザを変更します。
また、それに合わせてディレクトリのオーナを「amavisd-new」の実行ユーザに変更します。

# ee /usr/local/etc/clamd.conf

User clamav

User vscan <= 「amavisd-new」の実行ユーザに合わせる


# chown -R vscan:vscan /var/run/clamav <= オーナの変更
# chown -R vscan:vscan /var/log/clamav <= オーナの変更
# chmod 770 /var/run/clamav
パーミッションを777に変更しておく
# rm /var/log/clamav/clamd.log



# ee /etc/rc.conf
amavisd_enable="YES"




main.cfの設定

FreeBSD# vi /usr/local/etc/postfix/main.cf <= 設定ファイルの編集
content_filter = smtp-amavis:[127.0.0.1]:10024 <= 追加


master.cfの設定

FreeBSD# vi /usr/local/etc/postfix/master.cf <= 設定ファイルの編集
以下を追加( -o の前の空白はTABにする必要あり)

smtp-amavis unix - - n - 2 smtp
-o smtp_data_done_timeout=1200
-o disable_dns_lookups=yes

127.0.0.1:10025 inet n - n - - smtpd
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_client_restrictions=
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks=127.0.0.0/8
-o strict_rfc821_envelopes=yes

「Postfix」の設定をリロードします。
FreeBSD# /usr/local/sbin/postfix reload




スパムメールの手動での学習

SpamAssassin は受け取ったメールからスパムメールを自動的に学習するが、
誤判定されたメールを手動で振り分けて学習させることもできる。

手動で振り分けるためのメールボックスを2つ作成する。

* ハムと誤判定されたスパムメールを保存するための spam (~/Maildir/.spam/)
* スパムと誤判定されたハムメール(正常のメール)を保存するための ham (~/Maildir/.ham/)


SpamAssassin には、スパム/ハムメールを学習させるための sa-learn というスクリプトが用意されている。
スパム/ハムメールを振り分けたメールボックスをそれぞれ ~/Maildir/.spam/、 ~/Maildir/.ham/ とするとき、
shell から以下のように指定して起動する。

sa-learn --spam ~/Maildir/.spam/cur # スパムメールと学習させる
sa-learn --ham ~/Maildir/.ham/cur # ハムメールと学習させる














































































☆☆☆☆☆   こんな記事もあります。   ☆☆☆☆☆

NO5 sshの設定
起動時間を短縮
音を出す。
Webmin文字化け修正
印刷
スパム ウィルス 撃退
webdavを利用する
apache22のキャッシュ機能を利用してみる
インプレッション         インプレッションを書く

Copyright 2006B-CITY. All rights reserved.