From c61b3b73bd083a59f2b8c0d7d2779c3df7a091de Mon Sep 17 00:00:00 2001 From: Patrik Kernstock Date: Tue, 31 Dec 2019 05:48:36 +0100 Subject: [PATCH] Ability to add custom config to PHPFPM version Addresses #643 Signed-off-by: Patrik Kernstock --- install/froxlor.sql | 1 + .../updates/froxlor/0.10/update_0.10.inc.php | 7 ++ lib/Froxlor/Api/Commands/FpmDaemons.php | 16 +++- lib/Froxlor/Cron/Http/Php/Fpm.php | 7 ++ .../phpconfig/formfield.fpmconfig_add.php | 7 ++ .../phpconfig/formfield.fpmconfig_edit.php | 8 ++ lng/english.lng.php | 3 + lng/german.lng.php | 3 + .../Sparkle/admin/phpconfig/fpmconfig_add.tpl | 74 +++++++++++++++++++ .../admin/phpconfig/fpmconfig_edit.tpl | 74 +++++++++++++++++++ 10 files changed, 197 insertions(+), 3 deletions(-) diff --git a/install/froxlor.sql b/install/froxlor.sql index 449742e5..c90463e5 100644 --- a/install/froxlor.sql +++ b/install/froxlor.sql @@ -848,6 +848,7 @@ CREATE TABLE `panel_fpmdaemons` ( `max_requests` int(4) NOT NULL DEFAULT '0', `idle_timeout` int(4) NOT NULL DEFAULT '30', `limit_extensions` varchar(255) NOT NULL default '.php', + `custom_config` text NOT NULL DEFAULT '', PRIMARY KEY (`id`), UNIQUE KEY `reload` (`reload_cmd`), UNIQUE KEY `config` (`config_dir`) diff --git a/install/updates/froxlor/0.10/update_0.10.inc.php b/install/updates/froxlor/0.10/update_0.10.inc.php index bf2b44a5..370f612c 100644 --- a/install/updates/froxlor/0.10/update_0.10.inc.php +++ b/install/updates/froxlor/0.10/update_0.10.inc.php @@ -523,3 +523,10 @@ if (\Froxlor\Froxlor::isFroxlorVersion('0.10.9')) { showUpdateStep("Updating from 0.10.9 to 0.10.10", false); \Froxlor\Froxlor::updateToVersion('0.10.10'); } + +if (\Froxlor\Froxlor::isDatabaseVersion('201912100')) { + showUpdateStep("Adding custom phpfpm configuration field"); + Database::query("ALTER TABLE `" . TABLE_PANEL_PHPDAEMONS . "` ADD `custom_config` text NOT NULL DEFAULT '' AFTER `limit_extensions`;"); + lastStepStatus(0); + \Froxlor\Froxlor::updateToDbVersion('201912310'); +} diff --git a/lib/Froxlor/Api/Commands/FpmDaemons.php b/lib/Froxlor/Api/Commands/FpmDaemons.php index f36c1a19..4f94e2e9 100644 --- a/lib/Froxlor/Api/Commands/FpmDaemons.php +++ b/lib/Froxlor/Api/Commands/FpmDaemons.php @@ -150,6 +150,8 @@ class FpmDaemons extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc * optional, default 0 * @param string $limit_extensions * optional, limit execution to the following extensions, default '.php' + * @param string $custom_config + * optional, custom settings appended to phpfpm configuration * * @access admin * @throws \Exception @@ -173,6 +175,7 @@ class FpmDaemons extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc $max_requests = $this->getParam('max_requests', true, 0); $idle_timeout = $this->getParam('idle_timeout', true, 0); $limit_extensions = $this->getParam('limit_extensions', true, '.php'); + $custom_config = $this->getParam('custom_config', true, ''); // validation $description = \Froxlor\Validate\Validate::validate($description, 'description', '', '', array(), true); @@ -206,7 +209,8 @@ class FpmDaemons extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc `max_spare_servers` = :max_spare_servers, `max_requests` = :max_requests, `idle_timeout` = :idle_timeout, - `limit_extensions` = :limit_extensions + `limit_extensions` = :limit_extensions, + `custom_config` = :custom_config "); $ins_data = array( 'desc' => $description, @@ -219,7 +223,8 @@ class FpmDaemons extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc 'max_spare_servers' => $max_spare_servers, 'max_requests' => $max_requests, 'idle_timeout' => $idle_timeout, - 'limit_extensions' => $limit_extensions + 'limit_extensions' => $limit_extensions, + 'custom_config' => $custom_config ); Database::pexecute($ins_stmt, $ins_data); $id = Database::lastInsertId(); @@ -261,6 +266,8 @@ class FpmDaemons extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc * optional, default 0 * @param string $limit_extensions * optional, limit execution to the following extensions, default '.php' + * @param string $custom_config + * optional, custom settings appended to phpfpm configuration * * @access admin * @throws \Exception @@ -289,6 +296,7 @@ class FpmDaemons extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc $max_requests = $this->getParam('max_requests', true, $result['max_requests']); $idle_timeout = $this->getParam('idle_timeout', true, $result['idle_timeout']); $limit_extensions = $this->getParam('limit_extensions', true, $result['limit_extensions']); + $custom_config = $this->getParam('custom_config', true, $result['custom_config']); // validation $description = \Froxlor\Validate\Validate::validate($description, 'description', '', '', array(), true); @@ -322,7 +330,8 @@ class FpmDaemons extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc `max_spare_servers` = :max_spare_servers, `max_requests` = :max_requests, `idle_timeout` = :idle_timeout, - `limit_extensions` = :limit_extensions + `limit_extensions` = :limit_extensions, + `custom_config` = :custom_config WHERE `id` = :id "); $upd_data = array( @@ -337,6 +346,7 @@ class FpmDaemons extends \Froxlor\Api\ApiCommand implements \Froxlor\Api\Resourc 'max_requests' => $max_requests, 'idle_timeout' => $idle_timeout, 'limit_extensions' => $limit_extensions, + 'custom_config' => $custom_config, 'id' => $id ); Database::pexecute($upd_stmt, $upd_data, true, true); diff --git a/lib/Froxlor/Cron/Http/Php/Fpm.php b/lib/Froxlor/Cron/Http/Php/Fpm.php index ffb1338a..c74cace8 100644 --- a/lib/Froxlor/Cron/Http/Php/Fpm.php +++ b/lib/Froxlor/Cron/Http/Php/Fpm.php @@ -115,6 +115,7 @@ class Fpm $fpm_requests = (int) $this->fpm_cfg['max_requests']; $fpm_process_idle_timeout = (int) $this->fpm_cfg['idle_timeout']; $fpm_limit_extensions = $this->fpm_cfg['limit_extensions']; + $fpm_custom_config = $this->fpm_cfg['custom_config']; if ($fpm_children == 0) { $fpm_children = 1; @@ -260,6 +261,12 @@ class Fpm $fpm_config .= 'php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f ' . $this->domain['email'] . "\n"; } + // append custom phpfpm configuration + if (! empty($fpm_custom_config)) { + $fpm_config .= "\n; Custom Configuration\n"; + $fpm_config .= \Froxlor\PhpHelper::replaceVariables($fpm_custom_config, $php_ini_variables); + } + fwrite($fh, $fpm_config, strlen($fpm_config)); fclose($fh); } diff --git a/lib/formfields/admin/phpconfig/formfield.fpmconfig_add.php b/lib/formfields/admin/phpconfig/formfield.fpmconfig_add.php index b2074877..b2aa0c04 100644 --- a/lib/formfields/admin/phpconfig/formfield.fpmconfig_add.php +++ b/lib/formfields/admin/phpconfig/formfield.fpmconfig_add.php @@ -86,6 +86,13 @@ return array( 'desc' => $lng['serversettings']['phpfpm_settings']['limit_extensions']['description'], 'type' => 'text', 'value' => '.php' + ), + 'custom_config' => array( + 'label' => $lng['serversettings']['phpfpm_settings']['custom_config']['title'], + 'desc' => $lng['serversettings']['phpfpm_settings']['custom_config']['description'], + 'type' => 'textarea', + 'cols' => 50, + 'rows' => 7 ) ) ) diff --git a/lib/formfields/admin/phpconfig/formfield.fpmconfig_edit.php b/lib/formfields/admin/phpconfig/formfield.fpmconfig_edit.php index 01209b21..78fdcf72 100644 --- a/lib/formfields/admin/phpconfig/formfield.fpmconfig_edit.php +++ b/lib/formfields/admin/phpconfig/formfield.fpmconfig_edit.php @@ -87,6 +87,14 @@ return array( 'desc' => $lng['serversettings']['phpfpm_settings']['limit_extensions']['description'], 'type' => 'text', 'value' => $result['limit_extensions'] + ), + 'custom_config' => array( + 'label' => $lng['serversettings']['phpfpm_settings']['custom_config']['title'], + 'desc' => $lng['serversettings']['phpfpm_settings']['custom_config']['description'], + 'type' => 'textarea', + 'cols' => 50, + 'rows' => 7, + 'value' => $result['custom_config'] ) ) ) diff --git a/lng/english.lng.php b/lng/english.lng.php index 626ff1c7..a7ec7f80 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -2085,3 +2085,6 @@ $lng['serversettings']['apply_phpconfigs_default']['title'] = 'Default value for $lng['admin']['domain_sslenabled'] = 'Enable usage of SSL'; $lng['admin']['domain_honorcipherorder'] = 'Honor the (server) cipher order, default no'; $lng['admin']['domain_sessiontickets'] = 'Enable TLS sessiontickets (RFC 5077), default yes'; + +$lng['serversettings']['phpfpm_settings']['custom_config']['title'] = 'Custom Configuration'; +$lng['serversettings']['phpfpm_settings']['custom_config']['description'] = 'Add custom configuration to each PHP-FPM version instance, for example pm.status_path = /status for monitoring. Variables below can be used here.'; diff --git a/lng/german.lng.php b/lng/german.lng.php index 667f6ea3..92fbaf6a 100644 --- a/lng/german.lng.php +++ b/lng/german.lng.php @@ -1732,3 +1732,6 @@ $lng['serversettings']['apply_phpconfigs_default']['title'] = 'Standardwert für $lng['admin']['domain_sslenabled'] = 'Aktiviere Nutzung von SSL'; $lng['admin']['domain_honorcipherorder'] = 'Bevorzuge die serverseitige Cipher Reihenfolge, Standardwert nein'; $lng['admin']['domain_sessiontickets'] = 'Aktiviere TLS Sessiontickets (RFC 5077), Standardwert ja'; + +$lng['serversettings']['phpfpm_settings']['custom_config']['title'] = 'Benutzerdefinierte Konfiguration'; +$lng['serversettings']['phpfpm_settings']['custom_config']['description'] = 'Füge eine benutzerdefinierte Einstellungen zur PHP-FPM Instanz hinzu, beispielsweise pm.status_path = /status für Monitoring. Unten ersichtliche Variablen können verwendet werden.'; diff --git a/templates/Sparkle/admin/phpconfig/fpmconfig_add.tpl b/templates/Sparkle/admin/phpconfig/fpmconfig_add.tpl index 51a31dfd..6dd46ae1 100644 --- a/templates/Sparkle/admin/phpconfig/fpmconfig_add.tpl +++ b/templates/Sparkle/admin/phpconfig/fpmconfig_add.tpl @@ -21,4 +21,78 @@ $header + +
+
+
+

