Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
commit | author | age
20218c 1 <?php
M 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
b1a6a5 31 class installer extends installer_base
cb8c86 32 {
W 33     public function configure_jailkit()
b1a6a5 34     {
MC 35         global $conf;
36
cb8c86 37         if (is_dir($conf['jailkit']['config_dir']))
W 38         {
ff1d9a 39             $jkinit_content = $this->get_template_file($conf['jailkit']['jk_init'], true); //* get contents
cb8c86 40             $this->write_config_file($conf['jailkit']['config_dir'] . '/' . $conf['jailkit']['jk_init'], $jkinit_content);
b1a6a5 41
ff1d9a 42             $jkchroot_content = $this->get_template_file($conf['jailkit']['jk_chrootsh'], true); //* get contents
cb8c86 43             $this->write_config_file($conf['jailkit']['config_dir'] . '/' . $conf['jailkit']['jk_chrootsh'], $jkchroot_content);
W 44         }
b1a6a5 45
ff1d9a 46         $command = 'chown root:root /var/www';
W 47         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
b1a6a5 48     }
MC 49
cb8c86 50     public function configure_postfix($options = '')
b1a6a5 51     {
b51c22 52         global $conf,$autoinstall;
b1a6a5 53
MC 54         $cf = $conf['postfix'];
cb8c86 55         $config_dir = $cf['config_dir'];
b1a6a5 56
cb8c86 57         if(!is_dir($config_dir)){
b1a6a5 58             $this->error("The postfix configuration directory '$config_dir' does not exist.");
MC 59         }
60
61         //* Install virtual mappings
62         foreach (glob('tpl/mysql-virtual_*.master') as $filename) {
63             $this->process_postfix_config( basename($filename, '.master') );
64         }
65
ff1d9a 66         //* Changing mode and group of the new created config files.
cb8c86 67         caselog('chmod o= '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null',
b1a6a5 68             __FILE__, __LINE__, 'chmod on mysql-virtual_*.cf*', 'chmod on mysql-virtual_*.cf* failed');
MC 69         caselog('chgrp '.$cf['group'].' '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null',
70             __FILE__, __LINE__, 'chgrp on mysql-virtual_*.cf*', 'chgrp on mysql-virtual_*.cf* failed');
71
ff1d9a 72         //* Creating virtual mail user and group
cb8c86 73         $command = 'groupadd -g '.$cf['vmail_groupid'].' '.$cf['vmail_groupname'];
W 74         if (!is_group($cf['vmail_groupname'])) {
75             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
76         }
20218c 77
cb8c86 78         $command = 'useradd -g '.$cf['vmail_groupname'].' -u '.$cf['vmail_userid'].' '.$cf['vmail_username'].' -d '.$cf['vmail_mailbox_base'].' -m';
W 79         if (!is_user($cf['vmail_username'])) {
b1a6a5 80             caselog("$command &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
cb8c86 81         }
20218c 82
b67344 83         //* These postconf commands will be executed on installation and update
badfbe 84         $server_ini_rec = $this->db->queryOneRecord("SELECT config FROM ?? WHERE server_id = ?", $conf["mysql"]["database"].'.server', $conf['server_id']);
20f478 85         $server_ini_array = ini_to_array(stripslashes($server_ini_rec['config']));
D 86         unset($server_ini_rec);
87
88         //* If there are RBL's defined, format the list and add them to smtp_recipient_restrictions to prevent removeal after an update
89         $rbl_list = '';
90         if (@isset($server_ini_array['mail']['realtime_blackhole_list']) && $server_ini_array['mail']['realtime_blackhole_list'] != '') {
91             $rbl_hosts = explode(",", str_replace(" ", "", $server_ini_array['mail']['realtime_blackhole_list']));
92             foreach ($rbl_hosts as $key => $value) {
93                 $rbl_list .= ", reject_rbl_client ". $value;
94             }
95         }
96         unset($rbl_hosts);
97
98         //* If Postgrey is installed, configure it
99         $greylisting = '';
100         if($conf['postgrey']['installed'] == true) {
101             $greylisting = ', check_recipient_access mysql:/etc/postfix/mysql-virtual_policy_greylist.cf';
102         }
103         
104         $reject_sender_login_mismatch = '';
105         if(isset($server_ini_array['mail']['reject_sender_login_mismatch']) && ($server_ini_array['mail']['reject_sender_login_mismatch'] == 'y')) {
106             $reject_sender_login_mismatch = ', reject_authenticated_sender_login_mismatch';
107         }
108         unset($server_ini_array);
109         
b1a6a5 110         $postconf_placeholders = array('{config_dir}' => $config_dir,
MC 111             '{vmail_mailbox_base}' => $cf['vmail_mailbox_base'],
112             '{vmail_userid}' => $cf['vmail_userid'],
113             '{vmail_groupid}' => $cf['vmail_groupid'],
20f478 114             '{rbl_list}' => $rbl_list,
D 115             '{greylisting}' => $greylisting,
116             '{reject_slm}' => $reject_sender_login_mismatch,
117         );
b1a6a5 118
MC 119         $postconf_tpl = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/gentoo_postfix.conf.master', 'tpl/gentoo_postfix.conf.master');
120         $postconf_tpl = strtr($postconf_tpl, $postconf_placeholders);
121         $postconf_commands = array_filter(explode("\n", $postconf_tpl)); // read and remove empty lines
122
b67344 123         //* These postconf commands will be executed on installation only
T 124         if($this->is_update == false) {
b1a6a5 125             $postconf_commands = array_merge($postconf_commands, array(
MC 126                     'myhostname = '.$conf['hostname'],
127                     'mydestination = '.$conf['hostname'].', localhost, localhost.localdomain',
128                     'mynetworks = 127.0.0.0/8 [::1]/128'
129                 ));
b67344 130         }
b1a6a5 131
ff1d9a 132         //* Create the header and body check files
cb8c86 133         touch($config_dir.'/header_checks');
W 134         touch($config_dir.'/mime_header_checks');
135         touch($config_dir.'/nested_header_checks');
136         touch($config_dir.'/body_checks');
b1a6a5 137
MC 138
ff1d9a 139         //* Make a backup copy of the main.cf file
cb8c86 140         copy($config_dir.'/main.cf', $config_dir.'/main.cf~');
b1a6a5 141
ff1d9a 142         //* Executing the postconf commands
cb8c86 143         foreach($postconf_commands as $cmd) {
W 144             $command = "postconf -e '$cmd'";
ff1d9a 145             caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
cb8c86 146         }
b1a6a5 147
ff1d9a 148         //* Create the SSL certificate
b1a6a5 149         if (!stristr($options, 'dont-create-certs'))
cb8c86 150         {
b04e82 151             if(AUTOINSTALL){
TB 152                 $command = 'cd '.$config_dir.'; '
35846d 153                     ."openssl req -new -subj '/C=".escapeshellcmd($autoinstall['ssl_cert_country'])."/ST=".escapeshellcmd($autoinstall['ssl_cert_state'])."/L=".escapeshellcmd($autoinstall['ssl_cert_locality'])."/O=".escapeshellcmd($autoinstall['ssl_cert_organisation'])."/OU=".escapeshellcmd($autoinstall['ssl_cert_organisation_unit'])."/CN=".escapeshellcmd($autoinstall['ssl_cert_common_name'])."' -outform PEM -out smtpd.cert -newkey rsa:4096 -nodes -keyout smtpd.key -keyform PEM -days 3650 -x509";
b04e82 154             } else {
TB 155                 $command = 'cd '.$config_dir.'; '
35846d 156                     .'openssl req -new -outform PEM -out smtpd.cert -newkey rsa:4096 -nodes -keyout smtpd.key -keyform PEM -days 3650 -x509';
b04e82 157             }
cb8c86 158             exec($command);
b1a6a5 159
cb8c86 160             $command = 'chmod o= '.$config_dir.'/smtpd.key';
W 161             caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
162         }
b1a6a5 163
ff1d9a 164         //* We have to change the permissions of the courier authdaemon directory to make it accessible for maildrop.
W 165         $command = 'chmod 755  /var/lib/courier/authdaemon/';
166         if (is_dir('/var/lib/courier/authdaemon')) {
167             caselog($command.' &> /dev/null', __FILE__, __LINE__, 'EXECUTED: '.$command, 'Failed to execute the command '.$command);
168         }
b1a6a5 169
ff1d9a 170         //* Changing maildrop lines in posfix master.cf
cb8c86 171         $configfile = $config_dir.'/master.cf';
W 172         $content = rf($configfile);
173
b1a6a5 174         $content = preg_replace('/^#?maildrop/m', 'maildrop', $content);
MC 175         $content = preg_replace('/^#?(\s+)flags=DRhu user=vmail argv=\/usr\/bin\/maildrop -d/m',
176             '$1flags=DRhu user=vmail argv=/usr/bin/maildrop -d vmail \${extension} \${recipient} \${user} \${nexthop} \${sender}',
177             $content);
178
cb8c86 179         $this->write_config_file($configfile, $content);
b1a6a5 180
ff1d9a 181         //* Writing the Maildrop mailfilter file
615a0a 182         $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/mailfilter.master', 'tpl/mailfilter.master');
cb8c86 183         $content = str_replace('{dist_postfix_vmail_mailbox_base}', $cf['vmail_mailbox_base'], $content);
b1a6a5 184
cb8c86 185         $this->write_config_file($cf['vmail_mailbox_base'].'/.mailfilter', $content);
b1a6a5 186
ff1d9a 187         //* Create the directory for the custom mailfilters
b1a6a5 188         if (!is_dir($cf['vmail_mailbox_base'].'/mailfilters'))
cb8c86 189         {
W 190             $command = 'mkdir '.$cf['vmail_mailbox_base'].'/mailfilters';
ff1d9a 191             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
cb8c86 192         }
ec5716 193
T 194         //* postfix-dkim
195         $full_file_name=$config_dir.'/tag_as_originating.re';
196         if(is_file($full_file_name)) {
197             copy($full_file_name, $config_dir.$configfile.'~');
b1a6a5 198         }
MC 199         $this->write_config_file($full_file_name, '/^/ FILTER amavis:[127.0.0.1]:10026');
ec5716 200
b1a6a5 201         $full_file_name=$config_dir.'/tag_as_foreign.re';
MC 202         if(is_file($full_file_name)) {
203             copy($full_file_name, $config_dir.$configfile.'~');
204         }
205         $this->write_config_file($full_file_name, '/^/ FILTER amavis:[127.0.0.1]:10024');
206
ff1d9a 207         //* Chmod and chown the .mailfilter file
cb8c86 208         $command = 'chown -R '.$cf['vmail_username'].':'.$cf['vmail_groupname'].' '.$cf['vmail_mailbox_base'].'/.mailfilter';
W 209         caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
b1a6a5 210
cb8c86 211         $command = 'chmod -R 600 '.$cf['vmail_mailbox_base'].'/.mailfilter';
W 212         caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
b1a6a5 213
cb8c86 214     }
b1a6a5 215
MC 216     public function configure_saslauthd()
cb8c86 217     {
W 218         global $conf;
b1a6a5 219
ff1d9a 220         $content = $this->get_template_file('sasl_smtpd.conf', true, true); //* get contents & insert db cred
cb8c86 221         $this->write_config_file($conf['saslauthd']['config_dir'].'/smtpd.conf', $content);
b1a6a5 222
ff1d9a 223         //* Edit the file saslauthd config file
W 224         $content = rf($conf['saslauthd']['config_file']);
cb8c86 225         $content = preg_replace('/(?<=\n)SASLAUTHD_OPTS="\$\{SASLAUTHD_OPTS\}[^"]+"/', 'SASLAUTHD_OPTS="${SASLAUTHD_OPTS} -a pam -r -c -s 128 -t 30 -n 5"', $content);
b1a6a5 226
ff1d9a 227         $this->write_config_file($conf['saslauthd']['config_file'], $content);
cb8c86 228     }
b1a6a5 229
cb8c86 230     public function configure_courier()
b1a6a5 231     {
MC 232         global $conf;
233
ff1d9a 234         //* authmysqlrc
W 235         $content = $this->get_template_file('authmysqlrc', true, true); //* get contents & insert db cred
cb8c86 236         $this->write_config_file($conf['courier']['config_dir'].'/authmysqlrc', $content);
b1a6a5 237
ff1d9a 238         //* authdaemonrc
cb8c86 239         $configfile = $conf['courier']['config_dir'].'/authdaemonrc';
W 240
241         $content = rf($configfile);
242         $content = preg_replace('/(?<=\n)authmodulelist="[^"]+"/', "authmodulelist=\"authmysql\"", $content);
243         $this->write_config_file($configfile, $content);
b1a6a5 244
ff1d9a 245         //* create certificates
W 246         $command = 'mkimapdcert';
247         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
b1a6a5 248
ff1d9a 249         $command = 'mkpop3dcert';
cb8c86 250         caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
b1a6a5 251     }
MC 252
253     public function configure_dovecot()
254     {
255         global $conf;
256
a8aad2 257         $virtual_transport = 'dovecot';
8b23f8 258
FS 259         $configure_lmtp = false;
a8aad2 260         
DM 261         // check if virtual_transport must be changed
262         if ($this->is_update) {
cc7a82 263             $tmp = $this->db->queryOneRecord("SELECT * FROM ?? WHERE server_id = ?", $conf["mysql"]["database"].".server", $conf['server_id']);
a8aad2 264             $ini_array = ini_to_array(stripslashes($tmp['config']));
DM 265             // ini_array needs not to be checked, because already done in update.php -> updateDbAndIni()
266             
267             if(isset($ini_array['mail']['mailbox_virtual_uidgid_maps']) && $ini_array['mail']['mailbox_virtual_uidgid_maps'] == 'y') {
268                 $virtual_transport = 'lmtp:unix:private/dovecot-lmtp';
8b23f8 269                 $configure_lmtp = true;
a8aad2 270             }
DM 271         }
272
bd5d26 273         $config_dir = $conf['postfix']['config_dir'];
b1a6a5 274         //* Configure master.cf and add a line for deliver
bd5d26 275         if ($this->postfix_master()) {
FS 276             exec ("postconf -M dovecot.unix", $out, $ret);
277             $add_dovecot_service = @($out[0]=='')?true:false;
278         } else { //* fallback - postfix < 2.9
279             $content = rf($config_dir.'/master.cf');
280             $add_dovecot_service = @(!stristr($content, "dovecot/deliver"))?true:false;
ff1d9a 281         }
bd5d26 282         if($add_dovecot_service) {
FS 283             //* backup
284             if(is_file($config_dir.'/master.cf')){
285                 copy($config_dir.'/master.cf', $config_dir.'/master.cf~2');
286             }
287             if(is_file($config_dir.'/master.cf~')){
288                 chmod($config_dir.'/master.cf~2', 0400);
289             }
290             //* Configure master.cf and add a line for deliver
291             $content = rf($conf["postfix"]["config_dir"].'/master.cf');
c12031 292             $deliver_content = 'dovecot   unix  -       n       n       -       -       pipe'."\n".'  flags=DROhu user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${user}@${nexthop}';
091066 293             af($config_dir.'/master.cf', $deliver_content);
bd5d26 294             unset($content);
FS 295             unset($deliver_content);
296         }
b1a6a5 297
ff1d9a 298         //* Reconfigure postfix to use dovecot authentication
W 299         $postconf_commands = array (
b1a6a5 300             'dovecot_destination_recipient_limit = 1',
a8aad2 301             'virtual_transport = '.$virtual_transport,
b1a6a5 302             'smtpd_sasl_type = dovecot',
MC 303             'smtpd_sasl_path = private/auth'
ff1d9a 304         );
b1a6a5 305
ff1d9a 306         //* Make a backup copy of the main.cf file
b1a6a5 307         copy($conf['postfix']['config_dir'].'/main.cf', $conf['postfix']['config_dir'].'/main.cf~3');
MC 308
309         //* Executing the postconf commands
310         foreach($postconf_commands as $cmd)
ff1d9a 311         {
W 312             $command = "postconf -e '$cmd'";
313             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
314         }
b1a6a5 315
bd5d26 316         $config_dir = $conf['dovecot']['config_dir'];
ff1d9a 317         //* copy dovecot.conf
W 318         $configfile = $config_dir.'/dovecot.conf';
319         $content = $this->get_template_file('dovecot.conf', true);
320         $this->write_config_file($configfile, $content);
b1a6a5 321
8b23f8 322         //* dovecot-lmtpd
FS 323         if($configure_lmtp) {
324             replaceLine($config_dir.'/'.$configfile, 'protocols = imap pop3', 'protocols = imap pop3 lmtp', 1, 0);
325         }
326
ff1d9a 327         //* dovecot-sql.conf
W 328         $configfile = $config_dir.'/dovecot-sql.conf';
329         $content = $this->get_template_file('debian_dovecot-sql.conf', true, true);
330         $this->write_config_file($configfile, $content);
b1a6a5 331     }
MC 332
cb8c86 333     public function configure_spamassassin()
b1a6a5 334     {
cb8c86 335         return true;
b1a6a5 336     }
MC 337
cb8c86 338     public function configure_getmail()
b1a6a5 339     {
cb8c86 340         global $conf;
b1a6a5 341
cb8c86 342         $config_dir = $conf['getmail']['config_dir'];
b1a6a5 343
cb8c86 344         if (!is_dir($config_dir)) {
ff1d9a 345             exec('mkdir -p '.escapeshellcmd($config_dir));
cb8c86 346         }
W 347
348         $command = "useradd -d $config_dir ".$conf['getmail']['user'];
349         if (!is_user('getmail')) {
350             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
351         }
b1a6a5 352
cb8c86 353         $command = "chown -R getmail $config_dir";
W 354         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
b1a6a5 355
cb8c86 356         $command = "chmod -R 700 $config_dir";
W 357         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
b1a6a5 358
ff1d9a 359         //* Getmail will be run from cron. In order to have access to cron the getmail user needs to be part of the cron group.
cb8c86 360         $command = "gpasswd -a getmail " . $conf['cron']['group'];
W 361         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
362     }
b1a6a5 363
MC 364     public function configure_amavis()
365     {
cb8c86 366         global $conf;
b1a6a5 367
ff1d9a 368         //* Amavisd-new user config file
cb8c86 369         $conf_file = 'amavisd-ispconfig.conf';
W 370         $conf_path = dirname($conf['amavis']['config_file']) . '/' . $conf_file;
b1a6a5 371
ff1d9a 372         $content = $this->get_template_file($conf_file, true, true); //* get contents & insert db cred
cb8c86 373         $this->write_config_file($conf_path, $content);
b1a6a5 374
ff1d9a 375         //* Activate config directory in default file
cb8c86 376         $amavis_conf = rf($conf['amavis']['config_file']);
b1a6a5 377         if (stripos($amavis_conf, $conf_path) === false)
cb8c86 378         {
ff1d9a 379             $amavis_conf = preg_replace('/^(1;.*)$/m', "include_config_files('$conf_path');\n$1", $amavis_conf);
cb8c86 380             $this->write_config_file($conf['amavis']['config_file'], $amavis_conf);
W 381         }
b1a6a5 382
ff1d9a 383         //* Adding the amavisd commands to the postfix configuration
cb8c86 384         $postconf_commands = array (
W 385             'content_filter = amavis:[127.0.0.1]:10024',
386             'receive_override_options = no_address_mappings'
387         );
b1a6a5 388
MC 389         foreach($postconf_commands as $cmd) {
cb8c86 390             $command = "postconf -e '$cmd'";
ff1d9a 391             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
cb8c86 392         }
b1a6a5 393
bd5d26 394         $config_dir = $conf['postfix']['config_dir'];
FS 395
396         // Adding amavis-services to the master.cf file if the service does not already exists
397         if ($this->postfix_master()) {
398             exec ("postconf -M amavis.unix", $out, $ret);
399             $add_amavis = @($out[0]=='')?true:false;
400             unset($out);
401             exec ("postconf -M 127.0.0.1:10025.inet", $out, $ret);
402             $add_amavis_10025 = @($out[0]=='')?true:false;
403             unset($out);
404             exec ("postconf -M 127.0.0.1:10027.inet", $out, $ret);
405             $add_amavis_10027 = @($out[0]=='')?true:false;
406             unset($out);
407         } else { //* fallback - postfix < 2.9
44ae08 408             $content = rf($conf['postfix']['config_dir'].'/master.cf');
bd5d26 409             $add_amavis = @(!preg_match('/^amavis\s+unix\s+/m', $content))?true:false;
FS 410             $add_amavis_10025 = @(!preg_match('/^127.0.0.1:10025\s+/m', $content))?true:false;
411             $add_amavis_10027 = @(!preg_match('/^127.0.0.1:10027\s+/m', $content))?true:false;
44ae08 412         }
bd5d26 413
FS 414         if ($add_amavis || $add_amavis_10025 || $add_amavis_10027) {
415             //* backup master.cf
416             if(is_file($config_dir.'/master.cf')) copy($config_dir.'/master.cf', $config_dir.'/master.cf~');
417             // adjust amavis-config
418             if($add_amavis) {
419                 $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/master_cf_amavis.master', 'tpl/master_cf_amavis.master');
420                 af($config_dir.'/master.cf', $content);
421                 unset($content);
422             }
423             if ($add_amavis_10025) {
424                 $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/master_cf_amavis10025.master', 'tpl/master_cf_amavis10025.master');
425                 af($config_dir.'/master.cf', $content);
426                 unset($content);
427             }
428             if ($add_amavis_10027) {
429                 $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/master_cf_amavis10027.master', 'tpl/master_cf_amavis10027.master');
430                 af($config_dir.'/master.cf', $content);
431                 unset($content);
432             }
44ae08 433         }
b1a6a5 434
ff1d9a 435         //* Add the clamav user to the amavis group
cb8c86 436         exec('usermod -a -G amavis clamav');
b1a6a5 437     }
MC 438
439     public function configure_pureftpd()
440     {
cb8c86 441         global $conf;
b1a6a5 442
cb8c86 443         //* configure pure-ftpd for MySQL authentication against the ispconfig database
ff1d9a 444         $content = $this->get_template_file('pureftpd_mysql.conf', true, true); //* get contents & insert db cred
W 445         $content = str_replace('{server_id}', $conf['server_id'], $content);
b1a6a5 446
cb8c86 447         $this->write_config_file($conf['pureftpd']['mysql_config_file'], $content, 600, 'root', 'root');
b1a6a5 448
ff1d9a 449         //* enable pure-ftpd and server settings
cb8c86 450         $content = rf($conf["pureftpd"]["config_file"]);
b1a6a5 451
cb8c86 452         $content = preg_replace('/#?IS_CONFIGURED="(?:yes|no)"/', 'IS_CONFIGURED="yes"', $content);
W 453         $content = str_replace('AUTH="-l unix"', 'AUTH="-l mysql:'.$conf['pureftpd']['mysql_config_file'].'"', $content);
b1a6a5 454
ff1d9a 455         //* Logging defaults to syslog's ftp facility. Override this behaviour for better compatibility with debian/ubuntu
W 456         //* and specify the format.
cb8c86 457         $logdir = '/var/log/pure-ftpd';
W 458         if (!is_dir($logdir)) {
459             mkdir($logdir, 0755, true);
460         }
b1a6a5 461
ff1d9a 462         /**
cb8c86 463          * @link http://download.pureftpd.org/pub/pure-ftpd/doc/README
W 464          * -b brokenclientscompatibility
465          * -A chrooteveryone
466          * -E noanonymous
467          * -O altlog <format>:<log file>
468          * -Z customerproof (Add safe guards against common customer mistakes ie. like chmod 0 on their own files)
b1a6a5 469          * -D displaydotfiles
ff1d9a 470          * -H dontresolve
cb8c86 471          */
b1a6a5 472
MC 473
ff1d9a 474         $content = preg_replace('/MISC_OTHER="[^"]+"/', 'MISC_OTHER="-b -A -E -Z -D -H -O clf:'.$logdir.'/transfer.log"', $content);
b1a6a5 475
ff1d9a 476         $this->write_config_file($conf['pureftpd']['config_file'], $content);
b1a6a5 477     }
MC 478
479     public function configure_powerdns()
cb8c86 480     {
W 481         global $conf;
b1a6a5 482
cb8c86 483         //* Create the database
cc7a82 484         if(!$this->db->query('CREATE DATABASE IF NOT EXISTS ?? DEFAULT CHARACTER SET ?', $conf['powerdns']['database'], $conf['mysql']['charset'])) {
cb8c86 485             $this->error('Unable to create MySQL database: '.$conf['powerdns']['database'].'.');
W 486         }
b1a6a5 487
cb8c86 488         //* Create the ISPConfig database user in the local database
cc7a82 489         $query = 'GRANT ALL ON ??.* TO ?@?';
MC 490         if(!$this->db->query($query, $conf['powerdns']['database'], $conf['mysql']['ispconfig_user'], 'localhost')) {
cb8c86 491             $this->error('Unable to create user for powerdns database Error: '.$this->db->errorMessage);
W 492         }
b1a6a5 493
cb8c86 494         //* Reload database privelages
W 495         $this->db->query('FLUSH PRIVILEGES;');
b1a6a5 496
cb8c86 497         //* load the powerdns databse dump
W 498         if($conf['mysql']['admin_password'] == '') {
b1a6a5 499             caselog("mysql --default-character-set=".$conf['mysql']['charset']." -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' '".$conf['powerdns']['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/powerdns.sql' &> /dev/null",
MC 500                 __FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in powerdns.sql');
cb8c86 501         } else {
b1a6a5 502             caselog("mysql --default-character-set=".$conf['mysql']['charset']." -h '".$conf['mysql']['host']."' -u '".$conf['mysql']['admin_user']."' -p'".$conf['mysql']['admin_password']."' '".$conf['powerdns']['database']."' < '".ISPC_INSTALL_ROOT."/install/sql/powerdns.sql' &> /dev/null",
MC 503                 __FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in powerdns.sql');
cb8c86 504         }
b1a6a5 505
cb8c86 506         //* Create the powerdns config file
ff1d9a 507         $content = $this->get_template_file('pdns.local', true, true); //* get contents & insert db cred
cb8c86 508         $content = str_replace('{powerdns_database}', $conf['powerdns']['database'], $content);
b1a6a5 509
cb8c86 510         $this->write_config_file($conf["powerdns"]["config_dir"].'/'.$conf["powerdns"]["config_file"], $content, 600, 'root', 'root');
W 511
ff1d9a 512         //* Create symlink to init script to start the correct config file
cb8c86 513         if( !is_link($conf['init_scripts'].'/'.$conf['powerdns']['init_script']) ) {
W 514             symlink($conf['init_scripts'].'/pdns', $conf['init_scripts'].'/'.$conf['powerdns']['init_script']);
515         }
516     }
b1a6a5 517
d090db 518     public function configure_bind() {
W 519         global $conf;
520
b1a6a5 521         //* Check if the zonefile directory has a slash at the end
MC 522         $content=$conf['bind']['bind_zonefiles_dir'];
523         if(substr($content, -1, 1) != '/') {
524             $content .= '/';
d090db 525         }
b1a6a5 526
d090db 527         //* New default format of named.conf uses views. Check which version the system is using and include our zones file.
W 528         $named_conf = rf($conf['bind']['named_conf_path']);
b1a6a5 529         if (stripos($named_conf, 'include "'.$conf['bind']['named_conf_local_path'].'";') === false)
d090db 530         {
W 531             preg_match_all("/(?<=\n)view \"(?:public|internal)\" in \{.*\n\};/Us", $named_conf, $views);
532             if (count($views[0]) == 2) {
533                 foreach ($views[0] as $view) {
534                     $named_conf = str_replace($view, substr($view, 0, -2)."include \"{$conf['bind']['named_conf_local_path']}\";\n};", $named_conf);
535                 }
b1a6a5 536
d090db 537                 wf($conf['bind']['named_conf_path'], $named_conf);
W 538             }
539             else {
540                 af($conf['bind']['named_conf_path'], 'include "'.$conf['bind']['named_conf_local_path'].'";');
541             }
542         }
543     }
b1a6a5 544
cb8c86 545     public function configure_apache()
b1a6a5 546     {
cb8c86 547         global $conf;
b1a6a5 548
91324a 549         if($conf['apache']['installed'] == false) return;
ff1d9a 550         //* Create the logging directory for the vhost logfiles
W 551         if (!is_dir($conf['ispconfig_log_dir'].'/httpd')) {
552             mkdir($conf['ispconfig_log_dir'].'/httpd', 0755, true);
cb8c86 553         }
b1a6a5 554
MC 555         if (is_file($conf['suphp']['config_file']))
cb8c86 556         {
W 557             $content = rf($conf['suphp']['config_file']);
b1a6a5 558
ff1d9a 559             if (!preg_match('|^x-httpd-suphp=php:/usr/bin/php-cgi$|m', $content))
W 560             {
b1a6a5 561                 $content = preg_replace('/;Handler for php-scripts/', ";Handler for php-scripts\nx-httpd-suphp=php:/usr/bin/php-cgi", $content);
MC 562                 $content = preg_replace('/;?umask=\d+/', 'umask=0022', $content);
ff1d9a 563             }
b1a6a5 564
cb8c86 565             $this->write_config_file($conf['suphp']['config_file'], $content);
W 566         }
b1a6a5 567
ff1d9a 568         //* Enable ISPConfig default vhost settings
cb8c86 569         $default_vhost_path = $conf['apache']['vhost_conf_dir'].'/'.$conf['apache']['vhost_default'];
b1a6a5 570         if (is_file($default_vhost_path))
cb8c86 571         {
W 572             $content = rf($default_vhost_path);
b1a6a5 573
cb8c86 574             $content = preg_replace('/^#?\s*NameVirtualHost.*$/m', 'NameVirtualHost *:80', $content);
W 575             $content = preg_replace('/<VirtualHost[^>]+>/', '<VirtualHost *:80>', $content);
b1a6a5 576
cb8c86 577             $this->write_config_file($default_vhost_path, $content);
W 578         }
b1a6a5 579
ff1d9a 580         //* Generate default ssl certificates
cb8c86 581         if (!is_dir($conf['apache']['ssl_dir'])) {
W 582             mkdir($conf['apache']['ssl_dir']);
583         }
b1a6a5 584
MC 585         if ($conf['services']['mail'] == true)
cb8c86 586         {
W 587             copy($conf['postfix']['config_dir']."/smtpd.key", $conf['apache']['ssl_dir']."/server.key");
588             copy($conf['postfix']['config_dir']."/smtpd.cert", $conf['apache']['ssl_dir']."/server.crt");
589         }
590         else
591         {
592             if (!is_file($conf['apache']['ssl_dir'] . '/server.crt')) {
593                 exec("openssl req -new -outform PEM -out {$conf['apache']['ssl_dir']}/server.crt -newkey rsa:2048 -nodes -keyout {$conf['apache']['ssl_dir']}/server.key -keyform PEM -days 365 -x509");
594             }
595         }
b1a6a5 596
MC 597
598
ff1d9a 599         //* Copy the ISPConfig configuration include
ccbf14 600         $tpl = new tpl('apache_ispconfig.conf.master');
TB 601         $tpl->setVar('apache_version',getapacheversion());
602         
2af58c 603         $records = $this->db->queryAllRecords("SELECT * FROM ?? WHERE server_id = ? AND virtualhost = 'y'", $conf['mysql']['master_database'] . '.server_ip', $conf['server_id']);
ccbf14 604         $ip_addresses = array();
TB 605         
606         if(is_array($records) && count($records) > 0) {
607             foreach($records as $rec) {
608                 if($rec['ip_type'] == 'IPv6') {
609                     $ip_address = '['.$rec['ip_address'].']';
610                 } else {
611                     $ip_address = $rec['ip_address'];
612                 }
613                 $ports = explode(',', $rec['virtualhost_port']);
614                 if(is_array($ports)) {
615                     foreach($ports as $port) {
616                         $port = intval($port);
617                         if($port > 0 && $port < 65536 && $ip_address != '') {
618                             $ip_addresses[] = array('ip_address' => $ip_address, 'port' => $port);
619                         }
620                     }
621                 }
622             }
623         }
855547 624         
3de838 625         if(count($ip_addresses) > 0) $tpl->setLoop('ip_adresses',$ip_addresses);
ccbf14 626
TB 627         wf($conf['apache']['vhost_conf_dir'].'/000-ispconfig.conf', $tpl->grab());
628         unset($tpl);
b1a6a5 629
ff1d9a 630         //* Gentoo by default does not include .vhost files. Add include line to config file.
cb8c86 631         $content = rf($conf['apache']['config_file']);
W 632         if ( strpos($content, 'Include /etc/apache2/vhosts.d/*.vhost') === false ) {
b1a6a5 633             $content = preg_replace('|(Include /etc/apache2/vhosts.d/\*.conf)|', "$1\nInclude /etc/apache2/vhosts.d/*.vhost", $content);
cb8c86 634         }
b1a6a5 635
cb8c86 636         $this->write_config_file($conf['apache']['config_file'], $content);
b1a6a5 637
ff1d9a 638         //* make sure that webalizer finds its config file when it is directly in /etc
b1a6a5 639         if(is_file('/etc/webalizer.conf') && !is_dir('/etc/webalizer'))
cb8c86 640         {
W 641             mkdir('/etc/webalizer', 0755);
642             symlink('/etc/webalizer.conf', '/etc/webalizer/webalizer.conf');
643         }
b1a6a5 644
MC 645         if(is_file('/etc/webalizer/webalizer.conf')) //* Change webalizer mode to incremental
646             {
647             replaceLine('/etc/webalizer/webalizer.conf', '#IncrementalName', 'IncrementalName webalizer.current', 0, 0);
648             replaceLine('/etc/webalizer/webalizer.conf', '#Incremental', 'Incremental     yes', 0, 0);
649             replaceLine('/etc/webalizer/webalizer.conf', '#HistoryName', 'HistoryName     webalizer.hist', 0, 0);
cb8c86 650         }
b1a6a5 651
ff1d9a 652         //* add a sshusers group
b1a6a5 653         if (!is_group('sshusers'))
cb8c86 654         {
W 655             $command = 'groupadd sshusers';
656             caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
657         }
b1a6a5 658     }
MC 659
660     public function configure_apps_vhost()
cb8c86 661     {
W 662         global $conf;
b1a6a5 663
cb8c86 664         //* Create the ispconfig apps vhost user and group
165152 665         if($conf['apache']['installed'] == true){
91324a 666             $apps_vhost_user = escapeshellcmd($conf['web']['apps_vhost_user']);
F 667             $apps_vhost_group = escapeshellcmd($conf['web']['apps_vhost_group']);
668             $install_dir = escapeshellcmd($conf['web']['website_basedir'].'/apps');
b1a6a5 669
91324a 670             $command = 'groupadd '.$apps_vhost_user;
F 671             if ( !is_group($apps_vhost_group) ) {
672                 caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
673             }
b1a6a5 674
91324a 675             $command = "useradd -g '$apps_vhost_group' -d $install_dir $apps_vhost_group";
F 676             if ( !is_user($apps_vhost_user) ) {
677                 caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
678             }
b1a6a5 679
91324a 680             $command = 'adduser '.$conf['apache']['user'].' '.$apps_vhost_group;
F 681             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
b1a6a5 682
99b55b 683             if(!@is_dir($install_dir)){
91324a 684                 mkdir($install_dir, 0755, true);
99b55b 685             } else {
F 686                 chmod($install_dir, 0755);
91324a 687             }
F 688             chown($install_dir, $apps_vhost_user);
689             chgrp($install_dir, $apps_vhost_group);
b1a6a5 690
91324a 691             //* Copy the apps vhost file
F 692             $vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
693             $vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
694             $apps_vhost_servername = ($conf['web']['apps_vhost_servername'] == '') ? '' : 'ServerName '.$conf['web']['apps_vhost_servername'];
b1a6a5 695
91324a 696             //* Dont just copy over the virtualhost template but add some custom settings
F 697             $content = $this->get_template_file('apache_apps.vhost', true);
b1a6a5 698
91324a 699             $content = str_replace('{apps_vhost_ip}', $conf['web']['apps_vhost_ip'], $content);
F 700             $content = str_replace('{apps_vhost_port}', $conf['web']['apps_vhost_port'], $content);
701             $content = str_replace('{apps_vhost_dir}', $conf['web']['website_basedir'].'/apps', $content);
702             $content = str_replace('{website_basedir}', $conf['web']['website_basedir'], $content);
703             $content = str_replace('{apps_vhost_servername}', $apps_vhost_servername, $content);
b1a6a5 704
91324a 705             //* comment out the listen directive if port is 80 or 443
F 706             if($conf['web']['apps_vhost_ip'] == 80 or $conf['web']['apps_vhost_ip'] == 443) {
707                 $content = str_replace('{vhost_port_listen}', '#', $content);
708             } else {
709                 $content = str_replace('{vhost_port_listen}', '', $content);
710             }
b1a6a5 711
91324a 712             $this->write_config_file("$vhost_conf_dir/apps.vhost", $content);
b1a6a5 713
MC 714             //if ( !is_file($conf['web']['website_basedir'].'/php-fcgi-scripts/apps/.php-fcgi-starter') )
cc6568 715             //{
b1a6a5 716             $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/apache_apps_fcgi_starter.master', 'tpl/apache_apps_fcgi_starter.master');
MC 717             $content = str_replace('{fastcgi_bin}', $conf['fastcgi']['fastcgi_bin'], $content);
718             $content = str_replace('{fastcgi_phpini_path}', $conf['fastcgi']['fastcgi_phpini_path'], $content);
719             mkdir($conf['web']['website_basedir'].'/php-fcgi-scripts/apps', 0755, true);
720             //copy('tpl/apache_apps_fcgi_starter.master',$conf['web']['website_basedir'].'/php-fcgi-scripts/apps/.php-fcgi-starter');
721             wf($conf['web']['website_basedir'].'/php-fcgi-scripts/apps/.php-fcgi-starter', $content);
722             exec('chmod +x '.$conf['web']['website_basedir'].'/php-fcgi-scripts/apps/.php-fcgi-starter');
723             exec('chown -R ispapps:ispapps '.$conf['web']['website_basedir'].'/php-fcgi-scripts/apps');
724
cc6568 725             //}
91324a 726         }
165152 727         if($conf['nginx']['installed'] == true){
91324a 728             $apps_vhost_user = escapeshellcmd($conf['web']['apps_vhost_user']);
F 729             $apps_vhost_group = escapeshellcmd($conf['web']['apps_vhost_group']);
730             $install_dir = escapeshellcmd($conf['web']['website_basedir'].'/apps');
731
732             $command = 'groupadd '.$apps_vhost_user;
733             if(!is_group($apps_vhost_group)) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
734
735             $command = 'useradd -g '.$apps_vhost_group.' -d '.$install_dir.' '.$apps_vhost_group;
736             if(!is_user($apps_vhost_user)) caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
737
738
739             $command = 'adduser '.$conf['nginx']['user'].' '.$apps_vhost_group;
740             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
741
6e2d48 742             if(!@is_dir($install_dir)){
F 743                 mkdir($install_dir, 0755, true);
744             } else {
745                 chmod($install_dir, 0755);
746             }
91324a 747             chown($install_dir, $apps_vhost_user);
F 748             chgrp($install_dir, $apps_vhost_group);
749
750             //* Copy the apps vhost file
751             $vhost_conf_dir = $conf['nginx']['vhost_conf_dir'];
752             $vhost_conf_enabled_dir = $conf['nginx']['vhost_conf_enabled_dir'];
753             $apps_vhost_servername = ($conf['web']['apps_vhost_servername'] == '')?'_':$conf['web']['apps_vhost_servername'];
754
755             // Dont just copy over the virtualhost template but add some custom settings
615a0a 756             $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/nginx_apps.vhost.master', 'tpl/nginx_apps.vhost.master');
b1a6a5 757
91324a 758             if($conf['web']['apps_vhost_ip'] == '_default_'){
F 759                 $apps_vhost_ip = '';
760             } else {
761                 $apps_vhost_ip = $conf['web']['apps_vhost_ip'].':';
762             }
b1a6a5 763
ca0b77 764             $socket_dir = escapeshellcmd($conf['nginx']['php_fpm_socket_dir']);
b1a6a5 765             if(substr($socket_dir, -1) != '/') $socket_dir .= '/';
ca0b77 766             if(!is_dir($socket_dir)) exec('mkdir -p '.$socket_dir);
F 767             $fpm_socket = $socket_dir.'apps.sock';
8ab3cd 768             $cgi_socket = escapeshellcmd($conf['nginx']['cgi_socket']);
91324a 769
F 770             $content = str_replace('{apps_vhost_ip}', $apps_vhost_ip, $content);
771             $content = str_replace('{apps_vhost_port}', $conf['web']['apps_vhost_port'], $content);
772             $content = str_replace('{apps_vhost_dir}', $conf['web']['website_basedir'].'/apps', $content);
773             $content = str_replace('{apps_vhost_servername}', $apps_vhost_servername, $content);
ca0b77 774             //$content = str_replace('{fpm_port}', ($conf['nginx']['php_fpm_start_port']+1), $content);
F 775             $content = str_replace('{fpm_socket}', $fpm_socket, $content);
8ab3cd 776             $content = str_replace('{cgi_socket}', $cgi_socket, $content);
91324a 777
F 778             wf($vhost_conf_dir.'/apps.vhost', $content);
b1a6a5 779
91324a 780             // PHP-FPM
F 781             // Dont just copy over the php-fpm pool template but add some custom settings
615a0a 782             $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/apps_php_fpm_pool.conf.master', 'tpl/apps_php_fpm_pool.conf.master');
91324a 783             $content = str_replace('{fpm_pool}', 'apps', $content);
ca0b77 784             //$content = str_replace('{fpm_port}', ($conf['nginx']['php_fpm_start_port']+1), $content);
F 785             $content = str_replace('{fpm_socket}', $fpm_socket, $content);
91324a 786             $content = str_replace('{fpm_user}', $apps_vhost_user, $content);
F 787             $content = str_replace('{fpm_group}', $apps_vhost_group, $content);
788             wf($conf['nginx']['php_fpm_pool_dir'].'/apps.conf', $content);
789
790             //copy('tpl/nginx_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost");
791             //* and create the symlink
7e1cfb 792             if(@is_link($vhost_conf_enabled_dir.'/apps.vhost')) unlink($vhost_conf_enabled_dir.'/apps.vhost');
F 793             if(!@is_link($vhost_conf_enabled_dir.'/000-apps.vhost')) {
b1a6a5 794                 symlink($vhost_conf_dir.'/apps.vhost', $vhost_conf_enabled_dir.'/000-apps.vhost');
91324a 795             }
b1a6a5 796
cb8c86 797         }
W 798     }
b1a6a5 799
MC 800     public function install_ispconfig()
801     {
cb8c86 802         global $conf;
b1a6a5 803
cb8c86 804         $install_dir = $conf['ispconfig_install_dir'];
b1a6a5 805
MC 806         //* Create the ISPConfig installation directory
807         if(!is_dir($install_dir))
cb8c86 808         {
W 809             $command = "mkdir $install_dir";
810             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
811         }
b1a6a5 812
ff1d9a 813         //* Create a ISPConfig user and group
b1a6a5 814         if (!is_group('ispconfig'))
cb8c86 815         {
W 816             $command = 'groupadd ispconfig';
817             caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
818         }
b1a6a5 819
MC 820         if (!is_user('ispconfig'))
cb8c86 821         {
W 822             $command = "useradd -g ispconfig -d $install_dir ispconfig";
823             caselog($command.' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
824         }
b1a6a5 825
ff1d9a 826         //* copy the ISPConfig interface part
cb8c86 827         $command = "cp -rf ../interface $install_dir";
W 828         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
b1a6a5 829
ff1d9a 830         //* copy the ISPConfig server part
cb8c86 831         $command = "cp -rf ../server $install_dir";
W 832         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
a13af2 833         
fb6c56 834         //* Make a backup of the security settings
TB 835         if(is_file('/usr/local/ispconfig/security/security_settings.ini')) copy('/usr/local/ispconfig/security/security_settings.ini','/usr/local/ispconfig/security/security_settings.ini~');
836         
a13af2 837         //* copy the ISPConfig security part
TB 838         $command = 'cp -rf ../security '.$install_dir;
839         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
fb6c56 840         
TB 841         //* Apply changed security_settings.ini values to new security_settings.ini file
842         if(is_file('/usr/local/ispconfig/security/security_settings.ini~')) {
843             $security_settings_old = ini_to_array(file_get_contents('/usr/local/ispconfig/security/security_settings.ini~'));
844             $security_settings_new = ini_to_array(file_get_contents('/usr/local/ispconfig/security/security_settings.ini'));
845             if(is_array($security_settings_new) && is_array($security_settings_old)) {
846                 foreach($security_settings_new as $section => $sval) {
847                     if(is_array($sval)) {
848                         foreach($sval as $key => $val) {
849                             if(isset($security_settings_old[$section]) && isset($security_settings_old[$section][$key])) {
850                                 $security_settings_new[$section][$key] = $security_settings_old[$section][$key];
851                             }
852                         }
853                     }
854                 }
855                 file_put_contents('/usr/local/ispconfig/security/security_settings.ini',array_to_ini($security_settings_new));
856             }
857         }
b1a6a5 858
MC 859
ff1d9a 860         //* Create the config file for ISPConfig interface
cb8c86 861         $configfile = 'config.inc.php';
ff1d9a 862         $content = $this->get_template_file($configfile, true, true); //* get contents & insert db cred
b1a6a5 863
cb8c86 864         $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
W 865         $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
866         $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
867         $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
82e9b9 868         $content = str_replace('{mysql_master_server_port}', $conf['mysql']['master_port'], $content);
b1a6a5 869
cb8c86 870         $content = str_replace('{server_id}', $conf['server_id'], $content);
W 871         $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
872         $content = str_replace('{language}', $conf['language'], $content);
8cf78b 873         $content = str_replace('{timezone}', $conf['timezone'], $content);
41eaa8 874         $content = str_replace('{theme}', $conf['theme'], $content);
992797 875         $content = str_replace('{language_file_import_enabled}', ($conf['language_file_import_enabled'] == true)?'true':'false', $content);
b1a6a5 876
cb8c86 877         $this->write_config_file("$install_dir/interface/lib/$configfile", $content);
b1a6a5 878
ff1d9a 879         //* Create the config file for ISPConfig server
cb8c86 880         $this->write_config_file("$install_dir/server/lib/$configfile", $content);
b1a6a5 881
fb3a98 882         //* Create the config file for remote-actions (but only, if it does not exist, because
T 883         //  the value is a autoinc-value and so changed by the remoteaction_core_module
ff1d9a 884         if (!file_exists($install_dir.'/server/lib/remote_action.inc.php')) {
W 885             $content = '<?php' . "\n" . '$maxid_remote_action = 0;' . "\n" . '?>';
fb3a98 886             wf($install_dir.'/server/lib/remote_action.inc.php', $content);
ff1d9a 887         }
b1a6a5 888
MC 889         // Enable the server modules and plugins.
cb8c86 890         // TODO: Implement a selector which modules and plugins shall be enabled.
W 891         $dir = $install_dir.'/server/mods-available/';
892         if (is_dir($dir)) {
893             if ($dh = opendir($dir)) {
894                 while (($file = readdir($dh)) !== false) {
b1a6a5 895                     if($file != '.' && $file != '..' && substr($file, -8, 8) == '.inc.php') {
MC 896                         include_once $install_dir.'/server/mods-available/'.$file;
897                         $module_name = substr($file, 0, -8);
cb8c86 898                         $tmp = new $module_name;
W 899                         if($tmp->onInstall()) {
ff1d9a 900                             if(!@is_link($install_dir.'/server/mods-enabled/'.$file)) {
W 901                                 @symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-enabled/'.$file);
902                                 // @symlink($install_dir.'/server/mods-available/'.$file, '../mods-enabled/'.$file);
903                             }
cb8c86 904                             if (strpos($file, '_core_module') !== false) {
ff1d9a 905                                 if(!@is_link($install_dir.'/server/mods-core/'.$file)) {
W 906                                     @symlink($install_dir.'/server/mods-available/'.$file, $install_dir.'/server/mods-core/'.$file);
907                                     // @symlink($install_dir.'/server/mods-available/'.$file, '../mods-core/'.$file);
908                                 }
cb8c86 909                             }
W 910                         }
911                         unset($tmp);
912                     }
913                 }
914                 closedir($dh);
915             }
916         }
ff1d9a 917
cb8c86 918         $dir = $install_dir.'/server/plugins-available/';
W 919         if (is_dir($dir)) {
920             if ($dh = opendir($dir)) {
921                 while (($file = readdir($dh)) !== false) {
91324a 922                     if($conf['apache']['installed'] == true && $file == 'nginx_plugin.inc.php') continue;
F 923                     if($conf['nginx']['installed'] == true && $file == 'apache2_plugin.inc.php') continue;
b1a6a5 924                     if($file != '.' && $file != '..' && substr($file, -8, 8) == '.inc.php') {
MC 925                         include_once $install_dir.'/server/plugins-available/'.$file;
926                         $plugin_name = substr($file, 0, -8);
cb8c86 927                         $tmp = new $plugin_name;
b1a6a5 928                         if(method_exists($tmp, 'onInstall') && $tmp->onInstall()) {
ff1d9a 929                             if(!@is_link($install_dir.'/server/plugins-enabled/'.$file)) {
W 930                                 @symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-enabled/'.$file);
931                             }
cb8c86 932                             if (strpos($file, '_core_plugin') !== false) {
ff1d9a 933                                 if(!@is_link($install_dir.'/server/plugins-core/'.$file)) {
W 934                                     @symlink($install_dir.'/server/plugins-available/'.$file, $install_dir.'/server/plugins-core/'.$file);
935                                 }
cb8c86 936                             }
W 937                         }
938                         unset($tmp);
939                     }
940                 }
941                 closedir($dh);
942             }
943         }
b1a6a5 944
ff1d9a 945         //* Update the server config
cb8c86 946         $mail_server_enabled = ($conf['services']['mail'])?1:0;
W 947         $web_server_enabled = ($conf['services']['web'])?1:0;
948         $dns_server_enabled = ($conf['services']['dns'])?1:0;
949         $file_server_enabled = ($conf['services']['file'])?1:0;
950         $db_server_enabled = ($conf['services']['db'])?1:0;
951         $vserver_server_enabled = ($conf['services']['vserver'])?1:0;
b1a6a5 952
2af58c 953         $sql = "UPDATE `server` SET mail_server = ?, web_server = ?, dns_server = ?, file_server = ?, db_server = ?, vserver_server = ? WHERE server_id = ?";
b1a6a5 954
2af58c 955         $this->db->query($sql, $mail_server_enabled, $web_server_enabled, $dns_server_enabled, $file_server_enabled, $db_server_enabled, $vserver_server_enabled, $conf['server_id']);
cb8c86 956         if($conf['mysql']['master_slave_setup'] == 'y') {
2af58c 957             $this->dbmaster->query($sql, $mail_server_enabled, $web_server_enabled, $dns_server_enabled, $file_server_enabled, $db_server_enabled, $vserver_server_enabled, $conf['server_id']);
cb8c86 958         }
b1a6a5 959
3e0fc8 960         // chown install dir to root and chmod 755
TB 961         $command = 'chown root:root '.$install_dir;
962         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
963         $command = 'chmod 755 '.$install_dir;
cb8c86 964         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
W 965
fa029b 966         //* Chmod the files and directories in the install dir
3e0fc8 967         $command = 'chmod -R 750 '.$install_dir.'/*';
TB 968         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
969
970         //* chown the interface files to the ispconfig user and group
971         $command = 'chown -R ispconfig:ispconfig '.$install_dir.'/interface';
972         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
973         
974         //* chown the server files to the root user and group
975         $command = 'chown -R root:root '.$install_dir.'/server';
cb8c86 976         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
fa029b 977         
TB 978         //* chown the security files to the root user and group
979         $command = 'chown -R root:root '.$install_dir.'/security';
980         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
981         
982         //* chown the security directory and security_settings.ini to root:ispconfig
983         $command = 'chown root:ispconfig '.$install_dir.'/security/security_settings.ini';
984         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
985         $command = 'chown root:ispconfig '.$install_dir.'/security';
986         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
cb1221 987         $command = 'chown root:ispconfig '.$install_dir.'/security/ids.whitelist';
TB 988         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
989         $command = 'chown root:ispconfig '.$install_dir.'/security/ids.htmlfield';
990         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
991         $command = 'chown root:ispconfig '.$install_dir.'/security/apache_directives.blacklist';
cb8c86 992         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
b1a6a5 993
ff1d9a 994         //* Make the global language file directory group writable
cb8c86 995         exec("chmod -R 770 $install_dir/interface/lib/lang");
b1a6a5 996
ff1d9a 997         //* Make the temp directory for language file exports writable
W 998         if(is_dir($install_dir.'/interface/web/temp')) {
999             exec("chmod -R 770 $install_dir/interface/web/temp");
1000         }
b1a6a5 1001
MC 1002         //* Make all interface language file directories group writable
cb8c86 1003         $handle = @opendir($install_dir.'/interface/web');
b1a6a5 1004         while ($file = @readdir($handle)) {
MC 1005             if ($file != '.' && $file != '..') {
1006                 if(@is_dir($install_dir.'/interface/web'.'/'.$file.'/lib/lang')) {
cb8c86 1007                     $handle2 = opendir($install_dir.'/interface/web'.'/'.$file.'/lib/lang');
b1a6a5 1008                     chmod($install_dir.'/interface/web'.'/'.$file.'/lib/lang', 0770);
MC 1009                     while ($lang_file = @readdir($handle2)) {
cb8c86 1010                         if ($lang_file != '.' && $lang_file != '..') {
b1a6a5 1011                             chmod($install_dir.'/interface/web'.'/'.$file.'/lib/lang/'.$lang_file, 0770);
cb8c86 1012                         }
W 1013                     }
1014                 }
1015             }
1016         }
b1a6a5 1017
477d4e 1018         //* Make the APS directories group writable
T 1019         exec("chmod -R 770 $install_dir/interface/web/sites/aps_meta_packages");
1020         exec("chmod -R 770 $install_dir/server/aps_packages");
b1a6a5 1021
MC 1022         //* make sure that the server config file (not the interface one) is only readable by the root user
bfcdef 1023         chmod($install_dir.'/server/lib/config.inc.php', 0600);
T 1024         chown($install_dir.'/server/lib/config.inc.php', 'root');
1025         chgrp($install_dir.'/server/lib/config.inc.php', 'root');
b1a6a5 1026
bfcdef 1027         //* Make sure thet the interface config file is readable by user ispconfig only
T 1028         chmod($install_dir.'/interface/lib/config.inc.php', 0600);
1029         chown($install_dir.'/interface/lib/config.inc.php', 'ispconfig');
1030         chgrp($install_dir.'/interface/lib/config.inc.php', 'ispconfig');
ff1d9a 1031
W 1032         chmod($install_dir.'/server/lib/remote_action.inc.php', 0600);
1033         chown($install_dir.'/server/lib/remote_action.inc.php', 'root');
1034         chgrp($install_dir.'/server/lib/remote_action.inc.php', 'root');
1035
1036         if(@is_file($install_dir.'/server/lib/mysql_clientdb.conf')) {
1037             chmod($install_dir.'/server/lib/mysql_clientdb.conf', 0600);
1038             chown($install_dir.'/server/lib/mysql_clientdb.conf', 'root');
1039             chgrp($install_dir.'/server/lib/mysql_clientdb.conf', 'root');
cb8c86 1040         }
b1a6a5 1041
8cf78b 1042         if(is_dir($install_dir.'/interface/invoices')) {
e94a9f 1043             exec('chmod -R 770 '.escapeshellarg($install_dir.'/interface/invoices'));
T 1044             exec('chown -R ispconfig:ispconfig '.escapeshellarg($install_dir.'/interface/invoices'));
edf806 1045         }
980485 1046         
TB 1047         exec('chown -R root:root /usr/local/ispconfig/interface/ssl');
b1a6a5 1048
cb8c86 1049         // TODO: FIXME: add the www-data user to the ispconfig group. This is just for testing
W 1050         // and must be fixed as this will allow the apache user to read the ispconfig files.
1051         // Later this must run as own apache server or via suexec!
63b369 1052         if($conf['apache']['installed'] == true){
F 1053             $command = 'usermod -a -G ispconfig '.$conf['apache']['user'];
1054             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
272aec 1055             if(is_group('ispapps')){
F 1056                 $command = 'usermod -a -G ispapps '.$conf['apache']['user'];
1057                 caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
1058             }
63b369 1059         }
F 1060         if($conf['nginx']['installed'] == true){
1061             $command = 'usermod -a -G ispconfig '.$conf['nginx']['user'];
1062             caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
272aec 1063             if(is_group('ispapps')){
F 1064                 $command = 'usermod -a -G ispapps '.$conf['nginx']['user'];
1065                 caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
1066             }
63b369 1067         }
b1a6a5 1068
ff1d9a 1069         //* Make the shell scripts executable
cb8c86 1070         $command = "chmod +x $install_dir/server/scripts/*.sh";
W 1071         caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
b1a6a5 1072
7e1cfb 1073         if($conf['apache']['installed'] == true && $this->install_ispconfig_interface == true){
91324a 1074             //* Copy the ISPConfig vhost for the controlpanel
F 1075             $content = $this->get_template_file("apache_ispconfig.vhost", true);
1076             $content = str_replace('{vhost_port}', $conf['apache']['vhost_port'], $content);
b1a6a5 1077
91324a 1078             //* comment out the listen directive if port is 80 or 443
F 1079             if ($conf['apache']['vhost_port'] == 80 or $conf['apache']['vhost_port'] == 443) {
1080                 $content = str_replace('{vhost_port_listen}', '#', $content);
1081             } else {
1082                 $content = str_replace('{vhost_port_listen}', '', $content);
1083             }
b1a6a5 1084
91324a 1085             if(is_file($install_dir.'/interface/ssl/ispserver.crt') && is_file($install_dir.'/interface/ssl/ispserver.key')) {
F 1086                 $content = str_replace('{ssl_comment}', '', $content);
1087             } else {
1088                 $content = str_replace('{ssl_comment}', '#', $content);
1089             }
10b4c8 1090             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 1091                 $content = str_replace('{ssl_bundle_comment}', '', $content);
1092             } else {
1093                 $content = str_replace('{ssl_bundle_comment}', '#', $content);
1094             }
b1a6a5 1095
91324a 1096             $vhost_path = $conf['apache']['vhost_conf_dir'].'/ispconfig.vhost';
F 1097             $this->write_config_file($vhost_path, $content);
b1a6a5 1098
526b99 1099             if(!is_file('/var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter')) {
615a0a 1100                 $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/apache_ispconfig_fcgi_starter.master', 'tpl/apache_ispconfig_fcgi_starter.master');
526b99 1101                 $content = str_replace('{fastcgi_bin}', $conf['fastcgi']['fastcgi_bin'], $content);
T 1102                 $content = str_replace('{fastcgi_phpini_path}', $conf['fastcgi']['fastcgi_phpini_path'], $content);
cc6568 1103                 @mkdir('/var/www/php-fcgi-scripts/ispconfig', 0755, true);
526b99 1104                 wf('/var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter', $content);
91324a 1105                 exec('chmod +x /var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter');
F 1106                 chmod('/var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter', 0755);
b1a6a5 1107                 @symlink($install_dir.'/interface/web', '/var/www/ispconfig');
91324a 1108                 exec('chown -R ispconfig:ispconfig /var/www/php-fcgi-scripts/ispconfig');
F 1109             }
cb8c86 1110         }
91324a 1111
7e1cfb 1112         if($conf['nginx']['installed'] == true && $this->install_ispconfig_interface == true){
91324a 1113             //* Copy the ISPConfig vhost for the controlpanel
F 1114             $vhost_conf_dir = $conf['nginx']['vhost_conf_dir'];
1115             $vhost_conf_enabled_dir = $conf['nginx']['vhost_conf_enabled_dir'];
1116
1117             // Dont just copy over the virtualhost template but add some custom settings
615a0a 1118             $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/nginx_ispconfig.vhost.master', 'tpl/nginx_ispconfig.vhost.master');
91324a 1119             $content = str_replace('{vhost_port}', $conf['nginx']['vhost_port'], $content);
b1a6a5 1120
91324a 1121             if(is_file($install_dir.'/interface/ssl/ispserver.crt') && is_file($install_dir.'/interface/ssl/ispserver.key')) {
10b4c8 1122                 $content = str_replace('{ssl_on}', ' on', $content);
91324a 1123                 $content = str_replace('{ssl_comment}', '', $content);
F 1124                 $content = str_replace('{fastcgi_ssl}', 'on', $content);
1125             } else {
10b4c8 1126                 $content = str_replace('{ssl_on}', ' off', $content);
91324a 1127                 $content = str_replace('{ssl_comment}', '#', $content);
F 1128                 $content = str_replace('{fastcgi_ssl}', 'off', $content);
1129             }
b1a6a5 1130
ca0b77 1131             $socket_dir = escapeshellcmd($conf['nginx']['php_fpm_socket_dir']);
b1a6a5 1132             if(substr($socket_dir, -1) != '/') $socket_dir .= '/';
ca0b77 1133             if(!is_dir($socket_dir)) exec('mkdir -p '.$socket_dir);
F 1134             $fpm_socket = $socket_dir.'ispconfig.sock';
b1a6a5 1135
ca0b77 1136             //$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
F 1137             $content = str_replace('{fpm_socket}', $fpm_socket, $content);
91324a 1138
F 1139             wf($vhost_conf_dir.'/ispconfig.vhost', $content);
b1a6a5 1140
91324a 1141             unset($content);
b1a6a5 1142
91324a 1143             // PHP-FPM
F 1144             // Dont just copy over the php-fpm pool template but add some custom settings
615a0a 1145             $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/php_fpm_pool.conf.master', 'tpl/php_fpm_pool.conf.master');
91324a 1146             $content = str_replace('{fpm_pool}', 'ispconfig', $content);
ca0b77 1147             //$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
F 1148             $content = str_replace('{fpm_socket}', $fpm_socket, $content);
91324a 1149             $content = str_replace('{fpm_user}', 'ispconfig', $content);
F 1150             $content = str_replace('{fpm_group}', 'ispconfig', $content);
1151             wf($conf['nginx']['php_fpm_pool_dir'].'/ispconfig.conf', $content);
1152
1153             //copy('tpl/nginx_ispconfig.vhost.master', $vhost_conf_dir.'/ispconfig.vhost');
1154             //* and create the symlink
7e1cfb 1155             if($this->is_update == false) {
91324a 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')) {
b1a6a5 1158                     symlink($vhost_conf_dir.'/ispconfig.vhost', $vhost_conf_enabled_dir.'/000-ispconfig.vhost');
91324a 1159                 }
F 1160             }
cb8c86 1161         }
b1a6a5 1162
ff1d9a 1163         //* Install the update script
b34f99 1164         if (is_file('/usr/local/bin/ispconfig_update_from_dev.sh')) {
MC 1165             unlink('/usr/local/bin/ispconfig_update_from_dev.sh');
cb8c86 1166         }
b1a6a5 1167
b34f99 1168         chown($install_dir.'/server/scripts/update_from_dev.sh', 'root');
MC 1169         chmod($install_dir.'/server/scripts/update_from_dev.sh', 0700);
ff1d9a 1170         chown($install_dir.'/server/scripts/update_from_tgz.sh', 'root');
W 1171         chmod($install_dir.'/server/scripts/update_from_tgz.sh', 0700);
1172         chown($install_dir.'/server/scripts/ispconfig_update.sh', 'root');
1173         chmod($install_dir.'/server/scripts/ispconfig_update.sh', 0700);
b1a6a5 1174
b34f99 1175         if (!is_link('/usr/local/bin/ispconfig_update_from_dev.sh')) {
MC 1176             symlink($install_dir.'/server/scripts/ispconfig_update.sh', '/usr/local/bin/ispconfig_update_from_dev.sh');
cb8c86 1177         }
b1a6a5 1178
cb8c86 1179         if (!is_link('/usr/local/bin/ispconfig_update.sh')) {
ff1d9a 1180             symlink($install_dir.'/server/scripts/ispconfig_update.sh', '/usr/local/bin/ispconfig_update.sh');
cb8c86 1181         }
b1a6a5 1182
ff1d9a 1183         //* Make the logs readable for the ispconfig user
cb8c86 1184         if (is_file('/var/log/maillog')) {
W 1185             exec('chmod +r /var/log/maillog');
1186         }
1187         if (is_file('/var/log/messages')) {
1188             exec('chmod +r /var/log/messages');
1189         }
1190         if (is_file('/var/log/clamav/clamav.log')) {
1191             exec('chmod +r /var/log/clamav/clamav.log');
1192         }
1193         if (is_file('/var/log/clamav/freshclam.log')) {
1194             exec('chmod +r /var/log/clamav/freshclam.log');
1195         }
b1a6a5 1196
ff1d9a 1197         //* Create the ispconfig log directory
e38d14 1198         if (!is_dir($conf['ispconfig_log_dir'])) {
J 1199             mkdir($conf['ispconfig_log_dir']);
cb8c86 1200         }
e38d14 1201         if (!is_file($conf['ispconfig_log_dir'].'/ispconfig.log')) {
ff1d9a 1202             touch($conf['ispconfig_log_dir'].'/ispconfig.log');
cb8c86 1203         }
b1a6a5 1204
0799f8 1205         //* Create the ispconfig auth log file and set uid/gid
T 1206         if(!is_file($conf['ispconfig_log_dir'].'/auth.log')) {
1207             touch($conf['ispconfig_log_dir'].'/auth.log');
1208         }
1209         exec('chown ispconfig:ispconfig '. $conf['ispconfig_log_dir'].'/auth.log');
1210         exec('chmod 660 '. $conf['ispconfig_log_dir'].'/auth.log');
b1a6a5 1211
ff1d9a 1212         rename($install_dir.'/server/scripts/run-getmail.sh', '/usr/local/bin/run-getmail.sh');
b1a6a5 1213
ff1d9a 1214         if (is_user('getmail')) {
W 1215             chown('/usr/local/bin/run-getmail.sh', 'getmail');
1216         }
1217         chmod('/usr/local/bin/run-getmail.sh', 0744);
b1a6a5 1218
d71bae 1219         //* Remove Domain module as its functions are available in the client module now
T 1220         if(@is_dir('/usr/local/ispconfig/interface/web/domain')) exec('rm -rf /usr/local/ispconfig/interface/web/domain');
021aec 1221         
TB 1222         // Add symlink for patch tool
1223         if(!is_link('/usr/local/bin/ispconfig_patch')) exec('ln -s /usr/local/ispconfig/server/scripts/ispconfig_patch /usr/local/bin/ispconfig_patch');
c83951 1224         
TB 1225         // Change mode of a few files from amavisd
1226         if(is_file($conf['amavis']['config_dir'].'/conf.d/50-user')) chmod($conf['amavis']['config_dir'].'/conf.d/50-user', 0640);
1227         if(is_file($conf['amavis']['config_dir'].'/50-user~')) chmod($conf['amavis']['config_dir'].'/50-user~', 0400);
1228         if(is_file($conf['amavis']['config_dir'].'/amavisd.conf')) chmod($conf['amavis']['config_dir'].'/amavisd.conf', 0640);
1229         if(is_file($conf['amavis']['config_dir'].'/amavisd.conf~')) chmod($conf['amavis']['config_dir'].'/amavisd.conf~', 0400);
1230         
b1a6a5 1231     }
MC 1232
20218c 1233 }
M 1234
e38d14 1235 ?>