tbrehm
2010-10-06 e1cfe776605df96751b661e82dc09b51c635d67f
server/plugins-available/apache2_plugin.inc.php
@@ -415,9 +415,9 @@
            }
            else {
               exec("cp /usr/local/ispconfig/server/conf/index/standard_index.html_".substr(escapeshellcmd($conf["language"]),0,2)." ".escapeshellcmd($data["new"]["document_root"])."/web/index.html");
               exec("cp /usr/local/ispconfig/server/conf/index/favicon.ico ".escapeshellcmd($data["new"]["document_root"])."/web/");
               exec("cp /usr/local/ispconfig/server/conf/index/robots.txt ".escapeshellcmd($data["new"]["document_root"])."/web/");
               exec("cp /usr/local/ispconfig/server/conf/index/.htaccess ".escapeshellcmd($data["new"]["document_root"])."/web/");
               if(is_file('/usr/local/ispconfig/server/conf/index/favicon.ico')) exec("cp /usr/local/ispconfig/server/conf/index/favicon.ico ".escapeshellcmd($data["new"]["document_root"])."/web/");
               if(is_file('/usr/local/ispconfig/server/conf/index/robots.txt')) exec("cp /usr/local/ispconfig/server/conf/index/robots.txt ".escapeshellcmd($data["new"]["document_root"])."/web/");
               if(is_file('/usr/local/ispconfig/server/conf/index/.htaccess')) exec("cp /usr/local/ispconfig/server/conf/index/.htaccess ".escapeshellcmd($data["new"]["document_root"])."/web/");
            }
         }
         exec("chmod -R a+r ".escapeshellcmd($data["new"]["document_root"])."/web/");
@@ -489,7 +489,7 @@
         $this->_exec("chmod 751 ".escapeshellcmd($data["new"]["document_root"])."/*");
         $this->_exec("chmod 710 ".escapeshellcmd($data["new"]["document_root"]."/web"));
         // make temp direcory writable for the apache user and the website user
         // make temp directory writable for the apache and website users
         $this->_exec("chmod 777 ".escapeshellcmd($data["new"]["document_root"]."/tmp"));
         $command = 'usermod';
@@ -534,7 +534,7 @@
         $this->_exec("chmod 755 ".escapeshellcmd($data["new"]["document_root"]."/*"));
         $this->_exec("chown root:root ".escapeshellcmd($data["new"]["document_root"]."/"));
         // make temp direcory writable for the apache user and the website user
         // make temp directory writable for the apache and website users
         $this->_exec("chmod 777 ".escapeshellcmd($data["new"]["document_root"]."/tmp"));
      }
@@ -825,6 +825,10 @@
      }
      $vhost_file = escapeshellcmd($web_config["vhost_conf_dir"].'/'.$data["new"]["domain"].'.vhost');
      //* Make a backup copy of vhost file
      copy($vhost_file,$vhost_file.'~');
      //* Write vhost file
      file_put_contents($vhost_file,$tpl->grab());
      $app->log("Writing the vhost file: $vhost_file",LOGLEVEL_DEBUG);
      unset($tpl);
