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