tbrehm
2009-05-27 0182cafd95cd8985a500ca298639652dc96fb354
commit | author | age
0711af 1 <?php
T 2
3 /*
436ed8 4 Copyright (c) 2007, Till Brehm, projektfarm Gmbh
0711af 5 All rights reserved.
T 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
344393 31 class installer_dist extends installer_base {
0711af 32     
T 33     function configure_postfix($options = '')
34     {
35         global $conf;
36         $cf = $conf['postfix'];
37         $config_dir = $cf['config_dir'];
38         
39         if(!is_dir($config_dir)){
40             $this->error("The postfix configuration directory '$config_dir' does not exist.");
41         }
42         
43         //* mysql-virtual_domains.cf
44         $this->process_postfix_config('mysql-virtual_domains.cf');
45
46         //* mysql-virtual_forwardings.cf
47         $this->process_postfix_config('mysql-virtual_forwardings.cf');
48
49         //* mysql-virtual_mailboxes.cf
50         $this->process_postfix_config('mysql-virtual_mailboxes.cf');
51
52         //* mysql-virtual_email2email.cf
53         $this->process_postfix_config('mysql-virtual_email2email.cf');
54
55         //* mysql-virtual_transports.cf
56         $this->process_postfix_config('mysql-virtual_transports.cf');
57
58         //* mysql-virtual_recipient.cf
59         $this->process_postfix_config('mysql-virtual_recipient.cf');
60
61         //* mysql-virtual_sender.cf
62         $this->process_postfix_config('mysql-virtual_sender.cf');
63
64         //* mysql-virtual_client.cf
65         $this->process_postfix_config('mysql-virtual_client.cf');
66         
67         //* mysql-virtual_relaydomains.cf
68         $this->process_postfix_config('mysql-virtual_relaydomains.cf');
69
70         //* Changing mode and group of the new created config files.
71         caselog('chmod o= '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null',
72                  __FILE__, __LINE__, 'chmod on mysql-virtual_*.cf*', 'chmod on mysql-virtual_*.cf* failed');
73         caselog('chgrp '.$cf['group'].' '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null', 
74                 __FILE__, __LINE__, 'chgrp on mysql-virtual_*.cf*', 'chgrp on mysql-virtual_*.cf* failed');
75         
76         //* Creating virtual mail user and group
77         $command = 'groupadd -g '.$cf['vmail_groupid'].' '.$cf['vmail_groupname'];
392450 78         if(!is_group($cf['vmail_groupname'])) caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
0711af 79
T 80         $command = 'useradd -g '.$cf['vmail_groupname'].' -u '.$cf['vmail_userid'].' '.$cf['vmail_username'].' -d '.$cf['vmail_mailbox_base'].' -m';
392450 81         if(!is_user($cf['vmail_username'])) caselog("$command &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");        
0711af 82
T 83         $postconf_commands = array (
84             'myhostname = '.$conf['hostname'],
85             'mydestination = '.$conf['hostname'].', localhost, localhost.localdomain',
24854c 86             'mynetworks = 127.0.0.0/8 [::1]/128',
0711af 87             'virtual_alias_domains =',
T 88             'virtual_alias_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_forwardings.cf, mysql:'.$config_dir.'/mysql-virtual_email2email.cf',
89             'virtual_mailbox_domains = proxy:mysql:'.$config_dir.'/mysql-virtual_domains.cf',
90             'virtual_mailbox_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_mailboxes.cf',
91             'virtual_mailbox_base = '.$cf['vmail_mailbox_base'],
92             'virtual_uid_maps = static:'.$cf['vmail_userid'],
93             'virtual_gid_maps = static:'.$cf['vmail_groupid'],
94             'smtpd_sasl_auth_enable = yes',
95             'broken_sasl_auth_clients = yes',
5a3f36 96             'smtpd_sasl_authenticated_header = yes',
0711af 97             'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, check_recipient_access mysql:'.$config_dir.'/mysql-virtual_recipient.cf, reject_unauth_destination',
T 98             'smtpd_use_tls = yes',
e77915 99             'smtpd_tls_security_level = may',
01423f 100             'smtpd_tls_cert_file = '.$config_dir.'/smtpd.cert',
R 101             'smtpd_tls_key_file = '.$config_dir.'/smtpd.key',
0711af 102             'transport_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_transports.cf',
T 103             'relay_domains = mysql:'.$config_dir.'/mysql-virtual_relaydomains.cf',
104             'virtual_create_maildirsize = yes',
766a45 105             'virtual_maildir_extended = yes',
0711af 106             'virtual_mailbox_limit_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_mailbox_limit_maps.cf',
T 107             'virtual_mailbox_limit_override = yes',
108             'virtual_maildir_limit_message = "The user you are trying to reach is over quota."',
109             'virtual_overquota_bounce = yes',
110             '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',
111             'smtpd_sender_restrictions = check_sender_access mysql:'.$config_dir.'/mysql-virtual_sender.cf',
112             'smtpd_client_restrictions = check_client_access mysql:'.$config_dir.'/mysql-virtual_client.cf',
113             'maildrop_destination_concurrency_limit = 1',
114             'maildrop_destination_recipient_limit   = 1',
115             'virtual_transport = maildrop',
116             'header_checks = regexp:'.$config_dir.'/header_checks',
117             'mime_header_checks = regexp:'.$config_dir.'/mime_header_checks',
118             'nested_header_checks = regexp:'.$config_dir.'/nested_header_checks',
119             'body_checks = regexp:'.$config_dir.'/body_checks',
120             'inet_interfaces = all'
121         );
122         
123         //* Create the header and body check files
124         touch($config_dir.'/header_checks');
125         touch($config_dir.'/mime_header_checks');
126         touch($config_dir.'/nested_header_checks');
127         touch($config_dir.'/body_checks');
128         
129         
130         //* Make a backup copy of the main.cf file
131         copy($config_dir.'/main.cf', $config_dir.'/main.cf~');
132         
133         //* Executing the postconf commands
134         foreach($postconf_commands as $cmd) {
135             $command = "postconf -e '$cmd'";
136             caselog($command." &> /dev/null", __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
137         }
138         
139         if(!stristr($options,'dont-create-certs')) {
140             //* Create the SSL certificate
01423f 141             $command = 'cd '.$config_dir.'; '
e77915 142                       .'openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509';
0711af 143             exec($command);
T 144         
01423f 145             $command = 'chmod o= '.$config_dir.'/smtpd.key';
0711af 146             caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
T 147         }
148         
149         //** We have to change the permissions of the courier authdaemon directory to make it accessible for maildrop.
150         $command = 'chmod 755 /var/spool/authdaemon';
151         caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
152         
153         //* Changing maildrop lines in posfix master.cf
154         if(is_file($config_dir.'/master.cf')){
155             copy($config_dir.'/master.cf', $config_dir.'/master.cf~');
156         }
157         if(is_file($config_dir.'/master.cf~')){
158             exec('chmod 400 '.$config_dir.'/master.cf~');
159         }
160         $configfile = $config_dir.'/master.cf';
161         $content = rf($configfile);
2c8f94 162         // if postfix package is from fedora or centios main repo
0711af 163         $content = str_replace('#  flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}', 
T 164                    '  flags=R user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}',
165                      $content);
51c815 166                      
2c8f94 167         // If postfix package is from centos plus repo
T 168         $content = str_replace('#  flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}', 
169                    '  flags=R user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}',
170                      $content);
51c815 171                      
F 172         $content = str_replace('  flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}', 
173                    '  flags=R user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}',
174                      $content);
2c8f94 175         
T 176         
0711af 177         $content = str_replace('#maildrop  unix  -       n       n       -       -       pipe', 
T 178                    'maildrop  unix  -       n       n       -       -       pipe',
179                      $content);
180         
181         wf($configfile, $content);
182         
183         //* Writing the Maildrop mailfilter file
184         $configfile = 'mailfilter';
185         if(is_file($cf['vmail_mailbox_base'].'/.'.$configfile)){
186             copy($cf['vmail_mailbox_base'].'/.'.$configfile, $cf['vmail_mailbox_base'].'/.'.$configfile.'~');
187         }
188         $content = rf("tpl/$configfile.master");
189         $content = str_replace('{dist_postfix_vmail_mailbox_base}', $cf['vmail_mailbox_base'], $content);
190         wf($cf['vmail_mailbox_base'].'/.'.$configfile, $content);
191         
192         //* Create the directory for the custom mailfilters
193         $command = 'mkdir '.$cf['vmail_mailbox_base'].'/mailfilters';
194         caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
195         
196         //* Chmod and chown the .mailfilter file
197         $command = 'chown -R '.$cf['vmail_username'].':'.$cf['vmail_groupname'].' '.$cf['vmail_mailbox_base'].'/.mailfilter';
198         caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
199         
200         $command = 'chmod -R 600 '.$cf['vmail_mailbox_base'].'/.mailfilter';
201         caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
202         
203     }
204     
205     public function configure_saslauthd() {
206         global $conf;
207         
208         $configfile = 'tpl/fedora_saslauthd_smtpd_conf.master';
209         $content = rf($configfile);
210         wf('/usr/lib/sasl2/smtpd.conf',$content);
949e7e 211         if(is_dir('/usr/lib64')) wf('/usr/lib64/sasl/smtpd.conf',$content);
T 212         if(is_dir('/usr/lib64')) wf('/usr/lib64/sasl2/smtpd.conf',$content);
0711af 213         
T 214     }
215     
216     public function configure_pam()
217     {
218         global $conf;
219         $pam = $conf['pam'];
220         //* configure pam for SMTP authentication agains the ispconfig database
221         $configfile = 'pamd_smtp';
222         if(is_file("$pam/smtp"))    copy("$pam/smtp", "$pam/smtp~");
223         if(is_file("$pam/smtp~"))   exec("chmod 400 $pam/smtp~");
224
225         $content = rf("tpl/$configfile.master");
226         $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
227         $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
228         $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
229         $content = str_replace('{mysql_server_ip}', $conf['mysql']['ip'], $content);
230         wf("$pam/smtp", $content);
231         //exec("chmod 660 $pam/smtp");
232         //exec("chown root:root $pam/smtp");
233     
234     }
235     
236     public function configure_courier()
237     {
238         global $conf;
239         $config_dir = $conf['courier']['config_dir'];
240         //* authmysqlrc
241         $configfile = 'authmysqlrc';
242         if(is_file("$config_dir/$configfile")){
243             copy("$config_dir/$configfile", "$config_dir/$configfile~");
244         }
245         exec("chmod 400 $config_dir/$configfile~");
246         $content = rf("tpl/$configfile.master");
247         $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
248         $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
249         $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
250         $content = str_replace('{mysql_server_host}',$conf['mysql']['host'],$content);
251         wf("$config_dir/$configfile", $content);
252         
253         exec("chmod 660 $config_dir/$configfile");
254         exec("chown root:root $config_dir/$configfile");
255         
256         //* authdaemonrc
257         $configfile = $conf['courier']['config_dir'].'/authdaemonrc';
258         if(is_file($configfile)){
259             copy($configfile, $configfile.'~');
260         }
261         if(is_file($configfile.'~')){
262             exec('chmod 400 '.$configfile.'~');
263         }
264         $content = rf($configfile);
265         $content = str_replace('authmodulelist=', 'authmodulelist="authmysql"', $content);
266         wf($configfile, $content);
267     }
268     
269     public function configure_amavis() {
270         global $conf;
271         
272         // amavisd user config file
273         $configfile = 'fedora_amavisd_conf';
274         if(is_file($conf["amavis"]["config_dir"].'/amavisd.conf')) copy($conf["amavis"]["config_dir"].'/amavisd.conf',$conf["courier"]["config_dir"].'/amavisd.conf~');
275         if(is_file($conf["amavis"]["config_dir"].'/amavisd.conf~')) exec('chmod 400 '.$conf["amavis"]["config_dir"].'/amavisd.conf~');
276         $content = rf("tpl/".$configfile.".master");
277         $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
278         $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
279         $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
280         $content = str_replace('{mysql_server_port}',$conf["mysql"]["port"],$content);
281         $content = str_replace('{mysql_server_ip}',$conf['mysql']['ip'],$content);
282         $content = str_replace('{hostname}',$conf['hostname'],$content);
283         wf($conf["amavis"]["config_dir"].'/amavisd.conf',$content);
284         
285         
286         // Adding the amavisd commands to the postfix configuration
287         $postconf_commands = array (
288             'content_filter = amavis:[127.0.0.1]:10024',
289             'receive_override_options = no_address_mappings'
290         );
291         
292         // Make a backup copy of the main.cf file
293         copy($conf["postfix"]["config_dir"].'/main.cf',$conf["postfix"]["config_dir"].'/main.cf~2');
294         
295         // Executing the postconf commands
296         foreach($postconf_commands as $cmd) {
297             $command = "postconf -e '$cmd'";
298             caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
299         }
300         
301         // Append the configuration for amavisd to the master.cf file
302         if(is_file($conf["postfix"]["config_dir"].'/master.cf')) copy($conf["postfix"]["config_dir"].'/master.cf',$conf["postfix"]["config_dir"].'/master.cf~');
303         $content = rf($conf["postfix"]["config_dir"].'/master.cf');
304         // Only add the content if we had not addded it before
305         if(!stristr($content,"127.0.0.1:10025")) {
306             unset($content);
307             $content = rf("tpl/master_cf_amavis.master");
308             af($conf["postfix"]["config_dir"].'/master.cf',$content);
309         }
310         unset($content);
311         
312         removeLine('/etc/sysconfig/freshclam','FRESHCLAM_DELAY=disabled-warn   # REMOVE ME',1);
313         replaceLine('/etc/freshclam.conf','Example','# Example',1);
314         
315         // Add the clamav user to the vscan group
316         //exec('groupmod --add-user clamav vscan');
317         
318         
319     }
320     
321     public function configure_spamassassin()
322     {
323         global $conf;
324         
325         //* Enable spamasasssin on debian and ubuntu
326         /*
327         $configfile = '/etc/default/spamassassin';
328         if(is_file($configfile)){
329             copy($configfile, $configfile.'~');
330         }
331         $content = rf($configfile);
332         $content = str_replace('ENABLED=0', 'ENABLED=1', $content);
333         wf($configfile, $content);
334         */
335     }
336     
337     public function configure_getmail()
338     {
339         global $conf;
340         
341         $config_dir = $conf['getmail']['config_dir'];
342         
343         if(!is_dir($config_dir)) exec("mkdir -p ".escapeshellcmd($config_dir));
344
345         $command = "useradd -d $config_dir getmail";
392450 346         if(!is_user('getmail')) caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
0711af 347         
T 348         $command = "chown -R getmail $config_dir";
349         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
350         
351         $command = "chmod -R 700 $config_dir";
352         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
353     }
354     
355     
356     public function configure_pureftpd()
357     {
358         global $conf;
359         
360         $config_dir = $conf['pureftpd']['config_dir'];
361
362         //* configure pam for SMTP authentication agains the ispconfig database
363         $configfile = 'pureftpd-mysql.conf';
364         if(is_file("$config_dir/$configfile")){
365             copy("$config_dir/$configfile", "$config_dir/$configfile~");
366         }
367         if(is_file("$config_dir/$configfile~")){
368             exec("chmod 400 $config_dir/$configfile~");
369         }
370         $content = rf('tpl/pureftpd_mysql.conf.master');
371         $content = str_replace('{mysql_server_ispconfig_user}', $conf["mysql"]["ispconfig_user"], $content);
372         $content = str_replace('{mysql_server_ispconfig_password}', $conf["mysql"]["ispconfig_password"], $content);
373         $content = str_replace('{mysql_server_database}', $conf["mysql"]["database"], $content);
374         $content = str_replace('{mysql_server_ip}', $conf["mysql"]["ip"], $content);
375         $content = str_replace('{server_id}', $conf["server_id"], $content);
376         wf("$config_dir/$configfile", $content);
377         exec("chmod 600 $config_dir/$configfile");
378         exec("chown root:root $config_dir/$configfile");
379         
380         // copy our customized copy of pureftpd.conf to the pure-ftpd config directory
381         exec("cp tpl/fedora_pureftpd_conf.master $config_dir/pure-ftpd.conf");
382         
383     }
384     
385     public function configure_mydns()
386     {
387         global $conf;
388         
389         // configure mydns
390         $configfile = 'mydns.conf';
391         if(is_file($conf["mydns"]["config_dir"].'/'.$configfile)) copy($conf["mydns"]["config_dir"].'/'.$configfile,$conf["mydns"]["config_dir"].'/'.$configfile.'~');
392         if(is_file($conf["mydns"]["config_dir"].'/'.$configfile.'~')) exec('chmod 400 '.$conf["mydns"]["config_dir"].'/'.$configfile.'~');
393         $content = rf("tpl/".$configfile.".master");
394         $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
395         $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
396         $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
397         $content = str_replace('{mysql_server_host}',$conf["mysql"]["host"],$content);
398         $content = str_replace('{server_id}',$conf["server_id"],$content);
399         wf($conf["mydns"]["config_dir"].'/'.$configfile,$content);
400         exec('chmod 600 '.$conf["mydns"]["config_dir"].'/'.$configfile);
401         exec('chown root:root '.$conf["mydns"]["config_dir"].'/'.$configfile);
402     
403     }
404     
405     public function configure_apache()
406     {    
407         global $conf;
408         
bde98e 409         if(is_file('/etc/suphp.conf')) {
4c7fd5 410             //replaceLine('/etc/suphp.conf','php=php:/usr/bin','x-httpd-suphp=php:/usr/bin/php-cgi',0);
2ace6e 411             replaceLine('/etc/suphp.conf','docroot=','docroot=/var/www',0);
bde98e 412         }
T 413         
0711af 414         //* Create the logging directory for the vhost logfiles
T 415         exec('mkdir -p /var/log/ispconfig/httpd');
416         
417         // Sites enabled and avaulable dirs
418         exec('mkdir -p '.$conf['apache']['vhost_conf_enabled_dir']);
419         exec('mkdir -p '.$conf['apache']['vhost_conf_dir']);
420         
421         $content = rf('/etc/httpd/conf/httpd.conf');
422         if(!stristr($content,'Include /etc/httpd/conf/sites-enabled/')) {
7b28da 423             af('/etc/httpd/conf/httpd.conf',"\nNameVirtualHost *:80\nNameVirtualHost *:443\nInclude /etc/httpd/conf/sites-enabled/\n\n");
0711af 424         }
T 425         unset($content);
426         
9de0c4 427         //* Copy the ISPConfig configuration include
T 428         $vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
429         $vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
430         
86e3bb 431         // copy('tpl/apache_ispconfig.conf.master',$vhost_conf_dir.'/ispconfig.conf');
T 432         $content = rf("tpl/apache_ispconfig.conf.master");
433         $records = $this->db->queryAllRecords("SELECT * FROM server_ip WHERE server_id = ".$conf["server_id"]." AND virtualhost = 'y'");
434         if(count($records) > 0) {
435             foreach($records as $rec) {
436                 $content .= "NameVirtualHost ".$rec["ip_address"].":80\n";
437                 $content .= "NameVirtualHost ".$rec["ip_address"].":443\n";
438             }
439         }
440         $content .= "\n";
441         wf($vhost_conf_dir.'/ispconfig.conf',$content);
442         
9de0c4 443         if(!@is_link($vhost_conf_enabled_dir."/000-ispconfig.conf")) {
T 444             exec("ln -s ".$vhost_conf_dir."/ispconfig.conf ".$vhost_conf_enabled_dir."/000-ispconfig.conf");
445         }
446         
0711af 447     }
T 448     
449     public function configure_firewall()
450     {
451         global $conf;
452         
453         $dist_init_scripts = $conf['init_scripts'];
454           
455         if(is_dir("/etc/Bastille.backup")) caselog("rm -rf /etc/Bastille.backup", __FILE__, __LINE__);
456         if(is_dir("/etc/Bastille")) caselog("mv -f /etc/Bastille /etc/Bastille.backup", __FILE__, __LINE__);
457           @mkdir("/etc/Bastille", octdec($directory_mode));
458           if(is_dir("/etc/Bastille.backup/firewall.d")) caselog("cp -pfr /etc/Bastille.backup/firewall.d /etc/Bastille/", __FILE__, __LINE__);
459           caselog("cp -f tpl/bastille-firewall.cfg.master /etc/Bastille/bastille-firewall.cfg", __FILE__, __LINE__);
460           caselog("chmod 644 /etc/Bastille/bastille-firewall.cfg", __FILE__, __LINE__);
461           $content = rf("/etc/Bastille/bastille-firewall.cfg");
462           $content = str_replace("{DNS_SERVERS}", "", $content);
463
464           $tcp_public_services = '';
465           $udp_public_services = '';
466         
467         $row = $this->db->queryOneRecord("SELECT * FROM firewall WHERE server_id = ".intval($conf['server_id']));
468         
469           if(trim($row["tcp_port"]) != '' || trim($row["udp_port"]) != ''){
470             $tcp_public_services = trim(str_replace(',',' ',$row["tcp_port"]));
471             $udp_public_services = trim(str_replace(',',' ',$row["udp_port"]));
472           } else {
8d0600 473             $tcp_public_services = '21 22 25 53 80 110 443 3306 8080 10000';
0711af 474             $udp_public_services = '53';
T 475           }
9ce725 476         if(!stristr($tcp_public_services, $conf['apache']['vhost_port'])) {
96cc31 477             $tcp_public_services .= ' '.intval($conf['apache']['vhost_port']);
57299d 478             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']));
9ce725 479         }
T 480         
0711af 481           $content = str_replace("{TCP_PUBLIC_SERVICES}", $tcp_public_services, $content);
T 482           $content = str_replace("{UDP_PUBLIC_SERVICES}", $udp_public_services, $content);
483
484           wf("/etc/Bastille/bastille-firewall.cfg", $content);
485
486           if(is_file($dist_init_scripts."/bastille-firewall")) caselog("mv -f $dist_init_scripts/bastille-firewall $dist_init_scripts/bastille-firewall.backup", __FILE__, __LINE__);
487           caselog("cp -f apps/bastille-firewall $dist_init_scripts", __FILE__, __LINE__);
488           caselog("chmod 700 $dist_init_scripts/bastille-firewall", __FILE__, __LINE__);
489
490           if(is_file("/sbin/bastille-ipchains")) caselog("mv -f /sbin/bastille-ipchains /sbin/bastille-ipchains.backup", __FILE__, __LINE__);
491           caselog("cp -f apps/bastille-ipchains /sbin", __FILE__, __LINE__);
492           caselog("chmod 700 /sbin/bastille-ipchains", __FILE__, __LINE__);
493
494           if(is_file("/sbin/bastille-netfilter")) caselog("mv -f /sbin/bastille-netfilter /sbin/bastille-netfilter.backup", __FILE__, __LINE__);
495           caselog("cp -f apps/bastille-netfilter /sbin", __FILE__, __LINE__);
496           caselog("chmod 700 /sbin/bastille-netfilter", __FILE__, __LINE__);
497         
498         if(!@is_dir('/var/lock/subsys')) caselog("mkdir /var/lock/subsys", __FILE__, __LINE__);
499
500           exec("which ipchains &> /dev/null", $ipchains_location, $ret_val);
501           if(!is_file("/sbin/ipchains") && !is_link("/sbin/ipchains") && $ret_val == 0) phpcaselog(@symlink(shell_exec("which ipchains"), "/sbin/ipchains"), 'create symlink', __FILE__, __LINE__);
502           unset($ipchains_location);
503           exec("which iptables &> /dev/null", $iptables_location, $ret_val);
504           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__);
505           unset($iptables_location);
506
507     }
508     
509     
510     public function install_ispconfig()
511     {
512         global $conf;
513         
514         $install_dir = $conf['ispconfig_install_dir'];
515
516         //* Create the ISPConfig installation directory
517         if(!@is_dir("$install_dir")) {
518             $command = "mkdir $install_dir";
519             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
520         }
521         
522         //* Create a ISPConfig user and group
523         $command = 'groupadd ispconfig';
392450 524         if(!is_group('ispconfig')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
0711af 525         
T 526         $command = "useradd -g ispconfig -d $install_dir ispconfig";
392450 527         if(!is_user('ispconfig')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
0711af 528         
T 529         //* copy the ISPConfig interface part
530         $command = "cp -rf ../interface $install_dir";
531         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
532         
533         //* copy the ISPConfig server part
534         $command = "cp -rf ../server $install_dir";
535         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
536         
537         //* Create a symlink, so ISPConfig is accessible via web
538         // Replaced by a separate vhost definition for port 8080
539         // $command = "ln -s $install_dir/interface/web/ /var/www/ispconfig";
540         // caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
541         
542         //* Create the config file for ISPConfig interface
543         $configfile = 'config.inc.php';
544         if(is_file($install_dir.'/interface/lib/'.$configfile)){
545             copy("$install_dir/interface/lib/$configfile", "$install_dir/interface/lib/$configfile~");
546         }
547         $content = rf("tpl/$configfile.master");
548         $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
549         $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
550         $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
551         $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
12e3ba 552         
T 553         $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
554         $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
555         $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
556         $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
557         
0182ca 558         $content = str_replace('{server_id}', $conf['server_id'], $content);
0711af 559         $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
24854c 560         $content = str_replace('{language}', $conf['language'], $content);
T 561         
0711af 562         wf("$install_dir/interface/lib/$configfile", $content);
T 563         
564         //* Create the config file for ISPConfig server
565         $configfile = 'config.inc.php';
566         if(is_file($install_dir.'/server/lib/'.$configfile)){
567             copy("$install_dir/server/lib/$configfile", "$install_dir/interface/lib/$configfile~");
568         }
569         $content = rf("tpl/$configfile.master");
570         $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
571         $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
572         $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
573         $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
12e3ba 574         
T 575         $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
576         $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
577         $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
578         $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
579         
0711af 580         $content = str_replace('{server_id}', $conf['server_id'], $content);
T 581         $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
d1348b 582         $content = str_replace('{language}', $conf['language'], $content);
T 583         
0711af 584         wf("$install_dir/server/lib/$configfile", $content);
T 585         
586         
587         //* Enable the server modules and plugins.
588         // TODO: Implement a selector which modules and plugins shall be enabled.
589         $dir = $install_dir.'/server/mods-available/';
590         if (is_dir($dir)) {
591             if ($dh = opendir($dir)) {
592                 while (($file = readdir($dh)) !== false) {
392450 593                     if($file != '.' && $file != '..' && substr($file,-8,8) == '.inc.php') {
T 594                         include_once($install_dir.'/server/mods-available/'.$file);
595                         $module_name = substr($file,0,-8);
596                         $tmp = new $module_name;
597                         if($tmp->onInstall()) {
598                             if(!@is_link($install_dir.'/server/mods-enabled/'.$file)) @symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-enabled/'.$file);
599                             if (strpos($file, '_core_module') !== false) {
600                                 if(!@is_link($install_dir.'/server/mods-core/'.$file)) @symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-core/'.$file);
601                             }
0d0cd9 602                         }
392450 603                         unset($tmp);
0711af 604                     }
T 605                 }
606                 closedir($dh);
607             }
608         }
609         
610         $dir = $install_dir.'/server/plugins-available/';
611         if (is_dir($dir)) {
612             if ($dh = opendir($dir)) {
613                 while (($file = readdir($dh)) !== false) {
392450 614                     if($file != '.' && $file != '..' && substr($file,-8,8) == '.inc.php') {
T 615                         include_once($install_dir.'/server/plugins-available/'.$file);
616                         $plugin_name = substr($file,0,-8);
617                         $tmp = new $plugin_name;
618                         if($tmp->onInstall()) {
619                             if(!@is_link($install_dir.'/server/plugins-enabled/'.$file)) @symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-enabled/'.$file);
620                             if (strpos($file, '_core_plugin') !== false) {
621                                 if(!@is_link($install_dir.'/server/plugins-core/'.$file)) @symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-core/'.$file);
622                             }
0d0cd9 623                         }
392450 624                         unset($tmp);
0711af 625                     }
T 626                 }
627                 closedir($dh);
628             }
629         }
630         
392450 631         // Update the server config
T 632         $mail_server_enabled = ($conf['services']['mail'])?1:0;
633         $web_server_enabled = ($conf['services']['web'])?1:0;
634         $dns_server_enabled = ($conf['services']['dns'])?1:0;
635         $file_server_enabled = ($conf['services']['file'])?1:0;
636         $db_server_enabled = ($conf['services']['db'])?1:0;
637         $vserver_server_enabled = ($conf['services']['vserver'])?1:0;
638         $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']);
639         
640         if($conf['mysql']['master_slave_setup'] == 'y') {
641             $this->dbmaster->query($sql);
f66929 642             $this->db->query($sql);
392450 643         } else {
T 644             $this->db->query($sql);
645         }
646         
0711af 647         //* Chmod the files
T 648         $command = "chmod -R 750 $install_dir";
649         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
650
651         //* chown the files to the ispconfig user and group
652         $command = "chown -R ispconfig:ispconfig $install_dir";
653         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
654         
655         //* Make the global language file directory group writable
656         exec("chmod -R 770 $install_dir/interface/lib/lang");
657         
658         //* Make the temp directory for language file exports writable
659         exec("chmod -R 770 $install_dir/interface/web/temp");
660         
661         //* Make all interface language file directories group writable
662         $handle = @opendir($install_dir.'/interface/web');
663         while ($file = @readdir ($handle)) { 
664                if ($file != '.' && $file != '..') {
665                 if(@is_dir($install_dir.'/interface/web'.'/'.$file.'/lib/lang')) {
666                     $handle2 = opendir($install_dir.'/interface/web'.'/'.$file.'/lib/lang');
667                     chmod($install_dir.'/interface/web'.'/'.$file.'/lib/lang',0770);
668                     while ($lang_file = @readdir ($handle2)) {
669                         if ($lang_file != '.' && $lang_file != '..') {
670                             chmod($install_dir.'/interface/web'.'/'.$file.'/lib/lang/'.$lang_file,0770);
671                         }
672                     }
673                 }
674             }
675         }
676         
677         //* make sure that the server config file (not the interface one) is only readable by the root user
678         exec("chmod 600 $install_dir/server/lib/$configfile");
679         exec("chown root:root $install_dir/server/lib/$configfile");
680         if(@is_file("$install_dir/server/lib/mysql_clientdb.conf")) {
681             exec("chmod 600 $install_dir/server/lib/mysql_clientdb.conf");
682             exec("chown root:root $install_dir/server/lib/mysql_clientdb.conf");
683         }
684         
685         // TODO: FIXME: add the www-data user to the ispconfig group. This is just for testing
686         // and must be fixed as this will allow the apache user to read the ispconfig files.
687         // Later this must run as own apache server or via suexec!
688         $command = 'usermod -a -G ispconfig '.$conf['apache']['user'];
689         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
690         
691         //* Make the shell scripts executable
692         $command = "chmod +x $install_dir/server/scripts/*.sh";
693         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
694         
695         //* Copy the ISPConfig vhost for the controlpanel
696         // TODO: These are missing! should they be "vhost_dist_*_dir" ?
697         $vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
698         $vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
699         
700         
701         // Dont just copy over the virtualhost template but add some custom settings
702         $content = rf("tpl/apache_ispconfig.vhost.master");
703         $content = str_replace('{vhost_port}', $conf['apache']['vhost_port'], $content);
f6d745 704         
T 705         // comment out the listen directive if port is 80 or 443
706         if($conf['apache']['vhost_port'] == 80 or $conf['apache']['vhost_port'] == 443) {
707             $content = str_replace('{vhost_port_listen}', '#', $content);
708         } else {
709             $content = str_replace('{vhost_port_listen}', '', $content);
710         }
711         
0711af 712         wf("$vhost_conf_dir/ispconfig.vhost", $content);
T 713         
714         //copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost");
715         //* and create the symlink
4f68a7 716         if($this->install_ispconfig_interface == true && $this->is_update == false) {
0c78af 717             if(@is_link("$vhost_conf_enabled_dir/ispconfig.vhost")) unlink("$vhost_conf_enabled_dir/ispconfig.vhost");
T 718             if(!@is_link("$vhost_conf_enabled_dir/000-ispconfig.vhost")) {
719                 exec("ln -s $vhost_conf_dir/ispconfig.vhost $vhost_conf_enabled_dir/000-ispconfig.vhost");
0711af 720             }
76f197 721             
T 722             exec('mkdir -p /var/www/php-fcgi-scripts/ispconfig');
723             exec('cp tpl/apache_ispconfig_fcgi_starter.master /var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter');
724             exec('chmod +x /var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter');
725             exec('ln -s /usr/local/ispconfig/interface/web /var/www/ispconfig');
726             exec('chown -R ispconfig:ispconfig /var/www/php-fcgi-scripts/ispconfig');
727             
0f76eb 728             replaceLine('/var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter','PHPRC=','PHPRC=/etc/',0,0);
T 729             
76f197 730         }
T 731         
732         //copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost");
733         //* and create the symlink
734         if($this->install_ispconfig_interface == true && $this->is_update == false) {
735             if(@is_link("$vhost_conf_enabled_dir/ispconfig.vhost")) unlink("$vhost_conf_enabled_dir/ispconfig.vhost");
736             if(!@is_link("$vhost_conf_enabled_dir/000-ispconfig.vhost")) {
737                 exec("ln -s $vhost_conf_dir/ispconfig.vhost $vhost_conf_enabled_dir/000-ispconfig.vhost");
738             }
0711af 739         }
T 740         
741         // Make the Clamav log files readable by ISPConfig
742         //exec('chmod +r /var/log/clamav/clamav.log');
743         //exec('chmod +r /var/log/clamav/freshclam.log');
744         
66768a 745         //* Install the update script
T 746         if(is_file('/usr/local/bin/ispconfig_update_from_svn.sh')) unlink('/usr/local/bin/ispconfig_update_from_svn.sh');
747         exec('chown root /usr/local/ispconfig/server/scripts/update_from_svn.sh');
748         exec('chmod 700 /usr/local/ispconfig/server/scripts/update_from_svn.sh');
749         exec('chown root /usr/local/ispconfig/server/scripts/update_from_tgz.sh');
750         exec('chmod 700 /usr/local/ispconfig/server/scripts/update_from_tgz.sh');
751         exec('chown root /usr/local/ispconfig/server/scripts/ispconfig_update.sh');
752         exec('chmod 700 /usr/local/ispconfig/server/scripts/ispconfig_update.sh');
608a8c 753         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');
T 754         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');
0711af 755         
76f197 756         // set the fast cgi starter script to executable
T 757         // exec('chmod 755 '.$install_dir.'/interface/bin/php-fcgi');
0711af 758         
T 759         //* Make the logs readable for the ispconfig user
760         if(@is_file('/var/log/maillog')) exec('chmod +r /var/log/maillog');
761         //if(@is_file('/var/log/mail.warn')) exec('chmod +r /var/log/mail.warn');
762         //if(@is_file('/var/log/mail.err')) exec('chmod +r /var/log/mail.err');
763         if(@is_file('/var/log/messages')) exec('chmod +r /var/log/messages');
764         
765         //To enable apache to read the directories
766         // exec('chmod a+rx /usr/local/ispconfig');
767         // exec('chmod -R 751 /usr/local/ispconfig/interface');
768         // exec('chmod a+rx /usr/local/ispconfig/interface/web');
769         
d9c8a7 770         //* Create the ispconfig log directory
T 771         if(!is_dir('/var/log/ispconfig')) mkdir('/var/log/ispconfig');
77d8a9 772         if(!is_file('/var/log/ispconfig/ispconfig.log')) exec('touch /var/log/ispconfig/ispconfig.log');
d9c8a7 773         
fee7a4 774         exec('mv /usr/local/ispconfig/server/scripts/run-getmail.sh /usr/local/bin/run-getmail.sh');
T 775         exec('chown getmail /usr/local/bin/run-getmail.sh');
776         exec('chmod 744 /usr/local/bin/run-getmail.sh');
27c3a6 777         
0711af 778         
T 779     }
780     
781     public function configure_dbserver()
782     {
783         global $conf;
784         
785         //* If this server shall act as database server for client DB's, we configure this here
786         $install_dir = $conf['ispconfig_install_dir'];
787         
788         // Create a file with the database login details which 
789         // are used to create the client databases.
790         
791         if(!is_dir("$install_dir/server/lib")) {
792             $command = "mkdir $install_dir/server/lib";
793             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
794         }
795         
796         $content = rf("tpl/mysql_clientdb.conf.master");
797         $content = str_replace('{username}',$conf['mysql']['admin_user'],$content);
798         $content = str_replace('{password}',$conf['mysql']['admin_password'], $content);
799         wf("$install_dir/server/lib/mysql_clientdb.conf",$content);
800         exec('chmod 600 '."$install_dir/server/lib/mysql_clientdb.conf");
801         exec('chown root:root '."$install_dir/server/lib/mysql_clientdb.conf");
802         
803     }
804     
805     public function install_crontab()
806     {        
807         global $conf;
808         
809         //* Root Crontab
810         exec('crontab -u root -l > crontab.txt');
811         $existing_root_cron_jobs = file('crontab.txt');
812         
a8a328 813         // remove existing ispconfig cronjobs, in case the syntax has changed
T 814         foreach($existing_root_cron_jobs as $key => $val) {
815             if(stristr($val,'/usr/local/ispconfig')) unset($existing_root_cron_jobs[$key]);
816         }
817         
0711af 818         $root_cron_jobs = array(
T 819             '* * * * * /usr/local/ispconfig/server/server.sh &> /dev/null',
820             '30 00 * * * /usr/local/ispconfig/server/cron_daily.sh &> /dev/null'
821         );
822         foreach($root_cron_jobs as $cron_job) {
823             if(!in_array($cron_job."\n", $existing_root_cron_jobs)) {
824                 $existing_root_cron_jobs[] = $cron_job."\n";
825             }
826         }
827         file_put_contents('crontab.txt', $existing_root_cron_jobs);
828         exec('crontab -u root crontab.txt &> /dev/null');
829         unlink('crontab.txt');
830         
831         //* Getmail crontab
a8a328 832         if(is_user('getmail')) {
T 833             $cf = $conf['getmail'];
834             exec('crontab -u getmail -l > crontab.txt');
835             $existing_cron_jobs = file('crontab.txt');
0711af 836         
27c3a6 837             $cron_jobs = array(
fee7a4 838                 '*/5 * * * * /usr/local/bin/run-getmail.sh > /dev/null 2>> /var/log/ispconfig/cron.log'
27c3a6 839             );
T 840         
a8a328 841             // remove existing ispconfig cronjobs, in case the syntax has changed
9b30b0 842             foreach($existing_cron_jobs as $key => $val) {
27c3a6 843                 if(stristr($val,'getmail')) unset($existing_cron_jobs[$key]);
0711af 844             }
1f93c0 845         
a8a328 846             foreach($cron_jobs as $cron_job) {
T 847                 if(!in_array($cron_job."\n", $existing_cron_jobs)) {
848                     $existing_cron_jobs[] = $cron_job."\n";
849                 }
850             }
851             file_put_contents('crontab.txt', $existing_cron_jobs);
852             exec('crontab -u getmail crontab.txt &> /dev/null');
853             unlink('crontab.txt');
0711af 854         }
00d730 855         
T 856         exec('touch /var/log/ispconfig/cron.log');
9e2319 857         exec('chmod 666 /var/log/ispconfig/cron.log');
0711af 858     }
T 859
860 }
861
862 ?>