Marius Burkard
2016-04-20 4569cae57f127afd093794310ccd290d2d9fdf36
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'];
9c6782 54         if(!$this->get_postfix_service('dovecot', 'unix')) {
bd5d26 55             //* backup
FS 56             if(is_file($config_dir.'/master.cf')){
57                 copy($config_dir.'/master.cf', $config_dir.'/master.cf~2');
58             }
59             if(is_file($config_dir.'/master.cf~')){
60                 chmod($config_dir.'/master.cf~2', 0400);
61             }
62             //* Configure master.cf and add a line for deliver
63             $content = rf($conf["postfix"]["config_dir"].'/master.cf');
9c6782 64             $deliver_content = 'dovecot   unix  -       n       n       -       -       pipe'."\n".'  flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop}'."\n";
bd5d26 65             af($config_dir.'/master.cf', $deliver_content);
FS 66             unset($content);
67             unset($deliver_content);
94927b 68         }
b1a6a5 69
94927b 70         //* Reconfigure postfix to use dovecot authentication
T 71         // Adding the amavisd commands to the postfix configuration
72         $postconf_commands = array (
73             'dovecot_destination_recipient_limit = 1',
a8aad2 74             'virtual_transport = '.$virtual_transport,
94927b 75             'smtpd_sasl_type = dovecot',
T 76             'smtpd_sasl_path = private/auth'
77         );
b1a6a5 78
94927b 79         // Make a backup copy of the main.cf file
b1a6a5 80         copy($conf["postfix"]["config_dir"].'/main.cf', $conf["postfix"]["config_dir"].'/main.cf~3');
MC 81
94927b 82         // Executing the postconf commands
T 83         foreach($postconf_commands as $cmd) {
84             $command = "postconf -e '$cmd'";
85             caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
86         }
b1a6a5 87
94927b 88         //* copy dovecot.conf
bd5d26 89         $config_dir = $conf['dovecot']['config_dir'];
94927b 90         $configfile = 'dovecot.conf';
8e725d 91         if(is_file($config_dir.'/'.$configfile)){
J 92             copy($config_dir.'/'.$configfile, $config_dir.'/'.$configfile.'~');
93         }
b1a6a5 94
31e0d1 95         //* Get the dovecot version
b1a6a5 96         exec('dovecot --version', $tmp);
1fc360 97         $dovecot_version = $tmp[0];
31e0d1 98         unset($tmp);
b1a6a5 99
31e0d1 100         //* Copy dovecot configuration file
1fc360 101         if(version_compare($dovecot_version,2) >= 0) {
b1a6a5 102             if(is_file($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot2.conf.master')) {
MC 103                 copy($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot2.conf.master', $config_dir.'/'.$configfile);
104             } else {
105                 copy('tpl/debian6_dovecot2.conf.master', $config_dir.'/'.$configfile);
106             }
5e7306 107             replaceLine($config_dir.'/'.$configfile, 'postmaster_address = postmaster@example.com', 'postmaster_address = postmaster@'.$conf['hostname'], 1, 0);
1fc360 108             if(version_compare($dovecot_version,2.1) < 0) {
TB 109                 removeLine($config_dir.'/'.$configfile, 'ssl_protocols =');
110             }
31e0d1 111         } else {
b1a6a5 112             if(is_file($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot.conf.master')) {
MC 113                 copy($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot.conf.master', $config_dir.'/'.$configfile);
114             } else {
115                 copy('tpl/debian6_dovecot.conf.master', $config_dir.'/'.$configfile);
116             }
31e0d1 117         }
1fc360 118         
8b23f8 119         //* dovecot-lmtpd
FS 120         if($configure_lmtp) {
121             replaceLine($config_dir.'/'.$configfile, 'protocols = imap pop3', 'protocols = imap pop3 lmtp', 1, 0);
122         }
b1a6a5 123
94927b 124         //* dovecot-sql.conf
T 125         $configfile = 'dovecot-sql.conf';
8e725d 126         if(is_file($config_dir.'/'.$configfile)){
J 127             copy($config_dir.'/'.$configfile, $config_dir.'/'.$configfile.'~');
4586d5 128             chmod($config_dir.'/'.$configfile.'~', 0400);
8e725d 129         }
615a0a 130         $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot-sql.conf.master', 'tpl/debian6_dovecot-sql.conf.master');
b1a6a5 131         $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
MC 132         $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
133         $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
134         $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
82e9b9 135         $content = str_replace('{mysql_server_port}', $conf['mysql']['port'], $content);
032b86 136         $content = str_replace('{server_id}', $conf['server_id'], $content);
8e725d 137         wf($config_dir.'/'.$configfile, $content);
b1a6a5 138
8e725d 139         chmod($config_dir.'/'.$configfile, 0600);
J 140         chown($config_dir.'/'.$configfile, 'root');
141         chgrp($config_dir.'/'.$configfile, 'root');
5e7306 142         
TB 143         // Dovecot shall ignore mounts in website directory
9b6866 144         if(is_installed('doveadm')) exec("doveadm mount add '/var/www/*' ignore > /dev/null 2> /dev/null");
94927b 145
T 146     }
b1a6a5 147
1ca823 148     public function configure_apache() {
T 149         global $conf;
b1a6a5 150
MC 151         if(file_exists('/etc/apache2/mods-available/fcgid.conf')) replaceLine('/etc/apache2/mods-available/fcgid.conf', 'MaxRequestLen', 'MaxRequestLen 15728640', 0, 1);
152
1ca823 153         parent::configure_apache();
T 154     }
94927b 155
b1a6a5 156     public function configure_fail2ban() {
MC 157         /*
c12af9 158         copy('tpl/dovecot-pop3imap.conf.master',"/etc/fail2ban/filter.d/dovecot-pop3imap.conf");
L 159         copy('tpl/dovecot_fail2ban_jail.local.master','/etc/fail2ban/jail.local');
e44ec9 160     */
b1a6a5 161     }
MC 162
94927b 163 }
T 164
4586d5 165 ?>