Till Brehm
2014-10-18 1fc360dfaf61613735cb635c8e905af2b089cf68
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 {
7fe908 32
94927b 33     public function configure_dovecot()
7fe908 34     {
94927b 35         global $conf;
7fe908 36
94927b 37         $config_dir = $conf['dovecot']['config_dir'];
7fe908 38
94927b 39         //* Configure master.cf and add a line for deliver
T 40         if(is_file($config_dir.'/master.cf')){
8e725d 41             copy($config_dir.'/master.cf', $config_dir.'/master.cf~2');
J 42         }
94927b 43         if(is_file($config_dir.'/master.cf~')){
8e725d 44             chmod($config_dir.'/master.cf~2', 0400);
J 45         }
94927b 46         $content = rf($conf["postfix"]["config_dir"].'/master.cf');
T 47         // Only add the content if we had not addded it before
7fe908 48         if(!stristr($content, "dovecot/deliver")) {
94927b 49             $deliver_content = 'dovecot   unix  -       n       n       -       -       pipe'."\n".'  flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop}';
7fe908 50             af($conf["postfix"]["config_dir"].'/master.cf', $deliver_content);
94927b 51         }
T 52         unset($content);
53         unset($deliver_content);
7fe908 54
MC 55
94927b 56         //* Reconfigure postfix to use dovecot authentication
T 57         // Adding the amavisd commands to the postfix configuration
58         $postconf_commands = array (
59             'dovecot_destination_recipient_limit = 1',
60             'virtual_transport = dovecot',
61             'smtpd_sasl_type = dovecot',
62             'smtpd_sasl_path = private/auth'
63         );
7fe908 64
94927b 65         // Make a backup copy of the main.cf file
7fe908 66         copy($conf["postfix"]["config_dir"].'/main.cf', $conf["postfix"]["config_dir"].'/main.cf~3');
MC 67
94927b 68         // Executing the postconf commands
T 69         foreach($postconf_commands as $cmd) {
70             $command = "postconf -e '$cmd'";
71             caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
72         }
7fe908 73
94927b 74         //* copy dovecot.conf
T 75         $configfile = 'dovecot.conf';
8e725d 76         if(is_file($config_dir.'/'.$configfile)){
J 77             copy($config_dir.'/'.$configfile, $config_dir.'/'.$configfile.'~');
78         }
7fe908 79
31e0d1 80         //* Get the dovecot version
7fe908 81         exec('dovecot --version', $tmp);
1fc360 82         $dovecot_version = $tmp[0];
31e0d1 83         unset($tmp);
7fe908 84
31e0d1 85         //* Copy dovecot configuration file
1fc360 86         if(version_compare($dovecot_version,2) >= 0) {
7fe908 87             if(is_file($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot2.conf.master')) {
MC 88                 copy($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot2.conf.master', $config_dir.'/'.$configfile);
89             } else {
90                 copy('tpl/debian6_dovecot2.conf.master', $config_dir.'/'.$configfile);
91             }
5e7306 92             replaceLine($config_dir.'/'.$configfile, 'postmaster_address = postmaster@example.com', 'postmaster_address = postmaster@'.$conf['hostname'], 1, 0);
1fc360 93             if(version_compare($dovecot_version,2.1) < 0) {
TB 94                 removeLine($config_dir.'/'.$configfile, 'ssl_protocols =');
95             }
31e0d1 96         } else {
7fe908 97             if(is_file($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot.conf.master')) {
MC 98                 copy($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot.conf.master', $config_dir.'/'.$configfile);
99             } else {
100                 copy('tpl/debian6_dovecot.conf.master', $config_dir.'/'.$configfile);
101             }
31e0d1 102         }
1fc360 103         
TB 104         
7fe908 105
94927b 106         //* dovecot-sql.conf
T 107         $configfile = 'dovecot-sql.conf';
8e725d 108         if(is_file($config_dir.'/'.$configfile)){
J 109             copy($config_dir.'/'.$configfile, $config_dir.'/'.$configfile.'~');
4586d5 110             chmod($config_dir.'/'.$configfile.'~', 0400);
8e725d 111         }
615a0a 112         $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot-sql.conf.master', 'tpl/debian6_dovecot-sql.conf.master');
7fe908 113         $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
MC 114         $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
115         $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
116         $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
032b86 117         $content = str_replace('{server_id}', $conf['server_id'], $content);
8e725d 118         wf($config_dir.'/'.$configfile, $content);
7fe908 119
8e725d 120         chmod($config_dir.'/'.$configfile, 0600);
J 121         chown($config_dir.'/'.$configfile, 'root');
122         chgrp($config_dir.'/'.$configfile, 'root');
5e7306 123         
TB 124         // Dovecot shall ignore mounts in website directory
9b6866 125         if(is_installed('doveadm')) exec("doveadm mount add '/var/www/*' ignore > /dev/null 2> /dev/null");
94927b 126
T 127     }
7fe908 128
1ca823 129     public function configure_apache() {
T 130         global $conf;
7fe908 131
MC 132         if(file_exists('/etc/apache2/mods-available/fcgid.conf')) replaceLine('/etc/apache2/mods-available/fcgid.conf', 'MaxRequestLen', 'MaxRequestLen 15728640', 0, 1);
133
1ca823 134         parent::configure_apache();
T 135     }
94927b 136
7fe908 137     public function configure_fail2ban() {
MC 138         /*
c12af9 139         copy('tpl/dovecot-pop3imap.conf.master',"/etc/fail2ban/filter.d/dovecot-pop3imap.conf");
L 140         copy('tpl/dovecot_fail2ban_jail.local.master','/etc/fail2ban/jail.local');
e44ec9 141     */
7fe908 142     }
MC 143
94927b 144 }
T 145
4586d5 146 ?>