示例#1
0
 public function configure_dovecot()
 {
     global $conf;
     $config_dir = $conf['dovecot']['config_dir'];
     //* Configure master.cf and add a line for deliver
     if (is_file($config_dir . '/master.cf')) {
         copy($config_dir . '/master.cf', $config_dir . '/master.cf~2');
     }
     if (is_file($config_dir . '/master.cf~')) {
         chmod($config_dir . '/master.cf~2', 0400);
     }
     $content = rf($conf["postfix"]["config_dir"] . '/master.cf');
     // Only add the content if we had not addded it before
     if (!stristr($content, "dovecot/deliver")) {
         $deliver_content = 'dovecot   unix  -       n       n       -       -       pipe' . "\n" . '  flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop}';
         af($conf["postfix"]["config_dir"] . '/master.cf', $deliver_content);
     }
     unset($content);
     unset($deliver_content);
     //* Reconfigure postfix to use dovecot authentication
     // Adding the amavisd commands to the postfix configuration
     $postconf_commands = array('dovecot_destination_recipient_limit = 1', 'virtual_transport = dovecot', 'smtpd_sasl_type = dovecot', 'smtpd_sasl_path = private/auth');
     // Make a backup copy of the main.cf file
     copy($conf["postfix"]["config_dir"] . '/main.cf', $conf["postfix"]["config_dir"] . '/main.cf~3');
     // Executing the postconf commands
     foreach ($postconf_commands as $cmd) {
         $command = "postconf -e '{$cmd}'";
         caselog($command . " &> /dev/null", __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     }
     //* copy dovecot.conf
     $configfile = 'dovecot.conf';
     if (is_file($config_dir . '/' . $configfile)) {
         copy($config_dir . '/' . $configfile, $config_dir . '/' . $configfile . '~');
     }
     copy('tpl/debian6_dovecot.conf.master', $config_dir . '/' . $configfile);
     //* dovecot-sql.conf
     $configfile = 'dovecot-sql.conf';
     if (is_file($config_dir . '/' . $configfile)) {
         copy($config_dir . '/' . $configfile, $config_dir . '/' . $configfile . '~');
     }
     chmod($config_dir . '/' . $configfile . '~', 0400);
     $content = rf('tpl/debian6_dovecot-sql.conf.master');
     $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
     $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
     $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
     $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
     wf($config_dir . '/' . $configfile, $content);
     chmod($config_dir . '/' . $configfile, 0600);
     chown($config_dir . '/' . $configfile, 'root');
     chgrp($config_dir . '/' . $configfile, 'root');
 }
示例#2
0
function prepareDBDump()
{
    global $conf;
    //** load the pre update sql script do perform modifications on the database before the database is dumped
    if (is_file(ISPC_INSTALL_ROOT . "/install/sql/pre_update.sql")) {
        if ($conf['mysql']['admin_password'] == '') {
            caselog("mysql --default-character-set=" . escapeshellarg($conf['mysql']['charset']) . " -h " . escapeshellarg($conf['mysql']['host']) . " -u " . escapeshellarg($conf['mysql']['admin_user']) . " " . escapeshellarg($conf['mysql']['database']) . " < '" . ISPC_INSTALL_ROOT . "/install/sql/pre_update.sql' &> /dev/null", __FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in ispconfig3.sql');
        } else {
            caselog("mysql --default-character-set=" . escapeshellarg($conf['mysql']['charset']) . " -h " . escapeshellarg($conf['mysql']['host']) . " -u " . escapeshellarg($conf['mysql']['admin_user']) . " -p" . escapeshellarg($conf['mysql']['admin_password']) . " " . escapeshellarg($conf['mysql']['database']) . " < '" . ISPC_INSTALL_ROOT . "/install/sql/pre_update.sql' &> /dev/null", __FILE__, __LINE__, 'read in ispconfig3.sql', 'could not read in ispconfig3.sql');
        }
    }
    //** export the current database data
    if (!empty($conf["mysql"]["admin_password"])) {
        system("mysqldump -h " . escapeshellarg($conf['mysql']['host']) . " -u " . escapeshellarg($conf['mysql']['admin_user']) . " -p" . escapeshellarg($conf['mysql']['admin_password']) . " -c -t --add-drop-table --create-options --quick --result-file=existing_db.sql " . $conf['mysql']['database']);
    } else {
        system("mysqldump -h " . escapeshellarg($conf['mysql']['host']) . " -u " . escapeshellarg($conf['mysql']['admin_user']) . " -c -t --add-drop-table --create-options --quick --result-file=existing_db.sql " . $conf['mysql']['database']);
    }
    /*
     * If we have a server with nothing in it except VE's then the database of thie server is empty.
     * so the following line will no longer work!
     */
    //if(filesize('existing_db.sql') < 30000) die('Possible problem with dumping the database. We will stop here. Please check the file existing_db.sql');
    // create a backup copy of the ispconfig database in the root folder
    if (isset($conf['backup_path'])) {
        $backup_db_name = $conf['backup_path'] . '/ispconfig_db_backup.sql';
    } else {
        $backup_db_name = '/root/ispconfig_db_backup_' . @date('Y-m-d_H-i') . '.sql';
    }
    copy('existing_db.sql', $backup_db_name);
    chmod($backup_db_name, 0700);
    chown($backup_db_name, 'root');
    chgrp($backup_db_name, 'root');
    if ($conf['powerdns']['installed']) {
        //** export the current PowerDNS database data
        if (!empty($conf["mysql"]["admin_password"])) {
            system("mysqldump -h " . escapeshellarg($conf['mysql']['host']) . " -u " . escapeshellarg($conf['mysql']['admin_user']) . " -p" . escapeshellarg($conf['mysql']['admin_password']) . " -c -t --add-drop-table --create-options --quick --result-file=existing_powerdns_db.sql " . $conf['powerdns']['database']);
        } else {
            system("mysqldump -h " . escapeshellarg($conf['mysql']['host']) . " -u " . escapeshellarg($conf['mysql']['admin_user']) . " -c -t --add-drop-table --create-options --quick --result-file=existing_powerdns_db.sql " . $conf['powerdns']['database']);
        }
        // create a backup copy of the PowerDNS database in the root folder
        $backup_db_name = '/root/ispconfig_powerdns_db_backup_' . @date('Y-m-d_h-i') . '.sql';
        copy('existing_powerdns_db.sql', $backup_db_name);
        chmod($backup_db_name, 0700);
        chown($backup_db_name, 'root');
        chgrp($backup_db_name, 'root');
    }
}
示例#3
0
 public function configure_amavis()
 {
     global $conf;
     // amavisd user config file
     $configfile = 'fedora_amavisd_conf';
     if (is_file($conf["amavis"]["config_dir"] . '/amavisd.conf')) {
         copy($conf["amavis"]["config_dir"] . '/amavisd.conf', $conf["amavis"]["config_dir"] . '/amavisd.conf~');
     }
     if (is_file($conf["amavis"]["config_dir"] . '/amavisd.conf~')) {
         exec('chmod 400 ' . $conf["amavis"]["config_dir"] . '/amavisd.conf~');
     }
     if (!is_dir($conf["amavis"]["config_dir"])) {
         mkdir($conf["amavis"]["config_dir"]);
     }
     $content = rf("tpl/" . $configfile . ".master");
     $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
     $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
     $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
     $content = str_replace('{mysql_server_port}', $conf["mysql"]["port"], $content);
     $content = str_replace('{mysql_server_ip}', $conf['mysql']['ip'], $content);
     $content = str_replace('{hostname}', $conf['hostname'], $content);
     $content = str_replace('/var/spool/amavisd/clamd.sock', '/var/run/clamav/clamd.sock', $content);
     wf($conf["amavis"]["config_dir"] . '/amavisd.conf', $content);
     // Adding the amavisd commands to the postfix configuration
     $postconf_commands = array('content_filter = amavis:[127.0.0.1]:10024', 'receive_override_options = no_address_mappings');
     // Make a backup copy of the main.cf file
     copy($conf["postfix"]["config_dir"] . '/main.cf', $conf["postfix"]["config_dir"] . '/main.cf~2');
     // Executing the postconf commands
     foreach ($postconf_commands as $cmd) {
         $command = "postconf -e '{$cmd}'";
         caselog($command . " &> /dev/null", __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     }
     // Append the configuration for amavisd to the master.cf file
     if (is_file($conf["postfix"]["config_dir"] . '/master.cf')) {
         copy($conf["postfix"]["config_dir"] . '/master.cf', $conf["postfix"]["config_dir"] . '/master.cf~');
     }
     $content = rf($conf["postfix"]["config_dir"] . '/master.cf');
     // Only add the content if we had not addded it before
     if (!stristr($content, "127.0.0.1:10025")) {
         unset($content);
         $content = rf("tpl/master_cf_amavis.master");
         af($conf["postfix"]["config_dir"] . '/master.cf', $content);
     }
     unset($content);
     removeLine('/etc/sysconfig/freshclam', 'FRESHCLAM_DELAY=disabled-warn   # REMOVE ME', 1);
     replaceLine('/etc/freshclam.conf', 'Example', '# Example', 1);
 }
示例#4
0
 public function install_ispconfig()
 {
     global $conf;
     $install_dir = $conf['ispconfig_install_dir'];
     //* Create the ISPConfig installation directory
     if (!is_dir($install_dir)) {
         $command = "mkdir {$install_dir}";
         caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     }
     //* Create a ISPConfig user and group
     if (!is_group('ispconfig')) {
         $command = 'groupadd ispconfig';
         caselog($command . ' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     }
     if (!is_user('ispconfig')) {
         $command = "useradd -g ispconfig -d {$install_dir} ispconfig";
         caselog($command . ' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     }
     //* copy the ISPConfig interface part
     $command = "cp -rf ../interface {$install_dir}";
     caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     //* copy the ISPConfig server part
     $command = "cp -rf ../server {$install_dir}";
     caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     //* Create the config file for ISPConfig interface
     $configfile = 'config.inc.php';
     $content = $this->get_template_file($configfile, true, true);
     //* get contents & insert db cred
     $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
     $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
     $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
     $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
     $content = str_replace('{server_id}', $conf['server_id'], $content);
     $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
     $content = str_replace('{language}', $conf['language'], $content);
     $this->write_config_file("{$install_dir}/interface/lib/{$configfile}", $content);
     //* Create the config file for ISPConfig server
     $this->write_config_file("{$install_dir}/server/lib/{$configfile}", $content);
     //* Create the config file for remote-actions (but only, if it does not exist, because
     //  the value is a autoinc-value and so changed by the remoteaction_core_module
     if (!file_exists($install_dir . '/server/lib/remote_action.inc.php')) {
         $content = '<?php' . "\n" . '$maxid_remote_action = 0;' . "\n" . '?>';
         wf($install_dir . '/server/lib/remote_action.inc.php', $content);
     }
     // Enable the server modules and plugins.
     // TODO: Implement a selector which modules and plugins shall be enabled.
     $dir = $install_dir . '/server/mods-available/';
     if (is_dir($dir)) {
         if ($dh = opendir($dir)) {
             while (($file = readdir($dh)) !== false) {
                 if ($file != '.' && $file != '..' && substr($file, -8, 8) == '.inc.php') {
                     include_once $install_dir . '/server/mods-available/' . $file;
                     $module_name = substr($file, 0, -8);
                     $tmp = new $module_name();
                     if ($tmp->onInstall()) {
                         if (!@is_link($install_dir . '/server/mods-enabled/' . $file)) {
                             @symlink($install_dir . '/server/mods-available/' . $file, $install_dir . '/server/mods-enabled/' . $file);
                             // @symlink($install_dir.'/server/mods-available/'.$file, '../mods-enabled/'.$file);
                         }
                         if (strpos($file, '_core_module') !== false) {
                             if (!@is_link($install_dir . '/server/mods-core/' . $file)) {
                                 @symlink($install_dir . '/server/mods-available/' . $file, $install_dir . '/server/mods-core/' . $file);
                                 // @symlink($install_dir.'/server/mods-available/'.$file, '../mods-core/'.$file);
                             }
                         }
                     }
                     unset($tmp);
                 }
             }
             closedir($dh);
         }
     }
     $dir = $install_dir . '/server/plugins-available/';
     if (is_dir($dir)) {
         if ($dh = opendir($dir)) {
             while (($file = readdir($dh)) !== false) {
                 if ($conf['apache']['installed'] == true && $file == 'nginx_plugin.inc.php') {
                     continue;
                 }
                 if ($conf['nginx']['installed'] == true && $file == 'apache2_plugin.inc.php') {
                     continue;
                 }
                 if ($file != '.' && $file != '..' && substr($file, -8, 8) == '.inc.php') {
                     include_once $install_dir . '/server/plugins-available/' . $file;
                     $plugin_name = substr($file, 0, -8);
                     $tmp = new $plugin_name();
                     if (method_exists($tmp, 'onInstall') && $tmp->onInstall()) {
                         if (!@is_link($install_dir . '/server/plugins-enabled/' . $file)) {
                             @symlink($install_dir . '/server/plugins-available/' . $file, $install_dir . '/server/plugins-enabled/' . $file);
                         }
                         if (strpos($file, '_core_plugin') !== false) {
                             if (!@is_link($install_dir . '/server/plugins-core/' . $file)) {
                                 @symlink($install_dir . '/server/plugins-available/' . $file, $install_dir . '/server/plugins-core/' . $file);
                             }
                         }
                     }
                     unset($tmp);
                 }
             }
             closedir($dh);
         }
     }
     //* Update the server config
     $mail_server_enabled = $conf['services']['mail'] ? 1 : 0;
     $web_server_enabled = $conf['services']['web'] ? 1 : 0;
     $dns_server_enabled = $conf['services']['dns'] ? 1 : 0;
     $file_server_enabled = $conf['services']['file'] ? 1 : 0;
     $db_server_enabled = $conf['services']['db'] ? 1 : 0;
     $vserver_server_enabled = $conf['services']['vserver'] ? 1 : 0;
     $sql = "UPDATE `server` SET mail_server = '{$mail_server_enabled}', web_server = '{$web_server_enabled}', dns_server = '{$dns_server_enabled}', file_server = '{$file_server_enabled}', db_server = '{$db_server_enabled}', vserver_server = '{$vserver_server_enabled}' WHERE server_id = " . intval($conf['server_id']);
     if ($conf['mysql']['master_slave_setup'] == 'y') {
         $this->dbmaster->query($sql);
         $this->db->query($sql);
     } else {
         $this->db->query($sql);
     }
     //* Chmod the files
     $command = "chmod -R 750 {$install_dir}";
     caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     //* chown the files to the ispconfig user and group
     $command = "chown -R ispconfig:ispconfig {$install_dir}";
     caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     //* Make the global language file directory group writable
     exec("chmod -R 770 {$install_dir}/interface/lib/lang");
     //* Make the temp directory for language file exports writable
     if (is_dir($install_dir . '/interface/web/temp')) {
         exec("chmod -R 770 {$install_dir}/interface/web/temp");
     }
     //* Make all interface language file directories group writable
     $handle = @opendir($install_dir . '/interface/web');
     while ($file = @readdir($handle)) {
         if ($file != '.' && $file != '..') {
             if (@is_dir($install_dir . '/interface/web' . '/' . $file . '/lib/lang')) {
                 $handle2 = opendir($install_dir . '/interface/web' . '/' . $file . '/lib/lang');
                 chmod($install_dir . '/interface/web' . '/' . $file . '/lib/lang', 0770);
                 while ($lang_file = @readdir($handle2)) {
                     if ($lang_file != '.' && $lang_file != '..') {
                         chmod($install_dir . '/interface/web' . '/' . $file . '/lib/lang/' . $lang_file, 0770);
                     }
                 }
             }
         }
     }
     //* make sure that the server config file (not the interface one) is only readable by the root user
     chmod($install_dir . '/server/lib/' . $configfile, 0600);
     chown($install_dir . '/server/lib/' . $configfile, 'root');
     chgrp($install_dir . '/server/lib/' . $configfile, 'root');
     chmod($install_dir . '/server/lib/remote_action.inc.php', 0600);
     chown($install_dir . '/server/lib/remote_action.inc.php', 'root');
     chgrp($install_dir . '/server/lib/remote_action.inc.php', 'root');
     if (@is_file($install_dir . '/server/lib/mysql_clientdb.conf')) {
         chmod($install_dir . '/server/lib/mysql_clientdb.conf', 0600);
         chown($install_dir . '/server/lib/mysql_clientdb.conf', 'root');
         chgrp($install_dir . '/server/lib/mysql_clientdb.conf', 'root');
     }
     // TODO: FIXME: add the www-data user to the ispconfig group. This is just for testing
     // and must be fixed as this will allow the apache user to read the ispconfig files.
     // Later this must run as own apache server or via suexec!
     if ($conf['apache']['installed'] == true) {
         $command = 'usermod -a -G ispconfig ' . $conf['apache']['user'];
         caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
         if (is_group('ispapps')) {
             $command = 'usermod -a -G ispapps ' . $conf['apache']['user'];
             caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
         }
     }
     if ($conf['nginx']['installed'] == true) {
         $command = 'usermod -a -G ispconfig ' . $conf['nginx']['user'];
         caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
         if (is_group('ispapps')) {
             $command = 'usermod -a -G ispapps ' . $conf['nginx']['user'];
             caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
         }
     }
     //* Make the shell scripts executable
     $command = "chmod +x {$install_dir}/server/scripts/*.sh";
     caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     if ($conf['apache']['installed'] == true) {
         //* Copy the ISPConfig vhost for the controlpanel
         $content = $this->get_template_file("apache_ispconfig.vhost", true);
         $content = str_replace('{vhost_port}', $conf['apache']['vhost_port'], $content);
         //* comment out the listen directive if port is 80 or 443
         if ($conf['apache']['vhost_port'] == 80 or $conf['apache']['vhost_port'] == 443) {
             $content = str_replace('{vhost_port_listen}', '#', $content);
         } else {
             $content = str_replace('{vhost_port_listen}', '', $content);
         }
         if (is_file($install_dir . '/interface/ssl/ispserver.crt') && is_file($install_dir . '/interface/ssl/ispserver.key')) {
             $content = str_replace('{ssl_comment}', '', $content);
         } else {
             $content = str_replace('{ssl_comment}', '#', $content);
         }
         $vhost_path = $conf['apache']['vhost_conf_dir'] . '/ispconfig.vhost';
         $this->write_config_file($vhost_path, $content);
         if (!is_file('/var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter')) {
             mkdir('/var/www/php-fcgi-scripts/ispconfig', 0755, true);
             copy('tpl/apache_ispconfig_fcgi_starter.master', '/var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter');
             exec('chmod +x /var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter');
             chmod('/var/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter', 0755);
             symlink($install_dir . '/interface/web', '/var/www/ispconfig');
             exec('chown -R ispconfig:ispconfig /var/www/php-fcgi-scripts/ispconfig');
         }
     }
     if ($conf['nginx']['installed'] == true) {
         //* Copy the ISPConfig vhost for the controlpanel
         $vhost_conf_dir = $conf['nginx']['vhost_conf_dir'];
         $vhost_conf_enabled_dir = $conf['nginx']['vhost_conf_enabled_dir'];
         // Dont just copy over the virtualhost template but add some custom settings
         $content = rf('tpl/nginx_ispconfig.vhost.master');
         $content = str_replace('{vhost_port}', $conf['nginx']['vhost_port'], $content);
         if (is_file($install_dir . '/interface/ssl/ispserver.crt') && is_file($install_dir . '/interface/ssl/ispserver.key')) {
             $content = str_replace('{ssl_on}', ' ssl', $content);
             $content = str_replace('{ssl_comment}', '', $content);
             $content = str_replace('{fastcgi_ssl}', 'on', $content);
         } else {
             $content = str_replace('{ssl_on}', '', $content);
             $content = str_replace('{ssl_comment}', '#', $content);
             $content = str_replace('{fastcgi_ssl}', 'off', $content);
         }
         $socket_dir = escapeshellcmd($conf['nginx']['php_fpm_socket_dir']);
         if (substr($socket_dir, -1) != '/') {
             $socket_dir .= '/';
         }
         if (!is_dir($socket_dir)) {
             exec('mkdir -p ' . $socket_dir);
         }
         $fpm_socket = $socket_dir . 'ispconfig.sock';
         //$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
         $content = str_replace('{fpm_socket}', $fpm_socket, $content);
         wf($vhost_conf_dir . '/ispconfig.vhost', $content);
         unset($content);
         // PHP-FPM
         // Dont just copy over the php-fpm pool template but add some custom settings
         $content = rf('tpl/php_fpm_pool.conf.master');
         $content = str_replace('{fpm_pool}', 'ispconfig', $content);
         //$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
         $content = str_replace('{fpm_socket}', $fpm_socket, $content);
         $content = str_replace('{fpm_user}', 'ispconfig', $content);
         $content = str_replace('{fpm_group}', 'ispconfig', $content);
         wf($conf['nginx']['php_fpm_pool_dir'] . '/ispconfig.conf', $content);
         //copy('tpl/nginx_ispconfig.vhost.master', $vhost_conf_dir.'/ispconfig.vhost');
         //* and create the symlink
         if ($this->install_ispconfig_interface == true && $this->is_update == false) {
             if (@is_link($vhost_conf_enabled_dir . '/ispconfig.vhost')) {
                 unlink($vhost_conf_enabled_dir . '/ispconfig.vhost');
             }
             if (!@is_link($vhost_conf_enabled_dir . '/000-ispconfig.vhost')) {
                 symlink($vhost_conf_dir . '/ispconfig.vhost', $vhost_conf_enabled_dir . '/000-ispconfig.vhost');
             }
         }
     }
     //* Install the update script
     if (is_file('/usr/local/bin/ispconfig_update_from_svn.sh')) {
         unlink('/usr/local/bin/ispconfig_update_from_svn.sh');
     }
     chown($install_dir . '/server/scripts/update_from_svn.sh', 'root');
     chmod($install_dir . '/server/scripts/update_from_svn.sh', 0700);
     chown($install_dir . '/server/scripts/update_from_tgz.sh', 'root');
     chmod($install_dir . '/server/scripts/update_from_tgz.sh', 0700);
     chown($install_dir . '/server/scripts/ispconfig_update.sh', 'root');
     chmod($install_dir . '/server/scripts/ispconfig_update.sh', 0700);
     if (!is_link('/usr/local/bin/ispconfig_update_from_svn.sh')) {
         symlink($install_dir . '/server/scripts/ispconfig_update.sh', '/usr/local/bin/ispconfig_update_from_svn.sh');
     }
     if (!is_link('/usr/local/bin/ispconfig_update.sh')) {
         symlink($install_dir . '/server/scripts/ispconfig_update.sh', '/usr/local/bin/ispconfig_update.sh');
     }
     //* Make the logs readable for the ispconfig user
     if (is_file('/var/log/maillog')) {
         exec('chmod +r /var/log/maillog');
     }
     if (is_file('/var/log/messages')) {
         exec('chmod +r /var/log/messages');
     }
     if (is_file('/var/log/clamav/clamav.log')) {
         exec('chmod +r /var/log/clamav/clamav.log');
     }
     if (is_file('/var/log/clamav/freshclam.log')) {
         exec('chmod +r /var/log/clamav/freshclam.log');
     }
     //* Create the ispconfig log directory
     if (!is_dir($conf['ispconfig_log_dir'])) {
         mkdir($conf['ispconfig_log_dir']);
     }
     if (!is_file($conf['ispconfig_log_dir'] . '/ispconfig.log')) {
         touch($conf['ispconfig_log_dir'] . '/ispconfig.log');
     }
     rename($install_dir . '/server/scripts/run-getmail.sh', '/usr/local/bin/run-getmail.sh');
     if (is_user('getmail')) {
         chown('/usr/local/bin/run-getmail.sh', 'getmail');
     }
     chmod('/usr/local/bin/run-getmail.sh', 0744);
 }
示例#5
0
 public function configure_dbserver()
 {
     global $conf;
     //* If this server shall act as database server for client DB's, we configure this here
     $install_dir = $conf['ispconfig_install_dir'];
     // Create a file with the database login details which
     // are used to create the client databases.
     if (!is_dir("{$install_dir}/server/lib")) {
         $command = "mkdir {$install_dir}/server/lib";
         caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     }
     $content = rf("tpl/mysql_clientdb.conf.master");
     $content = str_replace('{username}', $conf['mysql']['admin_user'], $content);
     $content = str_replace('{password}', $conf['mysql']['admin_password'], $content);
     wf("{$install_dir}/server/lib/mysql_clientdb.conf", $content);
     exec('chmod 600 ' . "{$install_dir}/server/lib/mysql_clientdb.conf");
     exec('chown root:root ' . "{$install_dir}/server/lib/mysql_clientdb.conf");
 }
示例#6
0
 public function configure_dovecot()
 {
     global $conf;
     $config_dir = $conf['dovecot']['config_dir'];
     //* Configure master.cf and add a line for deliver
     if (is_file($config_dir . '/master.cf')) {
         copy($config_dir . '/master.cf', $config_dir . '/master.cf~2');
     }
     if (is_file($config_dir . '/master.cf~')) {
         chmod($config_dir . '/master.cf~2', 0400);
     }
     $content = rf($conf["postfix"]["config_dir"] . '/master.cf');
     // Only add the content if we had not addded it before
     if (!stristr($content, "dovecot/deliver")) {
         $deliver_content = 'dovecot   unix  -       n       n       -       -       pipe' . "\n" . '  flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -f ${sender} -d ${user}@${nexthop}';
         af($conf["postfix"]["config_dir"] . '/master.cf', $deliver_content);
     }
     unset($content);
     unset($deliver_content);
     //* Reconfigure postfix to use dovecot authentication
     // Adding the amavisd commands to the postfix configuration
     $postconf_commands = array('dovecot_destination_recipient_limit = 1', 'virtual_transport = dovecot', 'smtpd_sasl_type = dovecot', 'smtpd_sasl_path = private/auth');
     // Make a backup copy of the main.cf file
     copy($conf["postfix"]["config_dir"] . '/main.cf', $conf["postfix"]["config_dir"] . '/main.cf~3');
     // Executing the postconf commands
     foreach ($postconf_commands as $cmd) {
         $command = "postconf -e '{$cmd}'";
         caselog($command . " &> /dev/null", __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     }
     //* copy dovecot.conf
     $configfile = 'dovecot.conf';
     if (is_file($config_dir . '/' . $configfile)) {
         copy($config_dir . '/' . $configfile, $config_dir . '/' . $configfile . '~');
     }
     //* Get the dovecot version
     exec('dovecot --version', $tmp);
     $dovecot_version = $tmp[0];
     unset($tmp);
     //* Copy dovecot configuration file
     if (version_compare($dovecot_version, 2) >= 0) {
         if (is_file($conf['ispconfig_install_dir'] . '/server/conf-custom/install/debian6_dovecot2.conf.master')) {
             copy($conf['ispconfig_install_dir'] . '/server/conf-custom/install/debian6_dovecot2.conf.master', $config_dir . '/' . $configfile);
         } else {
             copy('tpl/debian6_dovecot2.conf.master', $config_dir . '/' . $configfile);
         }
         replaceLine($config_dir . '/' . $configfile, 'postmaster_address = postmaster@example.com', 'postmaster_address = postmaster@' . $conf['hostname'], 1, 0);
         if (version_compare($dovecot_version, 2.1) < 0) {
             removeLine($config_dir . '/' . $configfile, 'ssl_protocols =');
         }
     } else {
         if (is_file($conf['ispconfig_install_dir'] . '/server/conf-custom/install/debian6_dovecot.conf.master')) {
             copy($conf['ispconfig_install_dir'] . '/server/conf-custom/install/debian6_dovecot.conf.master', $config_dir . '/' . $configfile);
         } else {
             copy('tpl/debian6_dovecot.conf.master', $config_dir . '/' . $configfile);
         }
     }
     //* dovecot-sql.conf
     $configfile = 'dovecot-sql.conf';
     if (is_file($config_dir . '/' . $configfile)) {
         copy($config_dir . '/' . $configfile, $config_dir . '/' . $configfile . '~');
         chmod($config_dir . '/' . $configfile . '~', 0400);
     }
     $content = rfsel($conf['ispconfig_install_dir'] . '/server/conf-custom/install/debian6_dovecot-sql.conf.master', 'tpl/debian6_dovecot-sql.conf.master');
     $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
     $content = str_replace('{mysql_server_ispconfig_password}', $conf['mysql']['ispconfig_password'], $content);
     $content = str_replace('{mysql_server_database}', $conf['mysql']['database'], $content);
     $content = str_replace('{mysql_server_host}', $conf['mysql']['host'], $content);
     $content = str_replace('{server_id}', $conf['server_id'], $content);
     wf($config_dir . '/' . $configfile, $content);
     chmod($config_dir . '/' . $configfile, 0600);
     chown($config_dir . '/' . $configfile, 'root');
     chgrp($config_dir . '/' . $configfile, 'root');
     // Dovecot shall ignore mounts in website directory
     if (is_installed('doveadm')) {
         exec("doveadm mount add '/var/www/*' ignore > /dev/null 2> /dev/null");
     }
 }
 public function install_ispconfig()
 {
     global $conf;
     $install_dir = $conf['ispconfig_install_dir'];
     //* Create the ISPConfig installation directory
     if (!is_dir($install_dir)) {
         $command = "mkdir {$install_dir}";
         caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     }
     //* Create a ISPConfig user and group
     if (!is_group('ispconfig')) {
         $command = 'groupadd ispconfig';
         caselog($command . ' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     }
     if (!is_user('ispconfig')) {
         $command = "useradd -g ispconfig -d {$install_dir} ispconfig";
         caselog($command . ' &> /dev/null 2> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     }
     //* copy the ISPConfig interface part
     $command = "cp -rf ../interface {$install_dir}";
     caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     //* copy the ISPConfig server part
     $command = "cp -rf ../server {$install_dir}";
     caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     //* Make a backup of the security settings
     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~');
     }
     //* copy the ISPConfig security part
     $command = 'cp -rf ../security ' . $install_dir;
     caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     //* Apply changed security_settings.ini values to new security_settings.ini file
     if (is_file('/usr/local/ispconfig/security/security_settings.ini~')) {
         $security_settings_old = ini_to_array(file_get_contents('/usr/local/ispconfig/security/security_settings.ini~'));
         $security_settings_new = ini_to_array(file_get_contents('/usr/local/ispconfig/security/security_settings.ini'));
         if (is_array($security_settings_new) && is_array($security_settings_old)) {
             foreach ($security_settings_new as $section => $sval) {
                 if (is_array($sval)) {
                     foreach ($sval as $key => $val) {
                         if (isset($security_settings_old[$section]) && isset($security_settings_old[$section][$key])) {
                             $security_settings_new[$section][$key] = $security_settings_old[$section][$key];
                         }
                     }
                 }
             }
             file_put_contents('/usr/local/ispconfig/security/security_settings.ini', array_to_ini($security_settings_new));
         }
     }
     //* Create the config file for ISPConfig interface
     $configfile = 'config.inc.php';
     $content = $this->get_template_file($configfile, true, true);
     //* get contents & insert db cred
     $content = str_replace('{mysql_master_server_ispconfig_user}', $conf['mysql']['master_ispconfig_user'], $content);
     $content = str_replace('{mysql_master_server_ispconfig_password}', $conf['mysql']['master_ispconfig_password'], $content);
     $content = str_replace('{mysql_master_server_database}', $conf['mysql']['master_database'], $content);
     $content = str_replace('{mysql_master_server_host}', $conf['mysql']['master_host'], $content);
     $content = str_replace('{server_id}', $conf['server_id'], $content);
     $content = str_replace('{ispconfig_log_priority}', $conf['ispconfig_log_priority'], $content);
     $content = str_replace('{language}', $conf['language'], $content);
     $content = str_replace('{timezone}', $conf['timezone'], $content);
     $content = str_replace('{theme}', $conf['theme'], $content);
     $content = str_replace('{language_file_import_enabled}', $conf['language_file_import_enabled'] == true ? 'true' : 'false', $content);
     $this->write_config_file("{$install_dir}/interface/lib/{$configfile}", $content);
     //* Create the config file for ISPConfig server
     $this->write_config_file("{$install_dir}/server/lib/{$configfile}", $content);
     //* Create the config file for remote-actions (but only, if it does not exist, because
     //  the value is a autoinc-value and so changed by the remoteaction_core_module
     if (!file_exists($install_dir . '/server/lib/remote_action.inc.php')) {
         $content = '<?php' . "\n" . '$maxid_remote_action = 0;' . "\n" . '?>';
         wf($install_dir . '/server/lib/remote_action.inc.php', $content);
     }
     // Enable the server modules and plugins.
     // TODO: Implement a selector which modules and plugins shall be enabled.
     $dir = $install_dir . '/server/mods-available/';
     if (is_dir($dir)) {
         if ($dh = opendir($dir)) {
             while (($file = readdir($dh)) !== false) {
                 if ($file != '.' && $file != '..' && substr($file, -8, 8) == '.inc.php') {
                     include_once $install_dir . '/server/mods-available/' . $file;
                     $module_name = substr($file, 0, -8);
                     $tmp = new $module_name();
                     if ($tmp->onInstall()) {
                         if (!@is_link($install_dir . '/server/mods-enabled/' . $file)) {
                             @symlink($install_dir . '/server/mods-available/' . $file, $install_dir . '/server/mods-enabled/' . $file);
                             // @symlink($install_dir.'/server/mods-available/'.$file, '../mods-enabled/'.$file);
                         }
                         if (strpos($file, '_core_module') !== false) {
                             if (!@is_link($install_dir . '/server/mods-core/' . $file)) {
                                 @symlink($install_dir . '/server/mods-available/' . $file, $install_dir . '/server/mods-core/' . $file);
                                 // @symlink($install_dir.'/server/mods-available/'.$file, '../mods-core/'.$file);
                             }
                         }
                     }
                     unset($tmp);
                 }
             }
             closedir($dh);
         }
     }
     $dir = $install_dir . '/server/plugins-available/';
     if (is_dir($dir)) {
         if ($dh = opendir($dir)) {
             while (($file = readdir($dh)) !== false) {
                 if ($conf['apache']['installed'] == true && $file == 'nginx_plugin.inc.php') {
                     continue;
                 }
                 if ($conf['nginx']['installed'] == true && $file == 'apache2_plugin.inc.php') {
                     continue;
                 }
                 if ($file != '.' && $file != '..' && substr($file, -8, 8) == '.inc.php') {
                     include_once $install_dir . '/server/plugins-available/' . $file;
                     $plugin_name = substr($file, 0, -8);
                     $tmp = new $plugin_name();
                     if (method_exists($tmp, 'onInstall') && $tmp->onInstall()) {
                         if (!@is_link($install_dir . '/server/plugins-enabled/' . $file)) {
                             @symlink($install_dir . '/server/plugins-available/' . $file, $install_dir . '/server/plugins-enabled/' . $file);
                         }
                         if (strpos($file, '_core_plugin') !== false) {
                             if (!@is_link($install_dir . '/server/plugins-core/' . $file)) {
                                 @symlink($install_dir . '/server/plugins-available/' . $file, $install_dir . '/server/plugins-core/' . $file);
                             }
                         }
                     }
                     unset($tmp);
                 }
             }
             closedir($dh);
         }
     }
     //* Update the server config
     $mail_server_enabled = $conf['services']['mail'] ? 1 : 0;
     $web_server_enabled = $conf['services']['web'] ? 1 : 0;
     $dns_server_enabled = $conf['services']['dns'] ? 1 : 0;
     $file_server_enabled = $conf['services']['file'] ? 1 : 0;
     $db_server_enabled = $conf['services']['db'] ? 1 : 0;
     $vserver_server_enabled = $conf['services']['vserver'] ? 1 : 0;
     $sql = "UPDATE `server` SET mail_server = '{$mail_server_enabled}', web_server = '{$web_server_enabled}', dns_server = '{$dns_server_enabled}', file_server = '{$file_server_enabled}', db_server = '{$db_server_enabled}', vserver_server = '{$vserver_server_enabled}' WHERE server_id = " . intval($conf['server_id']);
     if ($conf['mysql']['master_slave_setup'] == 'y') {
         $this->dbmaster->query($sql);
         $this->db->query($sql);
     } else {
         $this->db->query($sql);
     }
     // chown install dir to root and chmod 755
     $command = 'chown root:root ' . $install_dir;
     caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     $command = 'chmod 755 ' . $install_dir;
     caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     //* Chmod the files and directories in the install dir
     $command = 'chmod -R 750 ' . $install_dir . '/*';
     caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     //* chown the interface files to the ispconfig user and group
     $command = 'chown -R ispconfig:ispconfig ' . $install_dir . '/interface';
     caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     //* chown the server files to the root user and group
     $command = 'chown -R root:root ' . $install_dir . '/server';
     caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     //* chown the security files to the root user and group
     $command = 'chown -R root:root ' . $install_dir . '/security';
     caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     //* chown the security directory and security_settings.ini to root:ispconfig
     $command = 'chown root:ispconfig ' . $install_dir . '/security/security_settings.ini';
     caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     $command = 'chown root:ispconfig ' . $install_dir . '/security';
     caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     $command = 'chown root:ispconfig ' . $install_dir . '/security/ids.whitelist';
     caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     $command = 'chown root:ispconfig ' . $install_dir . '/security/ids.htmlfield';
     caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     $command = 'chown root:ispconfig ' . $install_dir . '/security/apache_directives.blacklist';
     caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     //* Make the global language file directory group writable
     exec("chmod -R 770 {$install_dir}/interface/lib/lang");
     //* Make the temp directory for language file exports writable
     if (is_dir($install_dir . '/interface/web/temp')) {
         exec("chmod -R 770 {$install_dir}/interface/web/temp");
     }
     //* Make all interface language file directories group writable
     $handle = @opendir($install_dir . '/interface/web');
     while ($file = @readdir($handle)) {
         if ($file != '.' && $file != '..') {
             if (@is_dir($install_dir . '/interface/web' . '/' . $file . '/lib/lang')) {
                 $handle2 = opendir($install_dir . '/interface/web' . '/' . $file . '/lib/lang');
                 chmod($install_dir . '/interface/web' . '/' . $file . '/lib/lang', 0770);
                 while ($lang_file = @readdir($handle2)) {
                     if ($lang_file != '.' && $lang_file != '..') {
                         chmod($install_dir . '/interface/web' . '/' . $file . '/lib/lang/' . $lang_file, 0770);
                     }
                 }
             }
         }
     }
     //* Make the APS directories group writable
     exec("chmod -R 770 {$install_dir}/interface/web/sites/aps_meta_packages");
     exec("chmod -R 770 {$install_dir}/server/aps_packages");
     //* make sure that the server config file (not the interface one) is only readable by the root user
     chmod($install_dir . '/server/lib/config.inc.php', 0600);
     chown($install_dir . '/server/lib/config.inc.php', 'root');
     chgrp($install_dir . '/server/lib/config.inc.php', 'root');
     //* Make sure thet the interface config file is readable by user ispconfig only
     chmod($install_dir . '/interface/lib/config.inc.php', 0600);
     chown($install_dir . '/interface/lib/config.inc.php', 'ispconfig');
     chgrp($install_dir . '/interface/lib/config.inc.php', 'ispconfig');
     chmod($install_dir . '/server/lib/remote_action.inc.php', 0600);
     chown($install_dir . '/server/lib/remote_action.inc.php', 'root');
     chgrp($install_dir . '/server/lib/remote_action.inc.php', 'root');
     if (@is_file($install_dir . '/server/lib/mysql_clientdb.conf')) {
         chmod($install_dir . '/server/lib/mysql_clientdb.conf', 0600);
         chown($install_dir . '/server/lib/mysql_clientdb.conf', 'root');
         chgrp($install_dir . '/server/lib/mysql_clientdb.conf', 'root');
     }
     if (is_dir($install_dir . '/interface/invoices')) {
         exec('chmod -R 770 ' . escapeshellarg($install_dir . '/interface/invoices'));
         exec('chown -R ispconfig:ispconfig ' . escapeshellarg($install_dir . '/interface/invoices'));
     }
     exec('chown -R root:root /usr/local/ispconfig/interface/ssl');
     // TODO: FIXME: add the www-data user to the ispconfig group. This is just for testing
     // and must be fixed as this will allow the apache user to read the ispconfig files.
     // Later this must run as own apache server or via suexec!
     if ($conf['apache']['installed'] == true) {
         $command = 'usermod -a -G ispconfig ' . $conf['apache']['user'];
         caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
         if (is_group('ispapps')) {
             $command = 'usermod -a -G ispapps ' . $conf['apache']['user'];
             caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
         }
     }
     if ($conf['nginx']['installed'] == true) {
         $command = 'usermod -a -G ispconfig ' . $conf['nginx']['user'];
         caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
         if (is_group('ispapps')) {
             $command = 'usermod -a -G ispapps ' . $conf['nginx']['user'];
             caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
         }
     }
     //* Make the shell scripts executable
     $command = "chmod +x {$install_dir}/server/scripts/*.sh";
     caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     if ($conf['apache']['installed'] == true && $this->install_ispconfig_interface == true) {
         //* Copy the ISPConfig vhost for the controlpanel
         $content = $this->get_template_file("apache_ispconfig.vhost", true);
         $content = str_replace('{vhost_port}', $conf['apache']['vhost_port'], $content);
         //* comment out the listen directive if port is 80 or 8443
         if ($conf['apache']['vhost_port'] == 80 or $conf['apache']['vhost_port'] == 8443) {
             $content = str_replace('{vhost_port_listen}', '#', $content);
         } else {
             $content = str_replace('{vhost_port_listen}', '', $content);
         }
         if (is_file($install_dir . '/interface/ssl/ispserver.crt') && is_file($install_dir . '/interface/ssl/ispserver.key')) {
             $content = str_replace('{ssl_comment}', '', $content);
         } else {
             $content = str_replace('{ssl_comment}', '#', $content);
         }
         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')) {
             $content = str_replace('{ssl_bundle_comment}', '', $content);
         } else {
             $content = str_replace('{ssl_bundle_comment}', '#', $content);
         }
         $vhost_path = $conf['apache']['vhost_conf_dir'] . '/ispconfig.vhost';
         $this->write_config_file($vhost_path, $content);
         if (!is_file('/home/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter')) {
             $content = rfsel($conf['ispconfig_install_dir'] . '/server/conf-custom/install/apache_ispconfig_fcgi_starter.master', 'tpl/apache_ispconfig_fcgi_starter.master');
             $content = str_replace('{fastcgi_bin}', $conf['fastcgi']['fastcgi_bin'], $content);
             $content = str_replace('{fastcgi_phpini_path}', $conf['fastcgi']['fastcgi_phpini_path'], $content);
             @mkdir('/home/www/php-fcgi-scripts/ispconfig', 0755, true);
             wf('/home/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter', $content);
             exec('chmod +x /home/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter');
             chmod('/home/www/php-fcgi-scripts/ispconfig/.php-fcgi-starter', 0755);
             @symlink($install_dir . '/interface/web', '/home/www/ispconfig');
             exec('chown -R ispconfig:ispconfig /home/www/php-fcgi-scripts/ispconfig');
         }
     }
     if ($conf['nginx']['installed'] == true && $this->install_ispconfig_interface == true) {
         //* Copy the ISPConfig vhost for the controlpanel
         $vhost_conf_dir = $conf['nginx']['vhost_conf_dir'];
         $vhost_conf_enabled_dir = $conf['nginx']['vhost_conf_enabled_dir'];
         // Dont just copy over the virtualhost template but add some custom settings
         $content = rfsel($conf['ispconfig_install_dir'] . '/server/conf-custom/install/nginx_ispconfig.vhost.master', 'tpl/nginx_ispconfig.vhost.master');
         $content = str_replace('{vhost_port}', $conf['nginx']['vhost_port'], $content);
         if (is_file($install_dir . '/interface/ssl/ispserver.crt') && is_file($install_dir . '/interface/ssl/ispserver.key')) {
             $content = str_replace('{ssl_on}', ' on', $content);
             $content = str_replace('{ssl_comment}', '', $content);
             $content = str_replace('{fastcgi_ssl}', 'on', $content);
         } else {
             $content = str_replace('{ssl_on}', ' off', $content);
             $content = str_replace('{ssl_comment}', '#', $content);
             $content = str_replace('{fastcgi_ssl}', 'off', $content);
         }
         $socket_dir = escapeshellcmd($conf['nginx']['php_fpm_socket_dir']);
         if (substr($socket_dir, -1) != '/') {
             $socket_dir .= '/';
         }
         if (!is_dir($socket_dir)) {
             exec('mkdir -p ' . $socket_dir);
         }
         $fpm_socket = $socket_dir . 'ispconfig.sock';
         //$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
         $content = str_replace('{fpm_socket}', $fpm_socket, $content);
         wf($vhost_conf_dir . '/ispconfig.vhost', $content);
         unset($content);
         // PHP-FPM
         // Dont just copy over the php-fpm pool template but add some custom settings
         $content = rfsel($conf['ispconfig_install_dir'] . '/server/conf-custom/install/php_fpm_pool.conf.master', 'tpl/php_fpm_pool.conf.master');
         $content = str_replace('{fpm_pool}', 'ispconfig', $content);
         //$content = str_replace('{fpm_port}', $conf['nginx']['php_fpm_start_port'], $content);
         $content = str_replace('{fpm_socket}', $fpm_socket, $content);
         $content = str_replace('{fpm_user}', 'ispconfig', $content);
         $content = str_replace('{fpm_group}', 'ispconfig', $content);
         wf($conf['nginx']['php_fpm_pool_dir'] . '/ispconfig.conf', $content);
         //copy('tpl/nginx_ispconfig.vhost.master', $vhost_conf_dir.'/ispconfig.vhost');
         //* and create the symlink
         if ($this->is_update == false) {
             if (@is_link($vhost_conf_enabled_dir . '/ispconfig.vhost')) {
                 unlink($vhost_conf_enabled_dir . '/ispconfig.vhost');
             }
             if (!@is_link($vhost_conf_enabled_dir . '/000-ispconfig.vhost')) {
                 symlink($vhost_conf_dir . '/ispconfig.vhost', $vhost_conf_enabled_dir . '/000-ispconfig.vhost');
             }
         }
     }
     //* Install the update script
     if (is_file('/usr/local/bin/ispconfig_update_from_dev.sh')) {
         unlink('/usr/local/bin/ispconfig_update_from_dev.sh');
     }
     chown($install_dir . '/server/scripts/update_from_dev.sh', 'root');
     chmod($install_dir . '/server/scripts/update_from_dev.sh', 0700);
     chown($install_dir . '/server/scripts/update_from_tgz.sh', 'root');
     chmod($install_dir . '/server/scripts/update_from_tgz.sh', 0700);
     chown($install_dir . '/server/scripts/ispconfig_update.sh', 'root');
     chmod($install_dir . '/server/scripts/ispconfig_update.sh', 0700);
     if (!is_link('/usr/local/bin/ispconfig_update_from_dev.sh')) {
         symlink($install_dir . '/server/scripts/ispconfig_update.sh', '/usr/local/bin/ispconfig_update_from_dev.sh');
     }
     if (!is_link('/usr/local/bin/ispconfig_update.sh')) {
         symlink($install_dir . '/server/scripts/ispconfig_update.sh', '/usr/local/bin/ispconfig_update.sh');
     }
     //* Make the logs readable for the ispconfig user
     if (is_file('/var/log/maillog')) {
         exec('chmod +r /var/log/maillog');
     }
     if (is_file('/var/log/messages')) {
         exec('chmod +r /var/log/messages');
     }
     if (is_file('/var/log/clamav/clamav.log')) {
         exec('chmod +r /var/log/clamav/clamav.log');
     }
     if (is_file('/var/log/clamav/freshclam.log')) {
         exec('chmod +r /var/log/clamav/freshclam.log');
     }
     //* Create the ispconfig log directory
     if (!is_dir($conf['ispconfig_log_dir'])) {
         mkdir($conf['ispconfig_log_dir']);
     }
     if (!is_file($conf['ispconfig_log_dir'] . '/ispconfig.log')) {
         touch($conf['ispconfig_log_dir'] . '/ispconfig.log');
     }
     //* Create the ispconfig auth log file and set uid/gid
     if (!is_file($conf['ispconfig_log_dir'] . '/auth.log')) {
         touch($conf['ispconfig_log_dir'] . '/auth.log');
     }
     exec('chown ispconfig:ispconfig ' . $conf['ispconfig_log_dir'] . '/auth.log');
     exec('chmod 660 ' . $conf['ispconfig_log_dir'] . '/auth.log');
     rename($install_dir . '/server/scripts/run-getmail.sh', '/usr/local/bin/run-getmail.sh');
     if (is_user('getmail')) {
         chown('/usr/local/bin/run-getmail.sh', 'getmail');
     }
     chmod('/usr/local/bin/run-getmail.sh', 0744);
     //* Remove Domain module as its functions are available in the client module now
     if (@is_dir('/usr/local/ispconfig/interface/web/domain')) {
         exec('rm -rf /usr/local/ispconfig/interface/web/domain');
     }
     // Add symlink for patch tool
     if (!is_link('/usr/local/bin/ispconfig_patch')) {
         exec('ln -s /usr/local/ispconfig/server/scripts/ispconfig_patch /usr/local/bin/ispconfig_patch');
     }
     // Change mode of a few files from amavisd
     if (is_file($conf['amavis']['config_dir'] . '/conf.d/50-user')) {
         chmod($conf['amavis']['config_dir'] . '/conf.d/50-user', 0640);
     }
     if (is_file($conf['amavis']['config_dir'] . '/50-user~')) {
         chmod($conf['amavis']['config_dir'] . '/50-user~', 0400);
     }
     if (is_file($conf['amavis']['config_dir'] . '/amavisd.conf')) {
         chmod($conf['amavis']['config_dir'] . '/amavisd.conf', 0640);
     }
     if (is_file($conf['amavis']['config_dir'] . '/amavisd.conf~')) {
         chmod($conf['amavis']['config_dir'] . '/amavisd.conf~', 0400);
     }
 }
 public function configure_dbserver()
 {
     global $conf;
     //* If this server shall act as database server for client DB's, we configure this here
     $install_dir = $conf['ispconfig_install_dir'];
     // Create a file with the database login details which
     // are used to create the client databases.
     if (!is_dir($install_dir . '/server/lib')) {
         $command = "mkdir {$install_dir}/server/lib";
         caselog($command . ' &> /dev/null', __FILE__, __LINE__, "EXECUTED: {$command}", "Failed to execute the command {$command}");
     }
     $content = rfsel($conf['ispconfig_install_dir'] . '/server/conf-custom/install/mysql_clientdb.conf.master', 'tpl/mysql_clientdb.conf.master');
     $content = str_replace('{hostname}', $conf['mysql']['host'], $content);
     $content = str_replace('{username}', $conf['mysql']['admin_user'], $content);
     $content = str_replace('{password}', addslashes($conf['mysql']['admin_password']), $content);
     wf($install_dir . '/server/lib/mysql_clientdb.conf', $content);
     chmod($install_dir . '/server/lib/mysql_clientdb.conf', 0600);
     chown($install_dir . '/server/lib/mysql_clientdb.conf', 'root');
     chgrp($install_dir . '/server/lib/mysql_clientdb.conf', 'root');
 }