Skip to content

Commit 6cc49f2

Browse files
committed
Added support for dovecot in Debian Lenny.
Added Support for Sieve mail filtering language on dovecot servers.
1 parent 1f16ae5 commit 6cc49f2

23 files changed

+1799
-119
lines changed

install/dist/conf/centos52.conf.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@
124124
$conf['courier']['courier-pop'] = '';
125125
$conf['courier']['courier-pop-ssl'] = '';
126126

127+
//* Dovecot
128+
$conf['dovecot']['installed'] = false; // will be detected automatically during installation
129+
$conf['dovecot']['config_dir'] = '/etc/dovecot';
130+
$conf['dovecot']['init_script'] = 'dovecot';
131+
127132
//* SASL
128133
$conf['saslauthd']['installed'] = false; // will be detected automatically during installation
129134
$conf['saslauthd']['config'] = '/etc/sysconfig/saslauthd';

install/dist/conf/centos53.conf.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@
124124
$conf['courier']['courier-pop'] = '';
125125
$conf['courier']['courier-pop-ssl'] = '';
126126

127+
//* Dovecot
128+
$conf['dovecot']['installed'] = false; // will be detected automatically during installation
129+
$conf['dovecot']['config_dir'] = '/etc/dovecot';
130+
$conf['dovecot']['init_script'] = 'dovecot';
131+
127132
//* SASL
128133
$conf['saslauthd']['installed'] = false; // will be detected automatically during installation
129134
$conf['saslauthd']['config'] = '/etc/sysconfig/saslauthd';

install/dist/conf/debian40.conf.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@
123123
$conf['courier']['courier-imap-ssl'] = 'courier-imap-ssl';
124124
$conf['courier']['courier-pop'] = 'courier-pop';
125125
$conf['courier']['courier-pop-ssl'] = 'courier-pop-ssl';
126+
$conf['dovecot']['init_script'] = 'dovecot';
127+
128+
//* Dovecot
129+
$conf['dovecot']['installed'] = false; // will be detected automatically during installation
130+
$conf['dovecot']['config_dir'] = '/etc/dovecot';
126131

127132
//* SASL
128133
$conf['saslauthd']['installed'] = false; // will be detected automatically during installation

install/dist/conf/fedora9.conf.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@
124124
$conf['courier']['courier-pop'] = 'courier-imap';
125125
$conf['courier']['courier-pop-ssl'] = 'courier-imap';
126126

127+
//* Dovecot
128+
$conf['dovecot']['installed'] = false; // will be detected automatically during installation
129+
$conf['dovecot']['config_dir'] = '/etc/dovecot';
130+
$conf['dovecot']['init_script'] = 'dovecot';
131+
127132
//* SASL
128133
$conf['saslauthd']['installed'] = false; // will be detected automatically during installation
129134
$conf['saslauthd']['config'] = '/etc/sysconfig/saslauthd';

install/dist/conf/gentoo.conf.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@
148148
$conf['courier']['courier-pop'] = 'courier-pop3d';
149149
$conf['courier']['courier-pop-ssl'] = 'courier-pop3d-ssl';
150150

151+
//* Dovecot
152+
$conf['dovecot']['installed'] = false; // will be detected automatically during installation
153+
$conf['dovecot']['config_dir'] = '/etc/dovecot';
154+
$conf['dovecot']['init_script'] = 'dovecot';
155+
151156
//* SASL
152157
$conf['saslauthd']['installed'] = false; // will be detected automatically during installation
153158
$conf['saslauthd']['config_file'] = '/etc/conf.d/saslauthd';

install/dist/conf/opensuse110.conf.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@
124124
$conf['courier']['courier-pop'] = 'courier-pop';
125125
$conf['courier']['courier-pop-ssl'] = 'courier-pop-ssl';
126126

