combine webserver-reload command to parent class to avoid repeating code
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -3,7 +3,6 @@ namespace Froxlor\Cron\Http;
|
||||
|
||||
use Froxlor\Database\Database;
|
||||
use Froxlor\Settings;
|
||||
use Froxlor\Cron\Http\Php\Fpm;
|
||||
use Froxlor\Cron\Http\Php\PhpInterface;
|
||||
|
||||
/**
|
||||
@@ -46,30 +45,6 @@ class Apache extends HttpConfigBase
|
||||
*/
|
||||
private $deactivated = false;
|
||||
|
||||
public function reload()
|
||||
{
|
||||
if ((int) Settings::Get('phpfpm.enabled') == 1) {
|
||||
// get all start/stop commands
|
||||
$startstop_sel = Database::prepare("SELECT reload_cmd, config_dir FROM `" . TABLE_PANEL_FPMDAEMONS . "`");
|
||||
Database::pexecute($startstop_sel);
|
||||
$restart_cmds = $startstop_sel->fetchAll(\PDO::FETCH_ASSOC);
|
||||
// restart all php-fpm instances
|
||||
foreach ($restart_cmds as $restart_cmd) {
|
||||
// check whether the config dir is empty (no domains uses this daemon)
|
||||
// so we need to create a dummy
|
||||
$_conffiles = glob(\Froxlor\FileDir::makeCorrectFile($restart_cmd['config_dir'] . "/*.conf"));
|
||||
if ($_conffiles === false || empty($_conffiles)) {
|
||||
\Froxlor\FroxlorLogger::getInstanceOf()->logAction(\Froxlor\FroxlorLogger::CRON_ACTION, LOG_INFO, 'apache::reload: fpm config directory "' . $restart_cmd['config_dir'] . '" is empty. Creating dummy.');
|
||||
Fpm::createDummyPool($restart_cmd['config_dir']);
|
||||
}
|
||||
\Froxlor\FroxlorLogger::getInstanceOf()->logAction(\Froxlor\FroxlorLogger::CRON_ACTION, LOG_INFO, 'apache::reload: running ' . $restart_cmd['reload_cmd']);
|
||||
\Froxlor\FileDir::safe_exec(escapeshellcmd($restart_cmd['reload_cmd']));
|
||||
}
|
||||
}
|
||||
\Froxlor\FroxlorLogger::getInstanceOf()->logAction(\Froxlor\FroxlorLogger::CRON_ACTION, LOG_INFO, 'apache::reload: reloading apache');
|
||||
\Froxlor\FileDir::safe_exec(escapeshellcmd(Settings::Get('system.apachereload_command')));
|
||||
}
|
||||
|
||||
/**
|
||||
* define a standard <Directory>-statement, bug #32
|
||||
*/
|
||||
|
||||
@@ -128,7 +128,7 @@ class ConfigIO
|
||||
// iterate through all subdirs,
|
||||
// look for vhost/diroption files
|
||||
// and delete them
|
||||
foreach ($its as $fullFileName => $it) {
|
||||
foreach ($its as $it) {
|
||||
if ($it->isFile() && preg_match($pattern, $it->getFilename())) {
|
||||
// remove file
|
||||
\Froxlor\FileDir::safe_exec('rm -f ' . escapeshellarg(\Froxlor\FileDir::makeCorrectFile($its->getPathname())));
|
||||
@@ -232,7 +232,7 @@ class ConfigIO
|
||||
// look for php-fcgi-starter files
|
||||
// and take immutable-flag away from them
|
||||
// so we can delete them :)
|
||||
foreach ($its as $fullFileName => $it) {
|
||||
foreach ($its as $it) {
|
||||
if ($it->isFile() && $it->getFilename() == 'php-fcgi-starter') {
|
||||
// set chattr -i
|
||||
\Froxlor\FileDir::removeImmutable($its->getPathname());
|
||||
|
||||
@@ -3,6 +3,7 @@ namespace Froxlor\Cron\Http;
|
||||
|
||||
use Froxlor\Database\Database;
|
||||
use Froxlor\Settings;
|
||||
use Froxlor\Cron\Http\Php\Fpm;
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
@@ -27,6 +28,39 @@ use Froxlor\Settings;
|
||||
class HttpConfigBase
|
||||
{
|
||||
|
||||
public function reload()
|
||||
{
|
||||
$called_class = get_called_class();
|
||||
if ((int) Settings::Get('phpfpm.enabled') == 1) {
|
||||
// get all start/stop commands
|
||||
$startstop_sel = Database::prepare("SELECT reload_cmd, config_dir FROM `" . TABLE_PANEL_FPMDAEMONS . "`");
|
||||
Database::pexecute($startstop_sel);
|
||||
$restart_cmds = $startstop_sel->fetchAll(\PDO::FETCH_ASSOC);
|
||||
// restart all php-fpm instances
|
||||
foreach ($restart_cmds as $restart_cmd) {
|
||||
// check whether the config dir is empty (no domains uses this daemon)
|
||||
// so we need to create a dummy
|
||||
$_conffiles = glob(\Froxlor\FileDir::makeCorrectFile($restart_cmd['config_dir'] . "/*.conf"));
|
||||
if ($_conffiles === false || empty($_conffiles)) {
|
||||
\Froxlor\FroxlorLogger::getInstanceOf()->logAction(\Froxlor\FroxlorLogger::CRON_ACTION, LOG_INFO, $called_class . '::reload: fpm config directory "' . $restart_cmd['config_dir'] . '" is empty. Creating dummy.');
|
||||
Fpm::createDummyPool($restart_cmd['config_dir']);
|
||||
}
|
||||
\Froxlor\FroxlorLogger::getInstanceOf()->logAction(\Froxlor\FroxlorLogger::CRON_ACTION, LOG_INFO, $called_class . '::reload: running ' . $restart_cmd['reload_cmd']);
|
||||
\Froxlor\FileDir::safe_exec(escapeshellcmd($restart_cmd['reload_cmd']));
|
||||
}
|
||||
}
|
||||
\Froxlor\FroxlorLogger::getInstanceOf()->logAction(\Froxlor\FroxlorLogger::CRON_ACTION, LOG_INFO, $called_class . '::reload: reloading ' . $called_class);
|
||||
\Froxlor\FileDir::safe_exec(escapeshellcmd(Settings::Get('system.apachereload_command')));
|
||||
|
||||
/**
|
||||
* nginx does not auto-spawn fcgi-processes
|
||||
*/
|
||||
if (Settings::Get('system.webserver') == "nginx" && Settings::Get('system.phpreload_command') != '' && (int) Settings::Get('phpfpm.enabled') == 0) {
|
||||
\Froxlor\FroxlorLogger::getInstanceOf()->logAction(\Froxlor\FroxlorLogger::CRON_ACTION, LOG_INFO, $called_class . '::reload: restarting php processes');
|
||||
\Froxlor\FileDir::safe_exec(Settings::Get('system.phpreload_command'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* process special config as template, by substituting {VARIABLE} with the
|
||||
* respective value.
|
||||
|
||||
@@ -3,7 +3,6 @@ namespace Froxlor\Cron\Http;
|
||||
|
||||
use Froxlor\Database\Database;
|
||||
use Froxlor\Settings;
|
||||
use Froxlor\Cron\Http\Php\Fpm;
|
||||
use Froxlor\Cron\Http\Php\PhpInterface;
|
||||
|
||||
/**
|
||||
@@ -45,30 +44,6 @@ class Lighttpd extends HttpConfigBase
|
||||
*/
|
||||
private $deactivated = false;
|
||||
|
||||
public function reload()
|
||||
{
|
||||
if ((int) Settings::Get('phpfpm.enabled') == 1) {
|
||||
// get all start/stop commands
|
||||
$startstop_sel = Database::prepare("SELECT reload_cmd, config_dir FROM `" . TABLE_PANEL_FPMDAEMONS . "`");
|
||||
Database::pexecute($startstop_sel);
|
||||
$restart_cmds = $startstop_sel->fetchAll(\PDO::FETCH_ASSOC);
|
||||
// restart all php-fpm instances
|
||||
foreach ($restart_cmds as $restart_cmd) {
|
||||
// check whether the config dir is empty (no domains uses this daemon)
|
||||
// so we need to create a dummy
|
||||
$_conffiles = glob(\Froxlor\FileDir::makeCorrectFile($restart_cmd['config_dir'] . "/*.conf"));
|
||||
if ($_conffiles === false || empty($_conffiles)) {
|
||||
$this->logger->logAction(\Froxlor\FroxlorLogger::CRON_ACTION, LOG_INFO, 'lighttpd::reload: fpm config directory "' . $restart_cmd['config_dir'] . '" is empty. Creating dummy.');
|
||||
Fpm::createDummyPool($restart_cmd['config_dir']);
|
||||
}
|
||||
$this->logger->logAction(\Froxlor\FroxlorLogger::CRON_ACTION, LOG_INFO, 'lighttpd::reload: running ' . $restart_cmd['reload_cmd']);
|
||||
\Froxlor\FileDir::safe_exec(escapeshellcmd($restart_cmd['reload_cmd']));
|
||||
}
|
||||
}
|
||||
$this->logger->logAction(\Froxlor\FroxlorLogger::CRON_ACTION, LOG_INFO, 'lighttpd::reload: reloading lighttpd');
|
||||
\Froxlor\FileDir::safe_exec(escapeshellcmd(Settings::Get('system.apachereload_command')));
|
||||
}
|
||||
|
||||
public function createIpPort()
|
||||
{
|
||||
$result_ipsandports_stmt = Database::query("SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` ORDER BY `ip` ASC, `port` ASC");
|
||||
@@ -396,6 +371,7 @@ class Lighttpd extends HttpConfigBase
|
||||
protected function createLighttpdHosts($ipid, $ssl, $vhost_filename)
|
||||
{
|
||||
$domains = WebserverBase::getVhostsToCreate();
|
||||
$included_vhosts = array();
|
||||
foreach ($domains as $domain) {
|
||||
|
||||
if (is_dir(Settings::Get('system.apacheconf_vhost'))) {
|
||||
@@ -765,23 +741,21 @@ class Lighttpd extends HttpConfigBase
|
||||
));
|
||||
|
||||
while ($row_htpasswds = $result_stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||
if ($auth_backend_loaded[$domain['ipandport']] != 'yes' && $auth_backend_loaded[$domain['ssl_ipandport']] != 'yes') {
|
||||
if ($this->auth_backend_loaded[$domain['ipandport']] != 'yes' && $this->auth_backend_loaded[$domain['ssl_ipandport']] != 'yes') {
|
||||
$filename = $domain['customerid'] . '.htpasswd';
|
||||
|
||||
if ($this->auth_backend_loaded[$domain['ipandport']] != 'yes') {
|
||||
$auth_backend_loaded[$domain['ipandport']] = 'yes';
|
||||
$this->auth_backend_loaded[$domain['ipandport']] = 'yes';
|
||||
$diroption_text .= 'auth.backend = "htpasswd"' . "\n";
|
||||
$diroption_text .= 'auth.backend.htpasswd.userfile = "' . \Froxlor\FileDir::makeCorrectFile(Settings::Get('system.apacheconf_htpasswddir') . '/' . $filename) . '"' . "\n";
|
||||
$this->needed_htpasswds[$filename] = $row_htpasswds['username'] . ':' . $row_htpasswds['password'] . "\n";
|
||||
$diroption_text .= 'auth.require = ( ' . "\n";
|
||||
$previous_domain_id = '1';
|
||||
} elseif ($this->auth_backend_loaded[$domain['ssl_ipandport']] != 'yes') {
|
||||
$auth_backend_loaded[$domain['ssl_ipandport']] = 'yes';
|
||||
$this->auth_backend_loaded[$domain['ssl_ipandport']] = 'yes';
|
||||
$diroption_text .= 'auth.backend= "htpasswd"' . "\n";
|
||||
$diroption_text .= 'auth.backend.htpasswd.userfile = "' . \Froxlor\FileDir::makeCorrectFile(Settings::Get('system.apacheconf_htpasswddir') . '/' . $filename) . '"' . "\n";
|
||||
$this->needed_htpasswds[$filename] = $row_htpasswds['username'] . ':' . $row_htpasswds['password'] . "\n";
|
||||
$diroption_text .= 'auth.require = ( ' . "\n";
|
||||
$previous_domain_id = '1';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ namespace Froxlor\Cron\Http;
|
||||
|
||||
use Froxlor\Database\Database;
|
||||
use Froxlor\Settings;
|
||||
use Froxlor\Cron\Http\Php\Fpm;
|
||||
use Froxlor\Cron\Http\Php\PhpInterface;
|
||||
|
||||
/**
|
||||
@@ -55,39 +54,6 @@ class Nginx extends HttpConfigBase
|
||||
$this->nginx_server = $nginx_server;
|
||||
}
|
||||
|
||||
public function reload()
|
||||
{
|
||||
if ((int) Settings::Get('phpfpm.enabled') == 1) {
|
||||
// get all start/stop commands
|
||||
$startstop_sel = Database::prepare("SELECT reload_cmd, config_dir FROM `" . TABLE_PANEL_FPMDAEMONS . "`");
|
||||
Database::pexecute($startstop_sel);
|
||||
$restart_cmds = $startstop_sel->fetchAll(\PDO::FETCH_ASSOC);
|
||||
// restart all php-fpm instances
|
||||
foreach ($restart_cmds as $restart_cmd) {
|
||||
// check whether the config dir is empty (no domains uses this daemon)
|
||||
// so we need to create a dummy
|
||||
$_conffiles = glob(\Froxlor\FileDir::makeCorrectFile($restart_cmd['config_dir'] . "/*.conf"));
|
||||
if ($_conffiles === false || empty($_conffiles)) {
|
||||
\Froxlor\FroxlorLogger::getInstanceOf()->logAction(\Froxlor\FroxlorLogger::CRON_ACTION, LOG_INFO, 'nginx::reload: fpm config directory "' . $restart_cmd['config_dir'] . '" is empty. Creating dummy.');
|
||||
Fpm::createDummyPool($restart_cmd['config_dir']);
|
||||
}
|
||||
\Froxlor\FroxlorLogger::getInstanceOf()->logAction(\Froxlor\FroxlorLogger::CRON_ACTION, LOG_INFO, 'nginx::reload: running ' . $restart_cmd['reload_cmd']);
|
||||
\Froxlor\FileDir::safe_exec(escapeshellcmd($restart_cmd['reload_cmd']));
|
||||
}
|
||||
}
|
||||
|
||||
\Froxlor\FroxlorLogger::getInstanceOf()->logAction(\Froxlor\FroxlorLogger::CRON_ACTION, LOG_INFO, 'nginx::reload: reloading nginx');
|
||||
\Froxlor\FileDir::safe_exec(Settings::Get('system.apachereload_command'));
|
||||
|
||||
/**
|
||||
* nginx does not auto-spawn fcgi-processes
|
||||
*/
|
||||
if (Settings::Get('system.phpreload_command') != '' && (int) Settings::Get('phpfpm.enabled') == 0) {
|
||||
\Froxlor\FroxlorLogger::getInstanceOf()->logAction(\Froxlor\FroxlorLogger::CRON_ACTION, LOG_INFO, 'nginx::reload: restarting php processes');
|
||||
\Froxlor\FileDir::safe_exec(Settings::Get('system.phpreload_command'));
|
||||
}
|
||||
}
|
||||
|
||||
private function createLogformatEntry()
|
||||
{
|
||||
if (Settings::Get('system.logfiles_format') != '') {
|
||||
@@ -923,6 +889,7 @@ class Nginx extends HttpConfigBase
|
||||
$path = \Froxlor\FileDir::makeCorrectDir(substr($row_htpasswds['path'], strlen($domain['documentroot']) - 1));
|
||||
} else {
|
||||
// if the website contents is located in a subdirectory of the user
|
||||
$matches = array();
|
||||
preg_match('/^([\/[:print:]]*\/)([[:print:]\/]+){1}$/i', $row_htpasswds['path'], $matches);
|
||||
$path = \Froxlor\FileDir::makeCorrectDir(substr($row_htpasswds['path'], strlen($matches[1]) - 1));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user