Marius Cramer
2014-08-14 ad90a3fa3e169b054c52c5496828f9848a1dd7d5
install/dist/lib/fedora.lib.php
@@ -405,7 +405,6 @@
         'virtual_transport = lmtp:unix:private/dovecot-lmtp',
         'smtpd_sasl_type = dovecot',
         'smtpd_sasl_path = private/auth',
         'receive_override_options = no_address_mappings'
      );
      // Make a backup copy of the main.cf file
@@ -451,6 +450,8 @@
         copy("$config_dir/$configfile", "$config_dir/$configfile~");
         exec("chmod 400 $config_dir/$configfile~");
      }
      if(!@file_exists('/etc/dovecot-sql.conf')) exec('ln -s /etc/dovecot/dovecot-sql.conf /etc/dovecot-sql.conf');
      $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/fedora_dovecot-sql.conf.master', "tpl/fedora_dovecot-sql.conf.master");
      $content = str_replace('{mysql_server_ispconfig_user}', $conf['mysql']['ispconfig_user'], $content);
@@ -461,6 +462,9 @@
      exec("chmod 600 $config_dir/$configfile");
      exec("chown root:root $config_dir/$configfile");
      // Dovecot shall ignore mounts in website directory
      if(is_installed('doveadm')) exec("doveadm mount add '/var/www/*' ignore > /dev/null 2> /dev/null");
   }
@@ -667,10 +671,12 @@
      $vhost_conf_dir = $conf['apache']['vhost_conf_dir'];
      $vhost_conf_enabled_dir = $conf['apache']['vhost_conf_enabled_dir'];
      // copy('tpl/apache_ispconfig.conf.master',$vhost_conf_dir.'/ispconfig.conf');
      $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/apache_ispconfig.conf.master', 'tpl/apache_ispconfig.conf.master');
      $tpl = new tpl('apache_ispconfig.conf.master');
      $tpl->setVar('apache_version',getapacheversion());
      $records = $this->db->queryAllRecords('SELECT * FROM '.$conf['mysql']['master_database'].'.server_ip WHERE server_id = '.$conf['server_id']." AND virtualhost = 'y'");
      $ip_addresses = array();
      if(is_array($records) && count($records) > 0) {
         foreach($records as $rec) {
            if($rec['ip_type'] == 'IPv6') {
@@ -683,15 +689,17 @@
               foreach($ports as $port) {
                  $port = intval($port);
                  if($port > 0 && $port < 65536 && $ip_address != '') {
                     $content .= 'NameVirtualHost '.$ip_address.":".$port."\n";
                     $ip_addresses[] = array('ip_address' => $ip_address, 'port' => $port);
                  }
               }
            }
         }
      }
      if(count($ip_addresses) > 0) $tpl->setLoop('ip_adresses',$ip_addresses);
      $content .= "\n";
      wf($vhost_conf_dir.'/ispconfig.conf', $content);
      wf($vhost_conf_dir.'/ispconfig.conf', $tpl->grab());
      unset($tpl);
      if(!@is_link($vhost_conf_enabled_dir."/000-ispconfig.conf")) {
         exec("ln -s ".$vhost_conf_dir."/ispconfig.conf ".$vhost_conf_enabled_dir."/000-ispconfig.conf");
@@ -1055,28 +1063,30 @@
         // Dont just copy over the virtualhost template but add some custom settings
         $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/apache_ispconfig.vhost.master', "tpl/apache_ispconfig.vhost.master");
         $content = str_replace('{vhost_port}', $conf['apache']['vhost_port'], $content);
         $tpl = new tpl('apache_ispconfig.vhost.master');
         $tpl->setVar('vhost_port',$conf['apache']['vhost_port']);
         // 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);
            $tpl->setVar('vhost_port_listen','#');
         } else {
            $content = str_replace('{vhost_port_listen}', '', $content);
            $tpl->setVar('vhost_port_listen','');
         }
         if(is_file('/usr/local/ispconfig/interface/ssl/ispserver.crt') && is_file('/usr/local/ispconfig/interface/ssl/ispserver.key')) {
            $content = str_replace('{ssl_comment}', '', $content);
         if(is_file($install_dir.'/interface/ssl/ispserver.crt') && is_file($install_dir.'/interface/ssl/ispserver.key')) {
            $tpl->setVar('ssl_comment','');
         } else {
            $content = str_replace('{ssl_comment}', '#', $content);
            $tpl->setVar('ssl_comment','#');
         }
         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);
            $tpl->setVar('ssl_bundle_comment','');
         } else {
            $content = str_replace('{ssl_bundle_comment}', '#', $content);
            $tpl->setVar('ssl_bundle_comment','#');
         }
         $tpl->setVar('apache_version',getapacheversion());
         wf("$vhost_conf_dir/ispconfig.vhost", $content);
         wf($vhost_conf_dir.'/ispconfig.vhost', $tpl->grab());
         //copy('tpl/apache_ispconfig.vhost.master', "$vhost_conf_dir/ispconfig.vhost");
         //* and create the symlink
@@ -1218,94 +1228,11 @@
      //* 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');
   }
   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}', $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");
   }
   public function install_crontab()
   {
      global $conf;
      //* Root Crontab
      exec('crontab -u root -l > crontab.txt');
      $existing_root_cron_jobs = file('crontab.txt');
      // remove existing ispconfig cronjobs, in case the syntax has changed
      foreach($existing_root_cron_jobs as $key => $val) {
         if(stristr($val, '/usr/local/ispconfig')) unset($existing_root_cron_jobs[$key]);
      }
      $root_cron_jobs = array(
         '* * * * * /usr/local/ispconfig/server/server.sh &> /dev/null',
         '30 00 * * * /usr/local/ispconfig/server/cron_daily.sh &> /dev/null'
      );
      if ($conf['nginx']['installed'] == true) {
         $root_cron_jobs[] = "0 0 * * * /usr/local/ispconfig/server/scripts/create_daily_nginx_access_logs.sh &> /dev/null";
      }
      foreach($root_cron_jobs as $cron_job) {
         if(!in_array($cron_job."\n", $existing_root_cron_jobs)) {
            $existing_root_cron_jobs[] = $cron_job."\n";
         }
      }
      file_put_contents('crontab.txt', $existing_root_cron_jobs);
      exec('crontab -u root crontab.txt &> /dev/null');
      unlink('crontab.txt');
      //* Getmail crontab
      if(is_user('getmail')) {
         $cf = $conf['getmail'];
         exec('crontab -u getmail -l > crontab.txt');
         $existing_cron_jobs = file('crontab.txt');
         $cron_jobs = array(
            '*/5 * * * * /usr/local/bin/run-getmail.sh > /dev/null 2>> /dev/null'
         );
         // remove existing ispconfig cronjobs, in case the syntax has changed
         foreach($existing_cron_jobs as $key => $val) {
            if(stristr($val, 'getmail')) unset($existing_cron_jobs[$key]);
         }
         foreach($cron_jobs as $cron_job) {
            if(!in_array($cron_job."\n", $existing_cron_jobs)) {
               $existing_cron_jobs[] = $cron_job."\n";
            }
         }
         file_put_contents('crontab.txt', $existing_cron_jobs);
         exec('crontab -u getmail crontab.txt &> /dev/null');
         unlink('crontab.txt');
      }
      exec('touch /var/log/ispconfig/cron.log');
      exec('chmod 660 /var/log/ispconfig/cron.log');
   }
}
?>