127+
//* Dovecot
128+
$conf['dovecot']['installed'] = false; // will be detected automatically during installation
129+
$conf['dovecot']['config_dir'] = '/etc/dovecot';
130+
$conf['dovecot']['init_script'] = 'dovecot';
131+
127132
//* SASL
128133
$conf['saslauthd']['installed'] = false; // will be detected automatically during installation
129134
$conf['saslauthd']['config'] = '/etc/default/saslauthd';

install/install.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,16 @@
170170
//* Configure PAM
171171
swriteln('Configuring PAM');
172172
$inst->configure_pam();
173-
174-
//* Configure courier
175-
swriteln('Configuring Courier');
176-
$inst->configure_courier();
173+
174+
if($conf['dovecot']['installed'] == true) {
175+
//* Configure dovecot
176+
swriteln('Configuring Dovecot');
177+
$inst->configure_dovecot();
178+
} else {
179+
//* Configure courier
180+
swriteln('Configuring Courier');
181+
$inst->configure_courier();
182+
}
177183

178184
//* Configure Spamasassin
179185
swriteln('Configuring Spamassassin');
@@ -247,6 +253,7 @@
247253
if($conf['courier']['courier-imap-ssl'] != '' && is_file($conf['init_scripts'].'/'.$conf['courier']['courier-imap-ssl'])) system($conf['init_scripts'].'/'.$conf['courier']['courier-imap-ssl'].' restart');
248254
if($conf['courier']['courier-pop'] != '' && is_file($conf['init_scripts'].'/'.$conf['courier']['courier-pop'])) system($conf['init_scripts'].'/'.$conf['courier']['courier-pop'].' restart');
249255
if($conf['courier']['courier-pop-ssl'] != '' && is_file($conf['init_scripts'].'/'.$conf['courier']['courier-pop-ssl'])) system($conf['init_scripts'].'/'.$conf['courier']['courier-pop-ssl'].' restart');
256+
if($conf['dovecot']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['dovecot']['init_script'])) system($conf['init_scripts'].'/'.$conf['dovecot']['init_script'].' restart');
250257
if($conf['apache']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['apache']['init_script'])) system($conf['init_scripts'].'/'.$conf['apache']['init_script'].' restart');
251258
if($conf['pureftpd']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['pureftpd']['init_script'])) system($conf['init_scripts'].'/'.$conf['pureftpd']['init_script'].' restart');
252259
if($conf['mydns']['installed'] == true && $conf['mydns']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['mydns']['init_script'])) system($conf['init_scripts'].'/'.$conf['mydns']['init_script'].' restart &> /dev/null');
@@ -328,9 +335,15 @@
328335
swriteln('Configuring PAM');
329336
$inst->configure_pam();
330337

331-
//* Configure courier
332-
swriteln('Configuring Courier');
333-
$inst->configure_courier();
338+
if($conf['dovecot']['installed'] == true) {
339+
//* Configure dovecot
340+
swriteln('Configuring Dovecot');
341+
$inst->configure_dovecot();
342+
} else {
343+
//* Configure courier
344+
swriteln('Configuring Courier');
345+
$inst->configure_courier();
346+
}
334347

335348
//* Configure Spamasassin
336349
swriteln('Configuring Spamassassin');
@@ -353,6 +366,7 @@
353366
if($conf['courier']['courier-imap-ssl'] != '') system($conf['init_scripts'].'/'.$conf['courier']['courier-imap-ssl'].' restart');
354367
if($conf['courier']['courier-pop'] != '') system($conf['init_scripts'].'/'.$conf['courier']['courier-pop'].' restart');
355368
if($conf['courier']['courier-pop-ssl'] != '') system($conf['init_scripts'].'/'.$conf['courier']['courier-pop-ssl'].' restart');
369+
if($conf['dovecot']['init_script'] != '' && is_file($conf['init_scripts'].'/'.$conf['dovecot']['init_script'])) system($conf['init_scripts'].'/'.$conf['dovecot']['init_script'].' restart');
356370
}
357371

358372
//** Configure Jailkit

