tbrehm
2013-02-22 526b997c9891a796b152cdbab8e329b356b1f596
commit | author | age
32d8e9 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_dist extends installer_base {
526b99 32
T 33     public function configure_mailman($status = 'insert') {
34         global $conf;
35
36         $config_dir = $conf['mailman']['config_dir'].'/';
37         $full_file_name = $config_dir.'mm_cfg.py';
38         //* Backup exiting file
39         if(is_file($full_file_name)) {
40             copy($full_file_name, $config_dir.'mm_cfg.py~');
41         }
42
43         // load files
44         $content = rf('tpl/mm_cfg.py.master');
45         $old_file = rf($full_file_name);
46
47         $old_options = array();
48         $lines = explode("\n", $old_file);
49         foreach ($lines as $line)
50         {
51             if (trim($line) != '' && substr($line, 0, 1) != '#')
52             {
53                 @list($key, $value) = @explode("=", $line);
54                 if (!empty($value))
55                 {
56                     $key = rtrim($key);
57                     $old_options[$key] = trim($value);
58                 }
59             }
60         }
61         
62         $config_dir = $conf['mailman']['config_dir'].'/';
63         $full_file_name = $config_dir.'virtual_to_transport.sh';
64         
65         //* Backup exiting virtual_to_transport.sh script
66         if(is_file($full_file_name)) {
67             copy($full_file_name, $config_dir.'virtual_to_transport.sh~');
68         }
69         
70         copy('tpl/mailman-virtual_to_transport.sh',$full_file_name);
71         chgrp($full_file_name,'mailman');
72         chmod($full_file_name,0750);
73         
74         if(!is_file('/var/lib/mailman/data/transport-mailman')) touch('/var/lib/mailman/data/transport-mailman');
75         exec('/usr/sbin/postmap /var/lib/mailman/data/transport-mailman');
76         
77         exec('/usr/lib/mailman/bin/genaliases 2>/dev/null');
78
79         $virtual_domains = '';
80         if($status == 'update')
81         {
82             // create virtual_domains list
83             $domainAll = $this->db->queryAllRecords("SELECT domain FROM mail_mailinglist GROUP BY domain");
84
85             if(is_array($domainAll)) {
86             foreach($domainAll as $domain)
87             {
88                 if ($domainAll[0]['domain'] == $domain['domain'])
89                     $virtual_domains .= "'".$domain['domain']."'";
90                 else
91                     $virtual_domains .= ", '".$domain['domain']."'";
92             }
93             }
94         }
95         else
96             $virtual_domains = "' '";
97
98         $content = str_replace('{hostname}', $conf['hostname'], $content);
99         if(!isset($old_options['DEFAULT_SERVER_LANGUAGE'])) $old_options['DEFAULT_SERVER_LANGUAGE'] = '';
100         $content = str_replace('{default_language}', $old_options['DEFAULT_SERVER_LANGUAGE'], $content);
101         $content = str_replace('{virtual_domains}', $virtual_domains, $content);
102
103         wf($full_file_name, $content);
104     }
32d8e9 105     
T 106     function configure_postfix($options = '')
107     {
108         global $conf;
109         $cf = $conf['postfix'];
110         $config_dir = $cf['config_dir'];
111         
112         if(!is_dir($config_dir)){
113             $this->error("The postfix configuration directory '$config_dir' does not exist.");
114         }
115         
116         //* mysql-virtual_domains.cf
117         $this->process_postfix_config('mysql-virtual_domains.cf');
118
119         //* mysql-virtual_forwardings.cf
120         $this->process_postfix_config('mysql-virtual_forwardings.cf');
121
122         //* mysql-virtual_mailboxes.cf
123         $this->process_postfix_config('mysql-virtual_mailboxes.cf');
124
125         //* mysql-virtual_email2email.cf
126         $this->process_postfix_config('mysql-virtual_email2email.cf');
127
128         //* mysql-virtual_transports.cf
129         $this->process_postfix_config('mysql-virtual_transports.cf');
130
131         //* mysql-virtual_recipient.cf
132         $this->process_postfix_config('mysql-virtual_recipient.cf');
133
134         //* mysql-virtual_sender.cf
135         $this->process_postfix_config('mysql-virtual_sender.cf');
136
137         //* mysql-virtual_client.cf
138         $this->process_postfix_config('mysql-virtual_client.cf');
139         
140         //* mysql-virtual_relaydomains.cf
141         $this->process_postfix_config('mysql-virtual_relaydomains.cf');
429dcf 142         
T 143         //* mysql-virtual_relayrecipientmaps.cf
144         $this->process_postfix_config('mysql-virtual_relayrecipientmaps.cf');
32d8e9 145
T 146         //* Changing mode and group of the new created config files.
147         caselog('chmod o= '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null',
148                  __FILE__, __LINE__, 'chmod on mysql-virtual_*.cf*', 'chmod on mysql-virtual_*.cf* failed');
149         caselog('chgrp '.$cf['group'].' '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null', 
150                 __FILE__, __LINE__, 'chgrp on mysql-virtual_*.cf*', 'chgrp on mysql-virtual_*.cf* failed');
151         
1ca823 152         if(!is_dir($cf['vmail_mailbox_base'])) mkdir($cf['vmail_mailbox_base']);
T 153         
32d8e9 154         //* Creating virtual mail user and group
fdb514 155         if(is_group($cf['vmail_groupname'])) {
T 156             $command = 'groupmod -g '.$cf['vmail_groupid'].' '.$cf['vmail_groupname'];
157             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
158         } else {
159             $command = 'groupadd -g '.$cf['vmail_groupid'].' '.$cf['vmail_groupname'];
160             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
161         }
162         
163         if(is_user($cf['vmail_username'])) {
164             $command = 'usermod -g '.$cf['vmail_groupname'].' -u '.$cf['vmail_userid'].' -d '.$cf['vmail_mailbox_base'].' -s /bin/bash '.$cf['vmail_username'];
165             caselog("$command &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
166         } else {
167             $command = 'useradd -g '.$cf['vmail_groupname'].' -u '.$cf['vmail_userid'].' '.$cf['vmail_username'].' -d '.$cf['vmail_mailbox_base'].' -m';
168             caselog("$command &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
8f898a 169         }
T 170         
d2e848 171         if($cf['vmail_mailbox_base'] != '' && strlen($cf['vmail_mailbox_base']) >= 10 && $this->is_update === false) exec('chown -R '.$cf['vmail_username'].':'.$cf['vmail_groupname'].' '.$cf['vmail_mailbox_base']);
b67344 172         
T 173         //* These postconf commands will be executed on installation and update
32d8e9 174         $postconf_commands = array (
T 175             'virtual_alias_domains =',
176             'virtual_alias_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_forwardings.cf, mysql:'.$config_dir.'/mysql-virtual_email2email.cf',
177             'virtual_mailbox_domains = proxy:mysql:'.$config_dir.'/mysql-virtual_domains.cf',
178             'virtual_mailbox_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_mailboxes.cf',
179             'virtual_mailbox_base = '.$cf['vmail_mailbox_base'],
180             'virtual_uid_maps = static:'.$cf['vmail_userid'],
181             'virtual_gid_maps = static:'.$cf['vmail_groupid'],
182             'smtpd_sasl_auth_enable = yes',
183             'broken_sasl_auth_clients = yes',
184             'smtpd_sasl_authenticated_header = yes',
185             'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, check_recipient_access mysql:'.$config_dir.'/mysql-virtual_recipient.cf, reject_unauth_destination',
186             'smtpd_use_tls = yes',
187             'smtpd_tls_security_level = may',
188             'smtpd_tls_cert_file = '.$config_dir.'/smtpd.cert',
189             'smtpd_tls_key_file = '.$config_dir.'/smtpd.key',
72695f 190             'transport_maps = hash:/var/lib/mailman/data/transport-mailman, proxy:mysql:'.$config_dir.'/mysql-virtual_transports.cf',
32d8e9 191             'relay_domains = mysql:'.$config_dir.'/mysql-virtual_relaydomains.cf',
429dcf 192             'relay_recipient_maps = mysql:'.$config_dir.'/mysql-virtual_relayrecipientmaps.cf',
32d8e9 193             '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',
T 194             'smtpd_sender_restrictions = check_sender_access mysql:'.$config_dir.'/mysql-virtual_sender.cf',
195             'smtpd_client_restrictions = check_client_access mysql:'.$config_dir.'/mysql-virtual_client.cf',
196             'maildrop_destination_concurrency_limit = 1',
197             'maildrop_destination_recipient_limit   = 1',
198             'virtual_transport = maildrop',
199             'header_checks = regexp:'.$config_dir.'/header_checks',
200             'mime_header_checks = regexp:'.$config_dir.'/mime_header_checks',
201             'nested_header_checks = regexp:'.$config_dir.'/nested_header_checks',
202             'body_checks = regexp:'.$config_dir.'/body_checks',
203             'inet_interfaces = all'
204         );
b67344 205         
T 206         //* These postconf commands will be executed on installation only
207         if($this->is_update == false) {
208             $postconf_commands = array_merge($postconf_commands,array(
209                 'myhostname = '.$conf['hostname'],
210                 'mydestination = '.$conf['hostname'].', localhost, localhost.localdomain',
211                 'mynetworks = 127.0.0.0/8 [::1]/128'
212             ));
213         }
32d8e9 214         
T 215         //* Create the header and body check files
216         touch($config_dir.'/header_checks');
217         touch($config_dir.'/mime_header_checks');
218         touch($config_dir.'/nested_header_checks');
219         touch($config_dir.'/body_checks');
220         
221         
222         //* Make a backup copy of the main.cf file
223         copy($config_dir.'/main.cf', $config_dir.'/main.cf~');
224         
225         //* Executing the postconf commands
226         foreach($postconf_commands as $cmd) {
227             $command = "postconf -e '$cmd'";
228             caselog($command." &> /dev/null", __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
229         }
230         
231         if(!stristr($options,'dont-create-certs')) {
232             //* Create the SSL certificate
233             $command = 'cd '.$config_dir.'; '
234                       .'openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509';
235             exec($command);
236         
237             $command = 'chmod o= '.$config_dir.'/smtpd.key';
238             caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
239         }
240         
241         //** We have to change the permissions of the courier authdaemon directory to make it accessible for maildrop.
242         $command = 'chmod 755  /var/run/authdaemon.courier-imap';
243         caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
244         
245         //* Changing maildrop lines in posfix master.cf
246         if(is_file($config_dir.'/master.cf')){
247             copy($config_dir.'/master.cf', $config_dir.'/master.cf~');
248         }
249         if(is_file($config_dir.'/master.cf~')){
250             exec('chmod 400 '.$config_dir.'/master.cf~');
251         }
252         $configfile = $config_dir.'/master.cf';
253         $content = rf($configfile);
254         
255         $content = str_replace('  flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}', 
b2b3b1 256                    '  flags=DRhu user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}',
32d8e9 257                      $content);
T 258         
259         $content = str_replace('  flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}', 
b2b3b1 260                    '  flags=DRhu user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}',
32d8e9 261                      $content);
T 262         
fdb514 263         // enable tlsmanager
T 264         $content = str_replace('#tlsmgr    unix  -       -       n       1000?   1       tlsmgr','tlsmgr    unix  -       -       n       1000?   1       tlsmgr',$content);
265         
32d8e9 266         wf($configfile, $content);
T 267         
268         //* Writing the Maildrop mailfilter file
269         $configfile = 'mailfilter';
270         if(is_file($cf['vmail_mailbox_base'].'/.'.$configfile)){
271             copy($cf['vmail_mailbox_base'].'/.'.$configfile, $cf['vmail_mailbox_base'].'/.'.$configfile.'~');
272         }
273         $content = rf("tpl/$configfile.master");
274         $content = str_replace('{dist_postfix_vmail_mailbox_base}', $cf['vmail_mailbox_base'], $content);
275         wf($cf['vmail_mailbox_base'].'/.'.$configfile, $content);
276         
277         //* Create the directory for the custom mailfilters
278         $command = 'mkdir '.$cf['vmail_mailbox_base'].'/mailfilters';
279         caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
280         
281         //* Chmod and chown the .mailfilter file
282         $command = 'chown -R '.$cf['vmail_username'].':'.$cf['vmail_groupname'].' '.$cf['vmail_mailbox_base'].'/.mailfilter';
283         caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
284         
285         $command = 'chmod -R 600 '.$cf['vmail_mailbox_base'].'/.mailfilter';
286         caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
287         
288     }
289     
290     public function configure_saslauthd() {
291         global $conf;
292         
293         /*
294         $configfile = 'sasl_smtpd.conf';
295         if(is_file('/etc/sasl2/smtpd.conf')) copy('/etc/sasl2/smtpd.conf','/etc/sasl2/smtpd.conf~');
296         if(is_file('/etc/sasl2/smtpd.conf~')) exec('chmod 400 '.'/etc/sasl2/smtpd.conf~');
297         $content = rf("tpl/".$configfile.".master");
298         $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
299         $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
300         $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
301         $content = str_replace('{mysql_server_ip}',$conf['mysql']['ip'],$content);
302         wf('/etc/sasl2/smtpd.conf',$content);
303         */
304         
305         // TODO: Chmod and chown on the config file
306         
307         
308         /*
309         // Create the spool directory
310         exec('mkdir -p /var/spool/postfix/var/run/saslauthd');
311         
312         // Edit the file /etc/default/saslauthd
313         $configfile = $conf["saslauthd"]["config"];
314         if(is_file($configfile)) copy($configfile,$configfile.'~');
315         if(is_file($configfile.'~')) exec('chmod 400 '.$configfile.'~');
316         $content = rf($configfile);
317         $content = str_replace('START=no','START=yes',$content);
318         $content = str_replace('OPTIONS="-c"','OPTIONS="-m /var/spool/postfix/var/run/saslauthd -r"',$content);
319         wf($configfile,$content);
320         */
321         
322         // Edit the file /etc/init.d/saslauthd
323         $configfile = $conf["init_scripts"].'/'.$conf["saslauthd"]["init_script"];
324         $content = rf($configfile);
325         $content = str_replace('/sbin/startproc $AUTHD_BIN -a $SASLAUTHD_AUTHMECH -n $SASLAUTHD_THREADS > /dev/null 2>&1','/sbin/startproc $AUTHD_BIN -r -a $SASLAUTHD_AUTHMECH -n $SASLAUTHD_THREADS > /dev/null 2>&1',$content);
326         $content = str_replace('/sbin/startproc $AUTHD_BIN $SASLAUTHD_PARAMS -a $SASLAUTHD_AUTHMECH -n $SASLAUTHD_THREADS > /dev/null 2>&1','/sbin/startproc $AUTHD_BIN $SASLAUTHD_PARAMS -r -a $SASLAUTHD_AUTHMECH -n $SASLAUTHD_THREADS > /dev/null 2>&1',$content);
327         
328         
fdb514 329         if(is_file($configfile)) wf($configfile,$content);
32d8e9 330         
T 331         
332         
333     }
334     
335     public function configure_pam()
336     {
337         global $conf;
338         $pam = $conf['pam'];
339         //* configure pam for SMTP authentication agains the ispconfig database
340         $configfile = 'pamd_smtp';
341         if(is_file("$pam/smtp"))    copy("$pam/smtp", "$pam/smtp~");
342         if(is_file("$pam/smtp~"))   exec("chmod 400 $pam/smtp~");
343
344         $content = rf("tpl/$configfile.master");
345         $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
346         $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
347         $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
348         $content = str_replace('{mysql_server_ip}', $conf['mysql']['ip'], $content);
349         wf("$pam/smtp", $content);
03bff7 350         // On some OSes smtp is world readable which allows for reading database information.  Removing world readable rights should have no effect.
T 351         if(is_file("$pam/smtp"))    exec("chmod o= $pam/smtp");
32d8e9 352         //exec("chmod 660 $pam/smtp");
T 353         //exec("chown root:root $pam/smtp");
354     
355     }
356     
357     public function configure_courier()
358     {
359         global $conf;
360         $config_dir = $conf['courier']['config_dir'];
361         //* authmysqlrc
362         $configfile = 'authmysqlrc';
363         if(is_file("$config_dir/$configfile")){
364             copy("$config_dir/$configfile", "$config_dir/$configfile~");
365         }
366         exec("chmod 400 $config_dir/$configfile~");
367         $content = rf("tpl/$configfile.master");
368         $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
369         $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
370         $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
371         $content = str_replace('{mysql_server_host}',$conf['mysql']['host'],$content);
372         wf("$config_dir/$configfile", $content);
373         
374         exec("chmod 660 $config_dir/$configfile");
375         exec("chown root:root $config_dir/$configfile");
376         
377         //* authdaemonrc
378         $configfile = $conf['courier']['config_dir'].'/authdaemonrc';
379         if(is_file($configfile)){
380             copy($configfile, $configfile.'~');
381         }
382         if(is_file($configfile.'~')){
383             exec('chmod 400 '.$configfile.'~');
384         }
385         $content = rf($configfile);
386         $content = str_replace('authmodulelist=', 'authmodulelist="authmysql"', $content);
387         wf($configfile, $content);
388     }
389     
fdb514 390     public function configure_dovecot()
T 391     {
392         global $conf;
393         
394         $config_dir = $conf['dovecot']['config_dir'];
395         
396         //* Configure master.cf and add a line for deliver
397         if(is_file($config_dir.'/master.cf')){
398             copy($config_dir.'/master.cf', $config_dir.'/master.cf~2');
399         }
400         if(is_file($config_dir.'/master.cf~')){
401             exec('chmod 400 '.$config_dir.'/master.cf~2');
402         }
403         $content = rf($conf["postfix"]["config_dir"].'/master.cf');
404         // Only add the content if we had not addded it before
405         if(!stristr($content,"dovecot/deliver")) {
013ae4 406             $deliver_content = 'dovecot   unix  -       n       n       -       -       pipe'."\n".'  flags=DROhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop}';
fdb514 407             af($conf["postfix"]["config_dir"].'/master.cf',$deliver_content);
T 408         }
409         unset($content);
410         unset($deliver_content);
411         
412         
413         //* Reconfigure postfix to use dovecot authentication
414         // Adding the amavisd commands to the postfix configuration
415         $postconf_commands = array (
416             'dovecot_destination_recipient_limit = 1',
417             'virtual_transport = dovecot',
418             'smtpd_sasl_type = dovecot',
419             'smtpd_sasl_path = private/auth',
420             'receive_override_options = no_address_mappings'
421         );
422         
423         // Make a backup copy of the main.cf file
424         copy($conf["postfix"]["config_dir"].'/main.cf',$conf["postfix"]["config_dir"].'/main.cf~3');
425         
426         // Executing the postconf commands
427         foreach($postconf_commands as $cmd) {
428             $command = "postconf -e '$cmd'";
429             caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
430         }
431         
31e0d1 432         //* backup dovecot.conf
fdb514 433         $configfile = 'dovecot.conf';
T 434         if(is_file("$config_dir/$configfile")){
435             copy("$config_dir/$configfile", "$config_dir/$configfile~");
436         }
31e0d1 437         
T 438         //* Get the dovecot version
439         exec('dovecot --version',$tmp);
440         $parts = explode('.',trim($tmp[0]));
441         $dovecot_version = $parts[0];
442         unset($tmp);
443         unset($parts);
444         
445         //* Copy dovecot configuration file
446         if($dovecot_version == 2) {
447             copy('tpl/opensuse_dovecot2.conf.master',$config_dir.'/'.$configfile);
448         } else {
449             copy('tpl/opensuse_dovecot.conf.master',$config_dir.'/'.$configfile);
450         }
fdb514 451         
T 452         //* dovecot-sql.conf
453         $configfile = 'dovecot-sql.conf';
454         if(is_file("$config_dir/$configfile")){
455             copy("$config_dir/$configfile", "$config_dir/$configfile~");
b67344 456             exec("chmod 400 $config_dir/$configfile~");
fdb514 457         }
b67344 458         
fdb514 459         $content = rf("tpl/opensuse_dovecot-sql.conf.master");
T 460         $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
461         $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
462         $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
463         $content = str_replace('{mysql_server_host}',$conf['mysql']['host'],$content);
464         wf("$config_dir/$configfile", $content);
465         
466         exec("chmod 600 $config_dir/$configfile");
467         exec("chown root:root $config_dir/$configfile");
468
469     }
470     
32d8e9 471     public function configure_amavis() {
T 472         global $conf;
473         
474         // amavisd user config file
475         $configfile = 'opensuse_amavisd_conf';
df7e6d 476         if(is_file($conf["amavis"]["config_dir"].'/amavisd.conf')) @copy($conf["amavis"]["config_dir"].'/amavisd.conf',$conf["amavis"]["config_dir"].'/amavisd.conf~');
32d8e9 477         if(is_file($conf["amavis"]["config_dir"].'/amavisd.conf~')) exec('chmod 400 '.$conf["amavis"]["config_dir"].'/amavisd.conf~');
T 478         $content = rf("tpl/".$configfile.".master");
479         $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
480         $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
481         $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
482         $content = str_replace('{mysql_server_port}',$conf["mysql"]["port"],$content);
483         $content = str_replace('{mysql_server_ip}',$conf['mysql']['ip'],$content);
484         wf($conf["amavis"]["config_dir"].'/amavisd.conf',$content);
485         
486         
487         // Adding the amavisd commands to the postfix configuration
488         $postconf_commands = array (
489             'content_filter = amavis:[127.0.0.1]:10024',
490             'receive_override_options = no_address_mappings'
491         );
492         
493         // Make a backup copy of the main.cf file
494         copy($conf["postfix"]["config_dir"].'/main.cf',$conf["postfix"]["config_dir"].'/main.cf~2');
495         
496         // Executing the postconf commands
497         foreach($postconf_commands as $cmd) {
498             $command = "postconf -e '$cmd'";
499             caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
500         }
501         
502         // Append the configuration for amavisd to the master.cf file
503         if(is_file($conf["postfix"]["config_dir"].'/master.cf')) copy($conf["postfix"]["config_dir"].'/master.cf',$conf["postfix"]["config_dir"].'/master.cf~');
504         $content = rf($conf["postfix"]["config_dir"].'/master.cf');
505         // Only add the content if we had not addded it before
506         if(!stristr($content,"127.0.0.1:10025")) {
507             unset($content);
508             $content = rf("tpl/master_cf_amavis.master");
509             af($conf["postfix"]["config_dir"].'/master.cf',$content);
510         }
511         unset($content);
512         
513         // Add the clamav user to the vscan group
514         exec('groupmod --add-user clamav vscan');
515         
516         
517     }
518     
519     public function configure_spamassassin()
520     {
521         global $conf;
522         
523         //* Enable spamasasssin on debian and ubuntu
524         /*
525         $configfile = '/etc/default/spamassassin';
526         if(is_file($configfile)){
527             copy($configfile, $configfile.'~');
528         }
529         $content = rf($configfile);
530         $content = str_replace('ENABLED=0', 'ENABLED=1', $content);
531         wf($configfile, $content);
532         */
533     }
534     
535     public function configure_getmail()
536     {
537         global $conf;
538         
539         $config_dir = $conf['getmail']['config_dir'];
540         
541         if(!is_dir($config_dir)) exec("mkdir -p ".escapeshellcmd($config_dir));
542
543         $command = "useradd -d $config_dir getmail";
544         if(!is_user('getmail')) caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
545         
546         $command = "chown -R getmail $config_dir";
547         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
548         
549         $command = "chmod -R 700 $config_dir";
550         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
551     }
552     
553     
554     public function configure_pureftpd()
555     {
556         global $conf;
557         
558         $config_dir = $conf['pureftpd']['config_dir'];
559
560         //* configure pam for SMTP authentication agains the ispconfig database
561         $configfile = 'db/mysql.conf';
562         if(is_file("$config_dir/$configfile")){
563             copy("$config_dir/$configfile", "$config_dir/$configfile~");
564         }
565         if(is_file("$config_dir/$configfile~")){
566             exec("chmod 400 $config_dir/$configfile~");
567         }
568         $content = rf('tpl/pureftpd_mysql.conf.master');
569         $content = str_replace('{mysql_server_ispconfig_user}', $conf["mysql"]["ispconfig_user"], $content);
570         $content = str_replace('{mysql_server_ispconfig_password}', $conf["mysql"]["ispconfig_password"], $content);
571         $content = str_replace('{mysql_server_database}', $conf["mysql"]["database"], $content);
572         $content = str_replace('{mysql_server_ip}', $conf["mysql"]["ip"], $content);
573         $content = str_replace('{server_id}', $conf["server_id"], $content);
574         wf("$config_dir/$configfile", $content);
575         exec("chmod 600 $config_dir/$configfile");
576         exec("chown root:root $config_dir/$configfile");
577         
578         // copy our customized copy of pureftpd.conf to the pure-ftpd config directory
579         exec("cp tpl/opensuse_pureftpd_conf.master $config_dir/pure-ftpd.conf");
580         
581     }
582     
583     public function configure_mydns()
584     {
585         global $conf;
586         
587         // configure pam for SMTP authentication agains the ispconfig database
588         $configfile = 'mydns.conf';
589         if(is_file($conf["mydns"]["config_dir"].'/'.$configfile)) copy($conf["mydns"]["config_dir"].'/'.$configfile,$conf["mydns"]["config_dir"].'/'.$configfile.'~');
590         if(is_file($conf["mydns"]["config_dir"].'/'.$configfile.'~')) exec('chmod 400 '.$conf["mydns"]["config_dir"].'/'.$configfile.'~');
591         $content = rf("tpl/".$configfile.".master");
592         $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
593         $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
594         $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
595         $content = str_replace('{mysql_server_host}',$conf["mysql"]["host"],$content);
596         $content = str_replace('{server_id}',$conf["server_id"],$content);
597         wf($conf["mydns"]["config_dir"].'/'.$configfile,$content);
598         exec('chmod 600 '.$conf["mydns"]["config_dir"].'/'.$configfile);
599         exec('chown root:root '.$conf["mydns"]["config_dir"].'/'.$configfile);
600     
601     }
602     
603     public function configure_apache()
604     {    
605         global $conf;
606         
1bd269 607         if($conf['apache']['installed'] == false) return;
32d8e9 608         //* Create the logging directory for the vhost logfiles
T 609         exec('mkdir -p /var/log/ispconfig/httpd');
610         
611         //if(is_file('/etc/suphp.conf')) {
44c74c 612         replaceLine('/etc/suphp.conf','php=php','x-httpd-suphp="php:/srv/www/cgi-bin/php5"',0,0);
T 613         replaceLine('/etc/suphp.conf','php="php','x-httpd-suphp="php:/srv/www/cgi-bin/php5"',0,0);
32d8e9 614         replaceLine('/etc/suphp.conf','docroot=','docroot=/srv/www',0,0);
a4f044 615         replaceLine('/etc/suphp.conf','umask=0077','umask=0022',0);
32d8e9 616         //}
T 617         
26c0fc 618         if(!file_exists('/srv/www/cgi-bin/php5') && file_exists('/srv/www/cgi-bin/php')) {
T 619             symlink('/srv/www/cgi-bin/php','/srv/www/cgi-bin/php5');
620         }
621         
dbe5b0 622         // Sites enabled and available dirs
32d8e9 623         exec('mkdir -p '.$conf['apache']['vhost_conf_enabled_dir']);
T 624         exec('mkdir -p '.$conf['apache']['vhost_conf_dir']);
625         
626         $content = rf('/etc/apache2/httpd.conf');
627         if(!stristr($content,'Include /etc/apache2/sites-enabled/')) {
628             af('/etc/apache2/httpd.conf',"\n<Directory /srv/www>\n    Options FollowSymlinks\n</Directory>\n\nInclude /etc/apache2/sites-enabled/\n\n");
629         }
630         unset($content);
631         
632         //* Copy the ISPConfig configuration include
633         $vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
634         $vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
635         
636         //copy('tpl/apache_ispconfig.conf.master',$vhost_conf_dir.'/ispconfig.conf');
a2156e 637         $content = rf('tpl/apache_ispconfig.conf.master');
T 638         $records = $this->db->queryAllRecords('SELECT * FROM '.$conf['mysql']['master_database'].'.server_ip WHERE server_id = '.$conf['server_id']." AND virtualhost = 'y'");
639
fb3a98 640         if(is_array($records) && count($records) > 0) {
32d8e9 641             foreach($records as $rec) {
a2156e 642                 if($rec['ip_type'] == 'IPv6') {
T 643                     $ip_address = '['.$rec['ip_address'].']';
644                 } else {
645                     $ip_address = $rec['ip_address'];
646                 }
647                 $ports = explode(',',$rec['virtualhost_port']);
648                 if(is_array($ports)) {
649                     foreach($ports as $port) {
650                         $port = intval($port);
651                         if($port > 0 && $port < 65536 && $ip_address != '') {
652                             $content .= 'NameVirtualHost '.$ip_address.":".$port."\n";
653                         }
654                     }
655                 }
32d8e9 656             }
T 657         }
a2156e 658         
32d8e9 659         $content .= "\n";
T 660         wf($vhost_conf_dir.'/ispconfig.conf',$content);
661         
662         if(!@is_link($vhost_conf_enabled_dir."/000-ispconfig.conf")) {
663             exec("ln -s ".$vhost_conf_dir."/ispconfig.conf ".$vhost_conf_enabled_dir."/000-ispconfig.conf");
664         }
665         
99d5dc 666         //* make sure that webalizer finds its config file when it is directly in /etc
T 667         if(@is_file('/etc/webalizer.conf') && !@is_dir('/etc/webalizer')) {
668             exec('mkdir /etc/webalizer');
669             exec('ln -s /etc/webalizer.conf /etc/webalizer/webalizer.conf');
670         }
671         
672         if(is_file('/etc/webalizer/webalizer.conf')) {
673             // Change webalizer mode to incremental
7da533 674             replaceLine('/etc/webalizer/webalizer.conf','#IncrementalName','IncrementalName webalizer.current',0,0);
T 675             replaceLine('/etc/webalizer/webalizer.conf','#Incremental','Incremental     yes',0,0);
676             replaceLine('/etc/webalizer/webalizer.conf','#HistoryName','HistoryName     webalizer.hist',0,0);
99d5dc 677         }
T 678         
6b029a 679         //* add a sshusers group
T 680         $command = 'groupadd sshusers';
681         if(!is_group('sshusers')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
682         
526b99 683         // create PHP-FPM pool dir
T 684         exec('mkdir -p '.$conf['nginx']['php_fpm_pool_dir']);
685         
686         $content = rf('/etc/php5/fpm/php-fpm.conf');
687         if(stripos($content, 'include=/etc/php5/fpm/pool.d/*.conf') === false){
688             af('/etc/php5/fpm/php-fpm.conf',"\ninclude=/etc/php5/fpm/pool.d/*.conf");
689         }
690         unset($content);
691         if(!@is_file($conf['nginx']['php_fpm_ini_path'])){
692             if(@is_file('/etc/php5/cli/php.ini')){
693                 exec('cp -f /etc/php5/cli/php.ini '.$conf['nginx']['php_fpm_ini_path']);
694             } elseif(@is_file('/etc/php5/fastcgi/php.ini')){
695                 exec('cp -f /etc/php5/fastcgi/php.ini '.$conf['nginx']['php_fpm_ini_path']);
696             } elseif(@is_file('/etc/php5/apache2/php.ini')){
697                 exec('cp -f /etc/php5/apache2/php.ini '.$conf['nginx']['php_fpm_ini_path']);
698             }
699         }
700         
32d8e9 701     }
T 702     
2d86e1 703     public function configure_nginx(){
F 704         global $conf;
705         
706         if($conf['nginx']['installed'] == false) return;
707         //* Create the logging directory for the vhost logfiles
708         if(!@is_dir($conf['ispconfig_log_dir'].'/httpd')) mkdir($conf['ispconfig_log_dir'].'/httpd', 0755, true);
709         
dbe5b0 710         // Sites enabled and available dirs
2d86e1 711         exec('mkdir -p '.$conf['nginx']['vhost_conf_enabled_dir']);
F 712         exec('mkdir -p '.$conf['nginx']['vhost_conf_dir']);
713         
dbe5b0 714         $content = rf('/etc/nginx/nginx.conf');
F 715         if(stripos($content, 'include /etc/nginx/sites-enabled/*.vhost;') === false){
716             $content = trim($content);
717             $content = substr($content,0,-1)."\n    include /etc/nginx/sites-enabled/*.vhost;\n}";
718             wf('/etc/nginx/nginx.conf',$content);
719         }
2d86e1 720         unset($content);
F 721         
722         // create PHP-FPM pool dir
723         exec('mkdir -p '.$conf['nginx']['php_fpm_pool_dir']);
724         
725         $content = rf('/etc/php5/fpm/php-fpm.conf');
726         if(stripos($content, 'include=/etc/php5/fpm/pool.d/*.conf') === false){
727             af('/etc/php5/fpm/php-fpm.conf',"\ninclude=/etc/php5/fpm/pool.d/*.conf");
728         }
729         unset($content);
59feb7 730         if(!@is_file($conf['nginx']['php_fpm_ini_path'])){
F 731             if(@is_file('/etc/php5/cli/php.ini')){
732                 exec('cp -f /etc/php5/cli/php.ini '.$conf['nginx']['php_fpm_ini_path']);
733             } elseif(@is_file('/etc/php5/fastcgi/php.ini')){
734                 exec('cp -f /etc/php5/fastcgi/php.ini '.$conf['nginx']['php_fpm_ini_path']);
735             } elseif(@is_file('/etc/php5/apache2/php.ini')){
736                 exec('cp -f /etc/php5/apache2/php.ini '.$conf['nginx']['php_fpm_ini_path']);
737             }
738         }
2d86e1 739
F 740         //* make sure that webalizer finds its config file when it is directly in /etc
741         if(@is_file('/etc/webalizer.conf') && !@is_dir('/etc/webalizer')) {
742             mkdir('/etc/webalizer');
743             symlink('/etc/webalizer.conf','/etc/webalizer/webalizer.conf');
744         }
745
746         if(is_file('/etc/webalizer/webalizer.conf')) {
747             // Change webalizer mode to incremental
748             replaceLine('/etc/webalizer/webalizer.conf','#IncrementalName','IncrementalName webalizer.current',0,0);
749             replaceLine('/etc/webalizer/webalizer.conf','#Incremental','Incremental     yes',0,0);
750             replaceLine('/etc/webalizer/webalizer.conf','#HistoryName','HistoryName     webalizer.hist',0,0);
751         }
752         
753         // Check the awsatst script
754         if(!is_dir('/usr/share/awstats/tools')) exec('mkdir -p /usr/share/awstats/tools');
755         if(!file_exists('/usr/share/awstats/tools/awstats_buildstaticpages.pl') && file_exists('/usr/share/doc/awstats/examples/awstats_buildstaticpages.pl')) symlink('/usr/share/doc/awstats/examples/awstats_buildstaticpages.pl','/usr/share/awstats/tools/awstats_buildstaticpages.pl');
756         if(file_exists('/etc/awstats/awstats.conf.local')) replaceLine('/etc/awstats/awstats.conf.local','LogFormat=4','LogFormat=1',0,1);
757         
758         //* add a sshusers group
759         $command = 'groupadd sshusers';
760         if(!is_group('sshusers')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
761     }
762     
32d8e9 763     public function configure_firewall()
T 764     {
765         global $conf;
766         
767         $dist_init_scripts = $conf['init_scripts'];
768           
769         if(is_dir("/etc/Bastille.backup")) caselog("rm -rf /etc/Bastille.backup", __FILE__, __LINE__);
770         if(is_dir("/etc/Bastille")) caselog("mv -f /etc/Bastille /etc/Bastille.backup", __FILE__, __LINE__);
771           @mkdir("/etc/Bastille", octdec($directory_mode));
772           if(is_dir("/etc/Bastille.backup/firewall.d")) caselog("cp -pfr /etc/Bastille.backup/firewall.d /etc/Bastille/", __FILE__, __LINE__);
773           caselog("cp -f tpl/bastille-firewall.cfg.master /etc/Bastille/bastille-firewall.cfg", __FILE__, __LINE__);
774           caselog("chmod 644 /etc/Bastille/bastille-firewall.cfg", __FILE__, __LINE__);
775           $content = rf("/etc/Bastille/bastille-firewall.cfg");
776           $content = str_replace("{DNS_SERVERS}", "", $content);
777
778           $tcp_public_services = '';
779           $udp_public_services = '';
780         
fb3a98 781         $row = $this->db->queryOneRecord('SELECT * FROM '.$conf["mysql"]["database"].'.firewall WHERE server_id = '.intval($conf['server_id']));
32d8e9 782         
T 783           if(trim($row["tcp_port"]) != '' || trim($row["udp_port"]) != ''){
784             $tcp_public_services = trim(str_replace(',',' ',$row["tcp_port"]));
785             $udp_public_services = trim(str_replace(',',' ',$row["udp_port"]));
786           } else {
787             $tcp_public_services = '21 22 25 53 80 110 443 3306 8080 10000';
788             $udp_public_services = '53';
789           }
790         
791         if(!stristr($tcp_public_services, $conf['apache']['vhost_port'])) {
792             $tcp_public_services .= ' '.intval($conf['apache']['vhost_port']);
793             if($row["tcp_port"] != '') $this->db->query("UPDATE firewall SET tcp_port = tcp_port + ',".intval($conf['apache']['vhost_port'])."' WHERE server_id = ".intval($conf['server_id']));
794         }
795
796           $content = str_replace("{TCP_PUBLIC_SERVICES}", $tcp_public_services, $content);
797           $content = str_replace("{UDP_PUBLIC_SERVICES}", $udp_public_services, $content);
798         
799           wf("/etc/Bastille/bastille-firewall.cfg", $content);
800
801           if(is_file($dist_init_scripts."/bastille-firewall")) caselog("mv -f $dist_init_scripts/bastille-firewall $dist_init_scripts/bastille-firewall.backup", __FILE__, __LINE__);
802           caselog("cp -f apps/bastille-firewall $dist_init_scripts", __FILE__, __LINE__);
803           caselog("chmod 700 $dist_init_scripts/bastille-firewall", __FILE__, __LINE__);
804
805           if(is_file("/sbin/bastille-ipchains")) caselog("mv -f /sbin/bastille-ipchains /sbin/bastille-ipchains.backup", __FILE__, __LINE__);
806           caselog("cp -f apps/bastille-ipchains /sbin", __FILE__, __LINE__);
807           caselog("chmod 700 /sbin/bastille-ipchains", __FILE__, __LINE__);
808
809           if(is_file("/sbin/bastille-netfilter")) caselog("mv -f /sbin/bastille-netfilter /sbin/bastille-netfilter.backup", __FILE__, __LINE__);
810           caselog("cp -f apps/bastille-netfilter /sbin", __FILE__, __LINE__);
811           caselog("chmod 700 /sbin/bastille-netfilter", __FILE__, __LINE__);
812         
813         if(!@is_dir('/var/lock/subsys')) caselog("mkdir /var/lock/subsys", __FILE__, __LINE__);
814
815           exec("which ipchains &> /dev/null", $ipchains_location, $ret_val);
816           if(!is_file("/sbin/ipchains") && !is_link("/sbin/ipchains") && $ret_val == 0) phpcaselog(@symlink(shell_exec("which ipchains"), "/sbin/ipchains"), 'create symlink', __FILE__, __LINE__);
817           unset($ipchains_location);
818           exec("which iptables &> /dev/null", $iptables_location, $ret_val);
819           if(!is_file("/sbin/iptables") && !is_link("/sbin/iptables") && $ret_val == 0) phpcaselog(@symlink(trim(shell_exec("which iptables")), "/sbin/iptables"), 'create symlink', __FILE__, __LINE__);
820           unset($iptables_location);
821
822     }
4ae2a0 823
32d8e9 824     public function install_ispconfig()
T 825     {
826         global $conf;
827         
828         $install_dir = $conf['ispconfig_install_dir'];
829
830         //* Create the ISPConfig installation directory
831         if(!@is_dir("$install_dir")) {
832             $command = "mkdir $install_dir";
833             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
834         }
835         
836         //* Create a ISPConfig user and group
837         $command = 'groupadd ispconfig';
838         if(!is_group('ispconfig')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
839         
840         $command = "useradd -g ispconfig -d $install_dir ispconfig";
841         if(!is_user('ispconfig')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
842         
843         //* copy the ISPConfig interface part
844         $command = "cp -rf ../interface $install_dir";
845         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
846         
847         //* copy the ISPConfig server part
848         $command = "cp -rf ../server $install_dir";
849         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
850         
851         //* Create a symlink, so ISPConfig is accessible via web
852         // Replaced by a separate vhost definition for port 8080
853         // $command = "ln -s $install_dir/interface/web/ /var/www/ispconfig";
854         // caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
855         
856         //* Create the config file for ISPConfig interface
857         $configfile = 'config.inc.php';
858         if(is_file($install_dir.'/interface/lib/'.$configfile)){
859             copy("$install_dir/interface/lib/$configfile", "$install_dir/interface/lib/$configfile~");
860         }
861         $content = rf("tpl/$configfile.master");
862         $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
863         $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
864         $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
865         $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
866         
867         $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
868         $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
869         $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
870         $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
871         
7c3b60 872         $content = str_replace('{server_id}', $conf['server_id'], $content);
32d8e9 873         $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
56f1f4 874         $content = str_replace('{language}', $conf['language'], $content);
8cf78b 875         $content = str_replace('{timezone}', $conf['timezone'], $content);
41eaa8 876         $content = str_replace('{theme}', $conf['theme'], $content);
56f1f4 877         
32d8e9 878         wf("$install_dir/interface/lib/$configfile", $content);
T 879         
880         //* Create the config file for ISPConfig server
881         $configfile = 'config.inc.php';
882         if(is_file($install_dir.'/server/lib/'.$configfile)){
883             copy("$install_dir/server/lib/$configfile", "$install_dir/interface/lib/$configfile~");
884         }
885         $content = rf("tpl/$configfile.master");
886         $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
887         $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
888         $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
889         $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
890         
891         $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
892         $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
893         $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
894         $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
895         
896         $content = str_replace('{server_id}', $conf['server_id'], $content);
897         $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
5898e6 898         $content = str_replace('{language}', $conf['language'], $content);
8cf78b 899         $content = str_replace('{timezone}', $conf['timezone'], $content);
41eaa8 900         $content = str_replace('{theme}', $conf['theme'], $content);
5898e6 901         
32d8e9 902         wf("$install_dir/server/lib/$configfile", $content);
T 903         
fb3a98 904         //* Create the config file for remote-actions (but only, if it does not exist, because
T 905         //  the value is a autoinc-value and so changed by the remoteaction_core_module
906         if (!file_exists($install_dir.'/server/lib/remote_action.inc.php')) {
907             $content = '<?php' . "\n" . '$maxid_remote_action = 0;' . "\n" . '?>';
908             wf($install_dir.'/server/lib/remote_action.inc.php', $content);
909         }
32d8e9 910         
T 911         //* Enable the server modules and plugins.
912         // TODO: Implement a selector which modules and plugins shall be enabled.
913         $dir = $install_dir.'/server/mods-available/';
914         if (is_dir($dir)) {
915             if ($dh = opendir($dir)) {
916                 while (($file = readdir($dh)) !== false) {
917                     if($file != '.' && $file != '..' && substr($file,-8,8) == '.inc.php') {
918                         include_once($install_dir.'/server/mods-available/'.$file);
919                         $module_name = substr($file,0,-8);
920                         $tmp = new $module_name;
921                         if($tmp->onInstall()) {
922                             if(!@is_link($install_dir.'/server/mods-enabled/'.$file)) @symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-enabled/'.$file);
923                             if (strpos($file, '_core_module') !== false) {
924                                 if(!@is_link($install_dir.'/server/mods-core/'.$file)) @symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-core/'.$file);
925                             }
926                         }
927                         unset($tmp);
928                     }
929                 }
930                 closedir($dh);
931             }
932         }
933         
934         $dir = $install_dir.'/server/plugins-available/';
935         if (is_dir($dir)) {
936             if ($dh = opendir($dir)) {
937                 while (($file = readdir($dh)) !== false) {
1bd269 938                     if($conf['apache']['installed'] == true && $file == 'nginx_plugin.inc.php') continue;
F 939                     if($conf['nginx']['installed'] == true && $file == 'apache2_plugin.inc.php') continue;
32d8e9 940                     if($file != '.' && $file != '..' && substr($file,-8,8) == '.inc.php') {
T 941                         include_once($install_dir.'/server/plugins-available/'.$file);
942                         $plugin_name = substr($file,0,-8);
943                         $tmp = new $plugin_name;
944                         if($tmp->onInstall()) {
945                             if(!@is_link($install_dir.'/server/plugins-enabled/'.$file)) @symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-enabled/'.$file);
946                             if (strpos($file, '_core_plugin') !== false) {
947                                 if(!@is_link($install_dir.'/server/plugins-core/'.$file)) @symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-core/'.$file);
948                             }
949                         }
950                         unset($tmp);
951                     }
952                 }
953                 closedir($dh);
954             }
955         }
956         
957         // Update the server config
958         $mail_server_enabled = ($conf['services']['mail'])?1:0;
959         $web_server_enabled = ($conf['services']['web'])?1:0;
960         $dns_server_enabled = ($conf['services']['dns'])?1:0;
961         $file_server_enabled = ($conf['services']['file'])?1:0;
962         $db_server_enabled = ($conf['services']['db'])?1:0;
963         $vserver_server_enabled = ($conf['services']['vserver'])?1:0;
964         $sql = "UPDATE `server` SET mail_server = '$mail_server_enabled', web_server = '$web_server_enabled', dns_server = '$dns_server_enabled', file_server = '$file_server_enabled', db_server = '$db_server_enabled', vserver_server = '$vserver_server_enabled' WHERE server_id = ".intval($conf['server_id']);
965         
966         if($conf['mysql']['master_slave_setup'] == 'y') {
967             $this->dbmaster->query($sql);
968             $this->db->query($sql);
969         } else {
970             $this->db->query($sql);
971         }
972         
973         //* Chmod the files
974         $command = "chmod -R 750 $install_dir";
975         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
976
977         //* chown the files to the ispconfig user and group
978         $command = "chown -R ispconfig:ispconfig $install_dir";
979         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
980         
981         //* Make the global language file directory group writable
982         exec("chmod -R 770 $install_dir/interface/lib/lang");
983         
984         //* Make the temp directory for language file exports writable
985         exec("chmod -R 770 $install_dir/interface/web/temp");
986         
987         //* Make all interface language file directories group writable
988         $handle = @opendir($install_dir.'/interface/web');
989         while ($file = @readdir ($handle)) { 
990                if ($file != '.' && $file != '..') {
991                 if(@is_dir($install_dir.'/interface/web'.'/'.$file.'/lib/lang')) {
992                     $handle2 = opendir($install_dir.'/interface/web'.'/'.$file.'/lib/lang');
993                     chmod($install_dir.'/interface/web'.'/'.$file.'/lib/lang',0770);
994                     while ($lang_file = @readdir ($handle2)) {
995                         if ($lang_file != '.' && $lang_file != '..') {
996                             chmod($install_dir.'/interface/web'.'/'.$file.'/lib/lang/'.$lang_file,0770);
997                         }
998                     }
999                 }
1000             }
1001         }
1002         
477d4e 1003         //* Make the APS directories group writable
T 1004         exec("chmod -R 770 $install_dir/interface/web/sites/aps_meta_packages");
1005         exec("chmod -R 770 $install_dir/server/aps_packages");
1006         
32d8e9 1007         //* make sure that the server config file (not the interface one) is only readable by the root user
bfcdef 1008         chmod($install_dir.'/server/lib/config.inc.php', 0600);
T 1009         chown($install_dir.'/server/lib/config.inc.php', 'root');
1010         chgrp($install_dir.'/server/lib/config.inc.php', 'root');
1011         
1012         //* Make sure thet the interface config file is readable by user ispconfig only
1013         chmod($install_dir.'/interface/lib/config.inc.php', 0600);
1014         chown($install_dir.'/interface/lib/config.inc.php', 'ispconfig');
1015         chgrp($install_dir.'/interface/lib/config.inc.php', 'ispconfig');
1016         
32d8e9 1017         if(@is_file("$install_dir/server/lib/mysql_clientdb.conf")) {
T 1018             exec("chmod 600 $install_dir/server/lib/mysql_clientdb.conf");
1019             exec("chown root:root $install_dir/server/lib/mysql_clientdb.conf");
1020         }
1021         
1022         // TODO: FIXME: add the www-data user to the ispconfig group. This is just for testing
1023         // and must be fixed as this will allow the apache user to read the ispconfig files.
1024         // Later this must run as own apache server or via suexec!
63b369 1025         if($conf['apache']['installed'] == true){
F 1026             $command = 'groupmod --add-user '.$conf['apache']['user'].' ispconfig';
1027             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
272aec 1028             if(is_group('ispapps')){
F 1029                 $command = 'groupmod --add-user '.$conf['apache']['user'].' ispapps';
1030                 caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
1031             }
63b369 1032         }
F 1033         if($conf['nginx']['installed'] == true){
1034             $command = 'groupmod --add-user '.$conf['nginx']['user'].' ispconfig';
1035             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
272aec 1036             if(is_group('ispapps')){
F 1037                 $command = 'groupmod --add-user '.$conf['nginx']['user'].' ispapps';
1038                 caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
1039             }
63b369 1040         }
32d8e9 1041         
T 1042         //* Make the shell scripts executable
1043         $command = "chmod +x $install_dir/server/scripts/*.sh";
1044         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
1045         
1bd269 1046         
7e1cfb 1047         if($conf['apache']['installed'] == true && $this->install_ispconfig_interface == true){
1bd269 1048             //* Copy the ISPConfig vhost for the controlpanel
F 1049             // TODO: These are missing! should they be "vhost_dist_*_dir" ?
1050             $vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
1051             $vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
32d8e9 1052         
T 1053         
1bd269 1054             // Dont just copy over the virtualhost template but add some custom settings
32d8e9 1055          
1bd269 1056             $content = rf("tpl/apache_ispconfig.vhost.master");
F 1057             $content = str_replace('{vhost_port}', $conf['apache']['vhost_port'], $content);
32d8e9 1058         
1bd269 1059             // comment out the listen directive if port is 80 or 443
F 1060             if($conf['apache']['vhost_port'] == 80 or $conf['apache']['vhost_port'] == 443) {
1061                 $content = str_replace('{vhost_port_listen}', '#', $content);
1062             } else {
1063                 $content = str_replace('{vhost_port_listen}', '', $content);
1064             }
32d8e9 1065         
1bd269 1066             if(is_file('/usr/local/ispconfig/interface/ssl/ispserver.crt') && is_file('/usr/local/ispconfig/interface/ssl/ispserver.key')) {
F 1067                 $content = str_replace('{ssl_comment}', '', $content);
1068             } else {
1069                 $content = str_replace('{ssl_comment}', '#', $content);
1070             }
10b4c8 1071             if(is_file($install_dir.'/interface/ssl/ispserver.crt') && is_file($install_dir.'/interface/ssl/ispserver.key') && is_file($install_dir.'/interface/ssl/ispserver.bundle')) {
T 1072                 $content = str_replace('{ssl_bundle_comment}', '', $content);
1073             } else {
1074                 $content = str_replace('{ssl_bundle_comment}', '#', $content);
1075             }
4ae2a0 1076         
1bd269 1077             $content = str_replace('/var/www/', '/srv/www/', $content);
32d8e9 1078         
1bd269 1079             wf("$vhost_conf_dir/ispconfig.vhost", $content);
32d8e9 1080         
1bd269 1081             if(!is_file('/srv/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter')) {
526b99 1082                 $content = rf('tpl/apache_ispconfig_fcgi_starter.master');
T 1083                 $content = str_replace('{fastcgi_bin}', $conf['fastcgi']['fastcgi_bin'], $content);
1084                 $content = str_replace('{fastcgi_phpini_path}', $conf['fastcgi']['fastcgi_phpini_path'], $content);
1bd269 1085                 exec('mkdir -p /srv/www/php-fcgi-scripts/ispconfig');
526b99 1086                 wf('/srv/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter', $content);
1bd269 1087                 exec('chmod +x /srv/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter');
F 1088                 exec('ln -s /usr/local/ispconfig/interface/web /srv/www/ispconfig');
1089                 exec('chown -R ispconfig:ispconfig /srv/www/php-fcgi-scripts/ispconfig');
32d8e9 1090             
1bd269 1091             }
32d8e9 1092         
1bd269 1093             //copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost");
F 1094             //* and create the symlink
7e1cfb 1095             if($this->is_update == false) {
1bd269 1096                 if(@is_link("$vhost_conf_enabled_dir/ispconfig.vhost")) unlink("$vhost_conf_enabled_dir/ispconfig.vhost");
F 1097                 if(!@is_link("$vhost_conf_enabled_dir/000-ispconfig.vhost")) {
1098                     exec("ln -s $vhost_conf_dir/ispconfig.vhost $vhost_conf_enabled_dir/000-ispconfig.vhost");
1099                 }
1100             
1101             }
1102         
1103             // Fix a setting in vhost master file for suse
1104             replaceLine('/usr/local/ispconfig/server/conf/vhost.conf.master',"suPHP_UserGroup","        suPHP_UserGroup <tmpl_var name='system_user'> <tmpl_var name='system_group'>",0);
1105         }
1106
7e1cfb 1107         if($conf['nginx']['installed'] == true && $this->install_ispconfig_interface == true){
1bd269 1108             //* Copy the ISPConfig vhost for the controlpanel
F 1109             $vhost_conf_dir = $conf['nginx']['vhost_conf_dir'];
1110             $vhost_conf_enabled_dir = $conf['nginx']['vhost_conf_enabled_dir'];
1111
1112             // Dont just copy over the virtualhost template but add some custom settings
1113             $content = rf('tpl/nginx_ispconfig.vhost.master');
1114             $content = str_replace('{vhost_port}', $conf['nginx']['vhost_port'], $content);
1115         
1116             if(is_file($install_dir.'/interface/ssl/ispserver.crt') && is_file($install_dir.'/interface/ssl/ispserver.key')) {
10b4c8 1117                 $content = str_replace('{ssl_on}', ' on', $content);
1bd269 1118                 $content = str_replace('{ssl_comment}', '', $content);
F 1119                 $content = str_replace('{fastcgi_ssl}', 'on', $content);
1120             } else {
10b4c8 1121                 $content = str_replace('{ssl_on}', ' off', $content);
1bd269 1122                 $content = str_replace('{ssl_comment}', '#', $content);
F 1123                 $content = str_replace('{fastcgi_ssl}', 'off', $content);
32d8e9 1124             }
T 1125             
ca0b77 1126             $socket_dir = escapeshellcmd($conf['nginx']['php_fpm_socket_dir']);
F 1127             if(substr($socket_dir,-1) != '/') $socket_dir .= '/';
1128             if(!is_dir($socket_dir)) exec('mkdir -p '.$socket_dir);
1129             $fpm_socket = $socket_dir.'ispconfig.sock';
1130             
1131             //$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
1132             $content = str_replace('{fpm_socket}', $fpm_socket, $content);
1bd269 1133
F 1134             wf($vhost_conf_dir.'/ispconfig.vhost', $content);
1135             
1136             unset($content);
1137             
1138             // PHP-FPM
1139             // Dont just copy over the php-fpm pool template but add some custom settings
1140             $content = rf('tpl/php_fpm_pool.conf.master');
1141             $content = str_replace('{fpm_pool}', 'ispconfig', $content);
ca0b77 1142             //$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
F 1143             $content = str_replace('{fpm_socket}', $fpm_socket, $content);
1bd269 1144             $content = str_replace('{fpm_user}', 'ispconfig', $content);
F 1145             $content = str_replace('{fpm_group}', 'ispconfig', $content);
1146             wf($conf['nginx']['php_fpm_pool_dir'].'/ispconfig.conf', $content);
1147
1148             //copy('tpl/nginx_ispconfig.vhost.master', $vhost_conf_dir.'/ispconfig.vhost');
1149             //* and create the symlink
7e1cfb 1150             if($this->is_update == false) {
1bd269 1151                 if(@is_link($vhost_conf_enabled_dir.'/ispconfig.vhost')) unlink($vhost_conf_enabled_dir.'/ispconfig.vhost');
F 1152                 if(!@is_link($vhost_conf_enabled_dir.'/000-ispconfig.vhost')) {
1153                     symlink($vhost_conf_dir.'/ispconfig.vhost',$vhost_conf_enabled_dir.'/000-ispconfig.vhost');
1154                 }
1155             }
9aec3d 1156             
F 1157             // create symlinks from /usr/share to phpMyAdmin and SquirrelMail, if they are installed
1158             if(!@file_exists('/usr/share/phpmyadmin') && @is_dir('/srv/www/htdocs/phpMyAdmin')) symlink('/srv/www/htdocs/phpMyAdmin/','/usr/share/phpmyadmin');
1159             if(!@file_exists('/usr/share/squirrelmail') && @is_dir('/srv/www/htdocs/squirrelmail')) symlink('/srv/www/htdocs/squirrelmail/','/usr/share/squirrelmail');
32d8e9 1160         }
T 1161         
1162         
1163         // Make the Clamav log files readable by ISPConfig
1164         //exec('chmod +r /var/log/clamav/clamav.log');
1165         //exec('chmod +r /var/log/clamav/freshclam.log');
1166         
1167         //* Install the update script
1168         if(is_file('/usr/local/bin/ispconfig_update_from_svn.sh')) unlink('/usr/local/bin/ispconfig_update_from_svn.sh');
1169         exec('chown root /usr/local/ispconfig/server/scripts/update_from_svn.sh');
1170         exec('chmod 700 /usr/local/ispconfig/server/scripts/update_from_svn.sh');
1171         exec('chown root /usr/local/ispconfig/server/scripts/update_from_tgz.sh');
1172         exec('chmod 700 /usr/local/ispconfig/server/scripts/update_from_tgz.sh');
1173         exec('chown root /usr/local/ispconfig/server/scripts/ispconfig_update.sh');
1174         exec('chmod 700 /usr/local/ispconfig/server/scripts/ispconfig_update.sh');
1175         if(!is_link('/usr/local/bin/ispconfig_update_from_svn.sh')) exec('ln -s /usr/local/ispconfig/server/scripts/ispconfig_update.sh /usr/local/bin/ispconfig_update_from_svn.sh');
1176         if(!is_link('/usr/local/bin/ispconfig_update.sh')) exec('ln -s /usr/local/ispconfig/server/scripts/ispconfig_update.sh /usr/local/bin/ispconfig_update.sh');
1177         
1178         //set the fast cgi starter script to executable
1179         //exec('chmod 755 '.$install_dir.'/interface/bin/php-fcgi');
1180         
1181         //* Make the logs readable for the ispconfig user
1182         if(@is_file('/var/log/mail.log')) exec('chmod +r /var/log/mail.log');
1183         if(@is_file('/var/log/mail.warn')) exec('chmod +r /var/log/mail.warn');
1184         if(@is_file('/var/log/mail.err')) exec('chmod +r /var/log/mail.err');
1185         if(@is_file('/var/log/messages')) exec('chmod +r /var/log/messages');
1186         
1187         //To enable apache to read the directories
1188         exec('chmod a+rx /usr/local/ispconfig');
1189         exec('chmod -R 751 /usr/local/ispconfig/interface');
1190         exec('chmod a+rx /usr/local/ispconfig/interface/web');
1191         
1192         //* Create the ispconfig log directory
e38d14 1193         if(!is_dir($conf['ispconfig_log_dir'])) mkdir($conf['ispconfig_log_dir']);
J 1194         if(!is_file($conf['ispconfig_log_dir'].'/ispconfig.log')) exec('touch '.$conf['ispconfig_log_dir'].'/ispconfig.log');
32d8e9 1195         
0c5b42 1196         if(is_user('getmail')) {
T 1197             exec('mv /usr/local/ispconfig/server/scripts/run-getmail.sh /usr/local/bin/run-getmail.sh');
1198             exec('chown getmail /usr/local/bin/run-getmail.sh');
1199             exec('chmod 744 /usr/local/bin/run-getmail.sh');
1200         }
32d8e9 1201         
8cf78b 1202         if(is_dir($install_dir.'/interface/invoices')) {
e94a9f 1203             exec('chmod -R 770 '.escapeshellarg($install_dir.'/interface/invoices'));
T 1204             exec('chown -R ispconfig:ispconfig '.escapeshellarg($install_dir.'/interface/invoices'));
edf806 1205         }
T 1206         
0799f8 1207         //* Create the ispconfig auth log file and set uid/gid
T 1208         if(!is_file($conf['ispconfig_log_dir'].'/auth.log')) {
1209             touch($conf['ispconfig_log_dir'].'/auth.log');
1210         }
1211         exec('chown ispconfig:ispconfig '. $conf['ispconfig_log_dir'].'/auth.log');
1212         exec('chmod 660 '. $conf['ispconfig_log_dir'].'/auth.log');
1213         
d71bae 1214         //* Remove Domain module as its functions are available in the client module now
T 1215         if(@is_dir('/usr/local/ispconfig/interface/web/domain')) exec('rm -rf /usr/local/ispconfig/interface/web/domain');
1216         
32d8e9 1217         
T 1218     }
1219     
1220     public function configure_dbserver()
1221     {
1222         global $conf;
1223         
1224         //* If this server shall act as database server for client DB's, we configure this here
1225         $install_dir = $conf['ispconfig_install_dir'];
1226         
1227         // Create a file with the database login details which 
1228         // are used to create the client databases.
1229         
1230         if(!is_dir("$install_dir/server/lib")) {
1231             $command = "mkdir $install_dir/server/lib";
1232             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
1233         }
1234         
1235         $content = rf("tpl/mysql_clientdb.conf.master");
0fed3b 1236         $content = str_replace('{hostname}',$conf['mysql']['host'],$content);
32d8e9 1237         $content = str_replace('{username}',$conf['mysql']['admin_user'],$content);
T 1238         $content = str_replace('{password}',$conf['mysql']['admin_password'], $content);
1239         wf("$install_dir/server/lib/mysql_clientdb.conf",$content);
1240         exec('chmod 600 '."$install_dir/server/lib/mysql_clientdb.conf");
1241         exec('chown root:root '."$install_dir/server/lib/mysql_clientdb.conf");
1242         
1243     }
1244     
1245     public function install_crontab()
1246     {        
1247         global $conf;
1248         
1249         //* Root Crontab
1250         exec('crontab -u root -l > crontab.txt');
1251         $existing_root_cron_jobs = file('crontab.txt');
1252         
1253         // remove existing ispconfig cronjobs, in case the syntax has changed
1254         foreach($existing_root_cron_jobs as $key => $val) {
1255             if(stristr($val,'/usr/local/ispconfig')) unset($existing_root_cron_jobs[$key]);
1256         }
1257         
1258         $root_cron_jobs = array(
1259             '* * * * * /usr/local/ispconfig/server/server.sh &> /dev/null',
1260             '30 00 * * * /usr/local/ispconfig/server/cron_daily.sh &> /dev/null'
1261         );
b6a10a 1262         
F 1263         if ($conf['nginx']['installed'] == true) {
1264             $root_cron_jobs[] = "0 0 * * * /usr/local/ispconfig/server/scripts/create_daily_nginx_access_logs.sh &> /dev/null";
1265         }
1266         
32d8e9 1267         foreach($root_cron_jobs as $cron_job) {
T 1268             if(!in_array($cron_job."\n", $existing_root_cron_jobs)) {
1269                 $existing_root_cron_jobs[] = $cron_job."\n";
1270             }
1271         }
1272         file_put_contents('crontab.txt', $existing_root_cron_jobs);
1273         exec('crontab -u root crontab.txt &> /dev/null');
1274         unlink('crontab.txt');
1275         
1276         //* Getmail crontab
1277         if(is_user('getmail')) {
1278             $cf = $conf['getmail'];
1279             exec('crontab -u getmail -l > crontab.txt');
1280             $existing_cron_jobs = file('crontab.txt');
1281         
1282             $cron_jobs = array(
1283                 '*/5 * * * * /usr/local/bin/run-getmail.sh > /dev/null 2>> /var/log/ispconfig/cron.log'
1284             );
1285         
1286             // remove existing ispconfig cronjobs, in case the syntax has changed
1287             foreach($existing_cron_jobs as $key => $val) {
1288                 if(stristr($val,'getmail')) unset($existing_cron_jobs[$key]);
1289             }
1290         
1291             foreach($cron_jobs as $cron_job) {
1292                 if(!in_array($cron_job."\n", $existing_cron_jobs)) {
1293                     $existing_cron_jobs[] = $cron_job."\n";
1294                 }
1295             }
1296             file_put_contents('crontab.txt', $existing_cron_jobs);
1297             exec('crontab -u getmail crontab.txt &> /dev/null');
1298             unlink('crontab.txt');
1299         }
1300         
1301         exec('touch /var/log/ispconfig/cron.log');
1302         exec('chmod 666 /var/log/ispconfig/cron.log');
1303     }
1304
1305 }
1306
e38d14 1307 ?>