tbrehm
2009-09-03 5421462b39a5b41014569af59d3861b9ffe8a44f
commit | author | age
24854c 1 <?php
T 2
3 /*
4 Copyright (c) 2007, Till Brehm, projektfarm Gmbh
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9
10     * Redistributions of source code must retain the above copyright notice,
11       this list of conditions and the following disclaimer.
12     * Redistributions in binary form must reproduce the above copyright notice,
13       this list of conditions and the following disclaimer in the documentation
14       and/or other materials provided with the distribution.
15     * Neither the name of ISPConfig nor the names of its contributors
16       may be used to endorse or promote products derived from this software without
17       specific prior written permission.
18
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 class installer_dist extends installer_base {
32     
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'];
78         if(!is_group($cf['vmail_groupname'])) caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
79
80         $command = 'useradd -g '.$cf['vmail_groupname'].' -u '.$cf['vmail_userid'].' '.$cf['vmail_username'].' -d '.$cf['vmail_mailbox_base'].' -m';
81         if(!is_user($cf['vmail_username'])) caselog("$command &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");        
82
83         $postconf_commands = array (
84             'myhostname = '.$conf['hostname'],
85             'mydestination = '.$conf['hostname'].', localhost, localhost.localdomain',
86             'mynetworks = 127.0.0.0/8 [::1]/128',
87             'virtual_alias_domains =',
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',
96             'smtpd_sasl_authenticated_header = yes',
97             'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, check_recipient_access mysql:'.$config_dir.'/mysql-virtual_recipient.cf, reject_unauth_destination',
98             'smtpd_use_tls = yes',
99             'smtpd_tls_security_level = may',
100             'smtpd_tls_cert_file = '.$config_dir.'/smtpd.cert',
101             'smtpd_tls_key_file = '.$config_dir.'/smtpd.key',
102             'transport_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_transports.cf',
103             'relay_domains = mysql:'.$config_dir.'/mysql-virtual_relaydomains.cf',
104             'virtual_create_maildirsize = yes',
105             'virtual_maildir_extended = yes',
106             'virtual_mailbox_limit_maps = proxy:mysql:'.$config_dir.'/mysql-virtual_mailbox_limit_maps.cf',
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
141             $command = 'cd '.$config_dir.'; '
142                       .'openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509';
143             exec($command);
144         
145             $command = 'chmod o= '.$config_dir.'/smtpd.key';
146             caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
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/run/authdaemon.courier-imap';
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);
162         
163         $content = str_replace('  flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}', 
542146 164                    '  flags=DRhu user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}',
24854c 165                      $content);
T 166         
167         $content = str_replace('  flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}', 
542146 168                    '  flags=DRhu user='.$cf['vmail_username'].' argv=/usr/bin/maildrop -d ${recipient} ${extension} ${recipient} ${user} ${nexthop} ${sender}',
24854c 169                      $content);
T 170         
171         wf($configfile, $content);
172         
173         //* Writing the Maildrop mailfilter file
174         $configfile = 'mailfilter';
175         if(is_file($cf['vmail_mailbox_base'].'/.'.$configfile)){
176             copy($cf['vmail_mailbox_base'].'/.'.$configfile, $cf['vmail_mailbox_base'].'/.'.$configfile.'~');
177         }
178         $content = rf("tpl/$configfile.master");
179         $content = str_replace('{dist_postfix_vmail_mailbox_base}', $cf['vmail_mailbox_base'], $content);
180         wf($cf['vmail_mailbox_base'].'/.'.$configfile, $content);
181         
182         //* Create the directory for the custom mailfilters
183         $command = 'mkdir '.$cf['vmail_mailbox_base'].'/mailfilters';
184         caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
185         
186         //* Chmod and chown the .mailfilter file
187         $command = 'chown -R '.$cf['vmail_username'].':'.$cf['vmail_groupname'].' '.$cf['vmail_mailbox_base'].'/.mailfilter';
188         caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
189         
190         $command = 'chmod -R 600 '.$cf['vmail_mailbox_base'].'/.mailfilter';
191         caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
192         
193     }
194     
195     public function configure_saslauthd() {
196         global $conf;
197         
198         /*
199         $configfile = 'sasl_smtpd.conf';
200         if(is_file('/etc/sasl2/smtpd.conf')) copy('/etc/sasl2/smtpd.conf','/etc/sasl2/smtpd.conf~');
201         if(is_file('/etc/sasl2/smtpd.conf~')) exec('chmod 400 '.'/etc/sasl2/smtpd.conf~');
202         $content = rf("tpl/".$configfile.".master");
203         $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
204         $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
205         $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
206         $content = str_replace('{mysql_server_ip}',$conf['mysql']['ip'],$content);
207         wf('/etc/sasl2/smtpd.conf',$content);
208         */
209         
210         // TODO: Chmod and chown on the config file
211         
212         
213         /*
214         // Create the spool directory
215         exec('mkdir -p /var/spool/postfix/var/run/saslauthd');
216         
217         // Edit the file /etc/default/saslauthd
218         $configfile = $conf["saslauthd"]["config"];
219         if(is_file($configfile)) copy($configfile,$configfile.'~');
220         if(is_file($configfile.'~')) exec('chmod 400 '.$configfile.'~');
221         $content = rf($configfile);
222         $content = str_replace('START=no','START=yes',$content);
223         $content = str_replace('OPTIONS="-c"','OPTIONS="-m /var/spool/postfix/var/run/saslauthd -r"',$content);
224         wf($configfile,$content);
225         */
226         
227         // Edit the file /etc/init.d/saslauthd
228         $configfile = $conf["init_scripts"].'/'.$conf["saslauthd"]["init_script"];
229         $content = rf($configfile);
230         $content = str_replace('/sbin/startproc $AUTHD_BIN -a $SASLAUTHD_AUTHMECH -n $SASLAUTHD_THREADS > /dev/null 2>&1','/sbin/startproc $AUTHD_BIN -r -a $SASLAUTHD_AUTHMECH -n $SASLAUTHD_THREADS > /dev/null 2>&1',$content);
231         $content = str_replace('/sbin/startproc $AUTHD_BIN $SASLAUTHD_PARAMS -a $SASLAUTHD_AUTHMECH -n $SASLAUTHD_THREADS > /dev/null 2>&1','/sbin/startproc $AUTHD_BIN $SASLAUTHD_PARAMS -r -a $SASLAUTHD_AUTHMECH -n $SASLAUTHD_THREADS > /dev/null 2>&1',$content);
232         
233         
234         wf($configfile,$content);
235         
236         
237         
238     }
239     
240     public function configure_pam()
241     {
242         global $conf;
243         $pam = $conf['pam'];
244         //* configure pam for SMTP authentication agains the ispconfig database
245         $configfile = 'pamd_smtp';
246         if(is_file("$pam/smtp"))    copy("$pam/smtp", "$pam/smtp~");
247         if(is_file("$pam/smtp~"))   exec("chmod 400 $pam/smtp~");
248
249         $content = rf("tpl/$configfile.master");
250         $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
251         $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
252         $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
253         $content = str_replace('{mysql_server_ip}', $conf['mysql']['ip'], $content);
254         wf("$pam/smtp", $content);
255         //exec("chmod 660 $pam/smtp");
256         //exec("chown root:root $pam/smtp");
257     
258     }
259     
260     public function configure_courier()
261     {
262         global $conf;
263         $config_dir = $conf['courier']['config_dir'];
264         //* authmysqlrc
265         $configfile = 'authmysqlrc';
266         if(is_file("$config_dir/$configfile")){
267             copy("$config_dir/$configfile", "$config_dir/$configfile~");
268         }
269         exec("chmod 400 $config_dir/$configfile~");
270         $content = rf("tpl/$configfile.master");
271         $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
272         $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
273         $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
274         $content = str_replace('{mysql_server_host}',$conf['mysql']['host'],$content);
275         wf("$config_dir/$configfile", $content);
276         
277         exec("chmod 660 $config_dir/$configfile");
278         exec("chown root:root $config_dir/$configfile");
279         
280         //* authdaemonrc
281         $configfile = $conf['courier']['config_dir'].'/authdaemonrc';
282         if(is_file($configfile)){
283             copy($configfile, $configfile.'~');
284         }
285         if(is_file($configfile.'~')){
286             exec('chmod 400 '.$configfile.'~');
287         }
288         $content = rf($configfile);
289         $content = str_replace('authmodulelist=', 'authmodulelist="authmysql"', $content);
290         wf($configfile, $content);
291     }
292     
293     public function configure_amavis() {
294         global $conf;
295         
296         // amavisd user config file
297         $configfile = 'opensuse_amavisd_conf';
298         if(is_file($conf["amavis"]["config_dir"].'/amavisd.conf')) copy($conf["amavis"]["config_dir"].'/amavisd.conf',$conf["courier"]["config_dir"].'/amavisd.conf~');
299         if(is_file($conf["amavis"]["config_dir"].'/amavisd.conf~')) exec('chmod 400 '.$conf["amavis"]["config_dir"].'/amavisd.conf~');
300         $content = rf("tpl/".$configfile.".master");
301         $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
302         $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
303         $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
304         $content = str_replace('{mysql_server_port}',$conf["mysql"]["port"],$content);
305         $content = str_replace('{mysql_server_ip}',$conf['mysql']['ip'],$content);
306         wf($conf["amavis"]["config_dir"].'/amavisd.conf',$content);
307         
308         
309         // Adding the amavisd commands to the postfix configuration
310         $postconf_commands = array (
311             'content_filter = amavis:[127.0.0.1]:10024',
312             'receive_override_options = no_address_mappings'
313         );
314         
315         // Make a backup copy of the main.cf file
316         copy($conf["postfix"]["config_dir"].'/main.cf',$conf["postfix"]["config_dir"].'/main.cf~2');
317         
318         // Executing the postconf commands
319         foreach($postconf_commands as $cmd) {
320             $command = "postconf -e '$cmd'";
321             caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
322         }
323         
324         // Append the configuration for amavisd to the master.cf file
325         if(is_file($conf["postfix"]["config_dir"].'/master.cf')) copy($conf["postfix"]["config_dir"].'/master.cf',$conf["postfix"]["config_dir"].'/master.cf~');
326         $content = rf($conf["postfix"]["config_dir"].'/master.cf');
327         // Only add the content if we had not addded it before
328         if(!stristr($content,"127.0.0.1:10025")) {
329             unset($content);
330             $content = rf("tpl/master_cf_amavis.master");
331             af($conf["postfix"]["config_dir"].'/master.cf',$content);
332         }
333         unset($content);
334         
335         // Add the clamav user to the vscan group
336         exec('groupmod --add-user clamav vscan');
337         
338         
339     }
340     
341     public function configure_spamassassin()
342     {
343         global $conf;
344         
345         //* Enable spamasasssin on debian and ubuntu
346         /*
347         $configfile = '/etc/default/spamassassin';
348         if(is_file($configfile)){
349             copy($configfile, $configfile.'~');
350         }
351         $content = rf($configfile);
352         $content = str_replace('ENABLED=0', 'ENABLED=1', $content);
353         wf($configfile, $content);
354         */
355     }
356     
357     public function configure_getmail()
358     {
359         global $conf;
360         
361         $config_dir = $conf['getmail']['config_dir'];
362         
363         if(!is_dir($config_dir)) exec("mkdir -p ".escapeshellcmd($config_dir));
364
365         $command = "useradd -d $config_dir getmail";
366         if(!is_user('getmail')) caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
367         
368         $command = "chown -R getmail $config_dir";
369         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
370         
371         $command = "chmod -R 700 $config_dir";
372         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
373     }
374     
375     
376     public function configure_pureftpd()
377     {
378         global $conf;
379         
380         $config_dir = $conf['pureftpd']['config_dir'];
381
382         //* configure pam for SMTP authentication agains the ispconfig database
383         $configfile = 'db/mysql.conf';
384         if(is_file("$config_dir/$configfile")){
385             copy("$config_dir/$configfile", "$config_dir/$configfile~");
386         }
387         if(is_file("$config_dir/$configfile~")){
388             exec("chmod 400 $config_dir/$configfile~");
389         }
390         $content = rf('tpl/pureftpd_mysql.conf.master');
391         $content = str_replace('{mysql_server_ispconfig_user}', $conf["mysql"]["ispconfig_user"], $content);
392         $content = str_replace('{mysql_server_ispconfig_password}', $conf["mysql"]["ispconfig_password"], $content);
393         $content = str_replace('{mysql_server_database}', $conf["mysql"]["database"], $content);
394         $content = str_replace('{mysql_server_ip}', $conf["mysql"]["ip"], $content);
395         $content = str_replace('{server_id}', $conf["server_id"], $content);
396         wf("$config_dir/$configfile", $content);
397         exec("chmod 600 $config_dir/$configfile");
398         exec("chown root:root $config_dir/$configfile");
399         
400         // copy our customized copy of pureftpd.conf to the pure-ftpd config directory
401         exec("cp tpl/opensuse_pureftpd_conf.master $config_dir/pure-ftpd.conf");
402         
403     }
404     
405     public function configure_mydns()
406     {
407         global $conf;
408         
409         // configure pam for SMTP authentication agains the ispconfig database
410         $configfile = 'mydns.conf';
411         if(is_file($conf["mydns"]["config_dir"].'/'.$configfile)) copy($conf["mydns"]["config_dir"].'/'.$configfile,$conf["mydns"]["config_dir"].'/'.$configfile.'~');
412         if(is_file($conf["mydns"]["config_dir"].'/'.$configfile.'~')) exec('chmod 400 '.$conf["mydns"]["config_dir"].'/'.$configfile.'~');
413         $content = rf("tpl/".$configfile.".master");
414         $content = str_replace('{mysql_server_ispconfig_user}',$conf['mysql']['ispconfig_user'],$content);
415         $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
416         $content = str_replace('{mysql_server_database}',$conf['mysql']['database'],$content);
417         $content = str_replace('{mysql_server_host}',$conf["mysql"]["host"],$content);
418         $content = str_replace('{server_id}',$conf["server_id"],$content);
419         wf($conf["mydns"]["config_dir"].'/'.$configfile,$content);
420         exec('chmod 600 '.$conf["mydns"]["config_dir"].'/'.$configfile);
421         exec('chown root:root '.$conf["mydns"]["config_dir"].'/'.$configfile);
422     
423     }
424     
425     public function configure_apache()
426     {    
427         global $conf;
428         
429         //* Create the logging directory for the vhost logfiles
430         exec('mkdir -p /var/log/ispconfig/httpd');
431         
432         //if(is_file('/etc/suphp.conf')) {
433         replaceLine('/etc/suphp.conf','php=php','x-httpd-suphp=php:/srv/www/cgi-bin/php5',0,0);
434         replaceLine('/etc/suphp.conf','docroot=','docroot=/srv/www',0,0);
8c4aa3 435         replaceLine('/etc/suphp.conf','umask=0077','umask=0022',0);
24854c 436         //}
T 437         
438         // Sites enabled and avaulable dirs
439         exec('mkdir -p '.$conf['apache']['vhost_conf_enabled_dir']);
440         exec('mkdir -p '.$conf['apache']['vhost_conf_dir']);
441         
442         $content = rf('/etc/apache2/httpd.conf');
443         if(!stristr($content,'Include /etc/apache2/sites-enabled/')) {
444             af('/etc/apache2/httpd.conf',"\n<Directory /srv/www>\n    Options FollowSymlinks\n</Directory>\n\nInclude /etc/apache2/sites-enabled/\n\n");
445         }
446         unset($content);
447         
448         //* Copy the ISPConfig configuration include
449         $vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
450         $vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
451         
452         //copy('tpl/apache_ispconfig.conf.master',$vhost_conf_dir.'/ispconfig.conf');
453         $content = rf("tpl/apache_ispconfig.conf.master");
454         $records = $this->db->queryAllRecords("SELECT * FROM server_ip WHERE server_id = ".$conf["server_id"]." AND virtualhost = 'y'");
455         if(count($records) > 0) {
456             foreach($records as $rec) {
457                 $content .= "NameVirtualHost ".$rec["ip_address"].":80\n";
458                 $content .= "NameVirtualHost ".$rec["ip_address"].":443\n";
459             }
460         }
461         $content .= "\n";
462         wf($vhost_conf_dir.'/ispconfig.conf',$content);
463         
464         if(!@is_link($vhost_conf_enabled_dir."/000-ispconfig.conf")) {
465             exec("ln -s ".$vhost_conf_dir."/ispconfig.conf ".$vhost_conf_enabled_dir."/000-ispconfig.conf");
466         }
467         
8c4aa3 468         //* make sure that webalizer finds its config file when it is directly in /etc
T 469         if(@is_file('/etc/webalizer.conf') && !@is_dir('/etc/webalizer')) {
470             exec('mkdir /etc/webalizer');
471             exec('ln -s /etc/webalizer.conf /etc/webalizer/webalizer.conf');
472         }
473         
474         if(is_file('/etc/webalizer/webalizer.conf')) {
475             // Change webalizer mode to incremental
476             replaceLine('/etc/webalizer/webalizer.conf','Incremental     no','Incremental     yes',0,0);
477             replaceLine('/etc/webalizer/webalizer.conf','IncrementalName webalizer.current','IncrementalName webalizer.current',0,0);
478             replaceLine('/etc/webalizer/webalizer.conf','HistoryName     webalizer.hist','HistoryName     webalizer.hist',0,0);
479         }
480         
481         //* add a sshusers group
482         $command = 'groupadd sshusers';
483         if(!is_group('sshusers')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
484         
24854c 485     }
T 486     
487     public function configure_firewall()
488     {
489         global $conf;
490         
491         $dist_init_scripts = $conf['init_scripts'];
492           
493         if(is_dir("/etc/Bastille.backup")) caselog("rm -rf /etc/Bastille.backup", __FILE__, __LINE__);
494         if(is_dir("/etc/Bastille")) caselog("mv -f /etc/Bastille /etc/Bastille.backup", __FILE__, __LINE__);
495           @mkdir("/etc/Bastille", octdec($directory_mode));
496           if(is_dir("/etc/Bastille.backup/firewall.d")) caselog("cp -pfr /etc/Bastille.backup/firewall.d /etc/Bastille/", __FILE__, __LINE__);
497           caselog("cp -f tpl/bastille-firewall.cfg.master /etc/Bastille/bastille-firewall.cfg", __FILE__, __LINE__);
498           caselog("chmod 644 /etc/Bastille/bastille-firewall.cfg", __FILE__, __LINE__);
499           $content = rf("/etc/Bastille/bastille-firewall.cfg");
500           $content = str_replace("{DNS_SERVERS}", "", $content);
501
502           $tcp_public_services = '';
503           $udp_public_services = '';
504         
505         $row = $this->db->queryOneRecord("SELECT * FROM firewall WHERE server_id = ".intval($conf['server_id']));
506         
507           if(trim($row["tcp_port"]) != '' || trim($row["udp_port"]) != ''){
508             $tcp_public_services = trim(str_replace(',',' ',$row["tcp_port"]));
509             $udp_public_services = trim(str_replace(',',' ',$row["udp_port"]));
510           } else {
511             $tcp_public_services = '21 22 25 53 80 110 443 3306 8080 10000';
512             $udp_public_services = '53';
513           }
514         
515         if(!stristr($tcp_public_services, $conf['apache']['vhost_port'])) {
516             $tcp_public_services .= ' '.intval($conf['apache']['vhost_port']);
517             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']));
518         }
519
520           $content = str_replace("{TCP_PUBLIC_SERVICES}", $tcp_public_services, $content);
521           $content = str_replace("{UDP_PUBLIC_SERVICES}", $udp_public_services, $content);
522         
523           wf("/etc/Bastille/bastille-firewall.cfg", $content);
524
525           if(is_file($dist_init_scripts."/bastille-firewall")) caselog("mv -f $dist_init_scripts/bastille-firewall $dist_init_scripts/bastille-firewall.backup", __FILE__, __LINE__);
526           caselog("cp -f apps/bastille-firewall $dist_init_scripts", __FILE__, __LINE__);
527           caselog("chmod 700 $dist_init_scripts/bastille-firewall", __FILE__, __LINE__);
528
529           if(is_file("/sbin/bastille-ipchains")) caselog("mv -f /sbin/bastille-ipchains /sbin/bastille-ipchains.backup", __FILE__, __LINE__);
530           caselog("cp -f apps/bastille-ipchains /sbin", __FILE__, __LINE__);
531           caselog("chmod 700 /sbin/bastille-ipchains", __FILE__, __LINE__);
532
533           if(is_file("/sbin/bastille-netfilter")) caselog("mv -f /sbin/bastille-netfilter /sbin/bastille-netfilter.backup", __FILE__, __LINE__);
534           caselog("cp -f apps/bastille-netfilter /sbin", __FILE__, __LINE__);
535           caselog("chmod 700 /sbin/bastille-netfilter", __FILE__, __LINE__);
536         
537         if(!@is_dir('/var/lock/subsys')) caselog("mkdir /var/lock/subsys", __FILE__, __LINE__);
538
539           exec("which ipchains &> /dev/null", $ipchains_location, $ret_val);
540           if(!is_file("/sbin/ipchains") && !is_link("/sbin/ipchains") && $ret_val == 0) phpcaselog(@symlink(shell_exec("which ipchains"), "/sbin/ipchains"), 'create symlink', __FILE__, __LINE__);
541           unset($ipchains_location);
542           exec("which iptables &> /dev/null", $iptables_location, $ret_val);
543           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__);
544           unset($iptables_location);
545
546     }
547     
548     
549     public function install_ispconfig()
550     {
551         global $conf;
552         
553         $install_dir = $conf['ispconfig_install_dir'];
554
555         //* Create the ISPConfig installation directory
556         if(!@is_dir("$install_dir")) {
557             $command = "mkdir $install_dir";
558             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
559         }
560         
561         //* Create a ISPConfig user and group
562         $command = 'groupadd ispconfig';
563         if(!is_group('ispconfig')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
564         
565         $command = "useradd -g ispconfig -d $install_dir ispconfig";
566         if(!is_user('ispconfig')) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
567         
568         //* copy the ISPConfig interface part
569         $command = "cp -rf ../interface $install_dir";
570         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
571         
572         //* copy the ISPConfig server part
573         $command = "cp -rf ../server $install_dir";
574         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
575         
576         //* Create a symlink, so ISPConfig is accessible via web
577         // Replaced by a separate vhost definition for port 8080
578         // $command = "ln -s $install_dir/interface/web/ /var/www/ispconfig";
579         // caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
580         
581         //* Create the config file for ISPConfig interface
582         $configfile = 'config.inc.php';
583         if(is_file($install_dir.'/interface/lib/'.$configfile)){
584             copy("$install_dir/interface/lib/$configfile", "$install_dir/interface/lib/$configfile~");
585         }
586         $content = rf("tpl/$configfile.master");
587         $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
588         $content = str_replace('{mysql_server_ispconfig_password}',$conf['mysql']['ispconfig_password'], $content);
589         $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
590         $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
591         
592         $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
593         $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
594         $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
595         $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
596         
0182ca 597         $content = str_replace('{server_id}', $conf['server_id'], $content);
24854c 598         $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
T 599         $content = str_replace('{language}', $conf['language'], $content);
600         
601         wf("$install_dir/interface/lib/$configfile", $content);
602         
603         //* Create the config file for ISPConfig server
604         $configfile = 'config.inc.php';
605         if(is_file($install_dir.'/server/lib/'.$configfile)){
606             copy("$install_dir/server/lib/$configfile", "$install_dir/interface/lib/$configfile~");
607         }
608         $content = rf("tpl/$configfile.master");
609         $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
610         $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
611         $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
612         $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
613         
614         $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
615         $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
616         $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
617         $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
618         
619         $content = str_replace('{server_id}', $conf['server_id'], $content);
620         $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
949e7e 621         $content = str_replace('{language}', $conf['language'], $content);
T 622         
24854c 623         wf("$install_dir/server/lib/$configfile", $content);
T 624         
625         
626         //* Enable the server modules and plugins.
627         // TODO: Implement a selector which modules and plugins shall be enabled.
628         $dir = $install_dir.'/server/mods-available/';
629         if (is_dir($dir)) {
630             if ($dh = opendir($dir)) {
631                 while (($file = readdir($dh)) !== false) {
632                     if($file != '.' && $file != '..' && substr($file,-8,8) == '.inc.php') {
633                         include_once($install_dir.'/server/mods-available/'.$file);
634                         $module_name = substr($file,0,-8);
635                         $tmp = new $module_name;
636                         if($tmp->onInstall()) {
637                             if(!@is_link($install_dir.'/server/mods-enabled/'.$file)) @symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-enabled/'.$file);
638                             if (strpos($file, '_core_module') !== false) {
639                                 if(!@is_link($install_dir.'/server/mods-core/'.$file)) @symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-core/'.$file);
640                             }
641                         }
642                         unset($tmp);
643                     }
644                 }
645                 closedir($dh);
646             }
647         }
648         
649         $dir = $install_dir.'/server/plugins-available/';
650         if (is_dir($dir)) {
651             if ($dh = opendir($dir)) {
652                 while (($file = readdir($dh)) !== false) {
653                     if($file != '.' && $file != '..' && substr($file,-8,8) == '.inc.php') {
654                         include_once($install_dir.'/server/plugins-available/'.$file);
655                         $plugin_name = substr($file,0,-8);
656                         $tmp = new $plugin_name;
657                         if($tmp->onInstall()) {
658                             if(!@is_link($install_dir.'/server/plugins-enabled/'.$file)) @symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-enabled/'.$file);
659                             if (strpos($file, '_core_plugin') !== false) {
660                                 if(!@is_link($install_dir.'/server/plugins-core/'.$file)) @symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-core/'.$file);
661                             }
662                         }
663                         unset($tmp);
664                     }
665                 }
666                 closedir($dh);
667             }
668         }
669         
670         // Update the server config
671         $mail_server_enabled = ($conf['services']['mail'])?1:0;
672         $web_server_enabled = ($conf['services']['web'])?1:0;
673         $dns_server_enabled = ($conf['services']['dns'])?1:0;
674         $file_server_enabled = ($conf['services']['file'])?1:0;
675         $db_server_enabled = ($conf['services']['db'])?1:0;
676         $vserver_server_enabled = ($conf['services']['vserver'])?1:0;
677         $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']);
678         
679         if($conf['mysql']['master_slave_setup'] == 'y') {
680             $this->dbmaster->query($sql);
681             $this->db->query($sql);
682         } else {
683             $this->db->query($sql);
684         }
685         
686         //* Chmod the files
687         $command = "chmod -R 750 $install_dir";
688         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
689
690         //* chown the files to the ispconfig user and group
691         $command = "chown -R ispconfig:ispconfig $install_dir";
692         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
693         
694         //* Make the global language file directory group writable
695         exec("chmod -R 770 $install_dir/interface/lib/lang");
696         
697         //* Make the temp directory for language file exports writable
698         exec("chmod -R 770 $install_dir/interface/web/temp");
699         
700         //* Make all interface language file directories group writable
701         $handle = @opendir($install_dir.'/interface/web');
702         while ($file = @readdir ($handle)) { 
703                if ($file != '.' && $file != '..') {
704                 if(@is_dir($install_dir.'/interface/web'.'/'.$file.'/lib/lang')) {
705                     $handle2 = opendir($install_dir.'/interface/web'.'/'.$file.'/lib/lang');
706                     chmod($install_dir.'/interface/web'.'/'.$file.'/lib/lang',0770);
707                     while ($lang_file = @readdir ($handle2)) {
708                         if ($lang_file != '.' && $lang_file != '..') {
709                             chmod($install_dir.'/interface/web'.'/'.$file.'/lib/lang/'.$lang_file,0770);
710                         }
711                     }
712                 }
713             }
714         }
715         
716         //* make sure that the server config file (not the interface one) is only readable by the root user
717         exec("chmod 600 $install_dir/server/lib/$configfile");
718         exec("chown root:root $install_dir/server/lib/$configfile");
719         if(@is_file("$install_dir/server/lib/mysql_clientdb.conf")) {
720             exec("chmod 600 $install_dir/server/lib/mysql_clientdb.conf");
721             exec("chown root:root $install_dir/server/lib/mysql_clientdb.conf");
722         }
723         
724         // TODO: FIXME: add the www-data user to the ispconfig group. This is just for testing
725         // and must be fixed as this will allow the apache user to read the ispconfig files.
726         // Later this must run as own apache server or via suexec!
727         $command = 'groupmod --add-user wwwrun ispconfig';
728         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
729         
730         //* Make the shell scripts executable
731         $command = "chmod +x $install_dir/server/scripts/*.sh";
732         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
733         
734         //* Copy the ISPConfig vhost for the controlpanel
735         // TODO: These are missing! should they be "vhost_dist_*_dir" ?
736         $vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
737         $vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
738         
739         
740         // Dont just copy over the virtualhost template but add some custom settings
741          
742         $content = rf("tpl/apache_ispconfig.vhost.master");
743         $content = str_replace('{vhost_port}', $conf['apache']['vhost_port'], $content);
744         
745         // comment out the listen directive if port is 80 or 443
746         if($conf['apache']['vhost_port'] == 80 or $conf['apache']['vhost_port'] == 443) {
747             $content = str_replace('{vhost_port_listen}', '#', $content);
748         } else {
749             $content = str_replace('{vhost_port_listen}', '', $content);
750         }
751         
752         $content = str_replace('/var/www/', '/srv/www/', $content);
753         
754         wf("$vhost_conf_dir/ispconfig.vhost", $content);
755         
756         if(!is_file('/srv/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter')) {
757             exec('mkdir -p /srv/www/php-fcgi-scripts/ispconfig');
758             exec('cp tpl/apache_ispconfig_fcgi_starter.master /srv/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter');
759             exec('chmod +x /srv/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter');
760             exec('ln -s /usr/local/ispconfig/interface/web /srv/www/ispconfig');
761             exec('chown -R ispconfig:ispconfig /srv/www/php-fcgi-scripts/ispconfig');
762             
763         }
764         
765         //copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost");
766         //* and create the symlink
767         if($this->install_ispconfig_interface == true && $this->is_update == false) {
768             if(@is_link("$vhost_conf_enabled_dir/ispconfig.vhost")) unlink("$vhost_conf_enabled_dir/ispconfig.vhost");
769             if(!@is_link("$vhost_conf_enabled_dir/000-ispconfig.vhost")) {
770                 exec("ln -s $vhost_conf_dir/ispconfig.vhost $vhost_conf_enabled_dir/000-ispconfig.vhost");
771             }
772             
773         }
774         
775         // Fix a setting in vhost master file for suse
776         replaceLine('/usr/local/ispconfig/server/conf/vhost.conf.master',"suPHP_UserGroup","        suPHP_UserGroup <tmpl_var name='system_user'> <tmpl_var name='system_group'>",0);
777         
778         
779         
780         // Make the Clamav log files readable by ISPConfig
781         //exec('chmod +r /var/log/clamav/clamav.log');
782         //exec('chmod +r /var/log/clamav/freshclam.log');
783         
784         //* Install the update script
785         if(is_file('/usr/local/bin/ispconfig_update_from_svn.sh')) unlink('/usr/local/bin/ispconfig_update_from_svn.sh');
786         exec('chown root /usr/local/ispconfig/server/scripts/update_from_svn.sh');
787         exec('chmod 700 /usr/local/ispconfig/server/scripts/update_from_svn.sh');
788         exec('chown root /usr/local/ispconfig/server/scripts/update_from_tgz.sh');
789         exec('chmod 700 /usr/local/ispconfig/server/scripts/update_from_tgz.sh');
790         exec('chown root /usr/local/ispconfig/server/scripts/ispconfig_update.sh');
791         exec('chmod 700 /usr/local/ispconfig/server/scripts/ispconfig_update.sh');
792         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');
793         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');
794         
795         //set the fast cgi starter script to executable
796         //exec('chmod 755 '.$install_dir.'/interface/bin/php-fcgi');
797         
798         //* Make the logs readable for the ispconfig user
799         if(@is_file('/var/log/mail.log')) exec('chmod +r /var/log/mail.log');
800         if(@is_file('/var/log/mail.warn')) exec('chmod +r /var/log/mail.warn');
801         if(@is_file('/var/log/mail.err')) exec('chmod +r /var/log/mail.err');
802         if(@is_file('/var/log/messages')) exec('chmod +r /var/log/messages');
803         
804         //To enable apache to read the directories
805         exec('chmod a+rx /usr/local/ispconfig');
806         exec('chmod -R 751 /usr/local/ispconfig/interface');
807         exec('chmod a+rx /usr/local/ispconfig/interface/web');
808         
809         //* Create the ispconfig log directory
810         if(!is_dir('/var/log/ispconfig')) mkdir('/var/log/ispconfig');
811         if(!is_file('/var/log/ispconfig/ispconfig.log')) exec('touch /var/log/ispconfig/ispconfig.log');
812         
813         exec('mv /usr/local/ispconfig/server/scripts/run-getmail.sh /usr/local/bin/run-getmail.sh');
814         exec('chown getmail /usr/local/bin/run-getmail.sh');
815         exec('chmod 744 /usr/local/bin/run-getmail.sh');
816         
817         
818     }
819     
820     public function configure_dbserver()
821     {
822         global $conf;
823         
824         //* If this server shall act as database server for client DB's, we configure this here
825         $install_dir = $conf['ispconfig_install_dir'];
826         
827         // Create a file with the database login details which 
828         // are used to create the client databases.
829         
830         if(!is_dir("$install_dir/server/lib")) {
831             $command = "mkdir $install_dir/server/lib";
832             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
833         }
834         
835         $content = rf("tpl/mysql_clientdb.conf.master");
836         $content = str_replace('{username}',$conf['mysql']['admin_user'],$content);
837         $content = str_replace('{password}',$conf['mysql']['admin_password'], $content);
838         wf("$install_dir/server/lib/mysql_clientdb.conf",$content);
839         exec('chmod 600 '."$install_dir/server/lib/mysql_clientdb.conf");
840         exec('chown root:root '."$install_dir/server/lib/mysql_clientdb.conf");
841         
842     }
843     
844     public function install_crontab()
845     {        
846         global $conf;
847         
848         //* Root Crontab
849         exec('crontab -u root -l > crontab.txt');
850         $existing_root_cron_jobs = file('crontab.txt');
851         
852         // remove existing ispconfig cronjobs, in case the syntax has changed
853         foreach($existing_root_cron_jobs as $key => $val) {
854             if(stristr($val,'/usr/local/ispconfig')) unset($existing_root_cron_jobs[$key]);
855         }
856         
857         $root_cron_jobs = array(
858             '* * * * * /usr/local/ispconfig/server/server.sh &> /dev/null',
859             '30 00 * * * /usr/local/ispconfig/server/cron_daily.sh &> /dev/null'
860         );
861         foreach($root_cron_jobs as $cron_job) {
862             if(!in_array($cron_job."\n", $existing_root_cron_jobs)) {
863                 $existing_root_cron_jobs[] = $cron_job."\n";
864             }
865         }
866         file_put_contents('crontab.txt', $existing_root_cron_jobs);
867         exec('crontab -u root crontab.txt &> /dev/null');
868         unlink('crontab.txt');
869         
870         //* Getmail crontab
871         if(is_user('getmail')) {
872             $cf = $conf['getmail'];
873             exec('crontab -u getmail -l > crontab.txt');
874             $existing_cron_jobs = file('crontab.txt');
875         
876             $cron_jobs = array(
877                 '*/5 * * * * /usr/local/bin/run-getmail.sh > /dev/null 2>> /var/log/ispconfig/cron.log'
878             );
879         
880             // remove existing ispconfig cronjobs, in case the syntax has changed
881             foreach($existing_cron_jobs as $key => $val) {
882                 if(stristr($val,'getmail')) unset($existing_cron_jobs[$key]);
883             }
884         
885             foreach($cron_jobs as $cron_job) {
886                 if(!in_array($cron_job."\n", $existing_cron_jobs)) {
887                     $existing_cron_jobs[] = $cron_job."\n";
888                 }
889             }
890             file_put_contents('crontab.txt', $existing_cron_jobs);
891             exec('crontab -u getmail crontab.txt &> /dev/null');
892             unlink('crontab.txt');
893         }
894         
895         exec('touch /var/log/ispconfig/cron.log');
896         exec('chmod 666 /var/log/ispconfig/cron.log');
897     }
898
899 }
900
7d89f5 901 ?>