Till Brehm
2014-03-11 11ca0c5316e1c84ace4eb8e40c8d2868f508f13a
install/dist/lib/opensuse.lib.php
@@ -151,6 +151,19 @@
      //* mysql-virtual_relayrecipientmaps.cf
      $this->process_postfix_config('mysql-virtual_relayrecipientmaps.cf');
      //* postfix-dkim
      $full_file_name=$config_dir.'/tag_as_originating.re';
      if(is_file($full_file_name)) {
         copy($full_file_name, $config_dir.$configfile.'~');
      }
      wf($full_file_name, '/^/ FILTER amavis:[127.0.0.1]:10026');
      $full_file_name=$config_dir.'/tag_as_foreign.re';
      if(is_file($full_file_name)) {
         copy($full_file_name, $config_dir.$configfile.'~');
      }
      wf($full_file_name, '/^/ FILTER amavis:[127.0.0.1]:10024');
      //* Changing mode and group of the new created config files.
      caselog('chmod o= '.$config_dir.'/mysql-virtual_*.cf* &> /dev/null',
         __FILE__, __LINE__, 'chmod on mysql-virtual_*.cf*', 'chmod on mysql-virtual_*.cf* failed');
@@ -424,7 +437,7 @@
      // Adding the amavisd commands to the postfix configuration
      $postconf_commands = array (
         'dovecot_destination_recipient_limit = 1',
         'virtual_transport = dovecot',
         'virtual_transport = lmtp:unix:private/dovecot-lmtp',
         'smtpd_sasl_type = dovecot',
         'smtpd_sasl_path = private/auth',
         'receive_override_options = no_address_mappings'
@@ -483,6 +496,9 @@
      exec("chmod 600 $config_dir/$configfile");
      exec("chown root:root $config_dir/$configfile");
      // Dovecot shall ignore mounts in website directory
      exec("doveadm mount add '/srv/www/*' ignore");
   }
@@ -520,16 +536,30 @@
      // 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")) {
        // Only add the content if we had not addded it before
      if(!preg_match('/^amavis\s+unix\s+/m', $content)) {
         unset($content);
         $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/master_cf_amavis.master', "tpl/master_cf_amavis.master");
         af($conf["postfix"]["config_dir"].'/master.cf', $content);
         $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/master_cf_amavis.master', 'tpl/master_cf_amavis.master');
         af($conf['postfix']['config_dir'].'/master.cf', $content);
         $content = rf($conf['postfix']['config_dir'].'/master.cf');
      }
      if(!preg_match('/^127.0.0.1:10025\s+/m', $content)) {
         unset($content);
         $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/master_cf_amavis10025.master', 'tpl/master_cf_amavis10025.master');
         af($conf['postfix']['config_dir'].'/master.cf', $content);
         $content = rf($conf['postfix']['config_dir'].'/master.cf');
      }
      if(!preg_match('/^127.0.0.1:10027\s+/m', $content)) {
         unset($content);
         $content = rfsel($conf['ispconfig_install_dir'].'/server/conf-custom/install/master_cf_amavis10027.master', 'tpl/master_cf_amavis10027.master');
         af($conf['postfix']['config_dir'].'/master.cf', $content);
      }
      unset($content);
      // Add the clamav user to the vscan group
      exec('groupmod --add-user clamav vscan');
      //exec('groupmod --add-user clamav vscan');
      $command = 'usermod -a -G clamav vscan';
      caselog($command." &> /dev/null", __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
   }
@@ -647,7 +677,7 @@
      $content = rf('/etc/apache2/httpd.conf');
      if(!stristr($content, 'Include /etc/apache2/sites-enabled/')) {
         af('/etc/apache2/httpd.conf', "\n<Directory /srv/www>\n    Options FollowSymlinks\n</Directory>\n\nInclude /etc/apache2/sites-enabled/\n\n");
         af('/etc/apache2/httpd.conf', "\n<Directory /srv/www>\n    Options +FollowSymlinks\n</Directory>\n\nInclude /etc/apache2/sites-enabled/\n\n");
      }
      unset($content);
@@ -655,10 +685,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') {
@@ -671,15 +703,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);
                  }
               }
            }
         }
      }
      $content .= "\n";
      wf($vhost_conf_dir.'/ispconfig.conf', $content);
      if(count($ip_addresses) > 0) $tpl->setLoop('ip_adresses',$ip_addresses);
      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");
@@ -1051,18 +1085,22 @@
      // 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 = 'groupmod --add-user '.$conf['apache']['user'].' ispconfig';
         //$command = 'groupmod --add-user '.$conf['apache']['user'].' ispconfig';
         $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 = 'groupmod --add-user '.$conf['apache']['user'].' ispapps';
            //$command = 'groupmod --add-user '.$conf['apache']['user'].' 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 = 'groupmod --add-user '.$conf['nginx']['user'].' ispconfig';
         //$command = 'groupmod --add-user '.$conf['nginx']['user'].' ispconfig';
          $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 = 'groupmod --add-user '.$conf['nginx']['user'].' ispapps';
            //$command = 'groupmod --add-user '.$conf['nginx']['user'].' ispapps';
            $command = 'usermod -a -G ispapps '.$conf['nginx']['user'];
            caselog($command.' &> /dev/null', __FILE__, __LINE__, "EXECUTED: $command", "Failed to execute the command $command");
         }
      }
@@ -1080,31 +1118,32 @@
         // 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());
         $content = $tpl->grab();
         $content = str_replace('/var/www/', '/srv/www/', $content);
         wf("$vhost_conf_dir/ispconfig.vhost", $content);
         wf($vhost_conf_dir.'/ispconfig.vhost', $content);
         //if(!is_file('/srv/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');
@@ -1193,14 +1232,14 @@
      //exec('chmod +r /var/log/clamav/freshclam.log');
      //* Install the update script
      if(is_file('/usr/local/bin/ispconfig_update_from_svn.sh')) unlink('/usr/local/bin/ispconfig_update_from_svn.sh');
      exec('chown root /usr/local/ispconfig/server/scripts/update_from_svn.sh');
      exec('chmod 700 /usr/local/ispconfig/server/scripts/update_from_svn.sh');
      if(is_file('/usr/local/bin/ispconfig_update_from_dev.sh')) unlink('/usr/local/bin/ispconfig_update_from_dev.sh');
      exec('chown root /usr/local/ispconfig/server/scripts/update_from_dev.sh');
      exec('chmod 700 /usr/local/ispconfig/server/scripts/update_from_dev.sh');
      exec('chown root /usr/local/ispconfig/server/scripts/update_from_tgz.sh');
      exec('chmod 700 /usr/local/ispconfig/server/scripts/update_from_tgz.sh');
      exec('chown root /usr/local/ispconfig/server/scripts/ispconfig_update.sh');
      exec('chmod 700 /usr/local/ispconfig/server/scripts/ispconfig_update.sh');
      if(!is_link('/usr/local/bin/ispconfig_update_from_svn.sh')) exec('ln -s /usr/local/ispconfig/server/scripts/ispconfig_update.sh /usr/local/bin/ispconfig_update_from_svn.sh');
      if(!is_link('/usr/local/bin/ispconfig_update_from_dev.sh')) exec('ln -s /usr/local/ispconfig/server/scripts/ispconfig_update.sh /usr/local/bin/ispconfig_update_from_dev.sh');
      if(!is_link('/usr/local/bin/ispconfig_update.sh')) exec('ln -s /usr/local/ispconfig/server/scripts/ispconfig_update.sh /usr/local/bin/ispconfig_update.sh');
      //set the fast cgi starter script to executable