From 4986189f63d2f6178ac973f5ac12555e52c0a226 Mon Sep 17 00:00:00 2001
From: ftimme <ft@falkotimme.com>
Date: Mon, 19 Sep 2011 09:21:28 -0400
Subject: [PATCH] Added custom php.ini directives to nginx + PHP-FPM.

---
 server/plugins-available/nginx_plugin.inc.php |   47 ++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/server/plugins-available/nginx_plugin.inc.php b/server/plugins-available/nginx_plugin.inc.php
index 8ff7258..01c9e5c 100644
--- a/server/plugins-available/nginx_plugin.inc.php
+++ b/server/plugins-available/nginx_plugin.inc.php
@@ -640,7 +640,6 @@
 		$vhost_data['web_basedir'] = $web_config['website_basedir'];
 		$vhost_data['security_level'] = $web_config['security_level'];
 		$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);
@@ -1066,7 +1065,7 @@
 			return;
 		}
 		
-		if(!@is_file($pool_dir.'/'.$data['new']['domain'].'.conf') || ($data['old']['domain'] != '' && $data['new']['domain'] != $data['old']['domain'])) {
+		//if(!@is_file($pool_dir.'/'.$data['new']['domain'].'.conf') || ($data['old']['domain'] != '' && $data['new']['domain'] != $data['old']['domain'])) {
 			if ( @is_file($pool_dir.'/'.$data['old']['domain'].'.conf') ) {
 				unlink($pool_dir.'/'.$data['old']['domain'].'.conf');
 			}
@@ -1082,12 +1081,54 @@
 			$tpl->setVar('fpm_port', $web_config['php_fpm_start_port'] + $data['new']['domain_id']);
 			$tpl->setVar('fpm_user', $data['new']['system_user']);
 			$tpl->setVar('fpm_group', $data['new']['system_group']);
+			$php_open_basedir = ($data['new']['php_open_basedir'] == '')?$data['new']['document_root']:$data['new']['php_open_basedir'];
+			$tpl->setVar('php_open_basedir', $php_open_basedir);
+			if($php_open_basedir != ''){
+				$tpl->setVar('enable_php_open_basedir', '');
+			} else {
+				$tpl->setVar('enable_php_open_basedir', ';');
+			}
+			
+			// Custom php.ini settings
+			$final_php_ini_settings = array();
+			$custom_php_ini_settings = trim($data['new']['custom_php_ini']);
+			if($custom_php_ini_settings != ''){
+				// Make sure we only have Unix linebreaks
+				$custom_php_ini_settings = str_replace("\r\n", "\n", $custom_php_ini_settings);
+				$custom_php_ini_settings = str_replace("\r", "\n", $custom_php_ini_settings);
+				$ini_settings = explode("\n", $custom_php_ini_settings);
+				if(is_array($ini_settings) && !empty($ini_settings)){
+					foreach($ini_settings as $ini_setting){
+							list($key, $value) = explode('=', $ini_setting);
+							if($value){
+								$value = trim($value);
+								$key = trim($key);
+								switch (strtolower($value)) {
+									case 'on':
+									case 'off':
+									case '1':
+									case '0':
+									case 'true':
+									case 'false':
+									case 'yes':
+									case 'no':
+										$final_php_ini_settings[] = array('ini_setting' => 'php_admin_flag['.$key.'] = '.$value);
+										break;
+									default:
+										$final_php_ini_settings[] = array('ini_setting' => 'php_admin_value['.$key.'] = '.$value);
+								}
+							}
+					}
+				}
+			}
+			
+			$tpl->setLoop('custom_php_ini_settings', $final_php_ini_settings);
 			
 			file_put_contents($pool_dir.'/'.$data['new']['domain'].'.conf',$tpl->grab());
 			$app->log('Writing the PHP-FPM config file: '.$pool_dir.'/'.$data['new']['domain'].'.conf',LOGLEVEL_DEBUG);
 			unset($tpl);
 			//$reload = true;
-		}
+		//}
 		//if($reload == true) $app->services->restartService('php-fpm','reload');
 	}
 	

--
Gitblit v1.9.1