From e631410a14d68c6c54242cf833c0de9c79bc09dd Mon Sep 17 00:00:00 2001
From: tbrehm <t.brehm@ispconfig.org>
Date: Wed, 21 Jul 2010 11:41:48 -0400
Subject: [PATCH] Fixed: FS#1220 - /var/vmail/(domain)/(user) directories and files not delete when mail_user is deleted via remote.

---
 server/plugins-available/apache2_plugin.inc.php |   96 +++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 87 insertions(+), 9 deletions(-)

diff --git a/server/plugins-available/apache2_plugin.inc.php b/server/plugins-available/apache2_plugin.inc.php
index 61202c6..2f106ef 100644
--- a/server/plugins-available/apache2_plugin.inc.php
+++ b/server/plugins-available/apache2_plugin.inc.php
@@ -543,7 +543,30 @@
 		$this->_exec("chown $username:$groupname ".escapeshellcmd($data["new"]["document_root"])."/log/error.log");
 
 
-		// Create the vhost config file
+		//* Write the custom php.ini file, if custom_php_ini filed is not empty
+		$custom_php_ini_dir = $web_config['website_basedir'].'/conf/'.$data["new"]["system_user"];
+		if(!is_dir($web_config['website_basedir'].'/conf')) mkdir($web_config['website_basedir'].'/conf');
+		if(trim($data["new"]['custom_php_ini']) != '') {
+			$has_custom_php_ini = true;
+			if(!is_dir($custom_php_ini_dir)) mkdir($custom_php_ini_dir);
+			$php_ini_content = '';
+			if($data["new"]['php'] == 'mod') {
+				$master_php_ini_path = $web_config['php_ini_path_apache'];
+			} else {
+				$master_php_ini_path = $web_config['php_ini_path_cgi'];
+			}
+			if($master_php_ini_path != '' && substr($master_php_ini_path,-7) == 'php.ini' && is_file($master_php_ini_path)) {
+				$php_ini_content .= file_get_contents($master_php_ini_path)."\n";
+			}
+			$php_ini_content .= trim($data["new"]['custom_php_ini']);
+			file_put_contents($custom_php_ini_dir.'/php.ini',$php_ini_content);
+		} else {
+			$has_custom_php_ini = false;
+			if(is_file($custom_php_ini_dir.'/php.ini')) unlink($custom_php_ini_dir.'/php.ini');
+		}
+
+
+		//* Create the vhost config file
 		$app->load('tpl');
 
 		$tpl = new tpl();
@@ -557,6 +580,8 @@
 		$vhost_data["allow_override"] = ($data["new"]["allow_override"] == '')?'All':$data["new"]["allow_override"];
 		$vhost_data["php_open_basedir"] = ($data["new"]["php_open_basedir"] == '')?$data["new"]["document_root"]:$data["new"]["php_open_basedir"];
 		$vhost_data["ssl_domain"] = $data["new"]["ssl_domain"];
+		$vhost_data["has_custom_php_ini"] = $has_custom_php_ini;
+		$vhost_data["custom_php_ini_dir"] = escapeshellcmd($custom_php_ini_dir);
 
 		// Check if a SSL cert exists
 		$ssl_dir = $data["new"]["document_root"]."/ssl";
@@ -709,8 +734,12 @@
 
 			$fcgi_tpl = new tpl();
 			$fcgi_tpl->newTemplate("php-fcgi-starter.master");
-
-			$fcgi_tpl->setVar('php_ini_path',escapeshellcmd($fastcgi_config["fastcgi_phpini_path"]));
+			
+			if($has_custom_php_ini) {
+				$fcgi_tpl->setVar('php_ini_path',escapeshellcmd($custom_php_ini_dir));
+			} else {
+				$fcgi_tpl->setVar('php_ini_path',escapeshellcmd($fastcgi_config["fastcgi_phpini_path"]));
+			}
 			$fcgi_tpl->setVar('document_root',escapeshellcmd($data["new"]["document_root"]));
 			$fcgi_tpl->setVar('php_fcgi_children',escapeshellcmd($fastcgi_config["fastcgi_children"]));
 			$fcgi_tpl->setVar('php_fcgi_max_requests',escapeshellcmd($fastcgi_config["fastcgi_max_requests"]));
@@ -772,6 +801,13 @@
 			//$cgi_tpl->setVar('open_basedir', "/var/www/" . $data["new"]["domain"]);
 			$cgi_tpl->setVar('php_cgi_bin',$cgi_config["cgi_bin"]);
 			$cgi_tpl->setVar('security_level',$web_config["security_level"]);
