Florian Schaal
2015-11-14 c8679f3ed2c82c9315f2f8d0c2ba914717b5c3d4
server/plugins-available/nginx_plugin.inc.php
@@ -475,7 +475,8 @@
            }
            
            //* Unmount the old log directory bfore we move the log dir
            exec('umount '.escapeshellcmd($old_dir.'/log'));
            //exec('fuser -km '.escapeshellcmd($old_dir.'/log'));
            exec('umount '.escapeshellcmd($data['old']['document_root'].'/log'));
            //* Create new base directory, if it does not exist yet
            if(!is_dir($new_dir)) $app->system->mkdirpath($new_dir);
@@ -531,6 +532,7 @@
      if(!is_dir($data['new']['document_root'].'/' . $web_folder)) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder);
      if(!is_dir($data['new']['document_root'].'/' . $web_folder . '/error') and $data['new']['errordocs']) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder . '/error');
      if(!is_dir($data['new']['document_root'].'/' . $web_folder . '/stats')) $app->system->mkdirpath($data['new']['document_root'].'/' . $web_folder . '/stats');
      //if(!is_dir($data['new']['document_root'].'/'.$log_folder)) exec('mkdir -p '.$data['new']['document_root'].'/'.$log_folder);
      if(!is_dir($data['new']['document_root'].'/ssl')) $app->system->mkdirpath($data['new']['document_root'].'/ssl');
      if(!is_dir($data['new']['document_root'].'/cgi-bin')) $app->system->mkdirpath($data['new']['document_root'].'/cgi-bin');
@@ -556,6 +558,7 @@
         $app->system->removeLine('/etc/fstab', $fstab_line);
         //* Unmount log directory
         //exec('fuser -km '.escapeshellarg($data['old']['document_root'].'/'.$old_log_folder));
         exec('umount '.escapeshellarg($data['old']['document_root'].'/'.$old_log_folder));
      }
@@ -569,7 +572,8 @@
         $app->system->chmod($data['new']['document_root'].'/'.$log_folder, 0755);
         exec('mount --bind '.escapeshellarg('/var/log/ispconfig/httpd/'.$data['new']['domain']).' '.escapeshellarg($data['new']['document_root'].'/'.$log_folder));
         //* add mountpoint to fstab
         $fstab_line = '/var/log/ispconfig/httpd/'.$data['new']['domain'].' '.$data['new']['document_root'].'/'.$log_folder.'    none    bind,nobootwait,_netdev    0 0';
         $fstab_line = '/var/log/ispconfig/httpd/'.$data['new']['domain'].' '.$data['new']['document_root'].'/'.$log_folder.'    none    bind,nobootwait';
         $fstab_line .= @($web_config['network_filesystem'] == 'y')?',_netdev    0 0':'    0 0';
         $app->system->replaceLine('/etc/fstab', $fstab_line, $fstab_line, 1, 1);
      }
