From d87f76019fc231ec20d95126a7fee0487e7be5f0 Mon Sep 17 00:00:00 2001 From: tbrehm <t.brehm@ispconfig.org> Date: Tue, 14 Aug 2012 10:56:20 -0400 Subject: [PATCH] - Added new web folder named private to web folder layout. The folder is intended to store data that shall not be visible in the web directory, it is owned by the user of the web. - Changed ownership of web root directory to root user in all security modes to prevent symlink attacks. - Apache log files are now owned by user root. - Improved functions in system library. --- server/plugins-available/nginx_plugin.inc.php | 72 ++++++++++++++++++++++++++++-------- 1 files changed, 56 insertions(+), 16 deletions(-) diff --git a/server/plugins-available/nginx_plugin.inc.php b/server/plugins-available/nginx_plugin.inc.php index 0f3b034..9d444f5 100644 --- a/server/plugins-available/nginx_plugin.inc.php +++ b/server/plugins-available/nginx_plugin.inc.php @@ -713,12 +713,31 @@ // PHP-FPM // Support for multiple PHP versions + /* if(trim($data['new']['fastcgi_php_version']) != ''){ $default_php_fpm = false; list($custom_php_fpm_name, $custom_php_fpm_init_script, $custom_php_fpm_ini_dir, $custom_php_fpm_pool_dir) = explode(':', trim($data['new']['fastcgi_php_version'])); if(substr($custom_php_fpm_ini_dir,-1) != '/') $custom_php_fpm_ini_dir .= '/'; } else { $default_php_fpm = true; + } + */ + if($data['new']['php'] != 'no'){ + if(trim($data['new']['fastcgi_php_version']) != ''){ + $default_php_fpm = false; + list($custom_php_fpm_name, $custom_php_fpm_init_script, $custom_php_fpm_ini_dir, $custom_php_fpm_pool_dir) = explode(':', trim($data['new']['fastcgi_php_version'])); + if(substr($custom_php_fpm_ini_dir,-1) != '/') $custom_php_fpm_ini_dir .= '/'; + } else { + $default_php_fpm = true; + } + } else { + if(trim($data['old']['fastcgi_php_version']) != '' && $data['old']['php'] != 'no'){ + $default_php_fpm = false; + list($custom_php_fpm_name, $custom_php_fpm_init_script, $custom_php_fpm_ini_dir, $custom_php_fpm_pool_dir) = explode(':', trim($data['old']['fastcgi_php_version'])); + if(substr($custom_php_fpm_ini_dir,-1) != '/') $custom_php_fpm_ini_dir .= '/'; + } else { + $default_php_fpm = true; + } } if($default_php_fpm){ @@ -743,6 +762,9 @@ $fpm_socket = $socket_dir.$pool_name.'.sock'; $tpl->setVar('fpm_socket', $fpm_socket); $vhost_data['fpm_port'] = $web_config['php_fpm_start_port'] + $data['new']['domain_id'] - 1; + + // backwards compatibility; since ISPConfig 3.0.5, the PHP mode for nginx is called 'php-fpm' instead of 'fast-cgi'. The following line makes sure that old web sites that have 'fast-cgi' in the database still get PHP-FPM support. + if($vhost_data['php'] == 'fast-cgi') $vhost_data['php'] = 'php-fpm'; // Custom nginx directives $final_nginx_directives = array(); @@ -791,7 +813,7 @@ // Rewrite rules $rewrite_rules = array(); - if($data['new']['redirect_type'] != '') { + if($data['new']['redirect_type'] != '' && $data['new']['redirect_path'] != '') { if(substr($data['new']['redirect_path'],-1) != '/') $data['new']['redirect_path'] .= '/'; if(substr($data['new']['redirect_path'],0,8) == '[scheme]') $data['new']['redirect_path'] = '$scheme'.substr($data['new']['redirect_path'],8); @@ -917,7 +939,7 @@ } $app->log('Add server alias: '.$alias['domain'],LOGLEVEL_DEBUG); // Rewriting - if($alias['redirect_type'] != '') { + if($alias['redirect_type'] != '' && $alias['redirect_path'] != '') { if(substr($alias['redirect_path'],-1) != '/') $alias['redirect_path'] .= '/'; if(substr($alias['redirect_path'],0,8) == '[scheme]') $alias['redirect_path'] = '$scheme'.substr($alias['redirect_path'],8); @@ -1226,6 +1248,11 @@ exec('rm -rf '.$fastcgi_starter_path); } } + + // remove PHP-FPM pool + if ($data['old']['php'] == 'php-fpm') { + $this->php_fpm_pool_delete($data,$web_config); + } //remove the php cgi starter script if available if ($data['old']['php'] == 'cgi') { @@ -1502,6 +1529,7 @@ $awstats_conf_dir = $web_config['awstats_conf_dir']; + if(!is_dir($data['new']['document_root']."/web/stats/")) mkdir($data['new']['document_root']."/web/stats"); 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'); @@ -1536,14 +1564,31 @@ //* 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; - //$reload = false; - + /* if(trim($data['new']['fastcgi_php_version']) != ''){ $default_php_fpm = false; list($custom_php_fpm_name, $custom_php_fpm_init_script, $custom_php_fpm_ini_dir, $custom_php_fpm_pool_dir) = explode(':', trim($data['new']['fastcgi_php_version'])); if(substr($custom_php_fpm_ini_dir,-1) != '/') $custom_php_fpm_ini_dir .= '/'; } else { $default_php_fpm = true; + } + */ + if($data['new']['php'] != 'no'){ + if(trim($data['new']['fastcgi_php_version']) != ''){ + $default_php_fpm = false; + list($custom_php_fpm_name, $custom_php_fpm_init_script, $custom_php_fpm_ini_dir, $custom_php_fpm_pool_dir) = explode(':', trim($data['new']['fastcgi_php_version'])); + if(substr($custom_php_fpm_ini_dir,-1) != '/') $custom_php_fpm_ini_dir .= '/'; + } else { + $default_php_fpm = true; + } + } else { + if(trim($data['old']['fastcgi_php_version']) != '' && $data['old']['php'] != 'no'){ + $default_php_fpm = false; + list($custom_php_fpm_name, $custom_php_fpm_init_script, $custom_php_fpm_ini_dir, $custom_php_fpm_pool_dir) = explode(':', trim($data['old']['fastcgi_php_version'])); + if(substr($custom_php_fpm_ini_dir,-1) != '/') $custom_php_fpm_ini_dir .= '/'; + } else { + $default_php_fpm = true; + } } $app->uses("getconf"); @@ -1552,7 +1597,6 @@ if($data['new']['php'] == 'no'){ if(@is_file($pool_dir.$pool_name.'.conf')){ unlink($pool_dir.$pool_name.'.conf'); - //$reload = true; } if($data['old']['php'] != 'no'){ if(!$default_php_fpm){ @@ -1561,7 +1605,6 @@ $app->services->restartService('php-fpm','reload:'.$conf['init_scripts'].'/'.$web_config['php_fpm_init_script']); } } - //if($reload == true) $app->services->restartService('php-fpm','reload'); return; } @@ -1587,10 +1630,13 @@ $tpl->setVar('fpm_port', $web_config['php_fpm_start_port'] + $data['new']['domain_id'] - 1); $tpl->setVar('fpm_user', $data['new']['system_user']); $tpl->setVar('fpm_group', $data['new']['system_group']); + $tpl->setVar('pm', $data['new']['pm']); $tpl->setVar('pm_max_children', $data['new']['pm_max_children']); $tpl->setVar('pm_start_servers', $data['new']['pm_start_servers']); $tpl->setVar('pm_min_spare_servers', $data['new']['pm_min_spare_servers']); $tpl->setVar('pm_max_spare_servers', $data['new']['pm_max_spare_servers']); + $tpl->setVar('pm_process_idle_timeout', $data['new']['pm_process_idle_timeout']); + $tpl->setVar('pm_max_requests', $data['new']['pm_max_requests']); $tpl->setVar('document_root', $data['new']['document_root']); $tpl->setVar('security_level',$web_config['security_level']); $php_open_basedir = ($data['new']['php_open_basedir'] == '')?escapeshellcmd($data['new']['document_root']):escapeshellcmd($data['new']['php_open_basedir']); @@ -1616,12 +1662,12 @@ $value = escapeshellcmd(trim($value)); $key = escapeshellcmd(trim($key)); switch (strtolower($value)) { - case 'on': - case 'off': - case '1': case '0': // PHP-FPM might complain about invalid boolean value if you use 0 $value = 'off'; + case '1': + case 'on': + case 'off': case 'true': case 'false': case 'yes': @@ -1672,17 +1718,13 @@ } else { $app->services->restartService('php-fpm','reload:'.$conf['init_scripts'].'/'.$web_config['php_fpm_init_script']); } - - //$reload = true; - - //if($reload == true) $app->services->restartService('php-fpm','reload'); } //* Delete the PHP-FPM pool configuration file private function php_fpm_pool_delete ($data,$web_config) { global $app, $conf; - if(trim($data['old']['fastcgi_php_version']) != ''){ + if(trim($data['old']['fastcgi_php_version']) != '' && $data['old']['php'] != 'no'){ $default_php_fpm = false; list($custom_php_fpm_name, $custom_php_fpm_init_script, $custom_php_fpm_ini_dir, $custom_php_fpm_pool_dir) = explode(':', trim($data['old']['fastcgi_php_version'])); if(substr($custom_php_fpm_ini_dir,-1) != '/') $custom_php_fpm_ini_dir .= '/'; @@ -1702,8 +1744,6 @@ if ( @is_file($pool_dir.$pool_name.'.conf') ) { unlink($pool_dir.$pool_name.'.conf'); $app->log('Removed PHP-FPM config file: '.$pool_dir.$pool_name.'.conf',LOGLEVEL_DEBUG); - - //$app->services->restartService('php-fpm','reload'); } // delete pool in all other PHP versions -- Gitblit v1.9.1