ftimme
2012-06-07 9d583c3550c8f7afb4987695514f909307fe78c3
server/plugins-available/nginx_plugin.inc.php
@@ -41,7 +41,7 @@
   function onInstall() {
      global $conf;
      if($conf['services']['web'] == true) {
      if($conf['services']['web'] == true && !@is_link('/usr/local/ispconfig/server/plugins-enabled/apache2_plugin.inc.php')) {
         return true;
      } else {
         return false;
@@ -86,6 +86,8 @@
      
      $app->plugins->registerEvent('web_folder_update',$this->plugin_name,'web_folder_update');
      $app->plugins->registerEvent('web_folder_delete',$this->plugin_name,'web_folder_delete');
      $app->plugins->registerEvent('ftp_user_delete',$this->plugin_name,'ftp_user_delete');
   }
   // Handle the creation of SSL certificates
@@ -198,7 +200,7 @@
         if(trim($data["new"]["ssl_request"]) != '') file_put_contents($csr_file,$data["new"]["ssl_request"]);
         if(trim($data["new"]["ssl_cert"]) != '') file_put_contents($crt_file,$data["new"]["ssl_cert"]);
         // for nginx, bundle files have to be appended to the certificate file
         if(trim($data["new"]["ssl_bundle"]) != ''){
         if(trim($data["new"]["ssl_bundle"]) != ''){
            if(file_exists($crt_file)){
               $crt_file_contents = trim(file_get_contents($crt_file));
            } else {
@@ -206,7 +208,7 @@
            }
            if($crt_file_contents != '') $crt_file_contents .= "\n";
            $crt_file_contents .= $data["new"]["ssl_bundle"];
            file_put_contents($crt_file,$crt_file_contents);
            file_put_contents($crt_file,$app->file->unix_nl($crt_file_contents));
            unset($crt_file_contents);
         }
         /* Update the DB of the (local) Server */
@@ -256,7 +258,13 @@
   function update($event_name,$data) {
      global $app, $conf;
      //* Check if the apache plugin is enabled
      if(@is_link('/usr/local/ispconfig/server/plugins-enabled/apache2_plugin.inc.php')) {
         $app->log('The nginx plugin can not be used together with the apache2 plugin..',LOGLEVEL_WARN);
         return 0;
      }
      if($this->action != 'insert') $this->action = 'update';
      if($data['new']['type'] != 'vhost' && $data['new']['parent_domain_id'] > 0) {
@@ -333,8 +341,14 @@
         $tmp_docroot = explode('/',$data['old']['document_root']);
         unset($tmp_docroot[count($tmp_docroot)-1]);
         $old_dir = implode('/',$tmp_docroot);
         exec('rm -rf '.$data['new']['document_root']);
         //* Check if there is already some data in the new docroot and rename it as we need a clean path to move the existing site to the new path
         if(@is_dir($data['new']['document_root'])) {
            rename($data['new']['document_root'],$data['new']['document_root'].'_bak_'.date('Y_m_d'));
            $app->log('Renaming existing directory in new docroot location. mv '.$data['new']['document_root'].' '.$data['new']['document_root'].'_bak_'.date('Y_m_d'),LOGLEVEL_DEBUG);
         }
         //* Create new base directory, if it does not exist yet
         if(!is_dir($new_dir)) exec('mkdir -p '.$new_dir);
         exec('mv '.$data['old']['document_root'].' '.$new_dir);
         $app->log('Moving site to new document root: mv '.$data['old']['document_root'].' '.$new_dir,LOGLEVEL_DEBUG);
@@ -623,9 +637,10 @@
            * website root has to be owned by the root user and we have to chmod it to 755 then
            */
            //* Check if there is a jailkit user for this site
            //* Check if there is a jailkit user or cronjob for this site
            $tmp = $app->db->queryOneRecord('SELECT count(shell_user_id) as number FROM shell_user WHERE parent_domain_id = '.$data['new']['domain_id']." AND chroot = 'jailkit'");
            if($tmp['number'] > 0) {
            $tmp2 = $app->db->queryOneRecord('SELECT count(id) as number FROM cron WHERE parent_domain_id = '.$data['new']['domain_id']." AND `type` = 'chrooted'");
            if($tmp['number'] > 0 || $tmp2['number'] > 0) {
               $this->_exec('chmod 755 '.escapeshellcmd($data['new']['document_root']));
               $this->_exec('chown root:root '.escapeshellcmd($data['new']['document_root']));
            }
@@ -766,7 +781,7 @@
      // Rewrite rules
      $rewrite_rules = array();
      if($data['new']['redirect_type'] != '') {
      if($data['new']['redirect_type'] != '' && $data['new']['redirect_path'] != '') {
         if(substr($data['new']['redirect_path'],-1) != '/') $data['new']['redirect_path'] .= '/';
         if(substr($data['new']['redirect_path'],0,8) == '[scheme]') $data['new']['redirect_path'] = '$scheme'.substr($data['new']['redirect_path'],8);
         /* Disabled path extension
@@ -822,7 +837,7 @@
            }
            $app->log('Add server alias: '.$alias['domain'],LOGLEVEL_DEBUG);
            // Rewriting
            if($alias['redirect_type'] != '') {
            if($alias['redirect_type'] != '' && $alias['redirect_path'] != '') {
               if(substr($alias['redirect_path'],-1) != '/') $alias['redirect_path'] .= '/';
               if(substr($alias['redirect_path'],0,8) == '[scheme]') $alias['redirect_path'] = '$scheme'.substr($alias['redirect_path'],8);
               
@@ -1302,6 +1317,14 @@
      $this->update('web_domain_update', $webdata);
   }
   
   public function ftp_user_delete($event_name,$data) {
      global $app, $conf;
      $ftpquota_file = $data['old']['dir'].'/.ftpquota';
      if(file_exists($ftpquota_file)) unlink($ftpquota_file);
   }
   function _create_web_folder_auth_configuration($website){
      global $app, $conf;
      //* Create the domain.auth file which is included in the vhost configuration file
@@ -1338,6 +1361,7 @@
      
      $awstats_conf_dir = $web_config['awstats_conf_dir'];
      
      if(!is_dir($data['new']['document_root']."/web/stats/")) mkdir($data['new']['document_root']."/web/stats");
      if(!@is_file($awstats_conf_dir.'/awstats.'.$data['new']['domain'].'.conf') || ($data['old']['domain'] != '' && $data['new']['domain'] != $data['old']['domain'])) {
         if ( @is_file($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf') ) {
            unlink($awstats_conf_dir.'/awstats.'.$data['old']['domain'].'.conf');