commit | author | age
|
9200ad
|
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_base { |
|
32 |
|
|
33 |
var $wb = array(); |
|
34 |
var $language = 'en'; |
|
35 |
var $db; |
cc3fb3
|
36 |
public $conf; |
09e141
|
37 |
|
P |
38 |
|
32814e
|
39 |
public function __construct() |
5133cc
|
40 |
{ |
b0a1cc
|
41 |
global $conf; //TODO: maybe $conf should be passed to constructor |
P |
42 |
$this->conf = $conf; |
5133cc
|
43 |
} |
9200ad
|
44 |
|
32814e
|
45 |
//TODO uh ? |
P |
46 |
public function lng($text) |
|
47 |
{ |
ce9544
|
48 |
return $text; |
9200ad
|
49 |
} |
T |
50 |
|
32814e
|
51 |
public function error($msg) |
P |
52 |
{ |
9200ad
|
53 |
die("ERROR: ".$msg."\n"); |
T |
54 |
} |
|
55 |
|
32814e
|
56 |
public function simple_query($query, $answers, $default) |
P |
57 |
{ |
ce9544
|
58 |
$finished = false; |
T |
59 |
do { |
32814e
|
60 |
$answers_str = implode(',', $answers); |
239ce8
|
61 |
swrite($this->lng($query).' ('.$answers_str.') ['.$default.']: '); |
ce9544
|
62 |
$input = sread(); |
T |
63 |
|
32814e
|
64 |
//* Stop the installation |
ce9544
|
65 |
if($input == 'quit') { |
32814e
|
66 |
swriteln($this->lng("Installation terminated by user.\n")); |
239ce8
|
67 |
die(); |
ce9544
|
68 |
} |
T |
69 |
|
32814e
|
70 |
//* Select the default |
ce9544
|
71 |
if($input == '') { |
T |
72 |
$answer = $default; |
|
73 |
$finished = true; |
|
74 |
} |
|
75 |
|
32814e
|
76 |
//* Set answer id valid |
P |
77 |
if(in_array($input, $answers)) { |
ce9544
|
78 |
$answer = $input; |
T |
79 |
$finished = true; |
|
80 |
} |
|
81 |
|
|
82 |
} while ($finished == false); |
239ce8
|
83 |
swriteln(); |
ce9544
|
84 |
return $answer; |
T |
85 |
} |
|
86 |
|
32814e
|
87 |
public function free_query($query,$default) |
P |
88 |
{ |
239ce8
|
89 |
swrite($this->lng($query).' ['.$default.']: '); |
ce9544
|
90 |
$input = sread(); |
T |
91 |
|
32814e
|
92 |
//* Stop the installation |
ce9544
|
93 |
if($input == 'quit') { |
32814e
|
94 |
swriteln($this->lng("Installation terminated by user.\n")); |
P |
95 |
die(); |
ce9544
|
96 |
} |
T |
97 |
|
32814e
|
98 |
$answer = ($input == '') ? $default : $input; |
239ce8
|
99 |
swriteln(); |
ce9544
|
100 |
return $answer; |
T |
101 |
} |
|
102 |
|
32814e
|
103 |
// TODO: this function is not used atmo I think - pedro |
P |
104 |
function request_language(){ |
9200ad
|
105 |
|
T |
106 |
swriteln(lng('Enter your language')); |
|
107 |
swriteln(lng('de, en')); |
|
108 |
|
|
109 |
/* |
|
110 |
do { |
|
111 |
$lang = sread(2); |
|
112 |
} while (!$this->check_break($lang) or $this-> |
|
113 |
*/ |
|
114 |
|
|
115 |
} |
|
116 |
|
facccb
|
117 |
/** Create the database for ISPConfig */ |
P |
118 |
public function configure_database() |
|
119 |
{ |
9200ad
|
120 |
global $conf; |
facccb
|
121 |
$cf = $conf['mysql']; // make $conf['mysql'] more accessible |
P |
122 |
//** Create the database |
|
123 |
if(!$this->db->query('CREATE DATABASE IF NOT EXISTS '.$cf['database'])) { |
|
124 |
$this->error('Unable to create MySQL database: '.$cf['database'].'.'); |
9200ad
|
125 |
} |
T |
126 |
|
facccb
|
127 |
//* Create the ISPConfig database user |
P |
128 |
$query = 'GRANT SELECT, INSERT, UPDATE, DELETE ON '.$cf['database'].".* " |
|
129 |
."TO '".$cf['ispconfig_user']."'@'".$cf['host']."' " |
|
130 |
."IDENTIFIED BY '".$cf['ispconfig_password']."';"; |
|
131 |
if(!$this->db->query($query)) { |
|
132 |
$this->error('Unable to create database user: '.$cf['ispconfig_user']); |
9200ad
|
133 |
} |
T |
134 |
|
facccb
|
135 |
//* Reload database privelages |
9200ad
|
136 |
$this->db->query('FLUSH PRIVILEGES;'); |
T |
137 |
|
facccb
|
138 |
//* Set the database name in the DB library |
P |
139 |
$this->db->dbName = $cf['database']; |
9200ad
|
140 |
|
facccb
|
141 |
//* Load the database dump into the database, if database contains no tables |
9200ad
|
142 |
$db_tables = $this->db->getTables(); |
T |
143 |
if(count($db_tables) > 0) { |
66b4f9
|
144 |
$this->error('Stopped: Database already contains some tables.'); |
9200ad
|
145 |
} else { |
facccb
|
146 |
if($cf['admin_password'] == '') { |
P |
147 |
caselog("mysql -h '".$cf['host']."' -u '".$cf['admin_user']."' '".$cf['database']."' < 'sql/ispconfig3.sql' &> /dev/null", |
66b4f9
|
148 |
__FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in ispconfig3.sql'); |
9200ad
|
149 |
} else { |
facccb
|
150 |
caselog("mysql -h '".$cf['host']."' -u '".$cf['admin_user']."' -p'".$cf['admin_password']."' '".$cf['database']."' < 'sql/ispconfig3.sql' &> /dev/null", |
66b4f9
|
151 |
__FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in ispconfig3.sql'); |
9200ad
|
152 |
} |
T |
153 |
$db_tables = $this->db->getTables(); |
|
154 |
if(count($db_tables) == 0) { |
|
155 |
$this->error('Unable to load SQL-Dump into database table.'); |
|
156 |
} |
|
157 |
} |
|
158 |
} |
|
159 |
|
b41692
|
160 |
|
09e141
|
161 |
//** writes postfix configuration files |
b41692
|
162 |
private function process_postfix_config($configfile) |
P |
163 |
{ |
cc3fb3
|
164 |
$config_dir = $this->conf['postfix']['config_dir'].'/'; |
b41692
|
165 |
$full_file_name = $config_dir.$configfile; |
P |
166 |
//* Backup exiting file |
|
167 |
if(is_file($full_file_name)){ |
|
168 |
copy($full_file_name, $config_dir.$configfile.'~'); |
|
169 |
} |
|
170 |
$content = rf('tpl/'.$configfile.'.master'); |
|
171 |
$content = str_replace('{mysql_server_ispconfig_user}', $this->conf['mysql']['ispconfig_user'], $content); |
|
172 |
$content = str_replace('{mysql_server_ispconfig_password}', $this->conf['mysql']['ispconfig_password'], $content); |
|
173 |
$content = str_replace('{mysql_server_database}', $this->conf['mysql']['database'], $content); |
|
174 |
$content = str_replace('{mysql_server_ip}', $this->conf['mysql']['ip'], $content); |
|
175 |
$content = str_replace('{server_id}', $this->conf['server_id'], $content); |
|
176 |
wf($full_file_name, $content); |
|
177 |
} |
|
178 |
|
09e141
|
179 |
|
b41692
|
180 |
public function configure_postfix($options = '') |
P |
181 |
{ |
cc3fb3
|
182 |
$cf = $this->conf['postfix']; |
77ab0a
|
183 |
$config_dir = $cf['config_dir']; |
P |
184 |
|
b41692
|
185 |
if(!is_dir($config_dir)){ |
P |
186 |
$this->error("The postfix configuration directory '$config_dir' does not exist."); |
|
187 |
} |
|
188 |
|
|
189 |
//* mysql-virtual_domains.cf |
|
190 |
$this->process_postfix_config('mysql-virtual_domains.cf'); |
|
191 |
|
|
192 |
//* mysql-virtual_forwardings.cf |
|
193 |
$this->process_postfix_config('mysql-virtual_forwardings.cf'); |
|
194 |
|
|
195 |
//* mysql-virtual_mailboxes.cf |
|
196 |
$this->process_postfix_config('mysql-virtual_mailboxes.cf'); |
|
197 |
|
|
198 |
//* mysql-virtual_email2email.cf |
|
199 |
$this->process_postfix_config('mysql-virtual_email2email.cf'); |
|
200 |
|
|
201 |
//* mysql-virtual_transports.cf |
|
202 |
$this->process_postfix_config('mysql-virtual_transports.cf'); |
|
203 |
|
|
204 |
//* mysql-virtual_recipient.cf |
|
205 |
$this->process_postfix_config('mysql-virtual_recipient.cf'); |
|
206 |
|
|
207 |
//* mysql-virtual_sender.cf |
|
208 |
$this->process_postfix_config('mysql-virtual_sender.cf'); |
|
209 |
|
|
210 |
//* mysql-virtual_client.cf |
|
211 |
$this->process_postfix_config('mysql-virtual_client.cf'); |
5bf366
|
212 |
|
T |
213 |
//* mysql-virtual_relaydomains.cf |
|
214 |
$this->process_postfix_config('mysql-virtual_relaydomains.cf'); |
b41692
|
215 |
|
P |
216 |
//* Changing mode and group of the new created config files. |
77ab0a
|
217 |
caselog('chmod o= '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null', |
P |
218 |
__FILE__, __LINE__, 'chmod on mysql-virtual_*.cf*', 'chmod on mysql-virtual_*.cf* failed'); |
|
219 |
caselog('chgrp '.$cf['group'].' '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null', |
|
220 |
__FILE__, __LINE__, 'chgrp on mysql-virtual_*.cf*', 'chgrp on mysql-virtual_*.cf* failed'); |
9200ad
|
221 |
|
77ab0a
|
222 |
//* Creating virtual mail user and group |
P |
223 |
$command = 'groupadd -g '.$cf['vmail_groupid'].' '.$cf['vmail_groupname']; |
|
224 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
225 |
|
|
226 |
$command = 'useradd -g '.$cf['vmail_groupname'].' -u '.$cf['vmail_userid'].' '.$cf['vmail_username'].' -d '.$cf['vmail_mailbox_base'].' -m'; |
|
227 |
caselog("$command &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
9200ad
|
228 |
|
T |
229 |
$postconf_commands = array ( |
77ab0a
|
230 |
'myhostname = '.$this->conf['hostname'], |
P |
231 |
'mydestination = '.$this->conf['hostname'].', localhost, localhost.localdomain', |
9200ad
|
232 |
'mynetworks = 127.0.0.0/8', |
T |
233 |
'virtual_alias_domains =', |
438d9f
|
234 |
'virtual_alias_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_forwardings.cf, mysql:'.$config_dir.'/mysql-virtual_email2email.cf', |
P |
235 |
'virtual_mailbox_domains = proxy:mysql:'.$config_dir.'/mysql-virtual_domains.cf', |
77ab0a
|
236 |
'virtual_mailbox_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_mailboxes.cf', |
P |
237 |
'virtual_mailbox_base = '.$cf['vmail_mailbox_base'], |
|
238 |
'virtual_uid_maps = static:'.$cf['vmail_userid'], |
|
239 |
'virtual_gid_maps = static:'.$cf['vmail_groupid'], |
9200ad
|
240 |
'smtpd_sasl_auth_enable = yes', |
T |
241 |
'broken_sasl_auth_clients = yes', |
438d9f
|
242 |
'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, check_recipient_access mysql:'.$config_dir.'/mysql-virtual_recipient.cf, reject_unauth_destination', |
9200ad
|
243 |
'smtpd_use_tls = yes', |
438d9f
|
244 |
'smtpd_tls_cert_file = '.$config_dir.'/smtpd.cert', |
P |
245 |
'smtpd_tls_key_file = '.$config_dir.'/smtpd.key', |
|
246 |
'transport_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_transports.cf', |
5bf366
|
247 |
'relay_domains = mysql:'.$config_dir.'/mysql-virtual_relaydomains.cf', |
9200ad
|
248 |
'virtual_create_maildirsize = yes', |
T |
249 |
'virtual_mailbox_extended = yes', |
438d9f
|
250 |
'virtual_mailbox_limit_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_mailbox_limit_maps.cf', |
9200ad
|
251 |
'virtual_mailbox_limit_override = yes', |
T |
252 |
'virtual_maildir_limit_message = "The user you are trying to reach is over quota."', |
|
253 |
'virtual_overquota_bounce = yes', |
|
254 |
'proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps', |
438d9f
|
255 |
'smtpd_sender_restrictions = check_sender_access mysql:'.$config_dir.'/mysql-virtual_sender.cf', |
P |
256 |
'smtpd_client_restrictions = check_client_access mysql:'.$config_dir.'/mysql-virtual_client.cf', |
9200ad
|
257 |
'maildrop_destination_concurrency_limit = 1', |
T |
258 |
'maildrop_destination_recipient_limit = 1', |
54fb59
|
259 |
'virtual_transport = maildrop', |
438d9f
|
260 |
'header_checks = regexp:'.$config_dir.'/header_checks', |
P |
261 |
'mime_header_checks = regexp:'.$config_dir.'/mime_header_checks', |
|
262 |
'nested_header_checks = regexp:'.$config_dir.'/nested_header_checks', |
|
263 |
'body_checks = regexp:'.$config_dir.'/body_checks' |
9200ad
|
264 |
); |
T |
265 |
|
438d9f
|
266 |
//* Create the header and body check files |
P |
267 |
touch($config_dir.'/header_checks'); |
|
268 |
touch($config_dir.'/mime_header_checks'); |
|
269 |
touch($config_dir.'/nested_header_checks'); |
|
270 |
touch($config_dir.'/body_checks'); |
54fb59
|
271 |
|
T |
272 |
|
438d9f
|
273 |
//* Make a backup copy of the main.cf file |
P |
274 |
copy($config_dir.'/main.cf', $config_dir.'/main.cf~'); |
9200ad
|
275 |
|
438d9f
|
276 |
//* Executing the postconf commands |
9200ad
|
277 |
foreach($postconf_commands as $cmd) { |
T |
278 |
$command = "postconf -e '$cmd'"; |
438d9f
|
279 |
caselog($command." &> /dev/null", __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command); |
9200ad
|
280 |
} |
T |
281 |
|
|
282 |
// TODO: Change the master.cf file |
|
283 |
/* |
|
284 |
Add: |
77ab0a
|
285 |
maildrop unix - n n - - pipe |
P |
286 |
flags=R user=vmail argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender} |
9200ad
|
287 |
*/ |
fb7155
|
288 |
if(!stristr($options,'dont-create-certs')) { |
438d9f
|
289 |
//* Create the SSL certificate |
P |
290 |
$command = 'cd '.$config_dir.'; ' |
|
291 |
.'openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout ' |
|
292 |
.'smtpd.key -keyform PEM -days 365 -x509'; |
c58e3f
|
293 |
exec($command); |
9200ad
|
294 |
|
438d9f
|
295 |
$command = 'chmod o= '.$config_dir.'/smtpd.key'; |
P |
296 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command); |
c58e3f
|
297 |
} |
9200ad
|
298 |
|
77ab0a
|
299 |
//** We have to change the permissions of the courier authdaemon directory to make it accessible for maildrop. |
438d9f
|
300 |
$command = 'chmod 755 /var/run/courier/authdaemon/'; |
P |
301 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command); |
9200ad
|
302 |
|
438d9f
|
303 |
//* Changing maildrop lines in posfix master.cf |
P |
304 |
if(is_file($config_dir.'/master.cf')){ |
|
305 |
copy($config_dir.'/master.cf', $config_dir.'/master.cf~'); |
|
306 |
} |
|
307 |
if(is_file($config_dir.'/master.cf~')){ |
|
308 |
exec('chmod 400 '.$config_dir.'/master.cf~'); |
|
309 |
} |
|
310 |
$configfile = $config_dir.'/master.cf'; |
20e642
|
311 |
$content = rf($configfile); |
77ab0a
|
312 |
$content = str_replace(' flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}', |
P |
313 |
' flags=R user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}', |
|
314 |
$content); |
|
315 |
wf($configfile, $content); |
20e642
|
316 |
|
438d9f
|
317 |
//* Writing the Maildrop mailfilter file |
9200ad
|
318 |
$configfile = 'mailfilter'; |
77ab0a
|
319 |
if(is_file($cf['vmail_mailbox_base'].'/.'.$configfile)){ |
P |
320 |
copy($cf['vmail_mailbox_base'].'/.'.$configfile, $cf['vmail_mailbox_base'].'/.'.$configfile.'~'); |
|
321 |
} |
|
322 |
$content = rf("tpl/$configfile.master"); |
|
323 |
$content = str_replace('{dist_postfix_vmail_mailbox_base}', $cf['vmail_mailbox_base'], $content); |
|
324 |
wf($cf['vmail_mailbox_base'].'/.'.$configfile, $content); |
9200ad
|
325 |
|
77ab0a
|
326 |
//* Create the directory for the custom mailfilters |
P |
327 |
$command = 'mkdir '.$cf['vmail_mailbox_base'].'/mailfilters'; |
|
328 |
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
9200ad
|
329 |
|
77ab0a
|
330 |
//* Chmod and chown the .mailfilter file |
P |
331 |
$command = 'chown -R '.$cf['vmail_username'].':'.$cf['vmail_groupname'].' '.$cf['vmail_mailbox_base'].'/.mailfilter'; |
|
332 |
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
9200ad
|
333 |
|
77ab0a
|
334 |
$command = 'chmod -R 600 '.$cf['vmail_mailbox_base'].'/.mailfilter'; |
P |
335 |
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
9200ad
|
336 |
|
T |
337 |
} |
|
338 |
|
|
339 |
function configure_saslauthd() { |
|
340 |
global $conf; |
|
341 |
|
20e642
|
342 |
|
9200ad
|
343 |
$configfile = 'sasl_smtpd.conf'; |
cc3fb3
|
344 |
if(is_file($conf["postfix"]["config_dir"].'/sasl/smtpd.conf')) copy($conf["postfix"]["config_dir"].'/sasl/smtpd.conf',$conf["postfix"]["config_dir"].'/sasl/smtpd.conf~'); |
O |
345 |
if(is_file($conf["postfix"]["config_dir"].'/sasl/smtpd.conf~')) exec('chmod 400 '.$conf["postfix"]["config_dir"].'/sasl/smtpd.conf~'); |
9200ad
|
346 |
$content = rf("tpl/".$configfile.".master"); |
09e141
|
347 |
$content = str_replace('{mysql_server_ispconfig_user}',$this->conf['mysql']['ispconfig_user'],$content); |
P |
348 |
$content = str_replace('{mysql_server_ispconfig_password}',$this->conf['mysql']['ispconfig_password'], $content); |
|
349 |
$content = str_replace('{mysql_server_database}',$this->conf['mysql']['database'],$content); |
|
350 |
$content = str_replace('{mysql_server_ip}',$this->conf['mysql']['ip'],$content); |
cc3fb3
|
351 |
wf($conf["postfix"]["config_dir"].'/sasl/smtpd.conf',$content); |
9200ad
|
352 |
|
T |
353 |
// TODO: Chmod and chown on the config file |
20e642
|
354 |
|
T |
355 |
|
|
356 |
|
|
357 |
// Create the spool directory |
20218c
|
358 |
exec('mkdir -p /var/spool/postfix/var/run/saslauthd'); |
20e642
|
359 |
|
T |
360 |
// Edit the file /etc/default/saslauthd |
cc3fb3
|
361 |
$configfile = $conf["saslauthd"]["config"]; |
20e642
|
362 |
if(is_file($configfile)) copy($configfile,$configfile.'~'); |
e32699
|
363 |
if(is_file($configfile.'~')) exec('chmod 400 '.$configfile.'~'); |
20e642
|
364 |
$content = rf($configfile); |
T |
365 |
$content = str_replace('START=no','START=yes',$content); |
|
366 |
$content = str_replace('OPTIONS="-c"','OPTIONS="-m /var/spool/postfix/var/run/saslauthd -r"',$content); |
|
367 |
wf($configfile,$content); |
|
368 |
|
20218c
|
369 |
// Edit the file /etc/init.d/saslauthd |
cc3fb3
|
370 |
$configfile = $conf["init_scripts"].'/'.$conf["saslauthd"]["init_script"]; |
20e642
|
371 |
$content = rf($configfile); |
T |
372 |
$content = str_replace('PIDFILE=$RUN_DIR/saslauthd.pid','PIDFILE="/var/spool/postfix/var/run/${NAME}/saslauthd.pid"',$content); |
|
373 |
wf($configfile,$content); |
9200ad
|
374 |
|
T |
375 |
|
|
376 |
} |
|
377 |
|
09e141
|
378 |
public function configure_pam() |
P |
379 |
{ |
cc3fb3
|
380 |
$pam = $this->conf['pam']; |
09e141
|
381 |
//* configure pam for SMTP authentication agains the ispconfig database |
9200ad
|
382 |
$configfile = 'pamd_smtp'; |
09e141
|
383 |
if(is_file("$pam/smtp")) copy("$pam/smtp", "$pam/smtp~"); |
P |
384 |
if(is_file("$pam/smtp~")) exec("chmod 400 $pam/smtp~"); |
|
385 |
|
|
386 |
$content = rf("tpl/$configfile.master"); |
|
387 |
$content = str_replace('{mysql_server_ispconfig_user}', $this->conf['mysql']['ispconfig_user'], $content); |
|
388 |
$content = str_replace('{mysql_server_ispconfig_password}', $this->conf['mysql']['ispconfig_password'], $content); |
|
389 |
$content = str_replace('{mysql_server_database}', $this->conf['mysql']['database'], $content); |
|
390 |
$content = str_replace('{mysql_server_ip}', $this->conf['mysql']['ip'], $content); |
|
391 |
wf("$pam/smtp", $content); |
|
392 |
exec("chmod 660 $pam/smtp"); |
|
393 |
exec("chown daemon:daemon $pam/smtp"); |
9200ad
|
394 |
|
T |
395 |
} |
|
396 |
|
09e141
|
397 |
public function configure_courier() |
P |
398 |
{ |
cc3fb3
|
399 |
$config_dir = $this->conf['courier']['config_dir']; |
09e141
|
400 |
//* authmysqlrc |
9200ad
|
401 |
$configfile = 'authmysqlrc'; |
09e141
|
402 |
if(is_file("$config_dir/$configfile")){ |
P |
403 |
copy("$config_dir/$configfile", "$config_dir/$configfile~"); |
|
404 |
} |
|
405 |
exec("chmod 400 $config_dir/$configfile~"); |
|
406 |
$content = rf("tpl/$configfile.master"); |
|
407 |
$content = str_replace('{mysql_server_ispconfig_user}',$this->conf['mysql']['ispconfig_user'],$content); |
|
408 |
$content = str_replace('{mysql_server_ispconfig_password}',$this->conf['mysql']['ispconfig_password'], $content); |
|
409 |
$content = str_replace('{mysql_server_database}',$this->conf['mysql']['database'],$content); |
|
410 |
$content = str_replace('{mysql_server_host}',$this->conf['mysql']['host'],$content); |
|
411 |
wf("$config_dir/$configfile", $content); |
9200ad
|
412 |
|
09e141
|
413 |
exec("chmod 660 $config_dir/$configfile"); |
P |
414 |
exec("chown daemon:daemon $config_dir/$configfile"); |
20e642
|
415 |
|
09e141
|
416 |
//* authdaemonrc |
cc3fb3
|
417 |
$configfile = $this->conf['courier']['config_dir'].'/authdaemonrc'; |
09e141
|
418 |
if(is_file($configfile)){ |
P |
419 |
copy($configfile, $configfile.'~'); |
|
420 |
} |
|
421 |
if(is_file($configfile.'~')){ |
|
422 |
exec('chmod 400 '.$configfile.'~'); |
|
423 |
} |
20e642
|
424 |
$content = rf($configfile); |
09e141
|
425 |
$content = str_replace('authmodulelist="authpam"', 'authmodulelist="authmysql"', $content); |
P |
426 |
wf($configfile, $content); |
9200ad
|
427 |
} |
T |
428 |
|
|
429 |
function configure_amavis() { |
|
430 |
global $conf; |
|
431 |
|
|
432 |
// amavisd user config file |
|
433 |
$configfile = 'amavisd_user_config'; |
cc3fb3
|
434 |
if(is_file($conf["amavis"]["config_dir"].'/conf.d/50-user')) copy($conf["amavis"]["config_dir"].'/conf.d/50-user',$conf["courier"]["config_dir"].'/50-user~'); |
O |
435 |
if(is_file($conf["amavis"]["config_dir"].'/conf.d/50-user~')) exec('chmod 400 '.$conf["amavis"]["config_dir"].'/conf.d/50-user~'); |
9200ad
|
436 |
$content = rf("tpl/".$configfile.".master"); |
09e141
|
437 |
$content = str_replace('{mysql_server_ispconfig_user}',$this->conf['mysql']['ispconfig_user'],$content); |
P |
438 |
$content = str_replace('{mysql_server_ispconfig_password}',$this->conf['mysql']['ispconfig_password'], $content); |
|
439 |
$content = str_replace('{mysql_server_database}',$this->conf['mysql']['database'],$content); |
20218c
|
440 |
$content = str_replace('{mysql_server_port}',$conf["mysql"]["port"],$content); |
09e141
|
441 |
$content = str_replace('{mysql_server_ip}',$this->conf['mysql']['ip'],$content); |
cc3fb3
|
442 |
wf($conf["amavis"]["config_dir"].'/conf.d/50-user',$content); |
9200ad
|
443 |
|
T |
444 |
// TODO: chmod and chown on the config file |
|
445 |
|
|
446 |
|
|
447 |
// Adding the amavisd commands to the postfix configuration |
|
448 |
$postconf_commands = array ( |
|
449 |
'content_filter = amavis:[127.0.0.1]:10024', |
|
450 |
'receive_override_options = no_address_mappings' |
|
451 |
); |
|
452 |
|
|
453 |
// Make a backup copy of the main.cf file |
cc3fb3
|
454 |
copy($conf["postfix"]["config_dir"].'/main.cf',$conf["postfix"]["config_dir"].'/main.cf~2'); |
9200ad
|
455 |
|
T |
456 |
// Executing the postconf commands |
|
457 |
foreach($postconf_commands as $cmd) { |
|
458 |
$command = "postconf -e '$cmd'"; |
76b6b6
|
459 |
caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
9200ad
|
460 |
} |
T |
461 |
|
|
462 |
// Append the configuration for amavisd to the master.cf file |
cc3fb3
|
463 |
if(is_file($conf["postfix"]["config_dir"].'/master.cf')) copy($conf["postfix"]["config_dir"].'/master.cf',$conf["postfix"]["config_dir"].'/master.cf~'); |
9200ad
|
464 |
$content = rf("tpl/master_cf_amavis.master"); |
T |
465 |
// Only add the content if we had not addded it before |
|
466 |
if(!stristr("127.0.0.1:10025 inet n - - - - smtpd",$content)) { |
cc3fb3
|
467 |
af($conf["postfix"]["config_dir"].'/master.cf',$content); |
9200ad
|
468 |
} |
T |
469 |
|
|
470 |
// Add the clamav user to the amavis group |
|
471 |
exec('adduser clamav amavis'); |
|
472 |
|
|
473 |
|
|
474 |
} |
|
475 |
|
77ab0a
|
476 |
public function configure_spamassassin() |
P |
477 |
{ |
09e141
|
478 |
//* Enable spamasasssin on debian and ubuntu |
9200ad
|
479 |
$configfile = '/etc/default/spamassassin'; |
77ab0a
|
480 |
if(is_file($configfile)){ |
09e141
|
481 |
copy($configfile, $configfile.'~'); |
77ab0a
|
482 |
} |
9200ad
|
483 |
$content = rf($configfile); |
77ab0a
|
484 |
$content = str_replace('ENABLED=0', 'ENABLED=1', $content); |
P |
485 |
wf($configfile, $content); |
9200ad
|
486 |
} |
T |
487 |
|
09e141
|
488 |
public function configure_getmail() |
P |
489 |
{ |
cc3fb3
|
490 |
$config_dir = $this->conf['getmail']['config_dir']; |
03ade5
|
491 |
|
T |
492 |
if(!is_dir($config_dir)) exec("mkdir -p ".escapeshellcmd($config_dir)); |
09e141
|
493 |
|
P |
494 |
$command = "useradd -d $config_dir getmail"; |
|
495 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
ba747c
|
496 |
|
09e141
|
497 |
$command = "chown -R getmail $config_dir"; |
P |
498 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
3edf9d
|
499 |
|
09e141
|
500 |
$command = "chmod -R 700 $config_dir"; |
P |
501 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
ba747c
|
502 |
} |
T |
503 |
|
9200ad
|
504 |
|
09e141
|
505 |
public function configure_pureftpd() |
P |
506 |
{ |
cc3fb3
|
507 |
$config_dir = $this->conf['pureftpd']['config_dir']; |
09e141
|
508 |
|
P |
509 |
//* configure pam for SMTP authentication agains the ispconfig database |
20218c
|
510 |
$configfile = 'db/mysql.conf'; |
09e141
|
511 |
if(is_file("$config_dir/$configfile")){ |
P |
512 |
copy("$config_dir/$configfile", "$config_dir/$configfile~"); |
|
513 |
} |
|
514 |
if(is_file("$config_dir/$configfile~")){ |
|
515 |
exec("chmod 400 $config_dir/$configfile~"); |
|
516 |
} |
|
517 |
$content = rf('tpl/pureftpd_mysql.conf.master'); |
|
518 |
$content = str_replace('{mysql_server_ispconfig_user}', $this->conf["mysql"]["ispconfig_user"], $content); |
|
519 |
$content = str_replace('{mysql_server_ispconfig_password}', $this->conf["mysql"]["ispconfig_password"], $content); |
|
520 |
$content = str_replace('{mysql_server_database}', $this->conf["mysql"]["database"], $content); |
|
521 |
$content = str_replace('{mysql_server_ip}', $this->conf["mysql"]["ip"], $content); |
|
522 |
$content = str_replace('{server_id}', $this->conf["server_id"], $content); |
|
523 |
wf("$config_dir/$configfile", $content); |
|
524 |
exec("chmod 600 $config_dir/$configfile"); |
|
525 |
exec("chown root:root $config_dir/$configfile"); |
|
526 |
// **enable chrooting |
af8f1b
|
527 |
//exec('mkdir -p '.$config_dir.'/conf/ChrootEveryone'); |
09e141
|
528 |
exec('echo "yes" > '.$config_dir.'/conf/ChrootEveryone'); |
b4c750
|
529 |
} |
T |
530 |
|
09e141
|
531 |
public function configure_mydns() |
P |
532 |
{ |
99d85e
|
533 |
global $conf; |
T |
534 |
|
|
535 |
// configure pam for SMTP authentication agains the ispconfig database |
|
536 |
$configfile = 'mydns.conf'; |
cc3fb3
|
537 |
if(is_file($conf["mydns"]["config_dir"].'/'.$configfile)) copy($conf["mydns"]["config_dir"].'/'.$configfile,$conf["mydns"]["config_dir"].'/'.$configfile.'~'); |
O |
538 |
if(is_file($conf["mydns"]["config_dir"].'/'.$configfile.'~')) exec('chmod 400 '.$conf["mydns"]["config_dir"].'/'.$configfile.'~'); |
99d85e
|
539 |
$content = rf("tpl/".$configfile.".master"); |
09e141
|
540 |
$content = str_replace('{mysql_server_ispconfig_user}',$this->conf['mysql']['ispconfig_user'],$content); |
P |
541 |
$content = str_replace('{mysql_server_ispconfig_password}',$this->conf['mysql']['ispconfig_password'], $content); |
|
542 |
$content = str_replace('{mysql_server_database}',$this->conf['mysql']['database'],$content); |
20218c
|
543 |
$content = str_replace('{mysql_server_host}',$conf["mysql"]["host"],$content); |
99d85e
|
544 |
$content = str_replace('{server_id}',$conf["server_id"],$content); |
cc3fb3
|
545 |
wf($conf["mydns"]["config_dir"].'/'.$configfile,$content); |
O |
546 |
exec('chmod 600 '.$conf["mydns"]["config_dir"].'/'.$configfile); |
|
547 |
exec('chown root:root '.$conf["mydns"]["config_dir"].'/'.$configfile); |
99d85e
|
548 |
|
T |
549 |
} |
|
550 |
|
76b6b6
|
551 |
public function configure_apache() |
P |
552 |
{ |
|
553 |
//* Create the logging directory for the vhost logfiles |
|
554 |
exec('mkdir -p /var/log/ispconfig/httpd'); |
313e33
|
555 |
|
T |
556 |
} |
|
557 |
|
b4c750
|
558 |
|
76b6b6
|
559 |
public function install_ispconfig() |
P |
560 |
{ |
|
561 |
$install_dir = $this->conf['ispconfig_install_dir']; |
9200ad
|
562 |
|
76b6b6
|
563 |
//* Create the ISPConfig installation directory |
P |
564 |
$command = "mkdir $install_dir"; |
|
565 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
9200ad
|
566 |
|
76b6b6
|
567 |
//* Create a ISPConfig user and group |
P |
568 |
$command = 'groupadd ispconfig'; |
|
569 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
570 |
|
|
571 |
$command = "useradd -g ispconfig -d $install_dir ispconfig"; |
|
572 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
573 |
|
|
574 |
//* copy the ISPConfig interface part |
|
575 |
$command = "cp -rf ../interface $install_dir"; |
|
576 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
577 |
|
|
578 |
//* copy the ISPConfig server part |
|
579 |
$command = "cp -rf ../server $install_dir"; |
|
580 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
581 |
|
|
582 |
//* Create a symlink, so ISPConfig is accessible via web |
|
583 |
$command = "ln -s $install_dir/interface/web/ /var/www/ispconfig"; |
|
584 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
585 |
|
|
586 |
//* Create the config file for ISPConfig interface |
|
587 |
$configfile = 'config.inc.php'; |
|
588 |
if(is_file($install_dir.'/interface/lib/'.$configfile)){ |
|
589 |
copy("$install_dir/interface/lib/$configfile", "$install_dir/interface/lib/$configfile~"); |
|
590 |
} |
|
591 |
$content = rf("tpl/$configfile.master"); |
|
592 |
$content = str_replace('{mysql_server_ispconfig_user}', $this->conf['mysql']['ispconfig_user'], $content); |
|
593 |
$content = str_replace('{mysql_server_ispconfig_password}',$this->conf['mysql']['ispconfig_password'], $content); |
|
594 |
$content = str_replace('{mysql_server_database}', $this->conf['mysql']['database'], $content); |
|
595 |
$content = str_replace('{mysql_server_host}', $this->conf['mysql']['host'], $content); |
|
596 |
wf("$install_dir/interface/lib/$configfile", $content); |
|
597 |
|
|
598 |
//* Create the config file for ISPConfig server |
|
599 |
$configfile = 'config.inc.php'; |
|
600 |
if(is_file($install_dir.'/server/lib/'.$configfile)){ |
|
601 |
copy("$install_dir/server/lib/$configfile", "$install_dir/interface/lib/$configfile~"); |
|
602 |
} |
|
603 |
$content = rf("tpl/$configfile.master"); |
|
604 |
$content = str_replace('{mysql_server_ispconfig_user}', $this->conf['mysql']['ispconfig_user'], $content); |
|
605 |
$content = str_replace('{mysql_server_ispconfig_password}', $this->conf['mysql']['ispconfig_password'], $content); |
|
606 |
$content = str_replace('{mysql_server_database}', $this->conf['mysql']['database'], $content); |
|
607 |
$content = str_replace('{mysql_server_host}', $this->conf['mysql']['host'], $content); |
|
608 |
$content = str_replace('{server_id}', $this->conf['server_id'], $content); |
|
609 |
wf("$install_dir/server/lib/$configfile", $content); |
|
610 |
|
|
611 |
|
|
612 |
//* Chmod the files |
|
613 |
$command = "chmod -R 750 $install_dir"; |
|
614 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
615 |
|
|
616 |
//* chown the files to the ispconfig user and group |
|
617 |
$command = "chown -R ispconfig:ispconfig $install_dir"; |
|
618 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
|
619 |
|
|
620 |
//* make sure that the server config file (not the interface one) is only readable by the root user |
|
621 |
exec("chmod 600 $install_dir/server/lib/$configfile"); |
|
622 |
exec("chown root:root $install_dir/server/lib/$configfile"); |
2e1086
|
623 |
|
9200ad
|
624 |
// TODO: FIXME: add the www-data user to the ispconfig group. This is just for testing |
T |
625 |
// and must be fixed as this will allow the apache user to read the ispconfig files. |
|
626 |
// Later this must run as own apache server or via suexec! |
76b6b6
|
627 |
$command = 'adduser www-data ispconfig'; |
P |
628 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
9200ad
|
629 |
|
76b6b6
|
630 |
//* Make the shell scripts executable |
P |
631 |
$command = "chmod +x $install_dir/server/scripts/*.sh"; |
|
632 |
caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command"); |
9200ad
|
633 |
|
76b6b6
|
634 |
//* Copy the ISPConfig vhost for the controlpanel |
P |
635 |
//TODO These are missing! should they be "vhost_dist_*_dir" ? |
cc3fb3
|
636 |
$vhost_conf_dir = $this->conf['apache']['vhost_conf_dir']; |
O |
637 |
$vhost_conf_enabled_dir = $this->conf['apache']['vhost_conf_enabled_dir']; |
76b6b6
|
638 |
copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost"); |
P |
639 |
//* and create the symlink |
|
640 |
if(!is_link("$vhost_conf_enabled_dir/ispconfig.vhost")) { |
|
641 |
exec("ln -s $vhost_conf_dir/ispconfig.vhost $vhost_conf_enabled_dir/ispconfig.vhost"); |
a35764
|
642 |
} |
9200ad
|
643 |
} |
T |
644 |
|
76b6b6
|
645 |
public function install_crontab() |
5d54be
|
646 |
{ |
P |
647 |
//* Root Crontab |
|
648 |
exec('crontab -u root -l > crontab.txt'); |
daff5c
|
649 |
$existing_root_cron_jobs = file('crontab.txt'); |
T |
650 |
|
fffd4d
|
651 |
$root_cron_jobs = array('* * * * * /usr/local/ispconfig/server/server.sh &> /dev/null'); |
daff5c
|
652 |
foreach($root_cron_jobs as $cron_job) { |
5d54be
|
653 |
if(!in_array($cron_job."\n", $existing_root_cron_jobs)) { |
daff5c
|
654 |
$existing_root_cron_jobs[] = $cron_job."\n"; |
T |
655 |
} |
|
656 |
} |
5d54be
|
657 |
file_put_contents('crontab.txt', $existing_root_cron_jobs); |
P |
658 |
exec('crontab -u root crontab.txt &> /dev/null'); |
daff5c
|
659 |
unlink('crontab.txt'); |
T |
660 |
|
5d54be
|
661 |
//* Getmail crontab |
cc3fb3
|
662 |
$cf = $this->conf['getmail']; |
5d54be
|
663 |
exec('crontab -u getmail -l > crontab.txt'); |
daff5c
|
664 |
$existing_cron_jobs = file('crontab.txt'); |
T |
665 |
|
5d54be
|
666 |
$cron_jobs = array('*/5 * * * * '.$cf['program'].' -g '.$cf['config_dir'].' -r '.$cf['config_dir'].'/*.conf &> /dev/null'); |
daff5c
|
667 |
foreach($cron_jobs as $cron_job) { |
5d54be
|
668 |
if(!in_array($cron_job."\n", $existing_cron_jobs)) { |
daff5c
|
669 |
$existing_cron_jobs[] = $cron_job."\n"; |
T |
670 |
} |
|
671 |
} |
5d54be
|
672 |
file_put_contents('crontab.txt', $existing_cron_jobs); |
P |
673 |
exec('crontab -u getmail crontab.txt &> /dev/null'); |
daff5c
|
674 |
unlink('crontab.txt'); |
T |
675 |
} |
9200ad
|
676 |
|
T |
677 |
} |
|
678 |
|
5d54be
|
679 |
?> |