debian60.lib.php 6.85 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php

/*
Copyright (c) 2007, Till Brehm, projektfarm Gmbh
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

class installer extends installer_base {
32

33
	public function configure_dovecot()
34
	{
35
		global $conf;
Dominik Müller's avatar
Dominik Müller committed
36
37
		
		$virtual_transport = 'dovecot';
38
39

		$configure_lmtp = false;
Dominik Müller's avatar
Dominik Müller committed
40
41
42
		
		// check if virtual_transport must be changed
		if ($this->is_update) {
43
			$tmp = $this->db->queryOneRecord("SELECT * FROM ?? WHERE server_id = ?", $conf["mysql"]["database"] . ".server", $conf['server_id']);
Dominik Müller's avatar
Dominik Müller committed
44
45
46
47
48
			$ini_array = ini_to_array(stripslashes($tmp['config']));
			// ini_array needs not to be checked, because already done in update.php -> updateDbAndIni()
			
			if(isset($ini_array['mail']['mailbox_virtual_uidgid_maps']) && $ini_array['mail']['mailbox_virtual_uidgid_maps'] == 'y') {
				$virtual_transport = 'lmtp:unix:private/dovecot-lmtp';
49
				$configure_lmtp = true;
Dominik Müller's avatar
Dominik Müller committed
50
51
			}
		}
52

53
		$config_dir = $conf['postfix']['config_dir'];
54
		if(!$this->get_postfix_service('dovecot', 'unix')) {
55
56
57
58
59
60
61
62
63
			//* backup
			if(is_file($config_dir.'/master.cf')){
				copy($config_dir.'/master.cf', $config_dir.'/master.cf~2');
			}
			if(is_file($config_dir.'/master.cf~')){
				chmod($config_dir.'/master.cf~2', 0400);
			}
			//* Configure master.cf and add a line for deliver
			$content = rf($conf["postfix"]["config_dir"].'/master.cf');
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";
65
66
67
			af($config_dir.'/master.cf', $deliver_content);
			unset($content);
			unset($deliver_content);
68
		}
69

70
71
72
73
		//* Reconfigure postfix to use dovecot authentication
		// Adding the amavisd commands to the postfix configuration
		$postconf_commands = array (
			'dovecot_destination_recipient_limit = 1',
Dominik Müller's avatar
Dominik Müller committed
74
			'virtual_transport = '.$virtual_transport,
75
76
77
			'smtpd_sasl_type = dovecot',
			'smtpd_sasl_path = private/auth'
		);
78

79
		// Make a backup copy of the main.cf file
80
81
		copy($conf["postfix"]["config_dir"].'/main.cf', $conf["postfix"]["config_dir"].'/main.cf~3');

82
83
84
85
86
		// Executing the postconf commands
		foreach($postconf_commands as $cmd) {
			$command = "postconf -e '$cmd'";
			caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
		}
87

88
		//* copy dovecot.conf
89
		$config_dir = $conf['dovecot']['config_dir'];
90
		$configfile = 'dovecot.conf';
91
92
93
		if(is_file($config_dir.'/'.$configfile)){
			copy($config_dir.'/'.$configfile, $config_dir.'/'.$configfile.'~');
		}
94

95
		//* Get the dovecot version
96
		exec('dovecot --version', $tmp);
97
		$dovecot_version = $tmp[0];
98
		unset($tmp);
99

100
		//* Copy dovecot configuration file
101
		if(version_compare($dovecot_version,2) >= 0) {
102
103
104
105
106
			if(is_file($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot2.conf.master')) {
				copy($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot2.conf.master', $config_dir.'/'.$configfile);
			} else {
				copy('tpl/debian6_dovecot2.conf.master', $config_dir.'/'.$configfile);
			}
107
			replaceLine($config_dir.'/'.$configfile, 'postmaster_address = postmaster@example.com', 'postmaster_address = postmaster@'.$conf['hostname'], 1, 0);
108
109
110
			if(version_compare($dovecot_version,2.1) < 0) {
				removeLine($config_dir.'/'.$configfile, 'ssl_protocols =');
			}
111
		} else {
112
113
114
115
116
			if(is_file($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot.conf.master')) {
				copy($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot.conf.master', $config_dir.'/'.$configfile);
			} else {
				copy('tpl/debian6_dovecot.conf.master', $config_dir.'/'.$configfile);
			}
117
		}
118
		
119
120
121
122
		//* dovecot-lmtpd
		if($configure_lmtp) {
			replaceLine($config_dir.'/'.$configfile, 'protocols = imap pop3', 'protocols = imap pop3 lmtp', 1, 0);
		}
123

124
125
		//* dovecot-sql.conf
		$configfile = 'dovecot-sql.conf';
126
127
		if(is_file($config_dir.'/'.$configfile)){
			copy($config_dir.'/'.$configfile, $config_dir.'/'.$configfile.'~');
128
			chmod($config_dir.'/'.$configfile.'~', 0400);
129
		}
130
		$content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/debian6_dovecot-sql.conf.master', 'tpl/debian6_dovecot-sql.conf.master');
131
132
133
134
		$content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
		$content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
		$content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
		$content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
135
		$content = str_replace('{mysql_server_port}', $conf['mysql']['port'], $content);
136
		$content = str_replace('{server_id}', $conf['server_id'], $content);
137
		wf($config_dir.'/'.$configfile, $content);
138

139
140
141
		chmod($config_dir.'/'.$configfile, 0600);
		chown($config_dir.'/'.$configfile, 'root');
		chgrp($config_dir.'/'.$configfile, 'root');
142
143
		
		// Dovecot shall ignore mounts in website directory
Till Brehm's avatar
Till Brehm committed
144
		if(is_installed('doveadm')) exec("doveadm mount add '/var/www/*' ignore > /dev/null 2> /dev/null");
145
146

	}
147

148
149
	public function configure_apache() {
		global $conf;
150
151
152

		if(file_exists('/etc/apache2/mods-available/fcgid.conf')) replaceLine('/etc/apache2/mods-available/fcgid.conf', 'MaxRequestLen', 'MaxRequestLen 15728640', 0, 1);

153
154
		parent::configure_apache();
	}
155

156
157
	public function configure_fail2ban() {
		/*
latham's avatar
latham committed
158
159
        copy('tpl/dovecot-pop3imap.conf.master',"/etc/fail2ban/filter.d/dovecot-pop3imap.conf");
        copy('tpl/dovecot_fail2ban_jail.local.master','/etc/fail2ban/jail.local');
160
	*/
161
162
	}

163
164
}

165
?>