commit | author | age
|
94927b
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
|
5 |
All rights reserved. |
|
6 |
|
|
7 |
Redistribution and use in source and binary forms, with or without modification, |
|
8 |
are permitted provided that the following conditions are met: |
|
9 |
|
|
10 |
* Redistributions of source code must retain the above copyright notice, |
|
11 |
this list of conditions and the following disclaimer. |
|
12 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
13 |
this list of conditions and the following disclaimer in the documentation |
|
14 |
and/or other materials provided with the distribution. |
|
15 |
* Neither the name of ISPConfig nor the names of its contributors |
|
16 |
may be used to endorse or promote products derived from this software without |
|
17 |
specific prior written permission. |
|
18 |
|
|
19 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
20 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
21 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
22 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
23 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
24 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
26 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
27 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
28 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 |
*/ |
|
30 |
|
|
31 |
class installer extends installer_base { |
b1a6a5
|
32 |
|
94927b
|
33 |
public function configure_dovecot() |
b1a6a5
|
34 |
{ |
94927b
|
35 |
global $conf; |
a8aad2
|
36 |
|
DM |
37 |
$virtual_transport = 'dovecot'; |
8b23f8
|
38 |
|
FS |
39 |
$configure_lmtp = false; |
a8aad2
|
40 |
|
DM |
41 |
// check if virtual_transport must be changed |
|
42 |
if ($this->is_update) { |
2af58c
|
43 |
$tmp = $this->db->queryOneRecord("SELECT * FROM ?? WHERE server_id = ?", $conf["mysql"]["database"] . ".server", $conf['server_id']); |
a8aad2
|
44 |
$ini_array = ini_to_array(stripslashes($tmp['config'])); |
DM |
45 |
// ini_array needs not to be checked, because already done in update.php -> updateDbAndIni() |
|
46 |
|
|
47 |
if(isset($ini_array['mail']['mailbox_virtual_uidgid_maps']) && $ini_array['mail']['mailbox_virtual_uidgid_maps'] == 'y') { |
|
48 |
$virtual_transport = 'lmtp:unix:private/dovecot-lmtp'; |
8b23f8
|
49 |
$configure_lmtp = true; |
a8aad2
|
50 |
} |
DM |
51 |
} |
b1a6a5
|
52 |
|
bd5d26
|
53 |
$config_dir = $conf['postfix']['config_dir']; |
94927b
|
54 |
//* Configure master.cf and add a line for deliver |
bd5d26
|
55 |
if ($this->postfix_master()) { |
FS |
56 |
exec ("postconf -M dovecot.unix", $out, $ret); |
|
57 |
$add_dovecot_service = @($out[0]=='')?true:false; |
|
58 |
} else { //* fallback - postfix < 2.9 |
|
59 |
$content = rf($config_dir.'/master.cf'); |
|
60 |
$add_dovecot_service = @(!stristr($content, "dovecot/deliver"))?true:false; |
8e725d
|
61 |
} |
bd5d26
|
62 |
if($add_dovecot_service) { |
FS |
63 |
//* backup |
|
64 |
if(is_file($config_dir.'/master.cf')){ |
|
65 |
copy($config_dir.'/master.cf', $config_dir.'/master.cf~2'); |
|
66 |
} |
|
67 |
if(is_file($config_dir.'/master.cf~')){ |
|
68 |
chmod($config_dir.'/master.cf~2', 0400); |
|
69 |
} |
|
70 |
//* Configure master.cf and add a line for deliver |
|
71 |
$content = rf($conf["postfix"]["config_dir"].'/master.cf'); |
94927b
|
72 |
$deliver_content = 'dovecot unix - n n - - pipe'."\n".' flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop}'; |
bd5d26
|
73 |
af($config_dir.'/master.cf', $deliver_content); |
FS |
74 |
unset($content); |
|
75 |
unset($deliver_content); |
94927b
|
76 |
} |
b1a6a5
|
77 |
|
94927b
|
78 |
//* Reconfigure postfix to use dovecot authentication |
T |
79 |
// Adding the amavisd commands to the postfix configuration |
|
80 |
$postconf_commands = array ( |
|
81 |
'dovecot_destination_recipient_limit = 1', |
a8aad2
|
82 |
'virtual_transport = '.$virtual_transport, |
94927b
|
83 |
'smtpd_sasl_type = dovecot', |
T |
84 |
'smtpd_sasl_path = private/auth' |
|
85 |
); |
b1a6a5
|
86 |
|
94927b
|
87 |
// Make a backup copy of the main.cf file |
b1a6a5
|
88 |
copy($conf["postfix"]["config_dir"].'/main.cf', $conf["postfix"]["config_dir"].'/main.cf~3'); |
MC |
89 |
|
94927b
|
90 |
// Executing the postconf commands |
T |
91 |
foreach($postconf_commands as $cmd) { |
|
92 |
$command = "postconf -e '$cmd'"; |
|
93 |
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
94 |
} |
b1a6a5
|
95 |
|
94927b
|
96 |
//* copy dovecot.conf |
bd5d26
|
97 |
$config_dir = $conf['dovecot']['config_dir']; |
94927b
|
98 |
$configfile = 'dovecot.conf'; |
8e725d
|
99 |
if(is_file($config_dir.'/'.$configfile)){ |
J |
100 |
copy($config_dir.'/'.$configfile, $config_dir.'/'.$configfile.'~'); |
|
101 |
} |
b1a6a5
|
102 |
|
31e0d1
|
103 |
//* Get the dovecot version |
b1a6a5
|
104 |
exec('dovecot --version', $tmp); |
1fc360
|
105 |
$dovecot_version = $tmp[0]; |
31e0d1
|
106 |
unset($tmp); |
b1a6a5
|
107 |
|
31e0d1
|
108 |
//* Copy dovecot configuration file |
1fc360
|
109 |
if(version_compare($dovecot_version,2) >= 0) { |
b1a6a5
|
110 |
if(is_file($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot2.conf.master')) { |
MC |
111 |
copy($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot2.conf.master', $config_dir.'/'.$configfile); |
|
112 |
} else { |
|
113 |
copy('tpl/debian6_dovecot2.conf.master', $config_dir.'/'.$configfile); |
|
114 |
} |
5e7306
|
115 |
replaceLine($config_dir.'/'.$configfile, 'postmaster_address = postmaster@example.com', 'postmaster_address = postmaster@'.$conf['hostname'], 1, 0); |
1fc360
|
116 |
if(version_compare($dovecot_version,2.1) < 0) { |
TB |
117 |
removeLine($config_dir.'/'.$configfile, 'ssl_protocols ='); |
|
118 |
} |
31e0d1
|
119 |
} else { |
b1a6a5
|
120 |
if(is_file($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot.conf.master')) { |
MC |
121 |
copy($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot.conf.master', $config_dir.'/'.$configfile); |
|
122 |
} else { |
|
123 |
copy('tpl/debian6_dovecot.conf.master', $config_dir.'/'.$configfile); |
|
124 |
} |
31e0d1
|
125 |
} |
1fc360
|
126 |
|
8b23f8
|
127 |
//* dovecot-lmtpd |
FS |
128 |
if($configure_lmtp) { |
|
129 |
replaceLine($config_dir.'/'.$configfile, 'protocols = imap pop3', 'protocols = imap pop3 lmtp', 1, 0); |
|
130 |
} |
b1a6a5
|
131 |
|
94927b
|
132 |
//* dovecot-sql.conf |
T |
133 |
$configfile = 'dovecot-sql.conf'; |
8e725d
|
134 |
if(is_file($config_dir.'/'.$configfile)){ |
J |
135 |
copy($config_dir.'/'.$configfile, $config_dir.'/'.$configfile.'~'); |
4586d5
|
136 |
chmod($config_dir.'/'.$configfile.'~', 0400); |
8e725d
|
137 |
} |
615a0a
|
138 |
$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot-sql.conf.master', 'tpl/debian6_dovecot-sql.conf.master'); |
b1a6a5
|
139 |
$content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content); |
MC |
140 |
$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content); |
|
141 |
$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content); |
|
142 |
$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content); |
82e9b9
|
143 |
$content = str_replace('{mysql_server_port}', $conf['mysql']['port'], $content); |
032b86
|
144 |
$content = str_replace('{server_id}', $conf['server_id'], $content); |
8e725d
|
145 |
wf($config_dir.'/'.$configfile, $content); |
b1a6a5
|
146 |
|
8e725d
|
147 |
chmod($config_dir.'/'.$configfile, 0600); |
J |
148 |
chown($config_dir.'/'.$configfile, 'root'); |
|
149 |
chgrp($config_dir.'/'.$configfile, 'root'); |
5e7306
|
150 |
|
TB |
151 |
// Dovecot shall ignore mounts in website directory |
9b6866
|
152 |
if(is_installed('doveadm')) exec("doveadm mount add '/var/www/*' ignore > /dev/null 2> /dev/null"); |
94927b
|
153 |
|
T |
154 |
} |
b1a6a5
|
155 |
|
1ca823
|
156 |
public function configure_apache() { |
T |
157 |
global $conf; |
b1a6a5
|
158 |
|
MC |
159 |
if(file_exists('/etc/apache2/mods-available/fcgid.conf')) replaceLine('/etc/apache2/mods-available/fcgid.conf', 'MaxRequestLen', 'MaxRequestLen 15728640', 0, 1); |
|
160 |
|
1ca823
|
161 |
parent::configure_apache(); |
T |
162 |
} |
94927b
|
163 |
|
b1a6a5
|
164 |
public function configure_fail2ban() { |
MC |
165 |
/* |
c12af9
|
166 |
copy('tpl/dovecot-pop3imap.conf.master',"/etc/fail2ban/filter.d/dovecot-pop3imap.conf"); |
L |
167 |
copy('tpl/dovecot_fail2ban_jail.local.master','/etc/fail2ban/jail.local'); |
e44ec9
|
168 |
*/ |
b1a6a5
|
169 |
} |
MC |
170 |
|
94927b
|
171 |
} |
T |
172 |
|
4586d5
|
173 |
?> |