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