+ {$lng['admin']['templates']['template_replace_vars']} +

+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{$lng['panel']['variable']}{$lng['panel']['description']}
{PEAR_DIR}{$lng['admin']['phpconfig']['pear_dir']}
{OPEN_BASEDIR_C}{$lng['admin']['phpconfig']['open_basedir_c']}
{OPEN_BASEDIR}{$lng['admin']['phpconfig']['open_basedir']}
{OPEN_BASEDIR_GLOBAL}{$lng['admin']['phpconfig']['open_basedir_global']}
{TMP_DIR}{$lng['admin']['phpconfig']['tmp_dir']}
{CUSTOMER_EMAIL}{$lng['admin']['phpconfig']['customer_email']}
{ADMIN_EMAIL}{$lng['admin']['phpconfig']['admin_email']}
{DOMAIN}{$lng['admin']['phpconfig']['domain']}
{CUSTOMER}{$lng['admin']['phpconfig']['customer']}
{ADMIN}{$lng['admin']['phpconfig']['admin']}
{DOCUMENT_ROOT}{$lng['admin']['phpconfig']['docroot']}
{CUSTOMER_HOMEDIR}{$lng['admin']['phpconfig']['homedir']}
+ +
+ +
+ $footer diff --git a/templates/Sparkle/admin/phpconfig/fpmconfig_edit.tpl b/templates/Sparkle/admin/phpconfig/fpmconfig_edit.tpl index c1383a9b..1fa660a7 100644 --- a/templates/Sparkle/admin/phpconfig/fpmconfig_edit.tpl +++ b/templates/Sparkle/admin/phpconfig/fpmconfig_edit.tpl @@ -22,4 +22,78 @@ $header + +
+
+
+

+ {$lng['admin']['templates']['template_replace_vars']} +

+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{$lng['panel']['variable']}{$lng['panel']['description']}
{PEAR_DIR}{$lng['admin']['phpconfig']['pear_dir']}
{OPEN_BASEDIR_C}{$lng['admin']['phpconfig']['open_basedir_c']}
{OPEN_BASEDIR}{$lng['admin']['phpconfig']['open_basedir']}
{OPEN_BASEDIR_GLOBAL}{$lng['admin']['phpconfig']['open_basedir_global']}
{TMP_DIR}{$lng['admin']['phpconfig']['tmp_dir']}
{CUSTOMER_EMAIL}{$lng['admin']['phpconfig']['customer_email']}
{ADMIN_EMAIL}{$lng['admin']['phpconfig']['admin_email']}
{DOMAIN}{$lng['admin']['phpconfig']['domain']}
{CUSTOMER}{$lng['admin']['phpconfig']['customer']}
{ADMIN}{$lng['admin']['phpconfig']['admin']}
{DOCUMENT_ROOT}{$lng['admin']['phpconfig']['docroot']}
{CUSTOMER_HOMEDIR}{$lng['admin']['phpconfig']['homedir']}
+ +
+ +
+ $footer