ubuntu 10.04 をメールサーバーに (PostfixAdmin 設定編)

先日の記事で ubuntu 10.04 LTS Server Edition に、PostfixAdmin とそれを動かすのに必要なパッケージをインストールした。
しかしまだ単にインストールしただけなので、このままではまともに動かすことはできない。
引き続き PostfixAdmin を動かすための設定を行っていく。

先日の記事の最後で、PostfixAdmin のインストール中に選択、入力したデータベース関係の設定が /etc/postfixadmin/config.inc.php ファイルに書き込まれ、保存されていると書いた。
その他にも多くのパラメーターが /etc/postfixadmin/config.inc.php ファイルに書かれているので、これらのパラメーターを適切に編集していくことにする。

ただし、/etc/postfixadmin/config.inc.php ファイルを直接編集すると、今後 PostfixAdmin をアップグレードすることがあったときに書き換えられる可能性があるので、/etc/postfixadmin/config.local.php ファイルを作成してそこに記述、編集するようにする。
何故 /etc/postfixadmin/config.local.php ファイルかという理由は、以下に挙げるように /etc/postfixadmin/config.inc.php ファイルの最後の方の行を見れば分かる。

// If you want to keep most settings at default values and/or want to ensure
// that future updates work without problems, you can use a separate config
// file (config.local.php) instead of editing this file and override some
// settings there.
if (file_exists(dirname(__FILE__) . '/config.local.php')) {
    include(dirname(__FILE__) . '/config.local.php');
}

//
// END OF CONFIG FILE
//

なお、/etc/postfixadmin/config.inc.php ファイルが PostfixAdmin のアップグレードで書き換えられる可能性を考慮すると、データベースに関する設定も /etc/postfixadmin/config.local.php ファイルに書き写しておく方が良いだろう。
それ以外の設定については、/etc/postfixadmin/config.inc.php ファイルの該当する行を /etc/postfixadmin/config.local.php ファイルに転記して修正する。
特に変更しなくても良さそうな設定については、/etc/postfixadmin/config.local.php ファイルに転記せず、そのままにしておく。

個々の修正内容を解説するとかなりの量になるので、今回作成した /etc/postfixadmin/config.local.php ファイルを以下に挙げておくことにする。
このファイルでポイントになるのは $CONF['encrypt'] = ‘creartext’ の箇所だ。
この値を ‘creartext’ 以外にすると、SMTP 認証などで使うハッシュの種類 (認証メカニズム) が限定されてしまう。

具体的には $CONF['encrypt'] を ‘creartext’ 以外にすると、CRAM-MD5 や DIGEST-MD5 などが使えなくなる。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php

$CONF['configured'] = true;

// Postfix Admin Path
// Set the location of your Postfix Admin installation here.
// YOU MUST ENTER THE COMPLETE URL e.g. http://domain.tld/postfixadmin
$CONF['postfix_admin_url'] = 'http://***.compnet.jp/postfixadmin';

// Language config
// Language files are located in './languages', change as required..
$CONF['default_language'] = 'ja';

// Database Config
$CONF['database_type'] = 'mysql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfixadmin';
$CONF['database_password'] = '************';
$CONF['database_name'] = 'postfixadmin';


// Site Admin
// Define the Site Admins email address below.
// This will be used to send emails from to create mailboxes.
$CONF['admin_email'] = 'postmaster@compnet.jp';

// Encrypt
// In what way do you want the passwords to be crypted?
// md5crypt = internal postfix admin md5
// md5 = md5 sum of the password
// system = whatever you have set as your PHP system default
// cleartext = clear text passwords (ouch!)
// mysql_encrypt = useful for PAM integration
// authlib = support for courier-authlib style passwords
// dovecot:CRYPT-METHOD = use dovecotpw -s 'CRYPT-METHOD'. Example: dovecot:CRAM-MD5
$CONF['encrypt'] = 'cleartext';

// Page Size
// Set the number of entries that you would like to see
// in one page.
$CONF['page_size'] = '20';

