SquirrelMailの導入(CentOS編)
おやじは、今までSquirrelMailというPHPベースのWebメールを使用していましたが、CentOSにもRPMが用意されているのでそれを使用することにしました。
■しかくSquirrelMail導入のための必要条件
SquirrelMailを導入するための必要条件は下記のとおりです。
- SquirrelMailはPHPベースなので、PHPが使える環境が必要である。日本語環境で使用するには、mbstringが有効になっていなければならないが、デフォルトではmbstringはインストールされないので別途インストールが必要。ApacheのPHP対応については、こちらを参照のこと。
- 連携するためのimapサーバが必要である。最終的にはmobileimapとの関係でおやじはCourier-imapを使用したが、imapサーバとしては、cyrus、uw、exchange、courier、macosx他に対応しており、CentOS標準のDovecotでも問題はなく、SqurrelMail上の扱いはデフォルトのuw-imap相当で問題ない。なお、imapサーバは必ずしもSquirrelMailと同一のサーバである必要はない。sslも使用できるので、外部サーバであればこちらを利用すると良い。おやじは同じサーバ内なので未使用。
■しかくSqirrelMailのインストールと設定
SqirrelMailのインストールにあたって、WebサーバはPHP対応(mbstring含む)になっているものとします。ApacheのPHP対応については、
こちらを参照ください。
◆だいやまーくSquirrelMailのインストール
CentoOSではSquirrelMailのRPMが用意されているので、Yumで簡単にインストールできます。
# yum install squirrelmail
◆だいやまーくSquirrelMailの設定
SquirrelMailには設定ツールが用意されているので、それを使用して順次設定していきます。ここでは、IMAPサーバとしてCourier-IMAPを使うことで記述してます。
- 以下によりツールを起動する。
# /usr/share/squirrelmail/config/conf.pl
- ツールが起動すると以下のような画面が表示されるので、まずはOrganization
Preferencesで基本的な設定を行うため、1を選択する。
SquirrelMail Configuration : Read: config_default.php (1.4.0)
---------------------------------------------------------
Main Menu --
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books (LDAP)
7. Message of the Day (MOTD)
8. Plugins
9. Database
D. Set pre-defined settings for specific IMAP servers
C. Turn color on
S Save data
Q Quit
Command >> 1[Enter]
CentOSの場合、起動しても下記のようにパラメータが見えないので、カラー切り替えのため「C」を入力してEnterする。(入力してもエコーは見えないのでそのままEnterすること。)
: Read: config_default.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1. Organization Name :
2. Organization Logo :
3. Org. Logo Width/Height :
4. Organization Title :
5. Signout Page :
6. Default Language :
7. Top Frame :
8. Provider link :
9. Provider name
:
R Return to Main Menu
C. Turn color off
S Save data
Q Quit
Command >> C[Enter] ← 実際には見えない。
- 下記のような画面が表示されるので、default languageを選択(6を選択)し、ja_JPに変更する。 変更後 r
でメインメニューに戻る。
SquirrelMail Configuration : Read: config_default.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1. Organization Name : SquirrelMail
2. Organization Logo : ../images/sm_logo.png
3. Org. Logo Width/Height : (308/111)
4. Organization Title : SquirrelMail $version
5. Signout Page :
6. Default Language : en_US
7. Top Frame : _top
8. Provider link : http://www.squirrelmail.org/
9. Provider name
: SquirrelMail
R Return to Main Menu
C. Turn color on
S Save data
Q Quit
Command >> 6[Enter]
SquirrelMail attempts to set the language in many ways. If it
can not figure it out in another way, it will default to this
language. Please use the code for the desired language.
[en_US]: ja_JP[Enter]
SquirrelMail Configuration : Read: config_default.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1. Organization Name : SquirrelMail
2. Organization Logo : ../images/sm_logo.png
3. Org. Logo Width/Height : (308/111)
4. Organization Title : SquirrelMail $version
5. Signout Page :
6. Default Language : ja_JP
7. Top Frame : _top
8. Provider link : http://www.squirrelmail.org/
9. Provider name
: SquirrelMail
R Return to Main Menu
C. Turn color on
S Save data
Q Quit
Command >> r[Enter]
- 同様に以降も設定していく。メインメニューで、Server Settings(2を選択)でドメイン名とSMTPの変更およびIMAPサーバ(デフォルトはwu)の設定を行う。
SquirrelMail Configuration : Read: config_default.php (1.4.0)
---------------------------------------------------------
Server Settings
General
-------
1. Domain : mydomain.com
2. Invert Time : false
3. Sendmail or SMTP : Sendmail
A. Update IMAP Settings : localhost:143 (uw)
B. Change Sendmail Config : /usr/sbin/sendmail
R Return to Main Menu
C. Turn color on
S Save data
Q Quit
Command >> 1[Enter]
The domain name is the suffix at the end of all email addresses. If
for example, your email address is jdoe@myorg.com, then your domain
would be myorg.com.
[mydomain.com]: mail.aconus.com[Enter]
SquirrelMail Configuration : Read: config_default.php (1.4.0)
---------------------------------------------------------
Server Settings
General
-------
1. Domain
: mail.aconus.com
2. Invert Time : false
3. Sendmail or SMTP : Sendmail
A. Update IMAP Settings : localhost:143 (wu)
B. Change Sendmail Config : /usr/sbin/sendmail
R Return to Main Menu
C. Turn color on
S Save data
Q Quit
Command >> 3[Enter]
You now need to choose the method that you will use for sending
messages in SquirrelMail. You can either connect to an SMTP server
or use sendmail directly.
1. Sendmail
2. SMTP
Your choice [1/2] [1]: 2[Enter]
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Server Settings
General
-------
1. Domain : mail.aconus.com
2. Invert Time : false
3. Sendmail or SMTP : SMTP
A. Update IMAP Settings : localhost:143 (wu)
B. Update SMTP Settings : localhost:25
R Return to Main Menu
C. Turn color on
S Save data
Q Quit
Command >> a[Enter]
SquirrelMail Configuration : Read: config_default.php (1.4.0)
---------------------------------------------------------
Server Settings
General
-------
1. Domain
: mail.aconus.com
2. Invert Time : false
3. Sendmail or SMTP : SMTP
IMAP Settings
--------------
4. IMAP Server : localhost
5. IMAP Port : 143
6. Authentication type : login
7. Secure IMAP (TLS) : false
8. Server software : wu
9. Delimiter : detect
B. Update SMTP Settings : localhost:25
H. Hide IMAP Server Settings
R Return to Main Menu
C. Turn color on
S Save data
Q Quit
Command >> 8[Enter]
Each IMAP server has its own quirks. As much as we tried to stick
to standards, it doesn't help much if the IMAP server doesn't follow
the same principles. We have made some work-arounds for some of
these servers. If you would like to use them, please select your
IMAP server. If you do not wish to use these work-arounds, you can
set this to "other", and none will be used.
cyrus = Cyrus IMAP server
uw = University of Washington's IMAP server
exchange = Microsoft Exchange IMAP server
courier = Courier IMAP server
macosx = Mac OS X Mailserver
other = Not one of the above servers
[wu]: courier[Enter]
SquirrelMail Configuration : Read: config_default.php (1.4.0)
---------------------------------------------------------
Server Settings
General
-------
1. Domain : www.aconus.com
2. Invert Time : false
3. Sendmail or SMTP : SMTP
IMAP Settings
--------------
4. IMAP Server : localhost
5. IMAP Port : 143
6. Authentication type : login
7. Secure IMAP (TLS) : false
8. Server software : courier
9. Delimiter : detect
B. Update SMTP Settings : localhost:25
H. Hide IMAP Server Settings
R Return to Main Menu
C. Turn color on
S Save data
Q Quit
Command >> r[Enter]
- メインメニューで、General Options(4を選択)でDefault Charsetの変更(iso-8859-1 ->
iso-2022-jp)を行う。
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
General Options
1. Default Charset :
iso-8859-1
2. Data Directory :
/var/lib/squirrelmail/prefs/
3. Attachment Directory : /var/spool/squirrelmail/attach/
4. Directory Hash Level : 0
5. Default Left Size : 150
6. Usernames in Lowercase : false
7. Allow use of priority : true
8. Hide SM attributions : false
9. Allow use of receipts : true
10. Allow editing of identity : true/true
11. Allow server thread sort : true
12. Allow server-side sorting : true
13. Allow server charset search : true
14. Enable UID support : true
15. PHP session name : SQMSESSID
R Return to Main Menu
C. Turn color on
S Save data
Q Quit
Command >> 1[Enter]
This option controls what character set is used when sending
mail and when sending HTML to the browser. Do not set this
to US-ASCII, use ISO-8859-1 instead. For cyrillic, it is best
to use KOI8-R, since this implementation is faster than most
of the alternatives
[iso-8859-1]: iso-2022-jp[Enter]
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
General Options
1. Default Charset :
iso-8859-1
2. Data Directory :
/var/lib/squirrelmail/prefs/
3. Attachment Directory : /var/spool/squirrelmail/attach/
4. Directory Hash Level : 0
5. Default Left Size : 150
6. Usernames in Lowercase : false
7. Allow use of priority : true
8. Hide SM attributions : false
9. Allow use of receipts : true
10. Allow editing of identity : true/true
11. Allow server thread sort : true
12. Allow server-side sorting : true
13. Allow server charset search : true
14. Enable UID support : true
15. PHP session name : SQMSESSID
R Return to Main Menu
C. Turn color on
S Save data
Q Quit
Command >> r[Enter]
- 最後にデータをセーブ(sを入力)し、qを入力してconfigureは終了。
後はブラウザから、
http://www.aconus.com/webmail/
と起動し、imapサーバのユーザとパスワードでログインできればおしまいです。特に難しいことも無く動作し、文字化け等もないようです。
なお、アクセスを「webmail」から変更したい場合は、Apacheの/etc/httpd/conf.d/squirrelmail.conf
を下記のように編集することで変更(ex. webmail → squirrelmail)できます。
#Alias /webmail /usr/share/squirrelmail
Alias /squirrelmail /usr/share/squirrelmail
■しかくセキュリィティ対策
外部からアクセスするのに生では危険なので、httpでアクセスしてきたらhttpsにredirectするようにしました。当然のこととしてhttpsに対応していなければなりませんが、対処方法としては以下の3点ぐらいがあると思います。
- login.phpでredirectする方法
SqWebMailはconfigure時に指定すれば設定できたが、SquirreMailにはそのようなオプションが無いので、index.phpを下記のように変更(赤字を追加)して対応した。ホスト名は各自の環境に合わせてること。ssl化のためのpluginもあるようですが、こちらが簡単だったので・・・。
# vi /usr/share/squirrelmail/login.php
<?php
/**
*
index.php -- Displays the main frameset
*
*
Copyright (c) 1999-2003 The SquirrelMail Project Team
*
Licensed under the GNU GPL. For full terms see the file
COPYING.
*
* Redirects to the login page.
*
* $Id: index.php,v 1.14 2002年12月31日 12:49:29 kink Exp
$
*/
header("Location: https://www.aconus.com/webmail/src/login.php\n\n");
exit();
?>
[Esc]、[:]、[w]、[q]で保存。
- mod_rewriteによる方法
こちらにある方法でhttpsにredirectする。設定する場所は、環境に合わせること。通常はデフォルトサーバか非httpsのバーチャルサーバのはずである。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteLog
"logs/rewrite_log"
RewriteLogLevel
0
RewriteCond %{SERVER_PORT}
!^443$
RewriteRule ^/webmail/(.*)?$
https://%{HTTP_HOST}/webmail/1ドル
[L,R]
</IfModule>
- Redirect/RedirectMatchディレクティブによる方法
デフォルトサーバか非httpsのバーチャルサーバ内で下記設定を行うことにより、httpsにredirectする。無限ループしてしまうので、間違ってもhttps用バーチャルサーバに書かないこと。また、ホスト名は各自の環境に合わせること。
Redirect permanent /webmail https://www.aconus.com/webmail
または
RedirectMatch permanent ^/webmail/(.*)?$ https://www.aconus.com/webmail/1ドル
Top Pageへ