install/lib/installer_base.lib.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public function find_installed_apps() {
121121
if(is_installed('apache') || is_installed('apache2') || is_installed('httpd')) $conf['apache']['installed'] = true;
122122
if(is_installed('getmail')) $conf['getmail']['installed'] = true;
123123
if(is_installed('couriertcpd')) $conf['courier']['installed'] = true;
124+
if(is_installed('dovecot')) $conf['dovecot']['installed'] = true;
124125
if(is_installed('saslsauthd')) $conf['saslauthd']['installed'] = true;
125126
if(is_installed('amavisd-new')) $conf['amavis']['installed'] = true;
126127
if(is_installed('clamdscan')) $conf['clamav']['installed'] = true;
@@ -215,6 +216,8 @@ public function add_database_server_record() {
215216
$tpl_ini_array['web']['security_level'] = 20;
216217
$tpl_ini_array['web']['user'] = $conf['apache']['user'];
217218
$tpl_ini_array['web']['group'] = $conf['apache']['group'];
219+
$tpl_ini_array['mail']['pop3_imap_daemon'] = ($conf['dovecot']['installed'] == true)?'dovecot':'courier';
220+
$tpl_ini_array['mail']['mail_filter_syntax'] = ($conf['dovecot']['installed'] == true)?'sieve':'maildrop';
218221

219222
$server_ini_content = array_to_ini($tpl_ini_array);
220223
$server_ini_content = mysql_real_escape_string($server_ini_content);
@@ -226,6 +229,8 @@ public function add_database_server_record() {
226229
$db_server_enabled = ($conf['services']['db'])?1:0;
227230
$vserver_server_enabled = ($conf['services']['vserver'])?1:0;
228231

232+
233+
229234
if($conf['mysql']['master_slave_setup'] == 'y') {
230235

231236
//* Insert the server record in master DB
@@ -648,6 +653,72 @@ public function configure_courier()
648653
wf($configfile, $content);
649654
}
650655

656+
public function configure_dovecot()
657+
{
658+
global $conf;
659+
660+
$config_dir = $conf['dovecot']['config_dir'];
661+
662+
//* Configure master.cf and add a line for deliver
663+
if(is_file($config_dir.'/master.cf')){
664+
copy($config_dir.'/master.cf', $config_dir.'/master.cf~2');
665+
}
666+
if(is_file($config_dir.'/master.cf~')){
667+
exec('chmod 400 '.$config_dir.'/master.cf~2');
668+
}
669+
$content = rf($conf["postfix"]["config_dir"].'/master.cf');
670+
// Only add the content if we had not addded it before
671+
if(!stristr($content,"dovecot/deliver")) {
672+
$deliver_content = "dovecot unix - n n - - pipe\n flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop}";
673+
af($conf["postfix"]["config_dir"].'/master.cf',$deliver_content);
674+
}
675+
unset($content);
676+
unset($deliver_content);
677+
678+
679+
//* Reconfigure postfix to use dovecot authentication
680+
// Adding the amavisd commands to the postfix configuration
681+
$postconf_commands = array (
682+
'dovecot_destination_recipient_limit = 1',
683+
'virtual_transport = dovecot',
684+
'smtpd_sasl_type = dovecot',
685+
'smtpd_sasl_path = private/auth'
686+
);
687+
688+
// Make a backup copy of the main.cf file
689+
copy($conf["postfix"]["config_dir"].'/main.cf',$conf["postfix"]["config_dir"].'/main.cf~3');
690+
691+
// Executing the postconf commands
692+
foreach($postconf_commands as $cmd) {
693+
$command = "postconf -e '$cmd'";
694+
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
695+
}
696+
697+
//* copy dovecot.conf
698+
$configfile = 'dovecot.conf';
699+
if(is_file("$config_dir/$configfile")){
700+
copy("$config_dir/$configfile", "$config_dir/$configfile~");
701+
}
702+
copy('tpl/debian_dovecot.conf.master',"$config_dir/$configfile");
703+
704+
//* dovecot-sql.conf
705+
$configfile = 'dovecot-sql.conf';
706+
if(is_file("$config_dir/$configfile")){
707+
copy("$config_dir/$configfile", "$config_dir/$configfile~");
708+
}
709+
exec("chmod 400 $config_dir/$configfile~");
710+
$content = rf("tpl/debian_dovecot-sql.conf.master");
711+
$content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
712+
$content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
713+
$content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
714+
$content = str_replace('{mysql_server_host}',$conf['mysql']['host'],$content);
715+
wf("$config_dir/$configfile", $content);
716+
717+
exec("chmod 600 $config_dir/$configfile");
718+
exec("chown root:root $config_dir/$configfile");
719+
720+
}
721+
651722
public function configure_amavis() {
652723
global $conf;
653724

install/sql/ispconfig3.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,10 @@ CREATE TABLE `mail_user` (
549549
`custom_mailfilter` mediumtext,
550550
`postfix` enum('n','y') NOT NULL,
551551
`access` enum('n','y') NOT NULL,
552-
`disableimap` enum('0','1') NOT NULL default '0',
553-
`disablepop3` enum('0','1') NOT NULL default '0',
552+
`disableimap` enum('n','y') NOT NULL default 'n',
553+
`disablepop3` enum('n','y') NOT NULL default 'n',
554+
`disabledeliver` enum('n','y') NOT NULL default 'n',
555+
`disablesmtp` enum('n','y') NOT NULL default 'n',
554556
PRIMARY KEY (`mailuser_id`),
555557
KEY `server_id` (`server_id`,`email`),
556558
KEY `email_access` (`email`,`access`)
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# This file is opened as root, so it should be owned by root and mode 0600.
2+
#
3+
# http://wiki.dovecot.org/AuthDatabase/SQL
4+
#
5+
# For the sql passdb module, you'll need a database with a table that
6+
# contains fields for at least the userid and password. If you want to
7+
# use the user@domain syntax, you might want to have a separate domain
8+
# field as well.
9+
#
10+
# If your users all have the same uig/gid, and have predictable home
11+
# directories, you can use the static userdb module to generate the home
12+
# dir based on the userid and domain. In this case, you won't need fields
13+
# for home, uid, or gid in the database.
14+
#
15+
# If you prefer to use the sql userdb module, you'll want to add fields
16+
# for home, uid, and gid. Here is an example table:
17+
#
18+
# CREATE TABLE users (
19+
# userid VARCHAR(128) NOT NULL,
20+
# password VARCHAR(64) NOT NULL,
21+
# home VARCHAR(255) NOT NULL,
22+
# uid INTEGER NOT NULL,
23+
# gid INTEGER NOT NULL,
24+
# active CHAR(1) DEFAULT 'Y' NOT NULL
25+
# );
26+
27+
# Database driver: mysql, pgsql, sqlite
28+
#driver =
29+
30+
# Database connection string. This is driver-specific setting.
31+
#
32+
# pgsql:
33+
# For available options, see the PostgreSQL documention for the
34+
# PQconnectdb function of libpq.
35+
#
36+
# mysql:
37+
# Basic options emulate PostgreSQL option names:
38+
# host, port, user, password, dbname
39+
#
40+
# But also adds some new settings:
41+
# client_flags - See MySQL manual
42+
# ssl_ca, ssl_ca_path - Set either one or both to enable SSL
43+
# ssl_cert, ssl_key - For sending client-side certificates to server
44+
# ssl_cipher - Set minimum allowed cipher security (default: HIGH)
45+
#
46+
# You can connect to UNIX sockets by using host: host=/var/run/mysqld/mysqld.sock
47+
# Note that currently you can't use spaces in parameters.
48+
#
49+
# sqlite:
50+
# The path to the database file.
51+
#
52+
# Examples:
53+
# connect = host=192.168.1.1 dbname=users
54+
# connect = host=sql.example.com dbname=virtual user=virtual password=blarg
55+
# connect = /etc/dovecot/authdb.sqlite
56+
#
57+
#connect = dbname=virtual user=virtual
58+
59+
# Default password scheme.
60+
#
61+
# List of supported schemes is in
62+
# http://wiki.dovecot.org/Authentication/PasswordSchemes
63+
#
64+
#default_pass_scheme = PLAIN-MD5
65+
66+
# Query to retrieve the password.
67+
#
68+
# This query must return only one row with "user" and "password" columns.
69+
# The query can also return other fields which have a special meaning, see
70+
# http://wiki.dovecot.org/PasswordDatabase/ExtraFields
71+
#
72+
# The "user" column is needed to make sure the username gets used with exactly
73+
# the same casing as it's in the database. Note that if you store username and
74+
# domain in separate fields, you most likely want to return a combination of
75+
# them as the "user" column, otherwise the domain gets stripped.
76+
#
77+
# Commonly used available substitutions (see
78+
# http://wiki.dovecot.org/Variables for full list):
79+
# %u = entire userid
80+
# %n = user part of user@domain
81+
# %d = domain part of user@domain
82+
#
83+
# Note that these can be used only as input to SQL query. If the query outputs
84+
# any of these substitutions, they're not touched. Otherwise it would be
85+
# difficult to have eg. usernames containing '%' characters.
86+
#
87+
# Example:
88+
# password_query = SELECT concat(userid, '@', domain) AS user, password FROM users WHERE userid = '%n' AND domain = '%d'
89+
# password_query = SELECT pw AS password FROM users WHERE userid = '%u' AND active = 'Y'
90+
#
91+
#password_query = SELECT userid as user, password FROM users WHERE userid = '%u'
92+
93+
# Query to retrieve the user information.
94+
#
95+
# The query must return only one row. Commonly returned columns are:
96+
# uid - System UID
97+
# gid - System GID
98+
# home - Home directory
99+
# mail - Mail location
100+
#
101+
# Either home or mail is required. uid and gid are required. If more than one
102+
# row is returned or there are missing fields, the login will fail. For a list
103+
# of all fields that can be returned, see
104+
# http://wiki.dovecot.org/UserDatabase/ExtraFields
105+
#
106+
# Examples
107+
# user_query = SELECT home, uid, gid FROM users WHERE userid = '%n' AND domain = '%d'
108+
# user_query = SELECT dir AS home, user AS uid, group AS gid FROM users where userid = '%u'
109+
# user_query = SELECT home, 501 AS uid, 501 AS gid FROM users WHERE userid = '%u'
110+
#
111+
#user_query = SELECT home, uid, gid FROM users WHERE userid = '%u'
112+
113+
# If you wish to avoid two SQL lookups (passdb + userdb), you can use
114+
# userdb prefetch instead of userdb sql in dovecot.conf. In that case you'll
115+
# also have to return userdb fields in password_query prefixed with "userdb_"
116+
# string. For example:
117+
#password_query = SELECT userid as user, password, home as userdb_home, uid as userdb_uid, gid as userdb_gid FROM users WHERE userid = '%u'
118+
119+
driver = mysql
120+
connect = host={mysql_server_host} dbname={mysql_server_database} user={mysql_server_ispconfig_user} password={mysql_server_ispconfig_password}
121+
default_pass_scheme = CRYPT
122+
123+
password_query = SELECT password FROM mail_user WHERE email = '%u' AND disable%Ls = 'n'
124+
user_query = SELECT email as user, maildir as home, CONCAT(maildir, '/Maildir') as mail, uid, gid, CONCAT('maildir:storage=', quota) AS quota, CONCAT(maildir, '/.sieve') as sieve FROM mail_user WHERE email = '%u' AND disable%Ls = 'n'
125+
126+

0 commit comments

Comments
 (0)