// Default Aliases
// The default aliases that need to be created for all domains.
$CONF['default_aliases'] = array (
    'abuse' => 'abuse',
    'hostmaster' => 'hostmaster',
    'postmaster' => 'postmaster',
    'webmaster' => 'webmaster'
);

// Mailboxes
// If you want to store the mailboxes per domain set this to 'YES'.
// Examples:
//   YES: /usr/local/virtual/domain.tld/username@domain.tld
//   NO:  /usr/local/virtual/username@domain.tld
$CONF['domain_path'] = 'NO';
// If you don't want to have the domain in your mailbox set this to 'NO'.
// Examples:
//   YES: /usr/local/virtual/domain.tld/username@domain.tld
//   NO:  /usr/local/virtual/domain.tld/username
// Note: If $CONF['domain_path'] is set to NO, this setting will be forced to YES.
$CONF['domain_in_mailbox'] = 'YES';

// Default Domain Values
// Specify your default values below. Quota in MB.
$CONF['aliases'] = '10';
$CONF['mailboxes'] = '10';
$CONF['maxquota'] = '512';

// Quota
// When you want to enforce quota for your mailbox users set this to 'YES'.
$CONF['quota'] = 'NO';

// Virtual Vacation
// If you want to use virtual vacation for you mailbox users set this to 'YES'.
// NOTE: Make sure that you install the vacation module. (See VIRTUAL-VACATION/)
$CONF['vacation'] = 'NO';

// Alias Control
// Postfix Admin inserts an alias in the alias table for every mailbox it creates.
// The reason for this is that when you want catch-all and normal mailboxes
// to work you need to have the mailbox replicated in the alias table.
// If you want to take control of these aliases as well set this to 'YES'.
$CONF['alias_control'] = 'YES';

// Alias Control for admins
// Set to 'NO' if your domain admins shouldn't be able to edit user aliases.
$CONF['alias_control_admin'] = 'YES';

// Special Alias Control
// Set to 'NO' if your domain admins shouldn't be able to edit default aliases.
$CONF['special_alias_control'] = 'YES';


// Send Mail
// If you don't want sendmail tab set this to 'NO';
$CONF['sendmail'] = 'NO';

// Fetchmail
// If you don't want fetchmail tab set this to 'NO';
$CONF['fetchmail'] = 'NO';

// Footer
// Below information will be on all pages.
// If you don't want the footer information to appear set this to 'NO'.
$CONF['show_footer_text'] = 'YES';
$CONF['footer_text'] = 'Return to Main of Web site for compnet.jp';
$CONF['footer_link'] = 'http://www.conpmet.jp/';

// When creating mailboxes or aliases, check that the domain-part of the
// address is legal by performing a name server look-up.
$CONF['emailcheck_resolve_domain'] = 'NO';
PostfixAdmin の Web インターフェースの URL ($CONF['postfix_admin_url'] の値) と、MySQL に接続するときのパスワード ($CONF[]‘database_password’] の値) は伏せ字にした

作成した /etc/postfixadmin/config.local.php ファイルの所有者とアクセス権を、/etc/postfixadmin/config.inc.php ファイルと同じにするため、以下のコマンドを実行しておく。

~$ sudo chown root.www-data /etc/postfixadmin/config.local.php
~$ sudo chmod u=rw,g=r,o= /etc/postfixadmin/config.local.php

設定ファイルの修正ができたところで、続いてインストールした PostfixAdmin の Web インターフェースを有効にしよう。

Web インターフェースのための Web サーバーとして Lighttpd をインストールしておいた。
PostfixAdmin の Web インターフェースは Web サーバーの CGI を使って動作するので、まずは Lighttpd のCGI を有効にする。
そして PostfixAdmin の Web インターフェースのコンテンツファイルのディレクトリを Lighttpd に指示したら、Lighttpd に設定を読み込ませる。

