add possibility to add multiple php-fpm instances
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -17,13 +17,14 @@
|
||||
* @since 0.9.29
|
||||
*
|
||||
*/
|
||||
|
||||
class ConfigIO {
|
||||
class ConfigIO
|
||||
{
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*/
|
||||
public function __construct() {}
|
||||
public function __construct()
|
||||
{}
|
||||
|
||||
/**
|
||||
* clean up former created configs, including (if enabled)
|
||||
@@ -32,39 +33,40 @@ class ConfigIO {
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function cleanUp() {
|
||||
|
||||
public function cleanUp()
|
||||
{
|
||||
|
||||
// old error logs
|
||||
$this->_cleanErrLogs();
|
||||
|
||||
|
||||
// awstats files
|
||||
$this->_cleanAwstatsFiles();
|
||||
|
||||
|
||||
// fcgid files
|
||||
$this->_cleanFcgidFiles();
|
||||
|
||||
|
||||
// php-fpm files
|
||||
$this->_cleanFpmFiles();
|
||||
|
||||
|
||||
// clean webserver-configs
|
||||
$this->_cleanWebserverConfigs();
|
||||
|
||||
|
||||
// old htpasswd files
|
||||
$this->_cleanHtpasswdFiles();
|
||||
|
||||
|
||||
// customer-specified ssl-certificates
|
||||
$this->_cleanCustomerSslCerts();
|
||||
}
|
||||
|
||||
private function _cleanErrLogs() {
|
||||
|
||||
$err_dir = makeCorrectDir(FROXLOR_INSTALL_DIR."/logs/");
|
||||
if (@is_dir($err_dir)) {
|
||||
// now get rid of old stuff
|
||||
//(but append /*.log so we don't delete the directory)
|
||||
$err_dir.='/*.log';
|
||||
safe_exec('rm -rf '. makeCorrectFile($err_dir));
|
||||
}
|
||||
private function _cleanErrLogs()
|
||||
{
|
||||
$err_dir = makeCorrectDir(FROXLOR_INSTALL_DIR . "/logs/");
|
||||
if (@is_dir($err_dir)) {
|
||||
// now get rid of old stuff
|
||||
// (but append /*.log so we don't delete the directory)
|
||||
$err_dir .= '/*.log';
|
||||
safe_exec('rm -rf ' . makeCorrectFile($err_dir));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,8 +75,9 @@ class ConfigIO {
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
private function _cleanCustomerSslCerts() {
|
||||
|
||||
private function _cleanCustomerSslCerts()
|
||||
{
|
||||
|
||||
/*
|
||||
* only clean up if we're actually using SSL
|
||||
*/
|
||||
@@ -82,14 +85,14 @@ class ConfigIO {
|
||||
// get correct directory
|
||||
$configdir = $this->_getFile('system', 'customer_ssl_path');
|
||||
if ($configdir !== false) {
|
||||
|
||||
|
||||
$configdir = makeCorrectDir($configdir);
|
||||
|
||||
|
||||
if (@is_dir($configdir)) {
|
||||
// now get rid of old stuff
|
||||
//(but append /* so we don't delete the directory)
|
||||
$configdir.='/*';
|
||||
safe_exec('rm -rf '. makeCorrectFile($configdir));
|
||||
// (but append /* so we don't delete the directory)
|
||||
$configdir .= '/*';
|
||||
safe_exec('rm -rf ' . makeCorrectFile($configdir));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,39 +103,38 @@ class ConfigIO {
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
private function _cleanWebserverConfigs() {
|
||||
|
||||
private function _cleanWebserverConfigs()
|
||||
{
|
||||
|
||||
// get directories
|
||||
$configdirs = array();
|
||||
$dir = $this->_getFile('system', 'apacheconf_vhost');
|
||||
if ($dir !== false)
|
||||
$configdirs[] = makeCorrectDir($dir);
|
||||
|
||||
|
||||
$dir = $this->_getFile('system', 'apacheconf_diroptions');
|
||||
if ($dir !== false)
|
||||
$configdirs[] = makeCorrectDir($dir);
|
||||
|
||||
|
||||
// file pattern
|
||||
$pattern = "/^([0-9]){2}_(froxlor|syscp)_(.+)\.conf$/";
|
||||
|
||||
|
||||
// check ALL the folders
|
||||
foreach ($configdirs as $config_dir) {
|
||||
|
||||
|
||||
// check directory
|
||||
if (@is_dir($config_dir)) {
|
||||
|
||||
|
||||
// create directory iterator
|
||||
$its = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($config_dir)
|
||||
);
|
||||
|
||||
$its = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($config_dir));
|
||||
|
||||
// iterate through all subdirs,
|
||||
// look for vhost/diroption files
|
||||
// and delete them
|
||||
foreach ($its as $fullFileName => $it ) {
|
||||
foreach ($its as $fullFileName => $it) {
|
||||
if ($it->isFile() && preg_match($pattern, $it->getFilename())) {
|
||||
// remove file
|
||||
safe_exec('rm -f '. escapeshellarg(makeCorrectFile($its->getPathname())));
|
||||
safe_exec('rm -f ' . escapeshellarg(makeCorrectFile($its->getPathname())));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -144,19 +146,20 @@ class ConfigIO {
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
private function _cleanHtpasswdFiles() {
|
||||
|
||||
private function _cleanHtpasswdFiles()
|
||||
{
|
||||
|
||||
// get correct directory
|
||||
$configdir = $this->_getFile('system', 'apacheconf_htpasswddir');
|
||||
|
||||
|
||||
if ($configdir !== false) {
|
||||
$configdir = makeCorrectDir($configdir);
|
||||
|
||||
|
||||
if (@is_dir($configdir)) {
|
||||
// now get rid of old stuff
|
||||
//(but append /* so we don't delete the directory)
|
||||
$configdir.='/*';
|
||||
safe_exec('rm -rf '. makeCorrectFile($configdir));
|
||||
// (but append /* so we don't delete the directory)
|
||||
$configdir .= '/*';
|
||||
safe_exec('rm -rf ' . makeCorrectFile($configdir));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -166,37 +169,36 @@ class ConfigIO {
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
private function _cleanAwstatsFiles() {
|
||||
|
||||
private function _cleanAwstatsFiles()
|
||||
{
|
||||
if (Settings::Get('system.awstats_enabled') == '0') {
|
||||
return;
|
||||
}
|
||||
|
||||
//dhr: cleanout froxlor-generated awstats configs prior to re-creation
|
||||
|
||||
// dhr: cleanout froxlor-generated awstats configs prior to re-creation
|
||||
$awstatsclean['header'] = "## GENERATED BY FROXLOR\n";
|
||||
$awstatsclean['headerold'] = "## GENERATED BY SYSCP\n";
|
||||
$awstatsclean['path'] = $this->_getFile('system', 'awstats_conf');
|
||||
|
||||
|
||||
/**
|
||||
* don't do anything if the directory does not exist
|
||||
* (e.g. awstats not installed yet or whatever)
|
||||
* (e.g.
|
||||
* awstats not installed yet or whatever)
|
||||
* fixes #45
|
||||
*/
|
||||
*/
|
||||
if ($awstatsclean['path'] !== false && is_dir($awstatsclean['path'])) {
|
||||
$awstatsclean['dir'] = dir($awstatsclean['path']);
|
||||
while ($awstatsclean['entry'] = $awstatsclean['dir']->read()) {
|
||||
$awstatsclean['fullentry'] = makeCorrectFile($awstatsclean['path'].'/'.$awstatsclean['entry']);
|
||||
$awstatsclean['fullentry'] = makeCorrectFile($awstatsclean['path'] . '/' . $awstatsclean['entry']);
|
||||
/**
|
||||
* don't do anything if the file does not exist
|
||||
*/
|
||||
*/
|
||||
if (@file_exists($awstatsclean['fullentry'])) {
|
||||
$awstatsclean['fh'] = fopen($awstatsclean['fullentry'], 'r');
|
||||
$awstatsclean['headerRead'] = fgets($awstatsclean['fh'], strlen($awstatsclean['header'])+1);
|
||||
$awstatsclean['headerRead'] = fgets($awstatsclean['fh'], strlen($awstatsclean['header']) + 1);
|
||||
fclose($awstatsclean['fh']);
|
||||
|
||||
if ($awstatsclean['headerRead'] == $awstatsclean['header']
|
||||
|| $awstatsclean['headerRead'] == $awstatsclean['headerold']
|
||||
) {
|
||||
|
||||
if ($awstatsclean['headerRead'] == $awstatsclean['header'] || $awstatsclean['headerRead'] == $awstatsclean['headerold']) {
|
||||
$awstats_conf_file = makeCorrectFile($awstatsclean['fullentry']);
|
||||
@unlink($awstats_conf_file);
|
||||
}
|
||||
@@ -204,7 +206,7 @@ class ConfigIO {
|
||||
}
|
||||
}
|
||||
unset($awstatsclean);
|
||||
//end dhr
|
||||
// end dhr
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,39 +214,37 @@ class ConfigIO {
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
private function _cleanFcgidFiles() {
|
||||
|
||||
private function _cleanFcgidFiles()
|
||||
{
|
||||
if (Settings::Get('system.mod_fcgid') == '0') {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// get correct directory
|
||||
$configdir = $this->_getFile('system', 'mod_fcgid_configdir');
|
||||
if ($configdir !== false) {
|
||||
|
||||
|
||||
$configdir = makeCorrectDir($configdir);
|
||||
|
||||
|
||||
if (@is_dir($configdir)) {
|
||||
// create directory iterator
|
||||
$its = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($configdir)
|
||||
);
|
||||
|
||||
$its = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configdir));
|
||||
|
||||
// iterate through all subdirs,
|
||||
// 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 $fullFileName => $it) {
|
||||
if ($it->isFile() && $it->getFilename() == 'php-fcgi-starter') {
|
||||
// set chattr -i
|
||||
removeImmutable($its->getPathname());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// now get rid of old stuff
|
||||
//(but append /* so we don't delete the directory)
|
||||
$configdir.='/*';
|
||||
safe_exec('rm -rf '. makeCorrectFile($configdir));
|
||||
// (but append /* so we don't delete the directory)
|
||||
$configdir .= '/*';
|
||||
safe_exec('rm -rf ' . makeCorrectFile($configdir));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -254,33 +254,36 @@ class ConfigIO {
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
private function _cleanFpmFiles() {
|
||||
|
||||
private function _cleanFpmFiles()
|
||||
{
|
||||
if (Settings::Get('phpfpm.enabled') == '0') {
|
||||
return;
|
||||
}
|
||||
|
||||
// get correct directory
|
||||
$configdir = $this->_getFile('phpfpm', 'configdir');
|
||||
if ($configdir !== false) {
|
||||
|
||||
$configdir = makeCorrectDir($configdir);
|
||||
|
||||
|
||||
// get all fpm config paths
|
||||
$fpmconf_sel = Database::prepare("SELECT config_dir FROM `" . TABLE_PANEL_FPMDAEMONS . "`");
|
||||
Database::pexecute($fpmconf_sel);
|
||||
$fpmconf_paths = $fpmconf_sel->fetchAll(PDO::FETCH_ASSOC);
|
||||
// clean all php-fpm config-dirs
|
||||
foreach ($fpmconf_paths as $configdir) {
|
||||
$configdir = makeCorrectDir($configdir['config_dir']);
|
||||
if (@is_dir($configdir)) {
|
||||
// now get rid of old stuff
|
||||
//(but append /* so we don't delete the directory)
|
||||
$configdir.='/*';
|
||||
safe_exec('rm -rf '. makeCorrectFile($configdir));
|
||||
// (but append /* so we don't delete the directory)
|
||||
$configdir .= '/*';
|
||||
safe_exec('rm -rf ' . makeCorrectFile($configdir));
|
||||
} else {
|
||||
safe_exec('mkdir -p ' . $configdir);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// also remove aliasconfigdir #1273
|
||||
$aliasconfigdir = $this->_getFile('phpfpm', 'aliasconfigdir');
|
||||
if ($aliasconfigdir !== false) {
|
||||
$aliasconfigdir = makeCorrectDir($aliasconfigdir);
|
||||
if (@is_dir($aliasconfigdir)) {
|
||||
$aliasconfigdir.='/*';
|
||||
safe_exec('rm -rf '. makeCorrectFile($aliasconfigdir));
|
||||
$aliasconfigdir .= '/*';
|
||||
safe_exec('rm -rf ' . makeCorrectFile($aliasconfigdir));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -288,17 +291,21 @@ class ConfigIO {
|
||||
/**
|
||||
* returns a file/direcotry from the settings and checks whether it exists
|
||||
*
|
||||
* @param string $group settings-group
|
||||
* @param string $varname var-name
|
||||
* @param boolean $check_exists check if the file exists
|
||||
*
|
||||
* @param string $group
|
||||
* settings-group
|
||||
* @param string $varname
|
||||
* var-name
|
||||
* @param boolean $check_exists
|
||||
* check if the file exists
|
||||
*
|
||||
* @return string|boolean complete path including filename if any or false on error
|
||||
*/
|
||||
private function _getFile($group, $varname, $check_exists = true) {
|
||||
|
||||
private function _getFile($group, $varname, $check_exists = true)
|
||||
{
|
||||
|
||||
// read from settings
|
||||
$file = Settings::Get($group.'.'.$varname);
|
||||
|
||||
$file = Settings::Get($group . '.' . $varname);
|
||||
|
||||
// check whether it exists
|
||||
if ($check_exists && @file_exists($file) == false) {
|
||||
return false;
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
* @since 0.9.31
|
||||
*
|
||||
*/
|
||||
|
||||
class WebserverBase {
|
||||
class WebserverBase
|
||||
{
|
||||
|
||||
/**
|
||||
* returns an array with all entries required for all
|
||||
@@ -26,8 +26,8 @@ class WebserverBase {
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getVhostsToCreate() {
|
||||
|
||||
public static function getVhostsToCreate()
|
||||
{
|
||||
$query = "SELECT `d`.*, `pd`.`domain` AS `parentdomain`, `c`.`loginname`,
|
||||
`d`.`phpsettingid`, `c`.`adminid`, `c`.`guid`, `c`.`email`,
|
||||
`c`.`documentroot` AS `customerroot`, `c`.`deactivated`,
|
||||
@@ -35,20 +35,20 @@ class WebserverBase {
|
||||
`d`.`phpenabled` AS `phpenabled_vhost`,
|
||||
`d`.`mod_fcgid_starter`,`d`.`mod_fcgid_maxrequests`,
|
||||
`d`.`ocsp_stapling`
|
||||
FROM `".TABLE_PANEL_DOMAINS."` `d`
|
||||
FROM `" . TABLE_PANEL_DOMAINS . "` `d`
|
||||
|
||||
LEFT JOIN `".TABLE_PANEL_CUSTOMERS."` `c` USING(`customerid`)
|
||||
LEFT JOIN `".TABLE_PANEL_DOMAINS."` `pd` ON (`pd`.`id` = `d`.`parentdomainid`)
|
||||
LEFT JOIN `" . TABLE_PANEL_CUSTOMERS . "` `c` USING(`customerid`)
|
||||
LEFT JOIN `" . TABLE_PANEL_DOMAINS . "` `pd` ON (`pd`.`id` = `d`.`parentdomainid`)
|
||||
|
||||
WHERE `d`.`aliasdomain` IS NULL AND `d`.`email_only` <> '1'
|
||||
ORDER BY `d`.`parentdomainid` DESC, `d`.`iswildcarddomain`, `d`.`domain` ASC;
|
||||
";
|
||||
|
||||
|
||||
$result_domains_stmt = Database::query($query);
|
||||
|
||||
|
||||
$domains = array();
|
||||
while ($domain = $result_domains_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
|
||||
|
||||
// set whole domain
|
||||
$domains[$domain['domain']] = $domain;
|
||||
// set empty-defaults for non-ssl
|
||||
@@ -57,31 +57,46 @@ class WebserverBase {
|
||||
$domains[$domain['domain']]['ssl_key_file'] = '';
|
||||
$domains[$domain['domain']]['ssl_ca_file'] = '';
|
||||
$domains[$domain['domain']]['ssl_cert_chainfile'] = '';
|
||||
|
||||
|
||||
// now, if the domain has an ssl ip/port assigned, get
|
||||
// the corresponding information from the db
|
||||
if (domainHasSslIpPort($domain['id'])) {
|
||||
|
||||
|
||||
$ip_stmt = Database::prepare("
|
||||
SELECT `di`.`id_domain` , `p`.`ssl`, `p`.`ssl_cert_file`, `p`.`ssl_key_file`, `p`.`ssl_ca_file`, `p`.`ssl_cert_chainfile`
|
||||
FROM `".TABLE_DOMAINTOIP."` `di`, `".TABLE_PANEL_IPSANDPORTS."` `p`
|
||||
FROM `" . TABLE_DOMAINTOIP . "` `di`, `" . TABLE_PANEL_IPSANDPORTS . "` `p`
|
||||
WHERE `p`.`id` = `di`.`id_ipandports`
|
||||
AND `di`.`id_domain` = :domainid
|
||||
AND `p`.`ssl` = '1'
|
||||
");
|
||||
$ssl_ip = Database::pexecute_first($ip_stmt, array('domainid' => $domain['id']));
|
||||
|
||||
$ssl_ip = Database::pexecute_first($ip_stmt, array(
|
||||
'domainid' => $domain['id']
|
||||
));
|
||||
|
||||
// set ssl info for domain
|
||||
$domains[$domain['domain']]['ssl'] = '1';
|
||||
$domains[$domain['domain']]['ssl_cert_file'] = $ssl_ip['ssl_cert_file'];
|
||||
$domains[$domain['domain']]['ssl_key_file'] = $ssl_ip['ssl_key_file'];
|
||||
$domains[$domain['domain']]['ssl_ca_file'] = $ssl_ip['ssl_ca_file'];
|
||||
$domains[$domain['domain']]['ssl_cert_chainfile'] = $ssl_ip['ssl_cert_chainfile'];
|
||||
|
||||
}
|
||||
|
||||
// read fpm-config-id if using fpm
|
||||
if ((int) Settings::Get('phpfpm.enabled') == 1) {
|
||||
$fpm_sel_stmt = Database::prepare("
|
||||
SELECT f.id FROM `" . TABLE_PANEL_FPMDAEMONS . "` f
|
||||
LEFT JOIN `" . TABLE_PANEL_PHPCONFIGS . "` p ON p.fpmsettingid = f.id
|
||||
WHERE p.id = :phpconfigid
|
||||
");
|
||||
$fpm_config = Database::pexecute_first($fpm_sel_stmt, array(
|
||||
'phpconfigid' => $domain['phpsettingid']
|
||||
));
|
||||
if ($fpm_config) {
|
||||
$domains[$domain['domain']]['fpm_config_id'] = $fpm_config['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $domains;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user