Refactored documentation.

This commit is contained in:
Antoine Nguyen
2016-10-18 17:28:34 +02:00
parent 3decd518ad
commit e4e4e4c53c
27 changed files with 451 additions and 1182 deletions
+402
View File
@@ -0,0 +1,402 @@
.. _dovecot:
#######
Dovecot
#######
Modoboa requires Dovecot 2+ to work so the following documentation is
suitable for this combination.
In this section, we assume dovecot's configuration resides in
:file:`/etc/dovecot`, all pathes will be relative to this directory.
Mailboxes
=========
First, edit the :file:`conf.d/10-mail.conf` and set the ``mail_location``
variable::
# maildir
mail_location = maildir:~/.maildir
Then, edit the ``inbox`` namespace and add the following lines::
inbox = yes
mailbox Drafts {
auto = subscribe
special_use = \Drafts
}
mailbox Junk {
auto = subscribe
special_use = \Junk
}
mailbox Sent {
auto = subscribe
special_use = \Sent
}
mailbox Trash {
auto = subscribe
special_use = \Trash
}
With dovecot 2.1+, it ensures all the special mailboxes will be
automaticaly created for new accounts.
For dovecot 2.0 and older, use the `autocreate
<http://wiki2.dovecot.org/Plugins/Autocreate>`_ plugin.
.. _fs_operations:
Operations on the file system
-----------------------------
.. warning::
Modoboa needs to access the ``dovecot`` binary to check its
version. To find the binary path, we use the ``which`` command
first and then try known locations (:file:`/usr/sbin/dovecot` and
:file:`/usr/local/sbin/dovecot`). If you installed dovecot in a
custom location, please tell us where the binary is by using the
``DOVECOT_LOOKUP_PATH`` setting (see :file:`settings.py`).
Three operation types are considered:
#. Mailbox creation
#. Mailbox renaming
#. Mailbox deletion
The first one is managed by Dovecot. The last two ones may be managed
by Modoboa if it can access the file system where the mailboxes are
stored (see :ref:`admin-params` to activate this feature).
Those operations are treated asynchronously by a cron script. For
example, when you rename an e-mail address through the web UI, the
associated mailbox on the file system is not modified
directly. Instead of that, a *rename* order is created for this
mailbox. The mailbox will be considered unavailable until the order is
not executed (see :ref:`Postfix configuration <postfix_config>`).
Edit the crontab of the user who owns the mailboxes on the file system::
$ crontab -u <user> -e
And add the following line inside::
* * * * * python <modoboa_site>/manage.py handle_mailbox_operations
.. warning::
The cron script must be executed by the system user owning the mailboxes.
.. warning::
The user running the cron script must have access to the
:file:`settings.py` file of the modoboa instance.
The result of each order is recorded into Modoboa's log. Go to
*Modoboa > Logs* to consult them.
.. _dovecot_authentication:
Authentication
==============
To make the authentication work, edit the :file:`conf.d/10-auth.conf` and
uncomment the following line at the end::
#!include auth-system.conf.ext
!include auth-sql.conf.ext
#!include auth-ldap.conf.ext
#!include auth-passwdfile.conf.ext
#!include auth-checkpassword.conf.ext
#!include auth-vpopmail.conf.ext
#!include auth-static.conf.ext
Then, edit the :file:`conf.d/auth-sql.conf.ext` file and add the following
content inside::
passdb sql {
driver = sql
# Path for SQL configuration file, see example-config/dovecot-sql.conf.ext
args = /etc/dovecot/dovecot-sql.conf.ext
}
userdb sql {
driver = sql
args = /etc/dovecot/dovecot-sql.conf.ext
}
Make sure to activate only one backend (per type) inside your configuration
(just comment the other ones).
Edit the :file:`dovecot-sql.conf.ext` and modify the configuration according
to your database engine.
.. _dovecot_mysql_queries:
MySQL users
-----------
::
driver = mysql
connect = host=<mysqld socket> dbname=<database> user=<user> password=<password>
default_pass_scheme = CRYPT
password_query = SELECT email AS user, password FROM core_user WHERE email='%u' and is_active=1
user_query = SELECT '<mailboxes storage directory>/%Ld/%Ln' AS home, <uid> as uid, <gid> as gid, concat('*:bytes=', mb.quota, 'M') AS quota_rule FROM admin_mailbox mb INNER JOIN admin_domain dom ON mb.domain_id=dom.id WHERE mb.address='%Ln' AND dom.name='%Ld'
iterate_query = SELECT email AS username FROM core_user WHERE email<>''
.. _dovecot_pg_queries:
PostgreSQL users
----------------
::
driver = pgsql
connect = host=<postgres socket> dbname=<database> user=<user> password=<password>
default_pass_scheme = CRYPT
password_query = SELECT email AS user, password FROM core_user WHERE email='%u' and is_active
user_query = SELECT '<mailboxes storage directory>/%Ld/%Ln' AS home, <uid> as uid, <gid> as gid, '*:bytes=' || mb.quota || 'M' AS quota_rule FROM admin_mailbox mb INNER JOIN admin_domain dom ON mb.domain_id=dom.id WHERE mb.address='%Ln' AND dom.name='%Ld'
iterate_query = SELECT email AS username FROM core_user WHERE email<>''
SQLite users
------------
::
driver = sqlite
connect = <path to the sqlite db file>
default_pass_scheme = CRYPT
password_query = SELECT email AS user, password FROM core_user WHERE email='%u' and is_active=1
user_query = SELECT '<mailboxes storage directory>/%Ld/%Ln' AS home, <uid> as uid, <gid> as gid, ('*:bytes=' || mb.quota || 'M') AS quota_rule FROM admin_mailbox mb INNER JOIN admin_domain dom ON mb.domain_id=dom.id WHERE mb.address='%Ln' AND dom.name='%Ld'
iterate_query = SELECT email AS username FROM core_user WHERE email<>''
.. note::
Replace values between ``<>`` with yours.
LMTP
====
`Local Mail Transport Protocol
<http://en.wikipedia.org/wiki/Local_Mail_Transfer_Protocol>`_ is used
to let Postfix deliver messages to Dovecot.
First, make sure the protocol is activated by looking at the
``protocols`` setting (generally inside
:file:`dovecot.conf`). It should be similar to the following example::
protocols = imap pop3 lmtp
Then, open the :file:`conf.d/10-master.conf`, look for ``lmtp``
service definition and add the following content inside::
service lmtp {
# stuff before
unix_listener /var/spool/postfix/private/dovecot-lmtp {
mode = 0600
user = postfix
group = postfix
}
# stuff after
}
We assume here that Postfix is *chrooted* within
:file:`/var/spool/postfix`.
Finally, open the :file:`conf.d/20-lmtp.conf` and modify it as follows::
protocol lmtp {
postmaster_address = postmaster@<domain>
mail_plugins = $mail_plugins quota sieve
}
Replace ``<domain>`` by the appropriate value.
.. note::
If you don't plan to apply quota or to use filters, just adapt the
content of the ``mail_plugins`` setting.
.. _dovecot_quota:
Quota
=====
Modoboa lets adminstrators define per-domain and/or per-account limits
(quota). It also lists the current quota usage of each account. Those
features require Dovecot to be configured in a specific way.
Inside :file:`conf.d/10-mail.conf`, add the ``quota`` plugin to the default
activated ones::
mail_plugins = quota
Inside :file:`conf.d/10-master.conf`, update the ``dict`` service to set
proper permissions::
service dict {
# If dict proxy is used, mail processes should have access to its socket.
# For example: mode=0660, group=vmail and global mail_access_groups=vmail
unix_listener dict {
mode = 0600
user = <user owning mailboxes>
#group =
}
}
Inside :file:`conf.d/20-imap.conf`, activate the ``imap_quota`` plugin::
protocol imap {
# ...
mail_plugins = $mail_plugins imap_quota
# ...
}
Inside :file:`dovecot.conf`, activate the quota SQL dictionary backend::
dict {
quota = <driver>:/etc/dovecot/dovecot-dict-sql.conf.ext
}
Inside :file:`conf.d/90-quota.conf`, activate the *quota dictionary* backend::
plugin {
quota = dict:User quota::proxy::quota
}
It will tell Dovecot to keep quota usage in the SQL dictionary.
Finally, edit the :file:`dovecot-dict-sql.conf.ext` file and put the
following content inside::
connect = host=<db host> dbname=<db name> user=<db user> password=<password>
# SQLite users
# connect = /path/to/the/database.db
map {
pattern = priv/quota/storage
table = admin_quota
username_field = username
value_field = bytes
}
map {
pattern = priv/quota/messages
table = admin_quota
username_field = username
value_field = messages
}
*PostgreSQL* users
------------------
Database schema update
^^^^^^^^^^^^^^^^^^^^^^
The ``admin_quota`` table is created by Django but unfortunately it
doesn't support ``DEFAULT`` constraints (it only simulates them when the
ORM is used). As PostgreSQL is a bit strict about constraint
violations, you must execute the following query manually::
db=> ALTER TABLE admin_quota ALTER COLUMN bytes SET DEFAULT 0;
db=> ALTER TABLE admin_quota ALTER COLUMN messages SET DEFAULT 0;
Trigger
^^^^^^^
As indicated on `Dovecot's wiki
<http://wiki2.dovecot.org/Quota/Dict>`_, you need a trigger to
properly update the quota.
A working copy of this trigger is available on `Modoboa's website
<http://modoboa.org/resources/modoboa_postgres_trigger.sql>`_.
Download this file and copy it on the server running postgres. Then,
execute the following commands::
$ su - postgres
$ psql [modoboa database] < /path/to/modoboa_postgres_trigger.sql
$ exit
Replace ``[modoboa database]`` by the appropriate value.
Forcing recalculation
---------------------
For existing installations, *Dovecot* (> 2) offers a command to
recalculate the current quota usages. For example, if you want to
update all usages, run the following command::
$ doveadm quota recalc -A
Be carefull, it can take a while to execute.
ManageSieve/Sieve
=================
Modoboa lets users define filtering rules from the web interface. To
do so, it requires *ManageSieve* to be activated on your server.
Inside :file:`conf.d/20-managesieve.conf`, make sure the following lines are
uncommented::
protocols = $protocols sieve
service managesieve-login {
# ...
}
service managesieve {
# ...
}
protocol sieve {
# ...
}
Messages filtering using Sieve is done by the LDA.
Inside :file:`conf.d/15-lda.conf`, activate the ``sieve`` plugin like this::
protocol lda {
# Space separated list of plugins to load (default is global mail_plugins).
mail_plugins = $mail_plugins sieve
}
Finally, configure the ``sieve`` plugin by editing the
:file:`conf.d/90-sieve.conf` file. Put the follwing caontent inside::
plugin {
# Location of the active script. When ManageSieve is used this is actually
# a symlink pointing to the active script in the sieve storage directory.
sieve = ~/.dovecot.sieve
#
# The path to the directory where the personal Sieve scripts are stored. For
# ManageSieve this is where the uploaded scripts are stored.
sieve_dir = ~/sieve
}
Restart Dovecot.
Now, you can go to the :ref:`postfix` section to finish the installation.
+140
View File
@@ -0,0 +1,140 @@
#######
Modoboa
#######
This section describes the installation of the web interface (a
`Django <https://www.djangoproject.com/>`_ project).
Prepare the system
------------------
First of all, we recommand the following context:
* Use a dedicated system user
* Use a `virtualenv <http://www.virtualenv.org/en/latest/>`_ to
install the application because it will isolate it (and its
dependencies) from the rest of your system
The following example illustrates how to realize this (Debian like system):
.. sourcecode:: bash
> sudo apt-get install python-virtualenv python-pip
> sudo useradd modoboa
> sudo -i modoboa
> virtualenv env
(env)> source env/bin/activate
(env)> pip install -U pip
FIXME: dépendances système pour compilation
Then, install Modoboa:
.. sourcecode:: bash
(env)> pip install modoboa
Database
--------
.. warning::
This documentation does not cover the installation of a database
server but only the setup of a functional database that Modoboa
will use.
Thanks to Django, Modoboa is compatible with the following databases:
* PostgreSQL
* MySQL / MariaDB
* SQLite
Since the last one does not require particular actions, only the first
two ones are described.
PostgreSQL
**********
Install the corresponding Python binding:
.. sourcecode:: bash
(env)> pip install psycopg2
Then, create a user and a database:
.. sourcecode:: bash
> sudo -i postgres
>
MySQL / MariaDB
***************
Install the corresponding Python binding:
.. sourcecode:: bash
(env)> pip install MySQL-Python
Then, create a user and a database:
.. sourcecode:: bash
> mysqladmin -u root -p create modoboa
Deploy an instance
------------------
``modoboa-admin.py``, a command line tool, lets you deploy a
*ready-to-use* Modoboa site using only one instruction::
(env)> modoboa-admin.py deploy instance --collectstatic \
--domain <hostname of your server> --dburl default:database-url
.. note::
You can install additional extensions during the deploy process. To
do so, use the ``--extensions`` option which accepts a list of
names as argument (``--extensions ext1 ext2 ...``). If you want to
install all extensions, just use the ``all`` keyword like this
``--extensions all``.
If you choose to install extensions one at a time, you will have to
add their names in settings.py to ``MODOBOA_APPS``. Also ensure that
you have the line ``from modoboa_amavis.settings import *`` at the
end of this file.
The list of available extensions can be found on the :doc:`index
page <../index>`. Instructions to install them are available on
each extensions page.
.. note::
You can specify more than one database connection using the
``--dburl`` option. Multiple connections are differentiated by a
prefix.
The primary connection must use the ``default:`` prefix (as shown
in the example above). For the `amavis
<http://modoboa-amavis.readthedocs.org>`_ extension, use the
``amavis:`` prefix. For example: ``--dburl
default:<database url> amavis:<database url>``.
A database url should meet the following syntax
``<mysql|postgres>://[user:pass@][host:port]/dbname`` **OR**
``sqlite:////full/path/to/your/database/file.sqlite``.
The command will ask you a few questions, answer them and you're
done.
If you need a **silent installation** (e.g. if you're using
Salt-Stack, Ansible or whatever), it's possible to supply the database
credentials as commandline arguments.
You can consult the complete option list by running the following
command::
$ modoboa-admin.py help deploy
Now you can continue to the :ref:`webserver` section.
+67
View File
@@ -0,0 +1,67 @@
.. _postfix:
#######
Postfix
#######
This section gives an example about building a simple virtual hosting
configuration with *Postfix*. Refer to the `official documentation
<http://www.postfix.org/VIRTUAL_README.html>`_ for more explanation.
Map files
=========
You first need to create configuration files (or map files) that will
be used by Postfix to lookup into Modoboa tables.
To automaticaly generate the requested map files and store them in a
directory, run the following command::
$ modoboa-admin.py postfix_maps --dbtype <mysql|postgres|sqlite> <directory>
``<directory>`` is the directory where the files will be
stored. Answer the few questions and you're done.
.. _postfix_config:
Configuration
=============
Use the following configuration in the :file:`/etc/postfix/main.cf` file
(this is just one possible configuration)::
# Stuff before
virtual_transport = lmtp:unix:private/dovecot-lmtp
relay_domains =
virtual_mailbox_domains = <driver>:/etc/postfix/sql-domains.cf
virtual_alias_domains = <driver>:/etc/postfix/sql-domain-aliases.cf
virtual_alias_maps = <driver>:/etc/postfix/sql-aliases.cf
relay_domains = <driver>:/etc/postfix/sql-relaydomains.cf
transport_maps =
<driver>:/etc/postfix/sql-spliteddomains-transport.cf
<driver>:/etc/postfix/sql-relaydomains-transport.cf
smtpd_recipient_restrictions =
# ...
check_recipient_access
<driver>:/etc/postfix/sql-maintain.cf
<driver>:/etc/postfix/sql-relay-recipient-verification.cf
permit_mynetworks
reject_unauth_destination
reject_unverified_recipient
# ...
smtpd_sender_login_maps =
<driver>:/etc/postfix/sql-sender-login-mailboxes.cf
<driver>:/etc/postfix/sql-sender-login-aliases.cf
smtpd_sender_restrictions =
reject_sender_login_mismatch
# Stuff after
Replace ``<driver>`` by the name of the database you use.
Restart Postfix.
+299
View File
@@ -0,0 +1,299 @@
.. _webserver:
##########
Web server
##########
.. note::
The following instructions are meant to help you get your site up
and running quickly. However it is not possible for the people
contributing documentation to Modoboa to test every single
combination of web server, wsgi server, distribution, etc. So it is
possible that **your** installation of uwsgi or nginx or Apache or
what-have-you works differently. Keep this in mind.
.. _apache2:
Apache2
*******
First, make sure that ``mod_wsgi`` is installed on your server.
Create a new virtualhost in your Apache configuration and put the
following content inside::
<VirtualHost *:80>
ServerName <your value>
DocumentRoot <modoboa_instance_path>
Alias /media/ <modoboa_instance_path>/media/
<Directory <modoboa_instance_path>/media>
Order deny,allow
Allow from all
</Directory>
Alias /sitestatic/ <modoboa_instance_path>/sitestatic/
<Directory <modoboa_instance_path>/sitestatic>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias / <modoboa_instance_path>/<instance_name>/wsgi.py
</VirtualHost>
This is just one possible configuration.
To use mod_wsgi daemon mode, add the two following directives just
under ``WSGIScriptAlias``::
WSGIDaemonProcess example.com python-path=<modoboa_instance>:<virtualenv path>/lib/python2.7/site-packages
WSGIProcessGroup example.com
Replace values between ``<>`` with yours. If you don't use a
`virtualenv <http://virtualenv.readthedocs.org/en/latest/>`_, just
remove the last part of the ``WSGIDaemonProcess`` directive.
.. note::
You will certainly need more configuration in order to launch
Apache.
Now, you can go the :ref:`dovecot` section to continue the installation.
.. _nginx-label:
Nginx
*****
This section covers two different ways of running Modoboa behind
`Nginx <http://nginx.org/>`_ using a WSGI application server. Choose
the one you prefer between `Green Unicorn <http://gunicorn.org/>`_ or
`uWSGI <https://github.com/unbit/uwsgi>`_.
In both cases, you'll need to download and `install nginx
<http://wiki.nginx.org/Install>`_.
Green Unicorn
+++++++++++++
Firstly, `Download and install gunicorn
<http://gunicorn.org/install.html>`_. Then, use the following sample
gunicorn configuration (create a new file named
:file:`gunicorn.conf.py` inside Modoboa's root dir)::
backlog = 2048
bind = "unix:/var/run/gunicorn/modoboa.sock"
pidfile = "/var/run/gunicorn/modoboa.pid"
daemon = True
debug = False
workers = 2
logfile = "/var/log/gunicorn/modoboa.log"
loglevel = "info"
To start gunicorn, execute the following commands::
$ cd <modoboa dir>
$ gunicorn -c gunicorn.conf.py <modoboa dir>.wsgi:application
Now the nginx part. Just create a new virtual host and use the
following configuration::
upstream modoboa {
server unix:/var/run/gunicorn/modoboa.sock fail_timeout=0;
}
server {
listen 443 ssl;
ssl on;
keepalive_timeout 70;
server_name <host fqdn>;
root <modoboa_instance_path>;
access_log /var/log/nginx/<host fqdn>.access.log;
error_log /var/log/nginx/<host fqdn>.error.log;
ssl_certificate <ssl certificate for your site>;
ssl_certificate_key <ssl certificate key for your site>;
location /sitestatic/ {
autoindex on;
}
location /media/ {
autoindex on;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Forwarded-Protocol ssl;
proxy_pass http://modoboa;
}
}
If you do not plan to use SSL then change the listen directive to
``listen 80;`` and delete each of the following directives::
ssl on;
keepalive_timeout 70;
ssl_certificate <ssl certificate for your site>;
ssl_certificate_key <ssl certificate key for your site>;
proxy_set_header X-Forwarded-Protocol ssl;
If you do plan to use SSL, you'll have to generate a certificate and a
key. `This article
<http://wiki.nginx.org/HttpSslModule#Generate_Certificates>`__
contains information about how to do it.
Paste this content to your configuration (replace values between
``<>`` with yours) and restart nginx.
Now, you can go the :ref:`dovecot` section to continue the installation.
uWSGI
+++++
The following setup is meant to get you started quickly. You should
read the documentation of both nginx and uwsgi to understand how to
optimize their configuration for your site.
The Django documentation includes the following warning regarding
uwsgi:
.. warning::
Some distributions, including Debian and Ubuntu, ship an outdated
version of uWSGI that does not conform to the WSGI
specification. Versions prior to 1.2.6 do not call close on the
response object after handling a request. In those cases the
request_finished signal isn’t sent. This can result in idle
connections to database and memcache servers.
Use uwsgi 1.2.6 or newer. If you do not, you *will* run into
problems. Modoboa will fail in obscure ways.
To use this setup, first `download and install uwsgi
<http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html>`_.
Here is a sample nginx configuration::
server {
listen 443 ssl;
ssl on;
keepalive_timeout 70;
server_name <host fqdn>;
root <modoboa's settings dir>;
ssl_certificate <ssl certificate for your site>;
ssl_certificate_key <ssl certificate key for your site>;
access_log /var/log/nginx/<host fqdn>.access.log;
error_log /var/log/nginx/<host fqdn>.error.log;
location <modoboa's root url>/sitestatic/ {
autoindex on;
alias <location of sitestatic on your file system>;
}
# Whether or not Modoboa uses a media directory depends on how
# you configured Modoboa. It does not hurt to have this.
location <modoboa's root url>/media/ {
autoindex on;
alias <location of media on your file system>;
}
# This denies access to any file that begins with
# ".ht". Apache's .htaccess and .htpasswd are such files. A
# Modoboa installed from scratch would not contain any such
# files, but you never know what the future holds.
location ~ /\.ht {
deny all;
}
location <modoba's root url>/ {
include uwsgi_params;
uwsgi_pass <uwsgi port>;
uwsgi_param UWSGI_SCRIPT <modoboa instance name>.wsgi:application;
uwsgi_param UWSGI_SCHEME https;
}
}
``<modoboa instance name>`` must be replaced by the value you used
when :ref:`you deployed your instance <deployment>`.
If you do not plan to use SSL then change the listen directive to
``listen 80;`` and delete each of the following directives::
ssl on;
keepalive_timeout 70;
ssl_certificate <ssl certificate for your site>;
ssl_certificate_key <ssl certificate key for your site>;
uwsgi_param UWSGI_SCHEME https;
If you do plan to use SSL, you'll have to generate a certificate and a
key. `This article
<http://wiki.nginx.org/HttpSslModule#Generate_Certificates>`_
contains information about how to do it.
Make sure to replace the ``<...>`` in the sample configuration with
appropriate values. Here are some explanations for the cases that may
not be completely self-explanatory:
``<modoboa's settings dir>``
Where Modoboa's :file:`settings.py` resides. This is also where the
:file:`sitestatic` and :file:`media` directories reside.
``<modoboa's root url>``
This is the URL which will be the root of your Modoboa site at your
domain. For instance, if your Modoboa installation is reachable at
at ``https://foo/modoboa`` then ``<modoboa's root url>`` is
``/modoboa``. In this case you probably also have to set the
``alias`` directives to point to where Modoboa's sitestatic and
media directories are because otherwise nginx won't be able to find
them.
If Modoboa is at the root of your domain, then ``<modoboa root
url>`` is an empty string and can be deleted from the configuration
above. In this case, you probably do not need the ``alias``
directives.
``<uwsgi port>``
The location where uwsig is listening. It could be a unix domain
socket or an address:port combination. Ubuntu configures uwsgi so
that the port is::
unix:/run/uwsgi/app/<app name>/socket
where ``<app name>`` is the name of the application.
Your uwsgi configuration should be::
[uwsgi]
# Not needed when using uwsgi from pip
# plugins = python
chdir = <modoboa's top dir>
module = <name>.wsgi:application
master = true
harakiri = 60
processes = 4
vhost = true
no-default-app = true
The plugins directive should be turned on if you use a uwsgi
installation that requires it. If uwsgi was installed from pip, it
does not require it. In the configuration above:
``<modoboa's top dir>``
The directory where :file:`manage.py` resides. This directory is the
parent of ``<modoboa's settings dir>``
``<name>``
The name that you passed to ``modoboa-admin.py deploy`` when you
created your Modoboa instance.
Now, you can go the :ref:`dovecot` section to continue the installation.