From c5c04ebe9c1898b7c0b6c5e44b5491215b9eedb0 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Mon, 5 Feb 2024 22:09:49 +0100 Subject: [PATCH] fix adding/editing domains as customer when php is not enabled for the domain; don't add custom-vhost-content to deactivated domain-vhosts Signed-off-by: Michael Kaufmann --- lib/Froxlor/Api/Commands/Domains.php | 3 +- lib/Froxlor/Api/Commands/SubDomains.php | 33 ++++++++++--------- lib/Froxlor/Cron/Http/Apache.php | 44 +++++++++++++------------ 3 files changed, 43 insertions(+), 37 deletions(-) diff --git a/lib/Froxlor/Api/Commands/Domains.php b/lib/Froxlor/Api/Commands/Domains.php index c86929560d..6563f4c229 100644 --- a/lib/Froxlor/Api/Commands/Domains.php +++ b/lib/Froxlor/Api/Commands/Domains.php @@ -519,7 +519,8 @@ public function add() $mod_fcgid_maxrequests = '-1'; } } else { - $phpenabled = '1'; + // set default to whether the customer has php enabled or not + $phpenabled = $customer['phpenabled']; $openbasedir = '1'; if ((int)Settings::Get('phpfpm.enabled') == 1) { diff --git a/lib/Froxlor/Api/Commands/SubDomains.php b/lib/Froxlor/Api/Commands/SubDomains.php index 802239bff2..6c796234c0 100644 --- a/lib/Froxlor/Api/Commands/SubDomains.php +++ b/lib/Froxlor/Api/Commands/SubDomains.php @@ -296,21 +296,24 @@ public function add() // assign default config $phpsid_result['phpsettingid'] = 1; } - // check whether the customer has chosen its own php-config - if ($phpsettingid > 0 && $phpsettingid != $phpsid_result['phpsettingid']) { - $phpsid_result['phpsettingid'] = intval($phpsettingid); - } - $allowed_phpconfigs = $customer['allowed_phpconfigs']; - if (!empty($allowed_phpconfigs)) { - $allowed_phpconfigs = json_decode($allowed_phpconfigs, true); - } else { - $allowed_phpconfigs = []; - } - // only with fcgid/fpm enabled will it be possible to select a php-setting - if ((int)Settings::Get('system.mod_fcgid') == 1 || (int)Settings::Get('phpfpm.enabled') == 1) { - if (!in_array($phpsid_result['phpsettingid'], $allowed_phpconfigs)) { - Response::standardError('notallowedphpconfigused', '', true); + if ($domain_check['phpenabled'] == 1) { + // check whether the customer has chosen its own php-config + if ($phpsettingid > 0 && $phpsettingid != $phpsid_result['phpsettingid']) { + $phpsid_result['phpsettingid'] = intval($phpsettingid); + } + + $allowed_phpconfigs = $customer['allowed_phpconfigs']; + if (!empty($allowed_phpconfigs)) { + $allowed_phpconfigs = json_decode($allowed_phpconfigs, true); + } else { + $allowed_phpconfigs = []; + } + // only with fcgid/fpm enabled will it be possible to select a php-setting + if ((int)Settings::Get('system.mod_fcgid') == 1 || (int)Settings::Get('phpfpm.enabled') == 1) { + if (!in_array($phpsid_result['phpsettingid'], $allowed_phpconfigs)) { + Response::standardError('notallowedphpconfigused', '', true); + } } } @@ -797,7 +800,7 @@ public function update() $allowed_phpconfigs = []; } // only with fcgid/fpm enabled will it be possible to select a php-setting - if ((int)Settings::Get('system.mod_fcgid') == 1 || (int)Settings::Get('phpfpm.enabled') == 1) { + if ((int)$result['phpenabled'] == 1 && ((int)Settings::Get('system.mod_fcgid') == 1 || (int)Settings::Get('phpfpm.enabled') == 1)) { if (!in_array($phpsettingid, $allowed_phpconfigs)) { Response::standardError('notallowedphpconfigused', '', true); } diff --git a/lib/Froxlor/Cron/Http/Apache.php b/lib/Froxlor/Cron/Http/Apache.php index a7f2147bb9..22cb86f340 100644 --- a/lib/Froxlor/Cron/Http/Apache.php +++ b/lib/Froxlor/Cron/Http/Apache.php @@ -25,19 +25,19 @@ namespace Froxlor\Cron\Http; -use Froxlor\Froxlor; use Froxlor\Cron\Http\Php\PhpInterface; use Froxlor\Customer\Customer; use Froxlor\Database\Database; use Froxlor\Domain\Domain; use Froxlor\FileDir; +use Froxlor\Froxlor; use Froxlor\FroxlorLogger; use Froxlor\Http\Directory; use Froxlor\Http\Statistics; use Froxlor\PhpHelper; use Froxlor\Settings; -use Froxlor\Validate\Validate; use Froxlor\System\Crypt; +use Froxlor\Validate\Validate; use PDO; class Apache extends HttpConfigBase @@ -159,7 +159,7 @@ public function createIpPort() if (Settings::Get('system.froxlordirectlyviahostname')) { $relpath = "/"; } else { - $relpath = "/".basename(Froxlor::getInstallDir()); + $relpath = "/" . basename(Froxlor::getInstallDir()); } // protect lib/userdata.inc.php $this->virtualhosts_data[$vhosts_filename] .= ' ' . "\n"; @@ -842,24 +842,26 @@ protected function getVhostContent($domain, $ssl_vhost = false) } $vhost_content .= $this->getLogfiles($domain); - if ($domain['specialsettings'] != '' && ($ssl_vhost == false || ($ssl_vhost == true && $domain['include_specialsettings'] == 1))) { - $vhost_content .= $this->processSpecialConfigTemplate($domain['specialsettings'], $domain, $domain['ip'], $domain['port'], $ssl_vhost) . "\n"; - } + if ($this->deactivated == false) { + if ($domain['specialsettings'] != '' && ($ssl_vhost == false || ($ssl_vhost == true && $domain['include_specialsettings'] == 1))) { + $vhost_content .= $this->processSpecialConfigTemplate($domain['specialsettings'], $domain, $domain['ip'], $domain['port'], $ssl_vhost) . "\n"; + } - if ($domain['ssl_specialsettings'] != '' && $ssl_vhost == true) { - $vhost_content .= $this->processSpecialConfigTemplate($domain['ssl_specialsettings'], $domain, $domain['ip'], $domain['port'], $ssl_vhost) . "\n"; - } + if ($domain['ssl_specialsettings'] != '' && $ssl_vhost == true) { + $vhost_content .= $this->processSpecialConfigTemplate($domain['ssl_specialsettings'], $domain, $domain['ip'], $domain['port'], $ssl_vhost) . "\n"; + } - if ($_vhost_content != '') { - $vhost_content .= $_vhost_content; - } + if ($_vhost_content != '') { + $vhost_content .= $_vhost_content; + } - if (Settings::Get('system.default_vhostconf') != '' && ($ssl_vhost == false || ($ssl_vhost == true && Settings::Get('system.include_default_vhostconf') == 1))) { - $vhost_content .= $this->processSpecialConfigTemplate(Settings::Get('system.default_vhostconf'), $domain, $domain['ip'], $domain['port'], $ssl_vhost) . "\n"; - } + if (Settings::Get('system.default_vhostconf') != '' && ($ssl_vhost == false || ($ssl_vhost == true && Settings::Get('system.include_default_vhostconf') == 1))) { + $vhost_content .= $this->processSpecialConfigTemplate(Settings::Get('system.default_vhostconf'), $domain, $domain['ip'], $domain['port'], $ssl_vhost) . "\n"; + } - if (Settings::Get('system.default_sslvhostconf') != '' && $ssl_vhost == true) { - $vhost_content .= $this->processSpecialConfigTemplate(Settings::Get('system.default_sslvhostconf'), $domain, $domain['ip'], $domain['port'], $ssl_vhost) . "\n"; + if (Settings::Get('system.default_sslvhostconf') != '' && $ssl_vhost == true) { + $vhost_content .= $this->processSpecialConfigTemplate(Settings::Get('system.default_sslvhostconf'), $domain, $domain['ip'], $domain['port'], $ssl_vhost) . "\n"; + } } } @@ -964,8 +966,8 @@ protected function composePhpOptions(&$domain, $ssl_vhost = false) if ($domain['openbasedir'] == '1') { if ($domain['openbasedir_path'] == '1' || strstr($domain['documentroot'], ":") !== false) { $_phpappendopenbasedir = Domain::appendOpenBasedirPath($domain['customerroot'], true); - } else if ($domain['openbasedir_path'] == '2' && strpos(dirname($domain['documentroot']).'/', $domain['customerroot']) !== false) { - $_phpappendopenbasedir = Domain::appendOpenBasedirPath(dirname($domain['documentroot']).'/', true); + } else if ($domain['openbasedir_path'] == '2' && strpos(dirname($domain['documentroot']) . '/', $domain['customerroot']) !== false) { + $_phpappendopenbasedir = Domain::appendOpenBasedirPath(dirname($domain['documentroot']) . '/', true); } else { $_phpappendopenbasedir = Domain::appendOpenBasedirPath($domain['documentroot'], true); } @@ -1013,10 +1015,10 @@ protected function getStats($domain) } $statDocroot = FileDir::makeCorrectFile($domain['customerroot'] . '/' . $statTool . $statDomain); - $stats_text .= ' Alias /'.$statTool.' "' . $statDocroot . '"' . "\n"; + $stats_text .= ' Alias /' . $statTool . ' "' . $statDocroot . '"' . "\n"; // awstats special requirement for icons if ($statTool == 'awstats') { - $stats_text .= ' Alias /awstats-icon "' . FileDir::makeCorrectDir(Settings::Get('system.awstats_icons')) . '"' . "\n"; + $stats_text .= ' Alias /awstats-icon "' . FileDir::makeCorrectDir(Settings::Get('system.awstats_icons')) . '"' . "\n"; } return $stats_text;