@@ -879,14 +883,36 @@
      if($data["new"]["stats_type"] == 'awstats' && $data["new"]["type"] == "vhost") {
         $this->awstats_update($data,$web_config);
      }
      if($web_config['check_apache_config'] == 'y') {
         //* Test if apache starts with the new configuration file
         $apache_online_status_before_restart = $this->_checkTcp('localhost',80);
         $app->log("Apache status is: ".$apache_online_status_before_restart,LOGLEVEL_DEBUG);
      if($apache_chrooted) {
         $app->services->restartServiceDelayed('httpd','restart');
         $app->services->restartService('httpd','restart');
         //* Check if apache restarted successfully if it was online before
         $apache_online_status_after_restart = $this->_checkTcp('localhost',80);
         $app->log("Apache online status after restart is: ".$apache_online_status_after_restart,LOGLEVEL_DEBUG);
         if($apache_online_status_before_restart && !$apache_online_status_after_restart) {
            $app->log("Apache did not restart after the configuration change for website ".$data["new"]["domain"].' Reverting the configuration. Saved not working config as '.$vhost_file.'.err',LOGLEVEL_WARN);
            copy($vhost_file,$vhost_file.'.err');
            copy($vhost_file.'~',$vhost_file);
            $app->services->restartService('httpd','restart');
         }
      } else {
         // request a httpd reload when all records have been processed
         $app->services->restartServiceDelayed('httpd','reload');
         //* We do not check the apache config after changes (is faster)
         if($apache_chrooted) {
            $app->services->restartServiceDelayed('httpd','restart');
         } else {
            // request a httpd reload when all records have been processed
            $app->services->restartServiceDelayed('httpd','reload');
         }
      }
      // Remove the backup copy of the config file.
      unlink($vhost_file.'~');
      //* Unset action to clean it for next processed vhost.
      $this->action = '';
@@ -901,7 +927,7 @@
      $web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
      //* Check if this is a chrooted setup
      if($web_config['website_basedir'] != '' && @is_file($web_config['/var/www'].'/etc/passwd')) {
      if($web_config['website_basedir'] != '' && @is_file($web_config['website_basedir'].'/etc/passwd')) {
         $apache_chrooted = true;
      } else {
         $apache_chrooted = false;
@@ -1026,13 +1052,14 @@
    */
   public function webdav($event_name,$data) {
      global $app, $conf;
      /*
       * load the server configuration options
      */
      $app->uses("getconf");
      $web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
      if (($event_name == 'webdav_user_insert') || ($event_name == 'webdav_user_update')) {
         /*
          * load the server configuration options
         */
         $app->uses("getconf");
         $web_config = $app->getconf->get_server_config($conf["server_id"], 'web');
         /*
          * Get additional informations
@@ -1108,12 +1135,29 @@
         */
         $sitedata = $app->db->queryOneRecord("SELECT document_root, domain FROM web_domain WHERE domain_id = " . $data['old']['parent_domain_id']);
         $documentRoot = $sitedata['document_root'];
         $domain = $sitedata['domain'];
         /*
          * We dont't want to destroy any (transfer)-Data. So we do NOT delete any dir.
          * So the only thing, we have to do, is to delete the user from the password-file
         */
         $this->_writeHtDigestFile( $documentRoot . '/webdav/' . $data['old']['dir'] . '.htdigest', $data['old']['username'], $data['old']['dir'], '');
         /*
          * Next step, patch the vhost - file
         */
         $vhost_file = escapeshellcmd($web_config["vhost_conf_dir"] . '/' . $domain . '.vhost');
         $this->_patchVhostWebdav($vhost_file, $documentRoot . '/webdav');
         /*
          * Last, restart apache
         */
         if($apache_chrooted) {
            $app->services->restartServiceDelayed('httpd','restart');
         } else {
            // request a httpd reload when all records have been processed
            $app->services->restartServiceDelayed('httpd','reload');
         }
      }
   }
@@ -1129,26 +1173,29 @@
    */
   private function _writeHtDigestFile($filename, $username, $authname, $pwdhash ) {
      $changed = false;
      $in = fopen($filename, 'r');
      $output = '';
      /*
       * read line by line and search for the username and authname
      */
      while (preg_match("/:/", $line = fgets($in))) {
         $line = rtrim($line);
         $tmp = explode(':', $line);
         if ($tmp[0] == $username && $tmp[1] == $authname) {
            /*
             * found the user. delete or change it?
            */
            if ($pwdhash != '') {
               $output .= $tmp[0] . ':' . $tmp[1] . ':' . $pwdhash . "\n";
               }
            $changed = true;
      if(is_file($filename)) {
         $in = fopen($filename, 'r');
         $output = '';
         /*
         * read line by line and search for the username and authname
         */
         while (preg_match("/:/", $line = fgets($in))) {
            $line = rtrim($line);
            $tmp = explode(':', $line);
            if ($tmp[0] == $username && $tmp[1] == $authname) {
               /*
               * found the user. delete or change it?
               */
               if ($pwdhash != '') {
                  $output .= $tmp[0] . ':' . $tmp[1] . ':' . $pwdhash . "\n";
                  }
               $changed = true;
            }
            else {
               $output .= $line . "\n";
            }
         }
         else {
            $output .= $line . "\n";
         }
         fclose($in);
      }
      /*
       * if we didn't change anything, we have to add the new user at the end of the file
@@ -1156,12 +1203,16 @@
      if (!$changed) {
         $output .= $username . ':' . $authname . ':' . $pwdhash . "\n";
      }
      fclose($in);
      /*
       * Now lets write the new file
      */
      file_put_contents($filename, $output);
      if(trim($output) == '') {
         unlink($filename);
      } else {
         file_put_contents($filename, $output);
      }
   }
   /**
@@ -1195,7 +1246,8 @@
            /*
             * add all the webdav-dirs to the webdav-section
            */
            $files = scandir($webdavRoot);
            $files = @scandir($webdavRoot);
            if(is_array($files)) {
            foreach($files as $file) {
               if (substr($file, strlen($file) - strlen('.htdigest')) == '.htdigest') {
                  /*
@@ -1215,6 +1267,7 @@
                  $output .= "        Allow from all \n";
                  $output .= "      </Location> \n";
               }
            }
            }
         }
         /*
@@ -1283,8 +1336,20 @@
      $app->log("exec: ".$command,LOGLEVEL_DEBUG);
      exec($command);
   }
   private function _checkTcp ($host,$port) {
      $fp = @fsockopen ($host, $port, $errno, $errstr, 2);
      if ($fp) {
         fclose($fp);
         return true;
      } else {
         return false;
      }
   }
} // end class
?>
?>