~$ sudo lighttpd-enable-mod fastcgi
~$ sudo ln -s /etc/postfixadmin/lighttpd.conf /etc/lighttpd/conf-enabled/99-postfixadmin.conf
~$ sudo service lighttpd force-reload

上に書いたコマンドを実行した瞬間から、PostfixAdmin の Web インターフェースが有効になる。
PostfixAdmin の設定が全て終わったわけではないが、外部からの無用なアクセスを許さないように、セキュリティをしっかり確保しておこう(セキュリティについてはここに書かないのが、きちんと対処してあるものとする。)

ここまでくれば、PostfixAdmin の設定も残すは僅かだ。
Web ブラウザを使って Lighttpd の Web インターフェースにアクセスする。
ただし、接続する URL は Web インターフェースの URL に ‘/setup.php’ を繋げたものだ。
Web インターフェースの URL が http://****.compnet.jp/postfixadmin なら http://****.compnet.jp/postfixadmin/setup.php になる。

ところでちょっと待って欲しい。
Web ブラウザでその URL に接続する前にひとつだけやっておこことがある。
この URL に接続すると、PostfixAdmin がメールアカウントなどを登録するためのデータベースが構築されるのだが、なぜかテーブルの文字セットをわざわざ ‘latin1′ にして構築してしまう。
データベースに登録する情報がメールアカウントだけなら ‘latin1′ でも問題にはならないが、このままでは備考欄などに漢字で入力すると文字化けを起こしてしまう。

そこで、Web ブラウザで接続する前に、PostfixAdmin のスクリプトを少しだけ手直ししておく。
修正する箇所は /usr/share/postfixadmin/upgrade.php ファイルの 169 行目付近にある一行だけだ。
修正前と後を diff コマンドで比較した結果を以下に挙げておく。

~$ diff -c /usr/share/postfixadmin/upgrade.php.orig /usr/share/postfixadmin/upgrade.php
*** /usr/share/postfixadmin/upgrade.php.orig    2009-10-25 04:44:32.000000000 +0900
--- /usr/share/postfixadmin/upgrade.php         2010-07-10 06:23:56.172941097 +0900
***************
*** 166,172 ****
                  '{FULLTEXT}'        => 'FULLTEXT',
                  '{BOOLEAN}'         => 'tinyint(1) NOT NULL',
                  '{UTF-8}'           => '/*!40100 CHARACTER SET utf8 */',
!                 '{LATIN1}'          => '/*!40100 CHARACTER SET latin1 */',
                  '{IF_NOT_EXISTS}'   => 'IF NOT EXISTS',
                  '{RENAME_COLUMN}'   => 'CHANGE COLUMN',
                  '{MYISAM}'          => 'ENGINE=MyISAM',
--- 166,172 ----
                  '{FULLTEXT}'        => 'FULLTEXT',
                  '{BOOLEAN}'         => 'tinyint(1) NOT NULL',
                  '{UTF-8}'           => '/*!40100 CHARACTER SET utf8 */',
!                 '{LATIN1}'          => '/*!40100 CHARACTER SET utf8*/',
                  '{IF_NOT_EXISTS}'   => 'IF NOT EXISTS',
                  '{RENAME_COLUMN}'   => 'CHANGE COLUMN',
                  '{MYISAM}'          => 'ENGINE=MyISAM',

/usr/share/postfixadmin/upgrade.php ファイルを修正したら、Web ブラウザで http://****.compnet.jp/postfixadmin/setup.php に接続する。
すると PostfixAdmin の設定をチェックして、メールアカウントを登録するためのデータベースが構築される。

postfixadmin_setup_php

最後に /usr/share/postfixadmin/setup.php ファイルの名前を変えておく。
これは間違えて http://****.compnet.jp/postfixadmin/setup.php にアクセスされたときのことを考えてのことだ。
再セットアップすることを考えないのであれば、/usr/share/postfixadmin/setup.php ファイルを削除してしまっても良いだろう。
ファイルの名前を変更するときは、拡張子を.php 以外にしておく方が良い。
ここでは /usr/share/postfixadmin/setup.php_orig に名前を変えておく。

