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