| | |
| | | function onInstall() { |
| | | global $conf; |
| | | |
| | | if($conf['services']['web'] == true) { |
| | | if($conf['services']['web'] == true && !@is_link('/usr/local/ispconfig/server/plugins-enabled/apache2_plugin.inc.php')) { |
| | | return true; |
| | | } else { |
| | | return false; |
| | |
| | | |
| | | function update($event_name,$data) { |
| | | global $app, $conf; |
| | | |
| | | |
| | | //* Check if the apache plugin is enabled |
| | | if(@is_link('/usr/local/ispconfig/server/plugins-enabled/apache2_plugin.inc.php')) { |
| | | $app->log('The nginx plugin can not be used together with the apache2 plugin..',LOGLEVEL_WARN); |
| | | return 0; |
| | | } |
| | | |
| | | if($this->action != 'insert') $this->action = 'update'; |
| | | |
| | | if($data['new']['type'] != 'vhost' && $data['new']['parent_domain_id'] > 0) { |
| | |
| | | $tmp_docroot = explode('/',$data['old']['document_root']); |
| | | unset($tmp_docroot[count($tmp_docroot)-1]); |
| | | $old_dir = implode('/',$tmp_docroot); |
| | | |
| | | exec('rm -rf '.$data['new']['document_root']); |
| | | |
| | | //* Check if there is already some data in the new docroot and rename it as we need a clean path to move the existing site to the new path |
| | | if(@is_dir($data['new']['document_root'])) { |
| | | rename($data['new']['document_root'],$data['new']['document_root'].'_bak_'.date('Y_m_d')); |
| | | $app->log('Renaming existing directory in new docroot location. mv '.$data['new']['document_root'].' '.$data['new']['document_root'].'_bak_'.date('Y_m_d'),LOGLEVEL_DEBUG); |
| | | } |
| | | |
| | | //* Create new base directory, if it does not exist yet |
| | | if(!is_dir($new_dir)) exec('mkdir -p '.$new_dir); |
| | | exec('mv '.$data['old']['document_root'].' '.$new_dir); |
| | | $app->log('Moving site to new document root: mv '.$data['old']['document_root'].' '.$new_dir,LOGLEVEL_DEBUG); |
| | |
| | | if($data['new']['ipv6_address'] != '') $tpl->setVar('ipv6_enabled', 1); |
| | | |
| | | // PHP-FPM |
| | | $pool_dir = escapeshellcmd($web_config['php_fpm_pool_dir']); |
| | | // 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($default_php_fpm){ |
| | | $pool_dir = escapeshellcmd($web_config['php_fpm_pool_dir']); |
| | | } else { |
| | | $pool_dir = $custom_php_fpm_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']); |
| | |
| | | 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; |
| | | } |
| | | |
| | | $app->uses("getconf"); |
| | | $web_config = $app->getconf->get_server_config($conf["server_id"], 'web'); |
| | | |
| | | 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){ |
| | | $app->services->restartService('php-fpm','reload:'.$custom_php_fpm_init_script); |
| | | } else { |
| | | $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; |
| | | } |
| | | |
| | | $app->uses("getconf"); |
| | | $web_config = $app->getconf->get_server_config($conf["server_id"], 'web'); |
| | | |
| | | |
| | | $app->load('tpl'); |
| | | $tpl = new tpl(); |
| | | $tpl->newTemplate('php_fpm_pool.conf.master'); |
| | |
| | | file_put_contents($pool_dir.$pool_name.'.conf',$tpl->grab()); |
| | | $app->log('Writing the PHP-FPM config file: '.$pool_dir.$pool_name.'.conf',LOGLEVEL_DEBUG); |
| | | unset($tpl); |
| | | |
| | | // delete pool in all other PHP versions |
| | | $default_pool_dir = 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') ) { |
| | | unlink($default_pool_dir.$pool_name.'.conf'); |
| | | $app->log('Removed PHP-FPM config file: '.$default_pool_dir.$pool_name.'.conf',LOGLEVEL_DEBUG); |
| | | $app->services->restartService('php-fpm','reload:'.$conf['init_scripts'].'/'.$web_config['php_fpm_init_script']); |
| | | } |
| | | } |
| | | $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){ |
| | | 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') ) { |
| | | unlink($php_version['php_fpm_pool_dir'].$pool_name.'.conf'); |
| | | $app->log('Removed PHP-FPM config file: '.$php_version['php_fpm_pool_dir'].$pool_name.'.conf',LOGLEVEL_DEBUG); |
| | | $app->services->restartService('php-fpm','reload:'.$php_version['php_fpm_init_script']); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // Reload current PHP-FPM after all others |
| | | sleep(1); |
| | | if(!$default_php_fpm){ |
| | | $app->services->restartService('php-fpm','reload:'.$custom_php_fpm_init_script); |
| | | } 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; |
| | | global $app, $conf; |
| | | |
| | | $pool_dir = escapeshellcmd($web_config['php_fpm_pool_dir']); |
| | | if(trim($data['old']['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['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){ |
| | | $pool_dir = escapeshellcmd($web_config['php_fpm_pool_dir']); |
| | | } else { |
| | | $pool_dir = $custom_php_fpm_pool_dir; |
| | | } |
| | | |
| | | if(substr($pool_dir,-1) != '/') $pool_dir .= '/'; |
| | | $pool_name = 'web'.$data['old']['domain_id']; |
| | | |
| | | 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 |
| | | $default_pool_dir = 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') ) { |
| | | unlink($default_pool_dir.$pool_name.'.conf'); |
| | | $app->log('Removed PHP-FPM config file: '.$default_pool_dir.$pool_name.'.conf',LOGLEVEL_DEBUG); |
| | | $app->services->restartService('php-fpm','reload:'.$conf['init_scripts'].'/'.$web_config['php_fpm_init_script']); |
| | | } |
| | | } |
| | | $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){ |
| | | 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') ) { |
| | | unlink($php_version['php_fpm_pool_dir'].$pool_name.'.conf'); |
| | | $app->log('Removed PHP-FPM config file: '.$php_version['php_fpm_pool_dir'].$pool_name.'.conf',LOGLEVEL_DEBUG); |
| | | $app->services->restartService('php-fpm','reload:'.$php_version['php_fpm_init_script']); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // Reload current PHP-FPM after all others |
| | | sleep(1); |
| | | if(!$default_php_fpm){ |
| | | $app->services->restartService('php-fpm','reload:'.$custom_php_fpm_init_script); |
| | | } else { |
| | | $app->services->restartService('php-fpm','reload:'.$conf['init_scripts'].'/'.$web_config['php_fpm_init_script']); |
| | | } |
| | | } |
| | | |
| | | function client_delete($event_name,$data) { |