Marius Cramer
2014-08-13 42539643c396f9d8865dcf9a51b13dc869709d16
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);
MC 82         $parts = explode('.', trim($tmp[0]));
31e0d1 83         $dovecot_version = $parts[0];
T 84         unset($tmp);
85         unset($parts);
7fe908 86
31e0d1 87         //* Copy dovecot configuration file
T 88         if($dovecot_version == 2) {
7fe908 89             if(is_file($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot2.conf.master')) {
MC 90                 copy($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot2.conf.master', $config_dir.'/'.$configfile);
91             } else {
92                 copy('tpl/debian6_dovecot2.conf.master', $config_dir.'/'.$configfile);
93             }
5e7306 94             replaceLine($config_dir.'/'.$configfile, 'postmaster_address = postmaster@example.com', 'postmaster_address = postmaster@'.$conf['hostname'], 1, 0);
31e0d1 95         } else {
7fe908 96             if(is_file($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot.conf.master')) {
MC 97                 copy($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot.conf.master', $config_dir.'/'.$configfile);
98             } else {
99                 copy('tpl/debian6_dovecot.conf.master', $config_dir.'/'.$configfile);
100             }
31e0d1 101         }
7fe908 102
94927b 103         //* dovecot-sql.conf
T 104         $configfile = 'dovecot-sql.conf';
8e725d 105         if(is_file($config_dir.'/'.$configfile)){
J 106             copy($config_dir.'/'.$configfile, $config_dir.'/'.$configfile.'~');
4586d5 107             chmod($config_dir.'/'.$configfile.'~', 0400);
8e725d 108         }
615a0a 109         $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot-sql.conf.master', 'tpl/debian6_dovecot-sql.conf.master');
7fe908 110         $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
MC 111         $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
112         $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
113         $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
032b86 114         $content = str_replace('{server_id}', $conf['server_id'], $content);
8e725d 115         wf($config_dir.'/'.$configfile, $content);
7fe908 116
8e725d 117         chmod($config_dir.'/'.$configfile, 0600);
J 118         chown($config_dir.'/'.$configfile, 'root');
119         chgrp($config_dir.'/'.$configfile, 'root');
5e7306 120         
TB 121         // Dovecot shall ignore mounts in website directory
9b6866 122         if(is_installed('doveadm')) exec("doveadm mount add '/var/www/*' ignore > /dev/null 2> /dev/null");
94927b 123
T 124     }
7fe908 125
1ca823 126     public function configure_apache() {
T 127         global $conf;
7fe908 128
MC 129         if(file_exists('/etc/apache2/mods-available/fcgid.conf')) replaceLine('/etc/apache2/mods-available/fcgid.conf', 'MaxRequestLen', 'MaxRequestLen 15728640', 0, 1);
130
1ca823 131         parent::configure_apache();
T 132     }
94927b 133
7fe908 134     public function configure_fail2ban() {
MC 135         /*
c12af9 136         copy('tpl/dovecot-pop3imap.conf.master',"/etc/fail2ban/filter.d/dovecot-pop3imap.conf");
L 137         copy('tpl/dovecot_fail2ban_jail.local.master','/etc/fail2ban/jail.local');
e44ec9 138     */
7fe908 139     }
MC 140
94927b 141 }
T 142
4586d5 143 ?>