migrate phpinterface-classes to PDO database class, refs #1287

Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann (d00p)
2013-11-06 09:11:26 +01:00
parent 388156b7b8
commit 849da2a423
9 changed files with 222 additions and 289 deletions

View File

@@ -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];
}
}