tbrehm
2009-09-03 5421462b39a5b41014569af59d3861b9ffe8a44f
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}', 
542146 164                    '  flags=DRhu user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}',
0711af 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}', 
542146 169                    '  flags=DRhu user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}',
2c8f94 170                      $content);
51c815 171                      
F 172         $content = str_replace('  flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}', 
542146 173                    '  flags=DRhu user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}',
51c815 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);
8c4aa3 412             replaceLine('/etc/suphp.conf','umask=0077','umask=0022',0);
bde98e 413         }
T 414         
0711af 415         //* Create the logging directory for the vhost logfiles
T 416         exec('mkdir -p /var/log/ispconfig/httpd');
417         
418         // Sites enabled and avaulable dirs
419         exec('mkdir -p '.$conf['apache']['vhost_conf_enabled_dir']);
420         exec('mkdir -p '.$conf['apache']['vhost_conf_dir']);
421         
422         $content = rf('/etc/httpd/conf/httpd.conf');
423         if(!stristr($content,'Include /etc/httpd/conf/sites-enabled/')) {
7b28da 424             af('/etc/httpd/conf/httpd.conf',"\nNameVirtualHost *:80\nNameVirtualHost *:443\nInclude /etc/httpd/conf/sites-enabled/\n\n");
0711af 425         }
T 426         unset($content);
427         
9de0c4 428         //* Copy the ISPConfig configuration include
T 429         $vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
430         $vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
431         
86e3bb 432         // copy('tpl/apache_ispconfig.conf.master',$vhost_conf_dir.'/ispconfig.conf');
T 433         $content = rf("tpl/apache_ispconfig.conf.master");
434         $records = $this->db->queryAllRecords("SELECT * FROM server_ip WHERE server_id = ".$conf["server_id"]." AND virtualhost = 'y'");
435         if(count($records) > 0) {
436             foreach($records as $rec) {
437                 $content .= "NameVirtualHost ".$rec["ip_address"].":80\n";
438                 $content .= "NameVirtualHost ".$rec["ip_address"].":443\n";
439             }
440         }
441         $content .= "\n";
442         wf($vhost_conf_dir.'/ispconfig.conf',$content);
443         
9de0c4 444         if(!@is_link($vhost_conf_enabled_dir."/000-ispconfig.conf")) {
T 445             exec("ln -s ".$vhost_conf_dir."/ispconfig.conf ".$vhost_conf_enabled_dir."/000-ispconfig.conf");
446         }
447         
8c4aa3 448         //* make sure that webalizer finds its config file when it is directly in /etc
T 449         if(@is_file('/etc/webalizer.conf') && !@is_dir('/etc/webalizer')) {
450             exec('mkdir /etc/webalizer');
451             exec('ln -s /etc/webalizer.conf /etc/webalizer/webalizer.conf');
452         }
453         
454         if(is_file('/etc/webalizer/webalizer.conf')) {
455             // Change webalizer mode to incremental
456             replaceLine('/etc/webalizer/webalizer.conf','Incremental     no','Incremental     yes',0,0);
457             replaceLine('/etc/webalizer/webalizer.conf','IncrementalName webalizer.current','IncrementalName webalizer.current',0,0);
458             replaceLine('/etc/webalizer/webalizer.conf','HistoryName     webalizer.hist','HistoryName     webalizer.hist',0,0);
459         }
460         
461         //* add a sshusers group
462         $command = 'groupadd sshusers';
463         if(!is_group('sshusers')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
464         
0711af 465     }
T 466     
467     public function configure_firewall()
468     {
469         global $conf;
470         
471         $dist_init_scripts = $conf['init_scripts'];
472           
473         if(is_dir("/etc/Bastille.backup")) caselog("rm -rf /etc/Bastille.backup", __FILE__, __LINE__);
474         if(is_dir("/etc/Bastille")) caselog("mv -f /etc/Bastille /etc/Bastille.backup", __FILE__, __LINE__);
475           @mkdir("/etc/Bastille", octdec($directory_mode));
476           if(is_dir("/etc/Bastille.backup/firewall.d")) caselog("cp -pfr /etc/Bastille.backup/firewall.d /etc/Bastille/", __FILE__, __LINE__);
477           caselog("cp -f tpl/bastille-firewall.cfg.master /etc/Bastille/bastille-firewall.cfg", __FILE__, __LINE__);
478           caselog("chmod 644 /etc/Bastille/bastille-firewall.cfg", __FILE__, __LINE__);
479           $content = rf("/etc/Bastille/bastille-firewall.cfg");
480           $content = str_replace("{DNS_SERVERS}", "", $content);
481
482           $tcp_public_services = '';
483           $udp_public_services = '';
484         
485         $row = $this->db->queryOneRecord("SELECT * FROM firewall WHERE server_id = ".intval($conf['server_id']));
486         
487           if(trim($row["tcp_port"]) != '' || trim($row["udp_port"]) != ''){
488             $tcp_public_services = trim(str_replace(',',' ',$row["tcp_port"]));
489             $udp_public_services = trim(str_replace(',',' ',$row["udp_port"]));
490           } else {
8d0600 491             $tcp_public_services = '21 22 25 53 80 110 443 3306 8080 10000';
0711af 492             $udp_public_services = '53';
T 493           }
9ce725 494         if(!stristr($tcp_public_services, $conf['apache']['vhost_port'])) {
96cc31 495             $tcp_public_services .= ' '.intval($conf['apache']['vhost_port']);
57299d 496             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 497         }
T 498         
0711af 499           $content = str_replace("{TCP_PUBLIC_SERVICES}", $tcp_public_services, $content);
T 500           $content = str_replace("{UDP_PUBLIC_SERVICES}", $udp_public_services, $content);
501
502           wf("/etc/Bastille/bastille-firewall.cfg", $content);
503
504           if(is_file($dist_init_scripts."/bastille-firewall")) caselog("mv -f $dist_init_scripts/bastille-firewall $dist_init_scripts/bastille-firewall.backup", __FILE__, __LINE__);
505           caselog("cp -f apps/bastille-firewall $dist_init_scripts", __FILE__, __LINE__);
506           caselog("chmod 700 $dist_init_scripts/bastille-firewall", __FILE__, __LINE__);
507
508           if(is_file("/sbin/bastille-ipchains")) caselog("mv -f /sbin/bastille-ipchains /sbin/bastille-ipchains.backup", __FILE__, __LINE__);
509           caselog("cp -f apps/bastille-ipchains /sbin", __FILE__, __LINE__);
510           caselog("chmod 700 /sbin/bastille-ipchains", __FILE__, __LINE__);
511
512           if(is_file("/sbin/bastille-netfilter")) caselog("mv -f /sbin/bastille-netfilter /sbin/bastille-netfilter.backup", __FILE__, __LINE__);
513           caselog("cp -f apps/bastille-netfilter /sbin", __FILE__, __LINE__);
514           caselog("chmod 700 /sbin/bastille-netfilter", __FILE__, __LINE__);
515         
516         if(!@is_dir('/var/lock/subsys')) caselog("mkdir /var/lock/subsys", __FILE__, __LINE__);
517
518           exec("which ipchains &> /dev/null", $ipchains_location, $ret_val);
519           if(!is_file("/sbin/ipchains") && !is_link("/sbin/ipchains") && $ret_val == 0) phpcaselog(@symlink(shell_exec("which ipchains"), "/sbin/ipchains"), 'create symlink', __FILE__, __LINE__);
520           unset($ipchains_location);
521           exec("which iptables &> /dev/null", $iptables_location, $ret_val);
522           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__);
523           unset($iptables_location);
524
525     }
526     
527     
528     public function install_ispconfig()
529     {
530         global $conf;
531         
532         $install_dir = $conf['ispconfig_install_dir'];
533
534         //* Create the ISPConfig installation directory
535         if(!@is_dir("$install_dir")) {
536             $command = "mkdir $install_dir";
537             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
538         }
539         
540         //* Create a ISPConfig user and group
541         $command = 'groupadd ispconfig';
392450 542         if(!is_group('ispconfig')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
0711af 543         
T 544         $command = "useradd -g ispconfig -d $install_dir ispconfig";
392450 545         if(!is_user('ispconfig')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
0711af 546         
T 547         //* copy the ISPConfig interface part
548         $command = "cp -rf ../interface $install_dir";
549         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
550         
551         //* copy the ISPConfig server part
552         $command = "cp -rf ../server $install_dir";
553         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
554         
555         //* Create a symlink, so ISPConfig is accessible via web
556         // Replaced by a separate vhost definition for port 8080
557         // $command = "ln -s $install_dir/interface/web/ /var/www/ispconfig";
558         // caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
559         
560         //* Create the config file for ISPConfig interface
561         $configfile = 'config.inc.php';
562         if(is_file($install_dir.'/interface/lib/'.$configfile)){
563             copy("$install_dir/interface/lib/$configfile", "$install_dir/interface/lib/$configfile~");
564         }
565         $content = rf("tpl/$configfile.master");
566         $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
567         $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
568         $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
569         $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
12e3ba 570         
T 571         $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
572         $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
573         $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
574         $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
575         
0182ca 576         $content = str_replace('{server_id}', $conf['server_id'], $content);
0711af 577         $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
24854c 578         $content = str_replace('{language}', $conf['language'], $content);
T 579         
0711af 580         wf("$install_dir/interface/lib/$configfile", $content);
T 581         
582         //* Create the config file for ISPConfig server
583         $configfile = 'config.inc.php';
584         if(is_file($install_dir.'/server/lib/'.$configfile)){
585             copy("$install_dir/server/lib/$configfile", "$install_dir/interface/lib/$configfile~");
586         }
587         $content = rf("tpl/$configfile.master");
588         $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
589         $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
590         $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
591         $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
12e3ba 592         
T 593         $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
594         $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
595         $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
596         $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
597         
0711af 598         $content = str_replace('{server_id}', $conf['server_id'], $content);
T 599         $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
d1348b 600         $content = str_replace('{language}', $conf['language'], $content);
T 601         
0711af 602         wf("$install_dir/server/lib/$configfile", $content);
T 603         
604         
605         //* Enable the server modules and plugins.
606         // TODO: Implement a selector which modules and plugins shall be enabled.
607         $dir = $install_dir.'/server/mods-available/';
608         if (is_dir($dir)) {
609             if ($dh = opendir($dir)) {
610                 while (($file = readdir($dh)) !== false) {
392450 611                     if($file != '.' && $file != '..' && substr($file,-8,8) == '.inc.php') {
T 612                         include_once($install_dir.'/server/mods-available/'.$file);
613                         $module_name = substr($file,0,-8);
614                         $tmp = new $module_name;
615                         if($tmp->onInstall()) {
616                             if(!@is_link($install_dir.'/server/mods-enabled/'.$file)) @symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-enabled/'.$file);
617                             if (strpos($file, '_core_module') !== false) {
618                                 if(!@is_link($install_dir.'/server/mods-core/'.$file)) @symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-core/'.$file);
619                             }
0d0cd9 620                         }
392450 621                         unset($tmp);
0711af 622                     }
T 623                 }
624                 closedir($dh);
625             }
626         }
627         
628         $dir = $install_dir.'/server/plugins-available/';
629         if (is_dir($dir)) {
630             if ($dh = opendir($dir)) {
631                 while (($file = readdir($dh)) !== false) {
392450 632                     if($file != '.' && $file != '..' && substr($file,-8,8) == '.inc.php') {
T 633                         include_once($install_dir.'/server/plugins-available/'.$file);
634                         $plugin_name = substr($file,0,-8);
635                         $tmp = new $plugin_name;
636                         if($tmp->onInstall()) {
637                             if(!@is_link($install_dir.'/server/plugins-enabled/'.$file)) @symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-enabled/'.$file);
638                             if (strpos($file, '_core_plugin') !== false) {
639                                 if(!@is_link($install_dir.'/server/plugins-core/'.$file)) @symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-core/'.$file);
640                             }
0d0cd9 641                         }
392450 642                         unset($tmp);
0711af 643                     }
T 644                 }
645                 closedir($dh);
646             }
647         }
648         
392450 649         // Update the server config
T 650         $mail_server_enabled = ($conf['services']['mail'])?1:0;
651         $web_server_enabled = ($conf['services']['web'])?1:0;
652         $dns_server_enabled = ($conf['services']['dns'])?1:0;
653         $file_server_enabled = ($conf['services']['file'])?1:0;
654         $db_server_enabled = ($conf['services']['db'])?1:0;
655         $vserver_server_enabled = ($conf['services']['vserver'])?1:0;
656         $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']);
657         
658         if($conf['mysql']['master_slave_setup'] == 'y') {
659             $this->dbmaster->query($sql);
f66929 660             $this->db->query($sql);
392450 661         } else {
T 662             $this->db->query($sql);
663         }
664         
0711af 665         //* Chmod the files
T 666         $command = "chmod -R 750 $install_dir";
667         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
668
669         //* chown the files to the ispconfig user and group
670         $command = "chown -R ispconfig:ispconfig $install_dir";
671         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
672         
673         //* Make the global language file directory group writable
674         exec("chmod -R 770 $install_dir/interface/lib/lang");
675         
676         //* Make the temp directory for language file exports writable
677         exec("chmod -R 770 $install_dir/interface/web/temp");
678         
679         //* Make all interface language file directories group writable
680         $handle = @opendir($install_dir.'/interface/web');
681         while ($file = @readdir ($handle)) { 
682                if ($file != '.' && $file != '..') {
683                 if(@is_dir($install_dir.'/interface/web'.'/'.$file.'/lib/lang')) {
684                     $handle2 = opendir($install_dir.'/interface/web'.'/'.$file.'/lib/lang');
685                     chmod($install_dir.'/interface/web'.'/'.$file.'/lib/lang',0770);
686                     while ($lang_file = @readdir ($handle2)) {
687                         if ($lang_file != '.' && $lang_file != '..') {
688                             chmod($install_dir.'/interface/web'.'/'.$file.'/lib/lang/'.$lang_file,0770);
689                         }
690                     }
691                 }
692             }
693         }
694         
695         //* make sure that the server config file (not the interface one) is only readable by the root user
696         exec("chmod 600 $install_dir/server/lib/$configfile");
697         exec("chown root:root $install_dir/server/lib/$configfile");
698         if(@is_file("$install_dir/server/lib/mysql_clientdb.conf")) {
699             exec("chmod 600 $install_dir/server/lib/mysql_clientdb.conf");
700             exec("chown root:root $install_dir/server/lib/mysql_clientdb.conf");
701         }
702         
703         // TODO: FIXME: add the www-data user to the ispconfig group. This is just for testing
704         // and must be fixed as this will allow the apache user to read the ispconfig files.
705         // Later this must run as own apache server or via suexec!
706         $command = 'usermod -a -G ispconfig '.$conf['apache']['user'];
707         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
708         
709         //* Make the shell scripts executable
710         $command = "chmod +x $install_dir/server/scripts/*.sh";
711         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
712         
713         //* Copy the ISPConfig vhost for the controlpanel
714         // TODO: These are missing! should they be "vhost_dist_*_dir" ?
715         $vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
716         $vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
717         
718         
719         // Dont just copy over the virtualhost template but add some custom settings
720         $content = rf("tpl/apache_ispconfig.vhost.master");
721         $content = str_replace('{vhost_port}', $conf['apache']['vhost_port'], $content);
f6d745 722         
T 723         // comment out the listen directive if port is 80 or 443
724         if($conf['apache']['vhost_port'] == 80 or $conf['apache']['vhost_port'] == 443) {
725             $content = str_replace('{vhost_port_listen}', '#', $content);
726         } else {
727             $content = str_replace('{vhost_port_listen}', '', $content);
728         }
729         
0711af 730         wf("$vhost_conf_dir/ispconfig.vhost", $content);
T 731         
732         //copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost");
733         //* and create the symlink
4f68a7 734         if($this->install_ispconfig_interface == true && $this->is_update == false) {
0c78af 735             if(@is_link("$vhost_conf_enabled_dir/ispconfig.vhost")) unlink("$vhost_conf_enabled_dir/ispconfig.vhost");
T 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");
0711af 738             }
76f197 739             
T 740             exec('mkdir -p /var/www/php-fcgi-scripts/ispconfig');
741             exec('cp tpl/apache_ispconfig_fcgi_starter.master /var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter');
742             exec('chmod +x /var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter');
743             exec('ln -s /usr/local/ispconfig/interface/web /var/www/ispconfig');
744             exec('chown -R ispconfig:ispconfig /var/www/php-fcgi-scripts/ispconfig');
745             
0f76eb 746             replaceLine('/var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter','PHPRC=','PHPRC=/etc/',0,0);
T 747             
76f197 748         }
T 749         
750         //copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost");
751         //* and create the symlink
752         if($this->install_ispconfig_interface == true && $this->is_update == false) {
753             if(@is_link("$vhost_conf_enabled_dir/ispconfig.vhost")) unlink("$vhost_conf_enabled_dir/ispconfig.vhost");
754             if(!@is_link("$vhost_conf_enabled_dir/000-ispconfig.vhost")) {
755                 exec("ln -s $vhost_conf_dir/ispconfig.vhost $vhost_conf_enabled_dir/000-ispconfig.vhost");
756             }
0711af 757         }
T 758         
759         // Make the Clamav log files readable by ISPConfig
760         //exec('chmod +r /var/log/clamav/clamav.log');
761         //exec('chmod +r /var/log/clamav/freshclam.log');
762         
66768a 763         //* Install the update script
T 764         if(is_file('/usr/local/bin/ispconfig_update_from_svn.sh')) unlink('/usr/local/bin/ispconfig_update_from_svn.sh');
765         exec('chown root /usr/local/ispconfig/server/scripts/update_from_svn.sh');
766         exec('chmod 700 /usr/local/ispconfig/server/scripts/update_from_svn.sh');
767         exec('chown root /usr/local/ispconfig/server/scripts/update_from_tgz.sh');
768         exec('chmod 700 /usr/local/ispconfig/server/scripts/update_from_tgz.sh');
769         exec('chown root /usr/local/ispconfig/server/scripts/ispconfig_update.sh');
770         exec('chmod 700 /usr/local/ispconfig/server/scripts/ispconfig_update.sh');
608a8c 771         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 772         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 773         
76f197 774         // set the fast cgi starter script to executable
T 775         // exec('chmod 755 '.$install_dir.'/interface/bin/php-fcgi');
0711af 776         
T 777         //* Make the logs readable for the ispconfig user
778         if(@is_file('/var/log/maillog')) exec('chmod +r /var/log/maillog');
779         //if(@is_file('/var/log/mail.warn')) exec('chmod +r /var/log/mail.warn');
780         //if(@is_file('/var/log/mail.err')) exec('chmod +r /var/log/mail.err');
781         if(@is_file('/var/log/messages')) exec('chmod +r /var/log/messages');
782         
783         //To enable apache to read the directories
784         // exec('chmod a+rx /usr/local/ispconfig');
785         // exec('chmod -R 751 /usr/local/ispconfig/interface');
786         // exec('chmod a+rx /usr/local/ispconfig/interface/web');
787         
d9c8a7 788         //* Create the ispconfig log directory
T 789         if(!is_dir('/var/log/ispconfig')) mkdir('/var/log/ispconfig');
77d8a9 790         if(!is_file('/var/log/ispconfig/ispconfig.log')) exec('touch /var/log/ispconfig/ispconfig.log');
d9c8a7 791         
fee7a4 792         exec('mv /usr/local/ispconfig/server/scripts/run-getmail.sh /usr/local/bin/run-getmail.sh');
T 793         exec('chown getmail /usr/local/bin/run-getmail.sh');
794         exec('chmod 744 /usr/local/bin/run-getmail.sh');
27c3a6 795         
0711af 796         
T 797     }
798     
799     public function configure_dbserver()
800     {
801         global $conf;
802         
803         //* If this server shall act as database server for client DB's, we configure this here
804         $install_dir = $conf['ispconfig_install_dir'];
805         
806         // Create a file with the database login details which 
807         // are used to create the client databases.
808         
809         if(!is_dir("$install_dir/server/lib")) {
810             $command = "mkdir $install_dir/server/lib";
811             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
812         }
813         
814         $content = rf("tpl/mysql_clientdb.conf.master");
815         $content = str_replace('{username}',$conf['mysql']['admin_user'],$content);
816         $content = str_replace('{password}',$conf['mysql']['admin_password'], $content);
817         wf("$install_dir/server/lib/mysql_clientdb.conf",$content);
818         exec('chmod 600 '."$install_dir/server/lib/mysql_clientdb.conf");
819         exec('chown root:root '."$install_dir/server/lib/mysql_clientdb.conf");
820         
821     }
822     
823     public function install_crontab()
824     {        
825         global $conf;
826         
827         //* Root Crontab
828         exec('crontab -u root -l > crontab.txt');
829         $existing_root_cron_jobs = file('crontab.txt');
830         
a8a328 831         // remove existing ispconfig cronjobs, in case the syntax has changed
T 832         foreach($existing_root_cron_jobs as $key => $val) {
833             if(stristr($val,'/usr/local/ispconfig')) unset($existing_root_cron_jobs[$key]);
834         }
835         
0711af 836         $root_cron_jobs = array(
T 837             '* * * * * /usr/local/ispconfig/server/server.sh &> /dev/null',
838             '30 00 * * * /usr/local/ispconfig/server/cron_daily.sh &> /dev/null'
839         );
840         foreach($root_cron_jobs as $cron_job) {
841             if(!in_array($cron_job."\n", $existing_root_cron_jobs)) {
842                 $existing_root_cron_jobs[] = $cron_job."\n";
843             }
844         }
845         file_put_contents('crontab.txt', $existing_root_cron_jobs);
846         exec('crontab -u root crontab.txt &> /dev/null');
847         unlink('crontab.txt');
848         
849         //* Getmail crontab
a8a328 850         if(is_user('getmail')) {
T 851             $cf = $conf['getmail'];
852             exec('crontab -u getmail -l > crontab.txt');
853             $existing_cron_jobs = file('crontab.txt');
0711af 854         
27c3a6 855             $cron_jobs = array(
fee7a4 856                 '*/5 * * * * /usr/local/bin/run-getmail.sh > /dev/null 2>> /var/log/ispconfig/cron.log'
27c3a6 857             );
T 858         
a8a328 859             // remove existing ispconfig cronjobs, in case the syntax has changed
9b30b0 860             foreach($existing_cron_jobs as $key => $val) {
27c3a6 861                 if(stristr($val,'getmail')) unset($existing_cron_jobs[$key]);
0711af 862             }
1f93c0 863         
a8a328 864             foreach($cron_jobs as $cron_job) {
T 865                 if(!in_array($cron_job."\n", $existing_cron_jobs)) {
866                     $existing_cron_jobs[] = $cron_job."\n";
867                 }
868             }
869             file_put_contents('crontab.txt', $existing_cron_jobs);
870             exec('crontab -u getmail crontab.txt &> /dev/null');
871             unlink('crontab.txt');
0711af 872         }
00d730 873         
T 874         exec('touch /var/log/ispconfig/cron.log');
9e2319 875         exec('chmod 666 /var/log/ispconfig/cron.log');
0711af 876     }
T 877
878 }
879
880 ?>