著者はRocky8にて、OSロケールを日本語に設定(LANG=ja_JP.utf8)しており、
fail2banを動作させている。
[状況]
以下の設定/条件において、通知メールのメール本文が文字化けを起こす
・fail2banの設定で、ban確定IPアドレスのwhois結果をメール通知設定
(action = %(action_mw)s)
・banIPが日本(JPNIC)管理のIPアドレスの場合
fail2banの通知メール(テンプレート)は、英語表記だが、
日本(JPRS database)のwhoisサーバーで検索すると、whois結果は日本語で表示される
結果、メール本文(whois結果の部分)が文字化けを起こす
[対処方法]
日本(JPRS database)のwhoisサーバーで検索時は、/e 引数を追加すれば結果は英語表記となるが、
/e 引数が世界標準かは未調査。
日本人としては、せっかく日本語表記となっているので、通知メール(テンプレート)側で対応した。
・「Content-Type: text/plain; charset="UTF-8"」を追記
action.d/sendmail-whois.conf
actionban = printf %%b "Subject: [Fail2Ban] : banned from
Date: `LC_ALL=C date +"%%a, %%d %%h %%Y %%T %%z"`
From: <>
To:
Content-Type: text/plain; charset=\"UTF-8\"
\n
Hi,\n
The IP has just been banned by Fail2Ban after
attempts against .\n\n
Here is more information about :\n
`%(_whois_command)s`\n
Regards,\n
Fail2Ban" |