@@ -652,26 +656,28 @@
         }
         if (file_exists($conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2))) {
            exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
            if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
            if(is_file($conf['rootpath'] . '/conf-custom/index/favicon.ico')) {
               exec('cp ' . $conf['rootpath'] . '/conf-custom/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
               if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
            }
            if(is_file($conf['rootpath'] . '/conf-custom/index/robots.txt')) {
               exec('cp ' . $conf['rootpath'] . '/conf-custom/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
               if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
            }
            //if(is_file($conf['rootpath'] . '/conf-custom/index/.htaccess')) {
            //   exec('cp ' . $conf['rootpath'] . '/conf-custom/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
            //}
         }
         else {
         } else {
            if (file_exists($conf['rootpath'] . '/conf-custom/index/standard_index.html')) {
               exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
            }
            else {
               exec('cp ' . $conf['rootpath'] . '/conf/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
               if(is_file($conf['rootpath'] . '/conf/index/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
               if(is_file($conf['rootpath'] . '/conf/index/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
               if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html')) exec('cp ' . $conf['rootpath'] . '/conf-custom/index/standard_index.html '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
            } else {
               if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html')) exec('cp ' . $conf['rootpath'] . '/conf/index/standard_index.html_'.substr(escapeshellcmd($conf['language']), 0, 2).' '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/index.html');
               if(is_file($conf['rootpath'] . '/conf/index/favicon.ico')){
                  if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/favicon.ico')) exec('cp ' . $conf['rootpath'] . '/conf/index/favicon.ico '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
               }
               if(is_file($conf['rootpath'] . '/conf/index/robots.txt')){
                  if(!file_exists(escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/robots.txt')) exec('cp ' . $conf['rootpath'] . '/conf/index/robots.txt '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
               }
               //if(is_file($conf['rootpath'] . '/conf/index/.htaccess')) exec('cp ' . $conf['rootpath'] . '/conf/index/.htaccess '.escapeshellcmd($data['new']['document_root']).'/' . $web_folder . '/');
            }
         }
@@ -902,7 +908,18 @@
      $tpl = new tpl();
      $tpl->newTemplate('nginx_vhost.conf.master');
      // IPv4
      //* use ip-mapping for web-mirror
      if($data['new']['ip_address'] != '*' && $conf['mirror_server_id'] > 0) {
         $sql = "SELECT destination_ip FROM server_ip_map WHERE server_id = ? AND source_ip = ?";
         $newip = $app->db->queryOneRecord($sql, $conf['server_id'], $data['new']['ip_address']);
         $data['new']['ip_address'] = $newip['destination_ip'];
         unset($newip);
      }
      $vhost_data = $data['new'];
      //unset($vhost_data['ip_address']);
      $vhost_data['web_document_root'] = $data['new']['document_root'].'/' . $web_folder;
      $vhost_data['web_document_root_www'] = $web_config['website_basedir'].'/'.$data['new']['domain'].'/' . $web_folder;
@@ -936,7 +953,7 @@
         $default_php_fpm = true;
      }
      */
      if($data['new']['php'] != 'no'){
      if($data['new']['php'] == 'php-fpm'){
         if(trim($data['new']['fastcgi_php_version']) != ''){
            $default_php_fpm = false;
            list($custom_php_fpm_name, $custom_php_fpm_init_script, $custom_php_fpm_ini_dir, $custom_php_fpm_pool_dir) = explode(':', trim($data['new']['fastcgi_php_version']));
@@ -1866,10 +1883,12 @@
         if(is_array($log_folders) && !empty($log_folders)){
            foreach($log_folders as $log_folder){
               //if($app->system->is_mounted($data['old']['document_root'].'/'.$log_folder)) exec('umount '.escapeshellarg($data['old']['document_root'].'/'.$log_folder));
               //exec('fuser -km '.escapeshellarg($data['old']['document_root'].'/'.$log_folder).' 2>/dev/null');
               exec('umount '.escapeshellarg($data['old']['document_root'].'/'.$log_folder).' 2>/dev/null');
            }
         } else {
            //if($app->system->is_mounted($data['old']['document_root'].'/'.$log_folder)) exec('umount '.escapeshellarg($data['old']['document_root'].'/'.$log_folder));
            //exec('fuser -km '.escapeshellarg($data['old']['document_root'].'/'.$log_folder).' 2>/dev/null');
            exec('umount '.escapeshellarg($data['old']['document_root'].'/'.$log_folder).' 2>/dev/null');
         }
      }
@@ -2410,9 +2429,12 @@
         exec('/usr/sbin/update-rc.d hhvm_' . $data['new']['system_user'] . ' defaults >/dev/null 2>&1');
         exec('/etc/init.d/hhvm_' . $data['new']['system_user'] . ' restart >/dev/null 2>&1');
         
         $monit_content = str_replace('{SYSTEM_USER}', $data['new']['system_user'], $monit_content);
         file_put_contents('/etc/monit/conf.d/hhvm_' . $data['new']['system_user'], $monit_content);
         exec('/etc/init.d/monit restart >/dev/null 2>&1');
         if(is_dir('/etc/monit/conf.d')){
            $monit_content = str_replace('{SYSTEM_USER}', $data['new']['system_user'], $monit_content);
            file_put_contents('/etc/monit/conf.d/00-hhvm_' . $data['new']['system_user'], $monit_content);
            if(is_file('/etc/monit/conf.d/hhvm_' . $data['new']['system_user'])) unlink('/etc/monit/conf.d/hhvm_' . $data['new']['system_user']);
            exec('/etc/init.d/monit restart >/dev/null 2>&1');
         }
         
       } elseif($data['new']['php'] != 'hhvm' && $data['old']['php'] == 'hhvm') {
         exec('/etc/init.d/hhvm_' . $data['old']['system_user'] . ' stop >/dev/null 2>&1');
@@ -2420,8 +2442,13 @@
         unlink('/etc/init.d/hhvm_' . $data['old']['system_user']);
         if(is_file('/etc/hhvm/'.$data['old']['system_user'].'.ini')) unlink('/etc/hhvm/'.$data['old']['system_user'].'.ini');
         
         if(is_file('/etc/monit/conf.d/hhvm_' . $data['new']['system_user'])){
            unlink('/etc/monit/conf.d/hhvm_' . $data['new']['system_user']);
         if(is_file('/etc/monit/conf.d/hhvm_' . $data['new']['system_user']) || is_file('/etc/monit/conf.d/00-hhvm_' . $data['new']['system_user'])){
            if(is_file('/etc/monit/conf.d/hhvm_' . $data['new']['system_user'])){
               unlink('/etc/monit/conf.d/hhvm_' . $data['new']['system_user']);
            }
            if(is_file('/etc/monit/conf.d/00-hhvm_' . $data['new']['system_user'])){
               unlink('/etc/monit/conf.d/00-hhvm_' . $data['new']['system_user']);
            }
            exec('/etc/init.d/monit restart >/dev/null 2>&1');
         }
      }
@@ -2440,7 +2467,7 @@
         $default_php_fpm = true;
      }
      */
      if($data['new']['php'] != 'no'){
      if($data['new']['php'] == 'php-fpm'){
         if(trim($data['new']['fastcgi_php_version']) != ''){
            $default_php_fpm = false;
            list($custom_php_fpm_name, $custom_php_fpm_init_script, $custom_php_fpm_ini_dir, $custom_php_fpm_pool_dir) = explode(':', trim($data['new']['fastcgi_php_version']));
@@ -2461,7 +2488,7 @@
      $app->uses("getconf");
      $web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
      if($data['new']['php'] == 'no'){
      if($data['new']['php'] != 'php-fpm'){
         if(@is_file($pool_dir.$pool_name.'.conf')){
            $app->system->unlink($pool_dir.$pool_name.'.conf');
            //$reload = true;