~$ sudo mv /usr/share/postfixadmin/setup.php /usr/share/postfixadmin/setup.php_orig

最後に、PostfixAdmin に管理者としてログインするユーザーを登録するだけだ。
この最初の管理者ユーザーだけは MySQL で直接登録する必要があるので、以下のコマンドを使って登録する。

~$ echo "INSERT INTO admin (username, password, active) VALUES ('adminuser', 'passward', '1');" | mysql -u root -p postfixadmin
~$ echo "INSERT INTO domain_admins (username, domain, active) VALUES ('adminuser', 'ALL', '1');" | mysql -u root -p postfixadmin
adminuser は管理者としてログインするユーザー名、passward はそのパスワード。
なお、passward は、/etc/postfixadmin/config.local.php ファイルで $CONF['encrypt'] を ‘cleartext’ にしているので、暗号せず平文のままにしておく。

それぞれの行の実行毎に ‘Enter Password:’ のプロンプトが表示されるので、MySQL をインストールしたときに設定した MySQL の root ユーザーのパスワード (ubuntu の root ユーザーではない) を入力して、Enter を押す。

これで PostfixAdmin のインストールと設定がすべて終わった。
以後は Web ブラウザで http://****.compnet.jp/postfixadmin に接続して、MySQL に直接登録した管理者ユーザーでログインすれば、メールアカウントの管理ができる。

関連する記事 (Related posts):

  1. CentOS 5.6 をメールサーバーに (PostfixAdmin のインストール)
  2. ubuntu 10.04 をメールサーバーに (PostfixAdmin インストール編)
  3. ubuntu 10.04 をメールサーバーに (Postfix と PostfixAdmin の連携)
  4. ubuntu 10.04 をメールサーバーに (Dovecot 編)
  5. ubuntu 10.04 をメールサーバーに (グレイリスティング – Postgrey)