+			
+			$cgi_tpl->setVar('has_custom_php_ini',$has_custom_php_ini);
+			if($has_custom_php_ini) {
+				$cgi_tpl->setVar('php_ini_path',escapeshellcmd($custom_php_ini_dir));
+			} else {
+				$cgi_tpl->setVar('php_ini_path',escapeshellcmd($fastcgi_config["fastcgi_phpini_path"]));
+			}
 
 			$cgi_starter_script = escapeshellcmd($cgi_starter_path.$cgi_config["cgi_starter_script"]);
 			file_put_contents($cgi_starter_script,$cgi_tpl->grab());
@@ -837,6 +873,11 @@
 				chmod($data["new"]["document_root"].'/.htpasswd_stats',0755);
 				unset($htp_file);
 			}
+		}
+		
+		//* Create awstats configuration
+		if($data["new"]["stats_type"] == 'awstats' && $data["new"]["type"] == "vhost") {
+			$this->awstats_update($data,$web_config);
 		}
 
 
@@ -942,6 +983,11 @@
 			$command .= ' '.$data["old"]["system_user"];
 			exec($command);
 			if($apache_chrooted) $this->_exec("chroot ".escapeshellcmd($web_config['website_basedir'])." ".$command);
+			
+			//* Remove the awstats configuration file
+			if($data["old"]["stats_type"] == 'awstats') {
+				$this->awstats_delete($data,$web_config);
+			}
 
 		}
 	}
@@ -1085,7 +1131,6 @@
 		$changed = false;
 		$in = fopen($filename, 'r');
 		$output = '';
-
 		/*
 		 * read line by line and search for the username and authname
 		*/
@@ -1096,10 +1141,9 @@
 				/*
 				 * found the user. delete or change it?
 				*/
-				if ($pwd != '') {
-					$tmp[2] = $pwdhash;
-					$output .= $tmp[0] . ':' . $tmp[1] . ':' . $tmp[2] . "\n";
-				}
+				if ($pwdhash != '') {
+					$output .= $tmp[0] . ':' . $tmp[1] . ':' . $pwdhash . "\n";
+					}
 				$changed = true;
 			}
 			else {
@@ -1110,7 +1154,7 @@
 		 * if we didn't change anything, we have to add the new user at the end of the file
 		*/
 		if (!$changed) {
-			$output .= $username . ':' . $authname . ':' . md5($username . ':' . $authname . ':' . $pwd) . "\n";
+			$output .= $username . ':' . $authname . ':' . $pwdhash . "\n";
 		}
 		fclose($in);
 
@@ -1198,6 +1242,40 @@
 		file_put_contents($fileName, $output);
 
 	}
+	
+	//* Update the awstats configuration file
+	private function awstats_update ($data,$web_config) {
+		global $app;
+		
+		$awstats_conf_dir = $web_config['awstats_conf_dir'];
+		
+		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");
+			}
+			
+			$content = '';
+			$content .= "Include \"".$awstats_conf_dir."/awstats.conf\"\n";
+			$content .= "LogFile=\"/var/log/ispconfig/httpd/".$data["new"]["domain"]."/access.log\"\n";
+			$content .= "SiteDomain=\"".$data["new"]["domain"]."\"\n";
+			$content .= "HostAliases=\"www.".$data["new"]["domain"]."  localhost 127.0.0.1\"\n";
+			
+			file_put_contents($awstats_conf_dir.'/awstats.'.$data["new"]["domain"].'.conf',$content);
+			$app->log("Created awstats config file: ".$awstats_conf_dir.'/awstats.'.$data["new"]["domain"].'.conf',LOGLEVEL_DEBUG);
+		}
+	}
+	
+	//* Delete the awstats configuration file
+	private function awstats_delete ($data,$web_config) {
+		global $app;
+		
+		$awstats_conf_dir = $web_config['awstats_conf_dir'];
+		
+		if ( @is_file($awstats_conf_dir."/awstats.".$data["old"]["domain"].".conf") ) {
+			unlink($awstats_conf_dir."/awstats.".$data["old"]["domain"].".conf");
+			$app->log("Removed awstats config file: ".$awstats_conf_dir.'/awstats.'.$data["old"]["domain"].'.conf',LOGLEVEL_DEBUG);
+		}
+	}
 
 	//* Wrapper for exec function for easier debugging
 	private function _exec($command) {

--
Gitblit v1.9.1