From d2212dda734bb8c4b899faab848fa1bd7c1bf66e Mon Sep 17 00:00:00 2001 From: tbrehm <t.brehm@ispconfig.org> Date: Sun, 19 Sep 2010 08:01:47 -0400 Subject: [PATCH] Fixed bug in maildirmake function: http://www.howtoforge.com/forums/showthread.php?t=48890 --- server/plugins-available/apache2_plugin.inc.php | 102 ++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 88 insertions(+), 14 deletions(-) diff --git a/server/plugins-available/apache2_plugin.inc.php b/server/plugins-available/apache2_plugin.inc.php index c0fd822..8832d98 100644 --- a/server/plugins-available/apache2_plugin.inc.php +++ b/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")); } @@ -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()); @@ -789,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); @@ -843,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 = ''; @@ -1247,8 +1309,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 -?> \ No newline at end of file +?> -- Gitblit v1.9.1