From 4bc030979267303b2ff1668c99af0a4e7089824b Mon Sep 17 00:00:00 2001
From: Michel Kàˆser <mail@michelkaeser.ch>
Date: Sun, 17 May 2015 03:03:48 -0400
Subject: [PATCH] ensure the internal PHP scripts work even if system-wide PHP settings are set that could affect how ISPConfig would work. See FS#3293
---
server/plugins-available/apache2_plugin.inc.php | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 114 insertions(+), 3 deletions(-)
diff --git a/server/plugins-available/apache2_plugin.inc.php b/server/plugins-available/apache2_plugin.inc.php
index 1676a1a..e518f45 100644
--- a/server/plugins-available/apache2_plugin.inc.php
+++ b/server/plugins-available/apache2_plugin.inc.php
@@ -161,6 +161,26 @@
if($master_php_ini_path != '' && substr($master_php_ini_path, -7) == 'php.ini' && is_file($master_php_ini_path)) {
$php_ini_content .= $app->system->file_get_contents($master_php_ini_path)."\n";
}
+
+ if(intval($web_data['directive_snippets_id']) > 0){
+ $snippet = $app->db->queryOneRecord("SELECT * FROM directive_snippets WHERE directive_snippets_id = ? AND type = 'nginx' AND active = 'y' AND customer_viewable = 'y'", intval($web_data['directive_snippets_id']));
+ if(isset($snippet['required_php_snippets']) && trim($snippet['required_php_snippets']) != ''){
+ $required_php_snippets = explode(',', trim($snippet['required_php_snippets']));
+ if(is_array($required_php_snippets) && !empty($required_php_snippets)){
+ foreach($required_php_snippets as $required_php_snippet){
+ $required_php_snippet = intval($required_php_snippet);
+ if($required_php_snippet > 0){
+ $php_snippet = $app->db->queryOneRecord("SELECT * FROM directive_snippets WHERE directive_snippets_id = ? AND type = 'php' AND active = 'y'", $required_php_snippet);
+ $php_snippet['snippet'] = trim($php_snippet['snippet']);
+ if($php_snippet['snippet'] != ''){
+ $web_data['custom_php_ini'] .= "\n".$php_snippet['snippet'];
+ }
+ }
+ }
+ }
+ }
+ }
+
$php_ini_content .= str_replace("\r", '', trim($web_data['custom_php_ini']));
$app->system->file_put_contents($custom_php_ini_dir.'/php.ini', $php_ini_content);
$app->log('Info: rewrote custom php.ini for web ' . $web_data['domain_id'] . ' (' . $web_data['domain'] . ').', LOGLEVEL_DEBUG);
@@ -1008,6 +1028,26 @@
$php_ini_content .= $app->system->file_get_contents($master_php_ini_path)."\n";
}
$php_ini_content .= str_replace("\r", '', trim($data['new']['custom_php_ini']));
+
+ if(intval($data['new']['directive_snippets_id']) > 0){
+ $snippet = $app->db->queryOneRecord("SELECT * FROM directive_snippets WHERE directive_snippets_id = ? AND type = 'nginx' AND active = 'y' AND customer_viewable = 'y'", intval($data['new']['directive_snippets_id']));
+ if(isset($snippet['required_php_snippets']) && trim($snippet['required_php_snippets']) != ''){
+ $required_php_snippets = explode(',', trim($snippet['required_php_snippets']));
+ if(is_array($required_php_snippets) && !empty($required_php_snippets)){
+ foreach($required_php_snippets as $required_php_snippet){
+ $required_php_snippet = intval($required_php_snippet);
+ if($required_php_snippet > 0){
+ $php_snippet = $app->db->queryOneRecord("SELECT * FROM directive_snippets WHERE directive_snippets_id = ? AND type = 'php' AND active = 'y'", $required_php_snippet);
+ $php_snippet['snippet'] = trim($php_snippet['snippet']);
+ if($php_snippet['snippet'] != ''){
+ $php_ini_content .= "\n".$php_snippet['snippet'];
+ }
+ }
+ }
+ }
+ }
+ }
+
$app->system->file_put_contents($custom_php_ini_dir.'/php.ini', $php_ini_content);
} else {
$has_custom_php_ini = false;
@@ -1383,6 +1423,7 @@
} else {
$pool_dir = $custom_php_fpm_pool_dir;
}
+ $pool_dir = trim($pool_dir);
if(substr($pool_dir, -1) != '/') $pool_dir .= '/';
$pool_name = 'web'.$data['new']['domain_id'];
$socket_dir = escapeshellcmd($web_config['php_fpm_socket_dir']);
@@ -2759,23 +2800,70 @@
} else {
$content = file_get_contents($conf['rootpath'] . '/conf/hhvm_starter.master');
}
+ if(file_exists($conf['rootpath'] . '/conf-custom/hhvm_monit.master')) {
+ $monit_content = file_get_contents($conf['rootpath'] . '/conf-custom/hhvm_monit.master');
+ } else {
+ $monit_content = file_get_contents($conf['rootpath'] . '/conf/hhvm_monit.master');
+ }
- if($data['new']['php'] == 'hhvm' && $data['old']['php'] != 'hhvm') {
+ if($data['new']['php'] == 'hhvm' && $data['old']['php'] != 'hhvm' || $data['new']['custom_php_ini'] != $data['old']['custom_php_ini']) {
+
+ // Custom php.ini settings
+ $custom_php_ini_settings = trim($data['new']['custom_php_ini']);
+ if(intval($data['new']['directive_snippets_id']) > 0){
+ $snippet = $app->db->queryOneRecord("SELECT * FROM directive_snippets WHERE directive_snippets_id = ? AND type = 'nginx' AND active = 'y' AND customer_viewable = 'y'", intval($data['new']['directive_snippets_id']));
+ if(isset($snippet['required_php_snippets']) && trim($snippet['required_php_snippets']) != ''){
+ $required_php_snippets = explode(',', trim($snippet['required_php_snippets']));
+ if(is_array($required_php_snippets) && !empty($required_php_snippets)){
+ foreach($required_php_snippets as $required_php_snippet){
+ $required_php_snippet = intval($required_php_snippet);
+ if($required_php_snippet > 0){
+ $php_snippet = $app->db->queryOneRecord("SELECT * FROM directive_snippets WHERE directive_snippets_id = ? AND type = 'php' AND active = 'y'", $required_php_snippet);
+ $php_snippet['snippet'] = trim($php_snippet['snippet']);
+ if($php_snippet['snippet'] != ''){
+ $custom_php_ini_settings .= "\n".$php_snippet['snippet'];
+ }
+ }
+ }
+ }
+ }
+ }
+ 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);
+ file_put_contents('/etc/hhvm/'.$data['new']['system_user'].'.ini', $custom_php_ini_settings);
+ } else {
+ if(is_file('/etc/hhvm/'.$data['old']['system_user'].'.ini')) unlink('/etc/hhvm/'.$data['old']['system_user'].'.ini');
+ }
+
$content = str_replace('{SYSTEM_USER}', $data['new']['system_user'], $content);
file_put_contents('/etc/init.d/hhvm_' . $data['new']['system_user'], $content);
exec('chmod +x /etc/init.d/hhvm_' . $data['new']['system_user'] . ' >/dev/null 2>&1');
exec('/usr/sbin/update-rc.d hhvm_' . $data['new']['system_user'] . ' defaults >/dev/null 2>&1');
exec('/etc/init.d/hhvm_' . $data['new']['system_user'] . ' start >/dev/null 2>&1');
+
+ $monit_content = str_replace('{SYSTEM_USER}', $data['new']['system_user'], $monit_content);
+ file_put_contents('/etc/monit/conf.d/hhvm_' . $data['new']['system_user'], $monit_content);
+ exec('/etc/init.d/monit restart >/dev/null 2>&1');
+
} elseif($data['new']['php'] != 'hhvm' && $data['old']['php'] == 'hhvm') {
exec('/etc/init.d/hhvm_' . $data['old']['system_user'] . ' stop >/dev/null 2>&1');
exec('/usr/sbin/update-rc.d hhvm_' . $data['old']['system_user'] . ' remove >/dev/null 2>&1');
unlink('/etc/init.d/hhvm_' . $data['old']['system_user']);
+ if(is_file('/etc/hhvm/'.$data['old']['system_user'].'.ini')) unlink('/etc/hhvm/'.$data['old']['system_user'].'.ini');
+
+ if(is_file('/etc/monit/conf.d/hhvm_' . $data['new']['system_user'])){
+ unlink('/etc/monit/conf.d/hhvm_' . $data['new']['system_user']);
+ exec('/etc/init.d/monit restart >/dev/null 2>&1');
+ }
}
}
//* Update the PHP-FPM pool configuration file
private function php_fpm_pool_update ($data, $web_config, $pool_dir, $pool_name, $socket_dir) {
global $app, $conf;
+ $pool_dir = trim($pool_dir);
//$reload = false;
if($data['new']['php'] == 'php-fpm'){
@@ -2864,6 +2952,26 @@
// Custom php.ini settings
$final_php_ini_settings = array();
$custom_php_ini_settings = trim($data['new']['custom_php_ini']);
+
+ if(intval($data['new']['directive_snippets_id']) > 0){
+ $snippet = $app->db->queryOneRecord("SELECT * FROM directive_snippets WHERE directive_snippets_id = ? AND type = 'apache' AND active = 'y' AND customer_viewable = 'y'", intval($data['new']['directive_snippets_id']));
+ if(isset($snippet['required_php_snippets']) && trim($snippet['required_php_snippets']) != ''){
+ $required_php_snippets = explode(',', trim($snippet['required_php_snippets']));
+ if(is_array($required_php_snippets) && !empty($required_php_snippets)){
+ foreach($required_php_snippets as $required_php_snippet){
+ $required_php_snippet = intval($required_php_snippet);
+ if($required_php_snippet > 0){
+ $php_snippet = $app->db->queryOneRecord("SELECT * FROM directive_snippets WHERE directive_snippets_id = ? AND type = 'php' AND active = 'y'", $required_php_snippet);
+ $php_snippet['snippet'] = trim($php_snippet['snippet']);
+ if($php_snippet['snippet'] != ''){
+ $custom_php_ini_settings .= "\n".$php_snippet['snippet'];
+ }
+ }
+ }
+ }
+ }
+ }
+
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);
@@ -2907,7 +3015,7 @@
unset($tpl);
// delete pool in all other PHP versions
- $default_pool_dir = escapeshellcmd($web_config['php_fpm_pool_dir']);
+ $default_pool_dir = trim(escapeshellcmd($web_config['php_fpm_pool_dir']));
if(substr($default_pool_dir, -1) != '/') $default_pool_dir .= '/';
if($default_pool_dir != $pool_dir){
if ( @is_file($default_pool_dir.$pool_name.'.conf') ) {
@@ -2919,6 +3027,7 @@
$php_versions = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fpm_init_script != '' AND php_fpm_ini_dir != '' AND php_fpm_pool_dir != '' AND server_id = ?", $conf["server_id"]);
if(is_array($php_versions) && !empty($php_versions)){
foreach($php_versions as $php_version){
+ $php_version['php_fpm_pool_dir'] = trim($php_version['php_fpm_pool_dir']);
if(substr($php_version['php_fpm_pool_dir'], -1) != '/') $php_version['php_fpm_pool_dir'] .= '/';
if($php_version['php_fpm_pool_dir'] != $pool_dir){
if ( @is_file($php_version['php_fpm_pool_dir'].$pool_name.'.conf') ) {
@@ -2959,6 +3068,7 @@
} else {
$pool_dir = $custom_php_fpm_pool_dir;
}
+ $pool_dir = trim($pool_dir);
if(substr($pool_dir, -1) != '/') $pool_dir .= '/';
$pool_name = 'web'.$data['old']['domain_id'];
@@ -2971,7 +3081,7 @@
}
// delete pool in all other PHP versions
- $default_pool_dir = escapeshellcmd($web_config['php_fpm_pool_dir']);
+ $default_pool_dir = trim(escapeshellcmd($web_config['php_fpm_pool_dir']));
if(substr($default_pool_dir, -1) != '/') $default_pool_dir .= '/';
if($default_pool_dir != $pool_dir){
if ( @is_file($default_pool_dir.$pool_name.'.conf') ) {
@@ -2983,6 +3093,7 @@
$php_versions = $app->db->queryAllRecords("SELECT * FROM server_php WHERE php_fpm_init_script != '' AND php_fpm_ini_dir != '' AND php_fpm_pool_dir != '' AND server_id = ?", $data['old']['server_id']);
if(is_array($php_versions) && !empty($php_versions)){
foreach($php_versions as $php_version){
+ $php_version['php_fpm_pool_dir'] = trim($php_version['php_fpm_pool_dir']);
if(substr($php_version['php_fpm_pool_dir'], -1) != '/') $php_version['php_fpm_pool_dir'] .= '/';
if($php_version['php_fpm_pool_dir'] != $pool_dir){
if ( @is_file($php_version['php_fpm_pool_dir'].$pool_name.'.conf') ) {
--
Gitblit v1.9.1