diff --git a/lib/classes/phpinterface/class.phpinterface.php b/lib/classes/phpinterface/class.phpinterface.php index 01ff1e4c..b4474ea2 100644 --- a/lib/classes/phpinterface/class.phpinterface.php +++ b/lib/classes/phpinterface/class.phpinterface.php @@ -19,13 +19,7 @@ * */ -class phpinterface -{ - /** - * Database handler - * @var object - */ - private $_db = false; +class phpinterface { /** * Settings array @@ -54,9 +48,7 @@ class phpinterface /** * main constructor */ - public function __construct($db, $settings, $domain) - { - $this->_db = $db; + public function __construct($settings, $domain) { $this->_settings = $settings; $this->_domain = $domain; $this->_setInterface(); @@ -66,8 +58,7 @@ class phpinterface * returns the interface-object * from where we can control it */ - public function getInterface() - { + public function getInterface() { return $this->_interface; } @@ -76,16 +67,13 @@ class phpinterface * php-interface: fcgid or php-fpm * sets private $_interface variable */ - private function _setInterface() - { + private function _setInterface() { // php-fpm - if((int)$this->_settings['phpfpm']['enabled'] == 1) - { - $this->_interface = new phpinterface_fpm($this->_db, $this->_settings, $this->_domain); - } - elseif((int)$this->_settings['system']['mod_fcgid'] == 1) - { - $this->_interface = new phpinterface_fcgid($this->_db, $this->_settings, $this->_domain); + if ((int)$this->_settings['phpfpm']['enabled'] == 1) { + $this->_interface = new phpinterface_fpm($this->_settings, $this->_domain); + + } elseif ((int)$this->_settings['system']['mod_fcgid'] == 1) { + $this->_interface = new phpinterface_fcgid($this->_settings, $this->_domain); } } @@ -96,23 +84,21 @@ class phpinterface * * @return array */ - public function getPhpConfig($php_config_id) - { + public function getPhpConfig($php_config_id) { + $php_config_id = intval($php_config_id); // If domain has no config, we will use the default one. - - if($php_config_id == 0) - { + if ($php_config_id == 0) { $php_config_id = 1; } - if(!isset($this->php_configs_cache[$php_config_id])) - { - $this->_php_configs_cache[$php_config_id] = $this->_db->query_first( - "SELECT * FROM `" . TABLE_PANEL_PHPCONFIGS . "` - WHERE `id` = " . (int)$php_config_id + if (!isset($this->php_configs_cache[$php_config_id])) { + $stmt = Database::prepare(" + SELECT * FROM `" . TABLE_PANEL_PHPCONFIGS . "` WHERE `id` = :id" ); + Database::pexecute($stmt, array('id' => $php_config_id)); + $this->_php_configs_cache[$php_config_id] = $stmt->fetch(PDO::FETCH_ASSOC); } return $this->_php_configs_cache[$php_config_id]; diff --git a/lib/classes/phpinterface/class.phpinterface_fcgid.php b/lib/classes/phpinterface/class.phpinterface_fcgid.php index 690f4da4..622e4e08 100644 --- a/lib/classes/phpinterface/class.phpinterface_fcgid.php +++ b/lib/classes/phpinterface/class.phpinterface_fcgid.php @@ -19,13 +19,7 @@ * */ -class phpinterface_fcgid -{ - /** - * Database handler - * @var object - */ - private $_db = false; +class phpinterface_fcgid { /** * Settings array @@ -36,27 +30,25 @@ class phpinterface_fcgid /** * Domain-Data array * @var array - */ + */ private $_domain = array(); /** * Admin-Date cache array * @var array - */ + */ private $_admin_cache = array(); /** * main constructor - */ - public function __construct($db, $settings, $domain) - { - $this->_db = $db; + */ + public function __construct($settings, $domain) { $this->_settings = $settings; $this->_domain = $domain; } - public function createConfig($phpconfig) - { + public function createConfig($phpconfig) { + // create starter $starter_file = "#!/bin/sh\n\n"; $starter_file.= "#\n"; @@ -68,18 +60,13 @@ class phpinterface_fcgid $starter_file.= "export PHPRC\n"; // set number of processes for one domain - if((int)$this->_domain['mod_fcgid_starter'] != - 1) - { + if ((int)$this->_domain['mod_fcgid_starter'] != - 1) { $starter_file.= "PHP_FCGI_CHILDREN=" . (int)$this->_domain['mod_fcgid_starter'] . "\n"; - } - else - { - if((int)$phpconfig['mod_fcgid_starter'] != - 1) - { + + } else { + if ((int)$phpconfig['mod_fcgid_starter'] != - 1) { $starter_file.= "PHP_FCGI_CHILDREN=" . (int)$phpconfig['mod_fcgid_starter'] . "\n"; - } - else - { + } else { $starter_file.= "PHP_FCGI_CHILDREN=" . (int)$this->_settings['system']['mod_fcgid_starter'] . "\n"; } } @@ -87,18 +74,12 @@ class phpinterface_fcgid $starter_file.= "export PHP_FCGI_CHILDREN\n"; // set number of maximum requests for one domain - if((int)$this->_domain['mod_fcgid_maxrequests'] != - 1) - { + if ((int)$this->_domain['mod_fcgid_maxrequests'] != - 1) { $starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$this->_domain['mod_fcgid_maxrequests'] . "\n"; - } - else - { - if((int)$phpconfig['mod_fcgid_maxrequests'] != - 1) - { + } else { + if ((int)$phpconfig['mod_fcgid_maxrequests'] != - 1) { $starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$phpconfig['mod_fcgid_maxrequests'] . "\n"; - } - else - { + } else { $starter_file.= "PHP_FCGI_MAX_REQUESTS=" . (int)$this->_settings['system']['mod_fcgid_maxrequests'] . "\n"; } } @@ -109,8 +90,7 @@ class phpinterface_fcgid $starter_file.= "exec " . $phpconfig['binary'] . " -c " . escapeshellarg($this->getConfigDir()) . "\n"; //remove +i attibute, so starter can be overwritten - if(file_exists($this->getStarterFile())) - { + if (file_exists($this->getStarterFile())) { removeImmutable($this->getStarterFile()); } @@ -122,34 +102,36 @@ class phpinterface_fcgid setImmutable($this->getStarterFile()); } - public function createIniFile($phpconfig) - { + /** + * create customized php.ini + * + * @param array $phpconfig + */ + public function createIniFile($phpconfig) { + $openbasedir = ''; $openbasedirc = ';'; - if($this->_domain['openbasedir'] == '1') - { + if ($this->_domain['openbasedir'] == '1') { + $openbasedirc = ''; $_phpappendopenbasedir = ''; $_custom_openbasedir = explode(':', $this->_settings['system']['mod_fcgid_peardir']); - foreach($_custom_openbasedir as $cobd) - { + foreach ($_custom_openbasedir as $cobd) { $_phpappendopenbasedir .= appendOpenBasedirPath($cobd); } $_custom_openbasedir = explode(':', $this->_settings['system']['phpappendopenbasedir']); - foreach($_custom_openbasedir as $cobd) - { + foreach ($_custom_openbasedir as $cobd) { $_phpappendopenbasedir .= appendOpenBasedirPath($cobd); } - if($this->_domain['openbasedir_path'] == '0' && strstr($this->_domain['documentroot'], ":") === false) - { + if ($this->_domain['openbasedir_path'] == '0' + && strstr($this->_domain['documentroot'], ":") === false + ) { $openbasedir = appendOpenBasedirPath($this->_domain['documentroot'], true); - } - else - { + } else { $openbasedir = appendOpenBasedirPath($this->_domain['customerroot'], true); } @@ -158,34 +140,31 @@ class phpinterface_fcgid $openbasedir = explode(':', $openbasedir); $clean_openbasedir = array(); - foreach($openbasedir as $number => $path) - { - if(trim($path) != '/') - { + foreach ($openbasedir as $number => $path) { + if (trim($path) != '/') { $clean_openbasedir[] = makeCorrectDir($path); } } $openbasedir = implode(':', $clean_openbasedir); - } - else - { + + } else { $openbasedir = 'none'; $openbasedirc = ';'; } $admin = $this->_getAdminData($this->_domain['adminid']); $php_ini_variables = array( - 'SAFE_MODE' => 'Off', // keep this for compatibility, just in case - 'PEAR_DIR' => $this->_settings['system']['mod_fcgid_peardir'], - 'OPEN_BASEDIR' => $openbasedir, - 'OPEN_BASEDIR_C' => $openbasedirc, - 'OPEN_BASEDIR_GLOBAL' => $this->_settings['system']['phpappendopenbasedir'], - 'TMP_DIR' => $this->getTempDir(), - 'CUSTOMER_EMAIL' => $this->_domain['email'], - 'ADMIN_EMAIL' => $admin['email'], - 'DOMAIN' => $this->_domain['domain'], - 'CUSTOMER' => $this->_domain['loginname'], - 'ADMIN' => $admin['loginname'] + 'SAFE_MODE' => 'Off', // keep this for compatibility, just in case + 'PEAR_DIR' => $this->_settings['system']['mod_fcgid_peardir'], + 'OPEN_BASEDIR' => $openbasedir, + 'OPEN_BASEDIR_C' => $openbasedirc, + 'OPEN_BASEDIR_GLOBAL' => $this->_settings['system']['phpappendopenbasedir'], + 'TMP_DIR' => $this->getTempDir(), + 'CUSTOMER_EMAIL' => $this->_domain['email'], + 'ADMIN_EMAIL' => $admin['email'], + 'DOMAIN' => $this->_domain['domain'], + 'CUSTOMER' => $this->_domain['loginname'], + 'ADMIN' => $admin['loginname'] ); //insert a small header for the file @@ -206,17 +185,16 @@ class phpinterface_fcgid /** * fcgid-config directory - * + * * @param boolean $createifnotexists create the directory if it does not exist - * + * * @return string the directory */ - public function getConfigDir($createifnotexists = true) - { + public function getConfigDir($createifnotexists = true) { + $configdir = makeCorrectDir($this->_settings['system']['mod_fcgid_configdir'] . '/' . $this->_domain['loginname'] . '/' . $this->_domain['domain'] . '/'); - if(!is_dir($configdir) && $createifnotexists) - { + if (!is_dir($configdir) && $createifnotexists) { safe_exec('mkdir -p ' . escapeshellarg($configdir)); safe_exec('chown ' . $this->_domain['guid'] . ':' . $this->_domain['guid'] . ' ' . escapeshellarg($configdir)); } @@ -226,66 +204,62 @@ class phpinterface_fcgid /** * fcgid-temp directory - * + * * @param boolean $createifnotexists create the directory if it does not exist - * + * * @return string the directory */ - public function getTempDir($createifnotexists = true) - { + public function getTempDir($createifnotexists = true) { + $tmpdir = makeCorrectDir($this->_settings['system']['mod_fcgid_tmpdir'] . '/' . $this->_domain['loginname'] . '/'); - if(!is_dir($tmpdir) && $createifnotexists) - { + if (!is_dir($tmpdir) && $createifnotexists) { safe_exec('mkdir -p ' . escapeshellarg($tmpdir)); safe_exec('chown -R ' . $this->_domain['guid'] . ':' . $this->_domain['guid'] . ' ' . escapeshellarg($tmpdir)); safe_exec('chmod 0750 ' . escapeshellarg($tmpdir)); } - + return $tmpdir; } /** * return path of php-starter file - * + * * @return string the directory */ - public function getStarterFile() - { + public function getStarterFile() { $starter_filename = makeCorrectFile($this->getConfigDir() . '/php-fcgi-starter'); return $starter_filename; } /** * return path of php.ini file - * + * * @return string full with path file-name */ - public function getIniFile() - { + public function getIniFile() { $phpini_filename = makeCorrectFile($this->getConfigDir() . '/php.ini'); return $phpini_filename; } /** * return the admin-data of a specific admin - * + * * @param int $adminid id of the admin-user - * + * * @return array */ - private function _getAdminData($adminid) - { + private function _getAdminData($adminid) { + $adminid = intval($adminid); - if(!isset($this->_admin_cache[$adminid])) - { - $this->_admin_cache[$adminid] = $this->_db->query_first( - "SELECT `email`, `loginname` FROM `" . TABLE_PANEL_ADMINS . "` - WHERE `adminid` = " . (int)$adminid + if (!isset($this->_admin_cache[$adminid])) { + $stmt = Database::prepare("TABLE_PANEL_ADMINS + SELECT `email`, `loginname` FROM `" . TABLE_PANEL_ADMINS . "` WHERE `adminid` = :id" ); + Database::pexecute($stmt, array('id' => $adminid)); + $this->_admin_cache[$adminid] = $stmt->fetch(PDO::FETCH_ASSOC); } - return $this->_admin_cache[$adminid]; } } diff --git a/lib/classes/phpinterface/class.phpinterface_fpm.php b/lib/classes/phpinterface/class.phpinterface_fpm.php index 00017f29..a364b19c 100644 --- a/lib/classes/phpinterface/class.phpinterface_fpm.php +++ b/lib/classes/phpinterface/class.phpinterface_fpm.php @@ -19,13 +19,7 @@ * */ -class phpinterface_fpm -{ - /** - * Database handler - * @var object - */ - private $_db = false; +class phpinterface_fpm { /** * Settings array @@ -36,80 +30,83 @@ class phpinterface_fpm /** * Domain-Data array * @var array - */ + */ private $_domain = array(); /** * Admin-Date cache array * @var array - */ + */ private $_admin_cache = array(); /** * defines what can be used for pool-config from php.ini * @var array - */ + */ private $_ini = array( - 'php_value' => array( - 'error_reporting', - 'max_execution_time', - 'include_path', - 'upload_max_filesize', - 'log_errors_max_len' - ), - 'php_flag' => array( - 'short_open_tag', - 'asp_tags', - 'display_errors', - 'display_startup_errors', - 'log_errors', - 'track_errors', - 'html_errors', - 'magic_quotes_gpc', - 'magic_quotes_runtime', - 'magic_quotes_sybase' - ), - 'php_admin_value' => array( - 'precision', - 'output_buffering', - 'disable_functions', - 'max_input_time', - 'memory_limit', - 'post_max_size', - 'variables_order', - 'gpc_order', - 'date.timezone' - ), - 'php_admin_flag' => array( - 'allow_call_time_pass_reference', - 'allow_url_fopen', - 'cgi.force_redirect', - 'enable_dl', - 'expose_php', - 'ignore_repeated_errors', - 'ignore_repeated_source', - 'report_memleaks', - 'register_argc_argv', - 'file_uploads', - 'allow_url_fopen' - ) + 'php_value' => array( + 'error_reporting', + 'max_execution_time', + 'include_path', + 'upload_max_filesize', + 'log_errors_max_len' + ), + 'php_flag' => array( + 'short_open_tag', + 'asp_tags', + 'display_errors', + 'display_startup_errors', + 'log_errors', + 'track_errors', + 'html_errors', + 'magic_quotes_gpc', + 'magic_quotes_runtime', + 'magic_quotes_sybase' + ), + 'php_admin_value' => array( + 'precision', + 'output_buffering', + 'disable_functions', + 'max_input_time', + 'memory_limit', + 'post_max_size', + 'variables_order', + 'gpc_order', + 'date.timezone' + ), + 'php_admin_flag' => array( + 'allow_call_time_pass_reference', + 'allow_url_fopen', + 'cgi.force_redirect', + 'enable_dl', + 'expose_php', + 'ignore_repeated_errors', + 'ignore_repeated_source', + 'report_memleaks', + 'register_argc_argv', + 'file_uploads', + 'allow_url_fopen' + ) ); /** * main constructor - */ - public function __construct($db, $settings, $domain) - { - $this->_db = $db; + */ + public function __construct($settings, $domain) { $this->_settings = $settings; $this->_domain = $domain; } - public function createConfig($phpconfig) - { + /** + * create fpm-pool config + * + * @param array $phpconfig + */ + public function createConfig($phpconfig) { + $fh = @fopen($this->getConfigFile(), 'w'); - if($fh) - { + + if ($fh) { $fpm_pm = $this->_settings['phpfpm']['pm']; $fpm_children = (int)$this->_settings['phpfpm']['max_children']; $fpm_start_servers = (int)$this->_settings['phpfpm']['start_servers']; @@ -118,39 +115,34 @@ class phpinterface_fpm $fpm_requests = (int)$this->_settings['phpfpm']['max_requests']; $fpm_process_idle_timeout = (int)$this->_settings['phpfpm']['idle_timeout']; - if($fpm_children == 0) { + if ($fpm_children == 0) { $fpm_children = 1; } $fpm_config = ';PHP-FPM configuration for "'.$this->_domain['domain'].'" created on ' . date("Y.m.d H:i:s") . "\n"; $fpm_config.= '['.$this->_domain['domain'].']'."\n"; $fpm_config.= 'listen = '.$this->getSocketFile()."\n"; - if($this->_domain['loginname'] == 'froxlor.panel') - { + if ($this->_domain['loginname'] == 'froxlor.panel') { $fpm_config.= 'listen.owner = '.$this->_domain['guid']."\n"; $fpm_config.= 'listen.group = '.$this->_domain['guid']."\n"; - } - else - { + } else { $fpm_config.= 'listen.owner = '.$this->_domain['loginname']."\n"; $fpm_config.= 'listen.group = '.$this->_domain['loginname']."\n"; } $fpm_config.= 'listen.mode = 0666'."\n"; - if($this->_domain['loginname'] == 'froxlor.panel') - { + if ($this->_domain['loginname'] == 'froxlor.panel') { $fpm_config.= 'user = '.$this->_domain['guid']."\n"; $fpm_config.= 'group = '.$this->_domain['guid']."\n"; - } - else - { + } else { $fpm_config.= 'user = '.$this->_domain['loginname']."\n"; $fpm_config.= 'group = '.$this->_domain['loginname']."\n"; } $fpm_config.= 'pm = '.$fpm_pm."\n"; $fpm_config.= 'pm.max_children = '.$fpm_children."\n"; - if($fpm_pm == 'dynamic') { + + if ($fpm_pm == 'dynamic') { // failsafe, refs #955 if ($fpm_start_servers < $fpm_min_spare_servers) { $fpm_start_servers = $fpm_min_spare_servers; @@ -167,12 +159,10 @@ class phpinterface_fpm } $fpm_config.= 'pm.max_requests = '.$fpm_requests."\n"; - $fpm_config.= ';chroot = '.makeCorrectDir($this->_domain['documentroot'])."\n"; $tmpdir = makeCorrectDir($this->_settings['phpfpm']['tmpdir'] . '/' . $this->_domain['loginname'] . '/'); - if(!is_dir($tmpdir)) - { + if (!is_dir($tmpdir)) { $this->getTempDir(); } //$slowlog = makeCorrectFile($this->_settings['system']['logfiles_directory'] . $this->_domain['loginname'] . '/php-fpm_slow.log'); @@ -182,30 +172,26 @@ class phpinterface_fpm $fpm_config.= 'env[TEMP] = '.$tmpdir."\n"; $fpm_config.= 'php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f '.$this->_domain['email']."\n"; - if($this->_domain['loginname'] != 'froxlor.panel') - { - if($this->_domain['openbasedir'] == '1') - { + + if ($this->_domain['loginname'] != 'froxlor.panel') { + if ($this->_domain['openbasedir'] == '1') { $openbasedir = ''; $_phpappendopenbasedir = ''; $_custom_openbasedir = explode(':', $this->_settings['phpfpm']['peardir']); - foreach($_custom_openbasedir as $cobd) - { + foreach ($_custom_openbasedir as $cobd) { $_phpappendopenbasedir .= appendOpenBasedirPath($cobd); } $_custom_openbasedir = explode(':', $this->_settings['system']['phpappendopenbasedir']); - foreach($_custom_openbasedir as $cobd) - { + foreach ($_custom_openbasedir as $cobd) { $_phpappendopenbasedir .= appendOpenBasedirPath($cobd); } - if($this->_domain['openbasedir_path'] == '0' && strstr($this->_domain['documentroot'], ":") === false) - { + if ($this->_domain['openbasedir_path'] == '0' + && strstr($this->_domain['documentroot'], ":") === false + ) { $openbasedir = appendOpenBasedirPath($this->_domain['documentroot'], true); - } - else - { + } else { $openbasedir = appendOpenBasedirPath($this->_domain['customerroot'], true); } @@ -214,10 +200,8 @@ class phpinterface_fpm $openbasedir = explode(':', $openbasedir); $clean_openbasedir = array(); - foreach($openbasedir as $number => $path) - { - if(trim($path) != '/') - { + foreach ($openbasedir as $number => $path) { + if (trim($path) != '/') { $clean_openbasedir[] = makeCorrectDir($path); } } @@ -230,6 +214,7 @@ class phpinterface_fpm $fpm_config.= 'php_admin_value[upload_tmp_dir] = ' . makeCorrectDir($this->_settings['phpfpm']['tmpdir'] . '/' . $this->_domain['loginname'] . '/') . "\n"; $admin = $this->_getAdminData($this->_domain['adminid']); + $php_ini_variables = array( 'SAFE_MODE' => 'Off', // keep this for compatibility, just in case 'PEAR_DIR' => $this->_settings['system']['mod_fcgid_peardir'], @@ -265,8 +250,7 @@ class phpinterface_fpm * * @param string $phpconfig */ - public function createIniFile($phpconfig) - { + public function createIniFile($phpconfig) { return; } @@ -277,13 +261,12 @@ class phpinterface_fpm * * @return string the full path to the file */ - public function getConfigFile($createifnotexists = true) - { + public function getConfigFile($createifnotexists = true) { + $configdir = makeCorrectDir($this->_settings['phpfpm']['configdir']); $config = makeCorrectFile($configdir.'/'.$this->_domain['domain'].'.conf'); - if(!is_dir($configdir) && $createifnotexists) - { + if (!is_dir($configdir) && $createifnotexists) { safe_exec('mkdir -p ' . escapeshellarg($configdir)); } @@ -297,13 +280,12 @@ class phpinterface_fpm * * @return string the full path to the socket */ - public function getSocketFile($createifnotexists = true) - { + public function getSocketFile($createifnotexists = true) { + $socketdir = makeCorrectDir('/var/run/'.$this->_settings['system']['webserver'].'/'); $socket = makeCorrectFile($socketdir.'/'.$this->_domain['loginname'].'-'.$this->_domain['domain'].'-php-fpm.socket'); - if(!is_dir($socketdir) && $createifnotexists) - { + if (!is_dir($socketdir) && $createifnotexists) { safe_exec('mkdir -p '.escapeshellarg($socketdir)); safe_exec('chown -R '.$this->_settings['system']['httpuser'].':'.$this->_settings['system']['httpgroup'].' '.escapeshellarg($socketdir)); } @@ -318,12 +300,11 @@ class phpinterface_fpm * * @return string the directory */ - public function getTempDir($createifnotexists = true) - { + public function getTempDir($createifnotexists = true) { + $tmpdir = makeCorrectDir($this->_settings['phpfpm']['tmpdir'] . '/' . $this->_domain['loginname'] . '/'); - if(!is_dir($tmpdir) && $createifnotexists) - { + if (!is_dir($tmpdir) && $createifnotexists) { safe_exec('mkdir -p ' . escapeshellarg($tmpdir)); safe_exec('chown -R ' . $this->_domain['guid'] . ':' . $this->_domain['guid'] . ' ' . escapeshellarg($tmpdir)); safe_exec('chmod 0750 ' . escapeshellarg($tmpdir)); @@ -333,28 +314,27 @@ class phpinterface_fpm } /** - * fastcgi-fakedirectory directory - * - * @param boolean $createifnotexists create the directory if it does not exist - * - * @return string the directory - */ - public function getAliasConfigDir($createifnotexists = true) - { - // ensure default... - if (!isset($this->_settings['phpfpm']['aliasconfigdir'])) { - $this->_settings['phpfpm']['aliasconfigdir'] = '/var/www/php-fpm'; - } + * fastcgi-fakedirectory directory + * + * @param boolean $createifnotexists create the directory if it does not exist + * + * @return string the directory + */ + public function getAliasConfigDir($createifnotexists = true) { - $configdir = makeCorrectDir($this->_settings['phpfpm']['aliasconfigdir'] . '/' . $this->_domain['loginname'] . '/' . $this->_domain['domain'] . '/'); - if(!is_dir($configdir) && $createifnotexists) - { - safe_exec('mkdir -p ' . escapeshellarg($configdir)); - safe_exec('chown ' . $this->_domain['guid'] . ':' . $this->_domain['guid'] . ' ' . escapeshellarg($configdir)); - } + // ensure default... + if (!isset($this->_settings['phpfpm']['aliasconfigdir'])) { + $this->_settings['phpfpm']['aliasconfigdir'] = '/var/www/php-fpm'; + } - return $configdir; - } + $configdir = makeCorrectDir($this->_settings['phpfpm']['aliasconfigdir'] . '/' . $this->_domain['loginname'] . '/' . $this->_domain['domain'] . '/'); + if (!is_dir($configdir) && $createifnotexists) { + safe_exec('mkdir -p ' . escapeshellarg($configdir)); + safe_exec('chown ' . $this->_domain['guid'] . ':' . $this->_domain['guid'] . ' ' . escapeshellarg($configdir)); + } + + return $configdir; + } /** * return the admin-data of a specific admin @@ -364,15 +344,16 @@ class phpinterface_fpm * @return array */ private function _getAdminData($adminid) { + $adminid = intval($adminid); if (!isset($this->_admin_cache[$adminid])) { - $this->_admin_cache[$adminid] = $this->_db->query_first( - "SELECT `email`, `loginname` FROM `" . TABLE_PANEL_ADMINS . "` - WHERE `adminid` = " . (int)$adminid + $stmt = Database::prepare("TABLE_PANEL_ADMINS + SELECT `email`, `loginname` FROM `" . TABLE_PANEL_ADMINS . "` WHERE `adminid` = :id" ); + Database::pexecute($stmt, array('id' => $adminid)); + $this->_admin_cache[$adminid] = $stmt->fetch(PDO::FETCH_ASSOC); } - return $this->_admin_cache[$adminid]; } } diff --git a/scripts/jobs/cron_tasks.inc.http.10.apache.php b/scripts/jobs/cron_tasks.inc.http.10.apache.php index 8f36388d..abec451c 100644 --- a/scripts/jobs/cron_tasks.inc.http.10.apache.php +++ b/scripts/jobs/cron_tasks.inc.http.10.apache.php @@ -234,7 +234,7 @@ class apache 'loginname' => 'froxlor.panel', 'documentroot' => $mypath ); - $php = new phpinterface($this->getDB(), $this->settings, $domain); + $php = new phpinterface($this->settings, $domain); $phpconfig = $php->getPhpConfig($this->settings['system']['mod_fcgid_defaultini_ownvhost']); $starter_filename = makeCorrectFile($configdir . '/php-fcgi-starter'); @@ -273,7 +273,7 @@ class apache 'documentroot' => $mypath, ); - $php = new phpinterface($this->getDB(), $this->settings, $domain); + $php = new phpinterface($this->settings, $domain); $phpconfig = $php->getPhpConfig($this->settings['phpfpm']['vhost_defaultini']); $srvName = substr(md5($ipport),0,4).'.fpm.external'; if ($row_ipsandports['ssl']) { diff --git a/scripts/jobs/cron_tasks.inc.http.15.apache_fcgid.php b/scripts/jobs/cron_tasks.inc.http.15.apache_fcgid.php index 8caa27c5..215769fc 100644 --- a/scripts/jobs/cron_tasks.inc.http.15.apache_fcgid.php +++ b/scripts/jobs/cron_tasks.inc.http.15.apache_fcgid.php @@ -32,7 +32,7 @@ class apache_fcgid extends apache if($domain['phpenabled'] == '1') { - $php = new phpinterface($this->getDB(), $this->settings, $domain); + $php = new phpinterface($this->settings, $domain); $phpconfig = $php->getPhpConfig((int)$domain['phpsettingid']); if((int)$this->settings['phpfpm']['enabled'] == 1) @@ -93,8 +93,8 @@ class apache_fcgid extends apache // create starter-file | config-file $php->getInterface()->createConfig($phpconfig); - // create php.ini - // @TODO make php-fpm support this + // create php.ini (fpm does nothing here, as it + // defines ini-settings in its pool config) $php->getInterface()->createIniFile($phpconfig); } else @@ -143,7 +143,7 @@ class apache_fcgid extends apache safe_exec('chown -R ' . $user . ':' . $group . ' ' . escapeshellarg($mypath)); // get php.ini for our own vhost - $php = new phpinterface($this->getDB(), $this->settings, $domain); + $php = new phpinterface($this->settings, $domain); // get php-config if ($this->settings['phpfpm']['enabled'] == '1') { @@ -157,8 +157,8 @@ class apache_fcgid extends apache // create starter-file | config-file $php->getInterface()->createConfig($phpconfig); - // create php.ini - // @TODO make php-fpm support this + // create php.ini (fpm does nothing here, as it + // defines ini-settings in its pool config) $php->getInterface()->createIniFile($phpconfig); } } diff --git a/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php b/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php index ed9544bc..e4f7bd09 100644 --- a/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php +++ b/scripts/jobs/cron_tasks.inc.http.20.lighttpd.php @@ -151,7 +151,7 @@ class lighttpd 'documentroot' => $mypath ); - $php = new phpinterface($this->getDB(), $this->settings, $domain); + $php = new phpinterface($this->settings, $domain); $this->lighttpd_data[$vhost_filename].= ' fastcgi.server = ( '."\n"; $this->lighttpd_data[$vhost_filename].= "\t".'".php" => ('."\n"; diff --git a/scripts/jobs/cron_tasks.inc.http.25.lighttpd_fcgid.php b/scripts/jobs/cron_tasks.inc.http.25.lighttpd_fcgid.php index 160d4ef7..5b56175e 100644 --- a/scripts/jobs/cron_tasks.inc.http.25.lighttpd_fcgid.php +++ b/scripts/jobs/cron_tasks.inc.http.25.lighttpd_fcgid.php @@ -15,10 +15,6 @@ * */ -/* - * This script creates the php.ini's used by mod_suPHP+php-cgi - */ - if(@php_sapi_name() != 'cli' && @php_sapi_name() != 'cgi' && @php_sapi_name() != 'cgi-fcgi') @@ -34,7 +30,7 @@ class lighttpd_fcgid extends lighttpd if($domain['phpenabled'] == '1') { - $php = new phpinterface($this->getDB(), $this->settings, $domain); + $php = new phpinterface($this->settings, $domain); $phpconfig = $php->getPhpConfig((int)$domain['phpsettingid']); // vhost data for php-fpm @@ -105,8 +101,8 @@ class lighttpd_fcgid extends lighttpd // create starter-file | config-file $php->getInterface()->createConfig($phpconfig); - // create php.ini - // @TODO make php-fpm support this + // create php.ini (fpm does nothing here, as it + // defines ini-settings in its pool config) $php->getInterface()->createIniFile($phpconfig); } else @@ -145,7 +141,7 @@ class lighttpd_fcgid extends lighttpd safe_exec('chown -R ' . $user . ':' . $group . ' ' . escapeshellarg($mypath)); // get php.ini for our own vhost - $php = new phpinterface($this->getDB(), $this->settings, $domain); + $php = new phpinterface($this->settings, $domain); // get php-config if ($this->settings['phpfpm']['enabled'] == '1') { @@ -159,8 +155,8 @@ class lighttpd_fcgid extends lighttpd // create starter-file | config-file $php->getInterface()->createConfig($phpconfig); - // create php.ini - // @TODO make php-fpm support this + // create php.ini (fpm does nothing here, as it + // defines ini-settings in its pool config) $php->getInterface()->createIniFile($phpconfig); } } diff --git a/scripts/jobs/cron_tasks.inc.http.30.nginx.php b/scripts/jobs/cron_tasks.inc.http.30.nginx.php index 1fe93709..2c45e543 100644 --- a/scripts/jobs/cron_tasks.inc.http.30.nginx.php +++ b/scripts/jobs/cron_tasks.inc.http.30.nginx.php @@ -242,7 +242,7 @@ class nginx 'documentroot' => $mypath, ); - $php = new phpinterface($this->getDB(), $this->settings, $domain); + $php = new phpinterface($this->settings, $domain); $this->nginx_data[$vhost_filename] .= "\t\t".'fastcgi_pass unix:' . $php->getInterface()->getSocketFile() . ';' . "\n"; } else { $this->nginx_data[$vhost_filename] .= "\t\t".'fastcgi_pass ' . $this->settings['system']['nginx_php_backend'] . ';' . "\n"; diff --git a/scripts/jobs/cron_tasks.inc.http.35.nginx_phpfpm.php b/scripts/jobs/cron_tasks.inc.http.35.nginx_phpfpm.php index 391c7b10..93e10410 100644 --- a/scripts/jobs/cron_tasks.inc.http.35.nginx_phpfpm.php +++ b/scripts/jobs/cron_tasks.inc.http.35.nginx_phpfpm.php @@ -15,10 +15,6 @@ * */ -/* - * This script creates the php.ini's used by mod_suPHP+php-cgi - */ - if(@php_sapi_name() != 'cli' && @php_sapi_name() != 'cgi' && @php_sapi_name() != 'cgi-fcgi') @@ -34,7 +30,7 @@ class nginx_phpfpm extends nginx if($domain['phpenabled'] == '1') { - $php = new phpinterface($this->getDB(), $this->settings, $domain); + $php = new phpinterface($this->settings, $domain); $phpconfig = $php->getPhpConfig((int)$domain['phpsettingid']); $php_options_text = "\t".'location ~ \.php$ {'."\n"; @@ -52,8 +48,8 @@ class nginx_phpfpm extends nginx // create starter-file | config-file $php->getInterface()->createConfig($phpconfig); - // create php.ini - // @TODO make php-fpm support this + // create php.ini (fpm does nothing here, as it + // defines ini-settings in its pool config) $php->getInterface()->createIniFile($phpconfig); } else @@ -92,7 +88,7 @@ class nginx_phpfpm extends nginx safe_exec('chown -R ' . $user . ':' . $group . ' ' . escapeshellarg($mypath)); // get php.ini for our own vhost - $php = new phpinterface($this->getDB(), $this->settings, $domain); + $php = new phpinterface($this->settings, $domain); // get php-config if ($this->settings['phpfpm']['enabled'] == '1') { @@ -106,8 +102,8 @@ class nginx_phpfpm extends nginx // create starter-file | config-file $php->getInterface()->createConfig($phpconfig); - // create php.ini - // @TODO make php-fpm support this + // create php.ini (fpm does nothing here, as it + // defines ini-settings in its pool config) $php->getInterface()->createIniFile($phpconfig); } }