8 comments to ubuntu 10.04 をメールサーバーに (PostfixAdmin 設定編)

  • ubu003

    何度も長文のコメントを付けてしまい、すみません。
    /etc/lighttpd/lighttpd.conf
    を確認すると
       "mod_fastcgi",
       "mod_cgi",
    が有効になっていないように見えますが、これでよいのでしょうか。
    less /etc/lighttpd/lighttpd.conf
    server.modules = (
            "mod_access",
            "mod_alias",
            "mod_compress",
            "mod_redirect",
    #       "mod_rewrite",
    )
    server.document-root        = "/var/www"
    server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
    server.errorlog             = "/var/log/lighttpd/error.log"
    server.pid-file             = "/var/run/lighttpd.pid"
    server.username             = "www-data"
    server.groupname            = "www-data"
    index-file.names            = ( "index.php", "index.html",
                                    "index.htm", "default.htm",
                                   " index.lighttpd.html" )
    url.access-deny             = ( "~", ".inc" )
    static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
    ## Use ipv6 if available
    #include_shell "/usr/share/lighttpd/use-ipv6.pl"
    dir-listing.encoding        = "utf-8"
    server.dir-listing          = "enable"
    compress.cache-dir          = "/var/cache/lighttpd/compress/"
    compress.filetype           = ( "application/x-javascript", "text/css", "text/html", "text/plain" )
    include_shell "/usr/share/lighttpd/create-mime.assign.pl"
    include_shell "/usr/share/lighttpd/include-conf-enabled.pl"
    /etc/lighttpd/lighttpd.conf (END)
     
    ちなみにcgiを有効化するコマンドの実行結果は以下の通り。
    すでに有効。となっています。
    sudo lighttpd-enable-mod fastcgi
    Available modules: auth accesslog cgi evasive evhost expire fastcgi flv-streaming no-www proxy rrdtool simple-vhost ssi ssl status userdir usertrack fastcgi-php debian-doc
    Already enabled modules: fastcgi postfixadmin
    Enabling fastcgi: already enabled
    Run /etc/init.d/lighttpd force-reload to enable changes
    以上、よろしくお願いします。

    • 返答が大変遅くなりました。

      再検証せずに回答しますが、ざっと確認したところ lighttpd で fastcgi だけが有効になっていました。
      具体的には /etc/lighttpd/conf-enabled には 10-fastcgi.conf と 99-postfixadmin.conf の二つのファイルだけが存在しています。

      ご迷惑をおかけしていますように、自身でもこの記事の記載に色々と漏れがあるような気がして仕方ありません。
      いつまでという保証はできませんが、後日 再検証して記事を書き直そうと思います。

  • ubu003

    さっそくご回答いただいた上に、再検証まで実施いただき、ありがとうございます。

    まず、ログの確認を行いました。
    なぜか、access.logは作成されていませんでした。
    少なくとも
    http://*****.local/index.lighttpd.html
    にはアクセスできていたので、このあたりに原因があるのかもしれません。

    error.logは以下の通りで、何か関係があるようなエントリがあるようには見えませんでした。
    (ntpの設定をしてないので時刻がずれてます)
    less error.log
    2011-11-23 22:29:37: (log.c.166) server started
    2011-11-24 03:38:33: (server.c.1396) [note] graceful shutdown started
    2011-11-24 03:38:33: (log.c.166) server started
    2011-11-24 03:38:33: (server.c.1512) server stopped by UID = 0 PID = 30980
    2011-11-24 04:17:03: (server.c.1396) [note] graceful shutdown started
    2011-11-24 04:17:03: (log.c.166) server started
    2011-11-24 04:17:03: (server.c.1512) server stopped by UID = 0 PID = 31099
    次にシンボリックリンクの確認ですが、ファイルは正常に作成されているように見えます。
    /etc/lighttpd/conf-enabled/99-postfixadmin.conf
    ls- l 99-postfixadmin.conf
    lrwxrwxrwx 1 root root 31 2011-11-24 03:26 99-postfixadmin.conf -> /etc/postfixadmin/lighttpd.conf
    less 99-postfixadmin.conf
    # Alias for Postfixadmin
    alias.url += (
            "/postfixadmin" => "/usr/share/postfixadmin",
    )

    続いて、2回目にいただいたコメントについて確認を行いました。
    > PostfixAdmin は最新の 2.3.4 を使ったところ、/etc/lighttpd/conf-enable/99-postfixadmin.conf ファイルが作成されないようです。
    申し遅れましたが、当方もPostfixAdmin 2.3.4で構築しております。
    /etc/lighttpd/conf-enable
    → /etc/lighttpd/conf-enabled
    の誤記であれば、上述の通り99-postfixadmin.confは作成されています。
    誤記でないのであれば、当方の環境では
    /etc/lighttpd/conf-enable
    というディレクトリは存在しておりません。
     
    また
    /etc/lighttpd/conf-available/postfixadmin
    というファイルは存在しませんでした。
    /etc/lighttpd/conf-available# ls -l
    total 80
    -rw-r–r– 1 root root 843 2010-08-19 08:24 05-auth.conf
    -rw-r–r– 1 root root  91 2010-06-01 05:20 10-accesslog.conf
    -rw-r–r– 1 root root 347 2010-08-19 08:24 10-cgi.conf
    -rw-r–r– 1 root root  36 2010-11-08 08:43 10-evasive.conf
    -rw-r–r– 1 root root 128 2010-06-01 05:20 10-evhost.conf
    -rw-r–r– 1 root root 104 2010-08-19 08:24 10-expire.conf
    -rw-r–r– 1 root root 181 2010-08-19 08:24 10-fastcgi.conf
    -rw-r–r– 1 root root  42 2010-11-08 08:43 10-flv-streaming.conf
    -rw-r–r– 1 root root  82 2010-06-01 05:20 10-no-www.conf
    -rw-r–r– 1 root root 853 2010-08-19 08:24 10-proxy.conf
    -rw-r–r– 1 root root 257 2010-08-19 08:24 10-rrdtool.conf
    -rw-r–r– 1 root root 402 2010-08-19 08:24 10-simple-vhost.conf
    -rw-r–r– 1 root root 103 2010-08-19 08:24 10-ssi.conf
    -rw-r–r– 1 root root 144 2010-08-19 08:24 10-ssl.conf
    -rw-r–r– 1 root root 464 2010-08-19 08:24 10-status.conf
    -rw-r–r– 1 root root 454 2010-08-19 08:24 10-userdir.conf
    -rw-r–r– 1 root root  38 2010-11-08 08:43 10-usertrack.conf
    -rw-r–r– 1 root root 539 2010-08-19 08:24 15-fastcgi-php.conf
    -rw-r–r– 1 root root 508 2010-11-08 08:43 90-debian-doc.conf
    -rw-r–r– 1 root root 843 2007-02-20 07:17 README

    手順はもれなく実施したはずですが、もしかすると何かタイプミス等あったのかもしれません。
    今後は手順を追えるように、TeraTermで常にログを保存する運用に切り替えることにします。
    とりあえず、access.logが出力されない原因を調査してみたいと思います。
    以上、よろしくお願いします。

  • ubu003

    ubuntu初心者です。
    こちらのサイトは、丁寧に手順をまとめられているので、非常に参考になります。
    いつも、ありがとうございます。
     
    VMware上にUbuntu 11.10 serverをセットアップし、手順に従い
    Postfixインストール → Postfixadminのインストールまで実施しましたが
    http://****.local/postfixadmin/setup.php
    にアクセスした際、403 – Forbiddenが返却されました。
    http://****.local/index.lighttpd.html
    は正常に表示されます。
    CGIも有効にしましたし、lighttpdの再起動も試してみましたが、状況は同じです。
    ほかに確認すべきところがございましたら、ご教示願いますと幸いです。
    以上、よろしくお願いします。

    • /var/log/lighttpd/access.log ファイルと /var/log/lighttpd/error.log ファイルに何かヒントになるようなエラー情報が記されていないでしょうか?

      状況からすると、/etc/lighttpd/conf-enablee/99-postfixadmin.conf ファイルが正しく作られていない気がします。
      このファイルは /etc/postfixadmin/lighttpd.conf へのシンボリックリンクなので、もし無ければ sudo ln -s /etc/postfixadmin/lighttpd.conf /etc/lighttpd/conf-enablee/99-postfixadmin.conf コマンドを実行してください。
      記事では ubuntu 10.04 を使っていて、ubu003 さまは 11.10 を使っているということなので、また記事の記述から少々時間も経っているため PostfixAdmin 自体もバージョンが上がっていると思います。
      これらのバージョンの差異で PostfixAdmin のインストール動作に違いがあるのかもしれません。

      • VirtualBox に ubuntu 11.10 をインストールして確認しました。
        PostfixAdmin は最新の 2.3.4 を使ったところ、/etc/lighttpd/conf-enable/99-postfixadmin.conf ファイルが作成されないようです。
        /etc/lighttpd/conf-available/postfixadmin ファイルが作成されているので、これを有効にすれば (/etc/lighttpd/conf-enable/99-postfixadmin.conf ファイルを作成すれば) 良さそうです。
        通常なら sudo lilghttpd-enable-mod コマンドで有効にできるはずですが、ファイル名が異なっているためにこれが使えません。
        上のコメントのように sudo ln -s /etc/postfixadmin/lighttpd.conf /etc/lighttpd/conf-enabled/99-postfixadmin.conf コマンドで /etc/lighttpd/conf-enabled/99-postfixadmin.conf を作成して、sudo service lighttpd restart コマンドを実行してください。

  • [...] ubuntu でメール サーバーを構築したときの PostfixAdmin の設定のときには、Web ブラウザでこの setup.php を実行する前に、upgrade.php ファイルの編集、修正が必要だった。 [...]

  • [...] ubuntu 10.04 をメールサーバーに (PostfixAdmin 設定編) [...]

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <img localsrc="" alt="">