added new configio-class to reduce the duplicate code of removing config-files for the webservers (it's all pretty much the same), CAUTION: very untested
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
257
lib/classes/webserver/class.ConfigIO.php
Normal file
257
lib/classes/webserver/class.ConfigIO.php
Normal file
@@ -0,0 +1,257 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file is part of the Froxlor project.
|
||||||
|
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the COPYING
|
||||||
|
* file that was distributed with this source code. You can also view the
|
||||||
|
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||||
|
*
|
||||||
|
* @copyright (c) the authors
|
||||||
|
* @author Michael Kaufmann <mkaufmann@nutime.de>
|
||||||
|
* @author Froxlor team <team@froxlor.org> (2010-)
|
||||||
|
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||||
|
* @package Cron
|
||||||
|
*
|
||||||
|
* @since 0.9.29
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class ConfigIO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* internal settings array
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $_settings = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor gets the froxlor settings
|
||||||
|
* as array
|
||||||
|
*/
|
||||||
|
public function __construct(array $settings = null) {
|
||||||
|
$this->_settings = $settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clean up former created configs, including (if enabled)
|
||||||
|
* awstats, fcgid, php-fpm and of course automatically created
|
||||||
|
* webserver vhost and diroption files
|
||||||
|
*
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
public function cleanUp() {
|
||||||
|
// awstats files
|
||||||
|
$this->_cleanAwstatsFiles();
|
||||||
|
|
||||||
|
// fcgid files
|
||||||
|
$this->_cleanFcgidFiles();
|
||||||
|
|
||||||
|
// php-fpm files
|
||||||
|
$this->_cleanFpmFiles();
|
||||||
|
|
||||||
|
// clean webserver-configs
|
||||||
|
$this->_cleanWebserverConfigs();
|
||||||
|
|
||||||
|
// old htpasswd files
|
||||||
|
$this->_cleanHtpasswdFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove webserver related configuration files before regeneration
|
||||||
|
*
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
private function _cleanWebserverConfigs() {
|
||||||
|
|
||||||
|
// get directories
|
||||||
|
$configdirs = array();
|
||||||
|
$configdirs[] = makeCorrectDir($this->_getFile('system', 'apacheconf_vhost'));
|
||||||
|
$configdirs[] = makeCorrectDir($this->_getFile('system', 'apacheconf_diroptions'));
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
);
|
||||||
|
|
||||||
|
// iterate through all subdirs,
|
||||||
|
// look for vhost/diroption files
|
||||||
|
// and delete them
|
||||||
|
foreach ($its as $fullFileName => $it ) {
|
||||||
|
if ($it->isFile() && preg_match($pattern, $it->getFilename())) {
|
||||||
|
// remove file
|
||||||
|
safe_exec('rm -f '. escapeshellarg(makeCorrectFile($its->getPathname())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove htpasswd files before regeneration
|
||||||
|
*
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove awstats related configuration files before regeneration
|
||||||
|
*
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
private function _cleanAwstatsFiles() {
|
||||||
|
|
||||||
|
if ($this->_settings['system']['awstats_enabled'] == '0') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//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');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dont do anyting if the directory not exists
|
||||||
|
* (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']);
|
||||||
|
/**
|
||||||
|
* dont 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);
|
||||||
|
fclose($awstatsclean['fh']);
|
||||||
|
|
||||||
|
if ($awstatsclean['headerRead'] == $awstatsclean['header']
|
||||||
|
|| $awstatsclean['headerRead'] == $awstatsclean['headerold']
|
||||||
|
) {
|
||||||
|
$awstats_conf_file = makeCorrectFile($awstatsclean['fullentry']);
|
||||||
|
@unlink($awstats_conf_file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($awstatsclean);
|
||||||
|
//end dhr
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove fcgid related configuration files before regeneration
|
||||||
|
*
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
private function _cleanFcgidFiles() {
|
||||||
|
|
||||||
|
if ($this->_settings['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)
|
||||||
|
);
|
||||||
|
|
||||||
|
// 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 ) {
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove php-fpm related configuration files before regeneration
|
||||||
|
*
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
private function _cleanFpmFiles() {
|
||||||
|
|
||||||
|
if ($this->_settings['phpfpm']['enabled'] == '0') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get correct directory
|
||||||
|
$configdir = $this->_getFile('phpfpm', 'configdir');
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns a file/direcotry from the settings array and checks whether it 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) {
|
||||||
|
|
||||||
|
// read from settings
|
||||||
|
$file = $this->_settings[$group][$varname];
|
||||||
|
|
||||||
|
// check whether it exists
|
||||||
|
if ($check_exists && @file_exists($file) == false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return $file;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1120,15 +1120,8 @@ class apache
|
|||||||
fwrite($diroptions_file_handler, $diroptions_file);
|
fwrite($diroptions_file_handler, $diroptions_file);
|
||||||
fclose($diroptions_file_handler);
|
fclose($diroptions_file_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->wipeOutOldDiroptionConfigs();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// no more diroptions, but there might be some file-corpses which have to be removed
|
|
||||||
$this->wipeOutOldDiroptionConfigs();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write htpasswds
|
// Write htpasswds
|
||||||
|
|
||||||
@@ -1154,8 +1147,6 @@ class apache
|
|||||||
fwrite($htpasswd_file_handler, $htpasswd_file);
|
fwrite($htpasswd_file_handler, $htpasswd_file);
|
||||||
fclose($htpasswd_file_handler);
|
fclose($htpasswd_file_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->wipeOutOldHtpasswdConfigs();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1164,11 +1155,6 @@ class apache
|
|||||||
$this->logger->logAction(CRON_ACTION, LOG_WARNING, 'WARNING!!! ' . $this->settings['system']['apacheconf_htpasswddir'] . ' is not a directory. htpasswd directory protection is disabled!!!');
|
$this->logger->logAction(CRON_ACTION, LOG_WARNING, 'WARNING!!! ' . $this->settings['system']['apacheconf_htpasswddir'] . ' is not a directory. htpasswd directory protection is disabled!!!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// no more htpasswds, but there might be some file-corpses which have to be removed
|
|
||||||
$this->wipeOutOldHtpasswdConfigs();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write virtualhosts
|
// Write virtualhosts
|
||||||
|
|
||||||
@@ -1233,93 +1219,6 @@ class apache
|
|||||||
fclose($vhosts_file_handler);
|
fclose($vhosts_file_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->wipeOutOldVhostConfigs();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We remove old vhost config files
|
|
||||||
*/
|
|
||||||
|
|
||||||
protected function wipeOutOldVhostConfigs()
|
|
||||||
{
|
|
||||||
fwrite($this->debugHandler, ' apache::wipeOutOldVhostConfigs: cleaning ' . $this->settings['system']['apacheconf_vhost'] . "\n");
|
|
||||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, "cleaning " . $this->settings['system']['apacheconf_vhost']);
|
|
||||||
|
|
||||||
if(isConfigDir($this->settings['system']['apacheconf_vhost'], true))
|
|
||||||
{
|
|
||||||
$vhost_file_dirhandle = opendir($this->settings['system']['apacheconf_vhost']);
|
|
||||||
|
|
||||||
while(false !== ($vhost_filename = readdir($vhost_file_dirhandle)))
|
|
||||||
{
|
|
||||||
if($vhost_filename != '.'
|
|
||||||
&& $vhost_filename != '..'
|
|
||||||
&& !in_array($vhost_filename, $this->known_vhostfilenames)
|
|
||||||
&& preg_match('/^(05|10|20|21|22|30|50|51)_(froxlor|syscp)_(dirfix|ipandport|normal_vhost|wildcard_vhost|ssl_vhost)_(.+)\.conf$/', $vhost_filename)
|
|
||||||
&& file_exists(makeCorrectFile($this->settings['system']['apacheconf_vhost'] . '/' . $vhost_filename)))
|
|
||||||
{
|
|
||||||
fwrite($this->debugHandler, ' apache::wipeOutOldVhostConfigs: unlinking ' . $vhost_filename . "\n");
|
|
||||||
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'unlinking ' . $vhost_filename);
|
|
||||||
unlink(makeCorrectFile($this->settings['system']['apacheconf_vhost'] . '/' . $vhost_filename));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We remove old diroptions config files
|
|
||||||
*/
|
|
||||||
|
|
||||||
protected function wipeOutOldDiroptionConfigs()
|
|
||||||
{
|
|
||||||
fwrite($this->debugHandler, ' apache::wipeOutOldDiroptionConfigs: cleaning ' . $this->settings['system']['apacheconf_diroptions'] . "\n");
|
|
||||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, "cleaning " . $this->settings['system']['apacheconf_diroptions']);
|
|
||||||
|
|
||||||
if(isConfigDir($this->settings['system']['apacheconf_diroptions'], true))
|
|
||||||
{
|
|
||||||
$diroptions_file_dirhandle = opendir($this->settings['system']['apacheconf_diroptions']);
|
|
||||||
|
|
||||||
while(false !== ($diroptions_filename = readdir($diroptions_file_dirhandle)))
|
|
||||||
{
|
|
||||||
if($diroptions_filename != '.'
|
|
||||||
&& $diroptions_filename != '..'
|
|
||||||
&& !in_array($diroptions_filename, $this->known_diroptionsfilenames)
|
|
||||||
&& preg_match('/^40_(froxlor|syscp)_diroption_(.+)\.conf$/', $diroptions_filename)
|
|
||||||
&& file_exists(makeCorrectFile($this->settings['system']['apacheconf_diroptions'] . '/' . $diroptions_filename)))
|
|
||||||
{
|
|
||||||
fwrite($this->debugHandler, ' apache::wipeOutOldDiroptionConfigs: unlinking ' . $diroptions_filename . "\n");
|
|
||||||
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'unlinking ' . $diroptions_filename);
|
|
||||||
unlink(makeCorrectFile($this->settings['system']['apacheconf_diroptions'] . '/' . $diroptions_filename));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We remove old htpasswd config files
|
|
||||||
*/
|
|
||||||
|
|
||||||
protected function wipeOutOldHtpasswdConfigs()
|
|
||||||
{
|
|
||||||
fwrite($this->debugHandler, ' apache::wipeOutOldHtpasswdConfigs: cleaning ' . $this->settings['system']['apacheconf_htpasswddir'] . "\n");
|
|
||||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, "cleaning " . $this->settings['system']['apacheconf_htpasswddir']);
|
|
||||||
|
|
||||||
if(isConfigDir($this->settings['system']['apacheconf_htpasswddir'], true))
|
|
||||||
{
|
|
||||||
$htpasswds_file_dirhandle = opendir($this->settings['system']['apacheconf_htpasswddir']);
|
|
||||||
|
|
||||||
while(false !== ($htpasswd_filename = readdir($htpasswds_file_dirhandle)))
|
|
||||||
{
|
|
||||||
if($htpasswd_filename != '.'
|
|
||||||
&& $htpasswd_filename != '..'
|
|
||||||
&& !in_array($htpasswd_filename, $this->known_htpasswdsfilenames)
|
|
||||||
&& file_exists(makeCorrectFile($this->settings['system']['apacheconf_htpasswddir'] . '/' . $htpasswd_filename)))
|
|
||||||
{
|
|
||||||
fwrite($this->debugHandler, ' apache::wipeOutOldHtpasswdConfigs: unlinking ' . $htpasswd_filename . "\n");
|
|
||||||
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'unlinking ' . $htpasswd_filename);
|
|
||||||
unlink(makeCorrectFile($this->settings['system']['apacheconf_htpasswddir'] . '/' . $htpasswd_filename));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -947,8 +947,6 @@ class lighttpd
|
|||||||
fclose($vhosts_file_handler);
|
fclose($vhosts_file_handler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->wipeOutOldConfigs();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the diroptions
|
// Write the diroptions
|
||||||
@@ -969,29 +967,4 @@ class lighttpd
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function wipeOutOldConfigs()
|
|
||||||
{
|
|
||||||
fwrite($this->debugHandler, ' lighttpd::wipeOutOldConfigs: cleaning ' . $this->settings['system']['apacheconf_vhost'] . "\n");
|
|
||||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, "cleaning " . $this->settings['system']['apacheconf_vhost']);
|
|
||||||
|
|
||||||
if(isConfigDir($this->settings['system']['apacheconf_vhost'], true))
|
|
||||||
{
|
|
||||||
$vhost_file_dirhandle = opendir($this->settings['system']['apacheconf_vhost']);
|
|
||||||
|
|
||||||
while(false !== ($vhost_filename = readdir($vhost_file_dirhandle)))
|
|
||||||
{
|
|
||||||
if($vhost_filename != '.'
|
|
||||||
&& $vhost_filename != '..'
|
|
||||||
&& !in_array($vhost_filename, $this->known_filenames)
|
|
||||||
&& preg_match('/^(05|10|20|21|22|30|50|51)_(froxlor|syscp)_(dirfix|ipandport|normal_vhost|wildcard_vhost|ssl_vhost)_(.+)\.conf$/', $vhost_filename)
|
|
||||||
&& file_exists(makeCorrectFile($this->settings['system']['apacheconf_vhost'] . '/' . $vhost_filename)))
|
|
||||||
{
|
|
||||||
fwrite($this->debugHandler, ' lighttpd::wipeOutOldConfigs: unlinking ' . $vhost_filename . "\n");
|
|
||||||
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'unlinking ' . $vhost_filename);
|
|
||||||
unlink(makeCorrectFile($this->settings['system']['apacheconf_vhost'] . '/' . $vhost_filename));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -902,9 +902,6 @@ class nginx
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->wipeOutOldVhostConfigs();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -935,62 +932,6 @@ class nginx
|
|||||||
fwrite($htpasswd_file_handler, $htpasswd_file);
|
fwrite($htpasswd_file_handler, $htpasswd_file);
|
||||||
fclose($htpasswd_file_handler);
|
fclose($htpasswd_file_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->wipeOutOldHtpasswdConfigs();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function wipeOutOldVhostConfigs()
|
|
||||||
{
|
|
||||||
fwrite($this->debugHandler, ' nginx::wipeOutOldVhostConfigs: cleaning ' . $this->settings['system']['apacheconf_vhost'] . "\n");
|
|
||||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, "cleaning " . $this->settings['system']['apacheconf_vhost']);
|
|
||||||
|
|
||||||
if(isConfigDir($this->settings['system']['apacheconf_vhost'], true))
|
|
||||||
{
|
|
||||||
$vhost_file_dirhandle = opendir($this->settings['system']['apacheconf_vhost']);
|
|
||||||
|
|
||||||
while(false !== ($vhost_filename = readdir($vhost_file_dirhandle)))
|
|
||||||
{
|
|
||||||
if($vhost_filename != '.'
|
|
||||||
&& $vhost_filename != '..'
|
|
||||||
&& !in_array($vhost_filename, $this->known_filenames)
|
|
||||||
&& preg_match('/^(05|10|20|21|22|30|50|51)_(froxlor|syscp)_(dirfix|ipandport|normal_vhost|wildcard_vhost|ssl_vhost)_(.+)\.conf$/', $vhost_filename)
|
|
||||||
&& file_exists(makeCorrectFile($this->settings['system']['apacheconf_vhost'] . '/' . $vhost_filename)))
|
|
||||||
{
|
|
||||||
fwrite($this->debugHandler, ' nginx::wipeOutOldVhostConfigs: unlinking ' . $vhost_filename . "\n");
|
|
||||||
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'unlinking ' . $vhost_filename);
|
|
||||||
unlink(makeCorrectFile($this->settings['system']['apacheconf_vhost'] . '/' . $vhost_filename));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We remove old htpasswd config files
|
|
||||||
*/
|
|
||||||
protected function wipeOutOldHtpasswdConfigs()
|
|
||||||
{
|
|
||||||
fwrite($this->debugHandler, ' nginx::wipeOutOldHtpasswdConfigs: cleaning ' . $this->settings['system']['apacheconf_htpasswddir'] . "\n");
|
|
||||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, "cleaning " . $this->settings['system']['apacheconf_htpasswddir']);
|
|
||||||
|
|
||||||
if(isConfigDir($this->settings['system']['apacheconf_htpasswddir'])
|
|
||||||
&& file_exists($this->settings['system']['apacheconf_htpasswddir'])
|
|
||||||
&& is_dir($this->settings['system']['apacheconf_htpasswddir']))
|
|
||||||
{
|
|
||||||
$htpasswds_file_dirhandle = opendir($this->settings['system']['apacheconf_htpasswddir']);
|
|
||||||
|
|
||||||
while(false !== ($htpasswd_filename = readdir($htpasswds_file_dirhandle)))
|
|
||||||
{
|
|
||||||
if($htpasswd_filename != '.'
|
|
||||||
&& $htpasswd_filename != '..'
|
|
||||||
&& !in_array($htpasswd_filename, $this->known_htpasswdsfilenames)
|
|
||||||
&& file_exists(makeCorrectFile($this->settings['system']['apacheconf_htpasswddir'] . '/' . $htpasswd_filename)))
|
|
||||||
{
|
|
||||||
fwrite($this->debugHandler, ' nginx::wipeOutOldHtpasswdConfigs: unlinking ' . $htpasswd_filename . "\n");
|
|
||||||
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'unlinking ' . $htpasswd_filename);
|
|
||||||
unlink(makeCorrectFile($this->settings['system']['apacheconf_htpasswddir'] . '/' . $htpasswd_filename));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,12 +37,11 @@ $cronlog->logAction(CRON_ACTION, LOG_INFO, "Searching for tasks to do");
|
|||||||
$result_tasks = $db->query("SELECT `id`, `type`, `data` FROM `" . TABLE_PANEL_TASKS . "` ORDER BY `id` ASC");
|
$result_tasks = $db->query("SELECT `id`, `type`, `data` FROM `" . TABLE_PANEL_TASKS . "` ORDER BY `id` ASC");
|
||||||
$resultIDs = array();
|
$resultIDs = array();
|
||||||
|
|
||||||
while($row = $db->fetch_array($result_tasks))
|
while ($row = $db->fetch_array($result_tasks)) {
|
||||||
{
|
|
||||||
$resultIDs[] = $row['id'];
|
$resultIDs[] = $row['id'];
|
||||||
|
|
||||||
if($row['data'] != '')
|
if ($row['data'] != '') {
|
||||||
{
|
|
||||||
$row['data'] = unserialize($row['data']);
|
$row['data'] = unserialize($row['data']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,140 +49,42 @@ while($row = $db->fetch_array($result_tasks))
|
|||||||
* TYPE=1 MEANS TO REBUILD APACHE VHOSTS.CONF
|
* TYPE=1 MEANS TO REBUILD APACHE VHOSTS.CONF
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if($row['type'] == '1')
|
if ($row['type'] == '1') {
|
||||||
{
|
|
||||||
//dhr: cleanout froxlor-generated awstats configs prior to re-creation
|
|
||||||
if ($settings['system']['awstats_enabled'] == '1')
|
|
||||||
{
|
|
||||||
$awstatsclean['header'] = "## GENERATED BY FROXLOR\n";
|
|
||||||
$awstatsclean['headerold'] = "## GENERATED BY SYSCP\n";
|
|
||||||
$awstatsclean['path'] = $settings['system']['awstats_conf'];
|
|
||||||
|
|
||||||
/**
|
// get configuration-I/O object
|
||||||
* dont do anyting if the directory not exists
|
$configio = new ConfigIO($settings);
|
||||||
* (e.g. awstats not installed yet or whatever)
|
// clean up old configs
|
||||||
* fixes #45
|
$configio->cleanUp();
|
||||||
*/
|
|
||||||
if (is_dir($awstatsclean['path']))
|
|
||||||
{
|
|
||||||
$awstatsclean['dir'] = dir($awstatsclean['path']);
|
|
||||||
while($awstatsclean['entry'] = $awstatsclean['dir']->read()) {
|
|
||||||
$awstatsclean['fullentry'] = makeCorrectFile($awstatsclean['path'].'/'.$awstatsclean['entry']);
|
|
||||||
/**
|
|
||||||
* dont 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);
|
|
||||||
fclose($awstatsclean['fh']);
|
|
||||||
if($awstatsclean['headerRead'] == $awstatsclean['header'] || $awstatsclean['headerRead'] == $awstatsclean['headerold']) {
|
|
||||||
$awstats_conf_file = makeCorrectFile($awstatsclean['fullentry']);
|
|
||||||
$cronlog->logAction(CRON_ACTION, LOG_INFO, "Removing awstats configuration ".$awstats_conf_file." for re-creation");
|
|
||||||
@unlink($awstats_conf_file);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$cronlog->logAction(CRON_ACTION, LOG_WARNING, "File '".$awstatsclean['fullentry']."' could not be found, please check if you followed all the instructions on the configuration page");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unset($awstatsclean);
|
|
||||||
}
|
|
||||||
//end dhr
|
|
||||||
|
|
||||||
// clear fcgid - starter files prior to re-creation to keep it clean, #367
|
if (!isset($webserver)) {
|
||||||
if ($settings['system']['mod_fcgid'] == '1')
|
if ($settings['system']['webserver'] == "apache2") {
|
||||||
{
|
$websrv = 'apache';
|
||||||
$configdir = makeCorrectDir($settings['system']['mod_fcgid_configdir']);
|
if ($settings['system']['mod_fcgid'] == 1 || $settings['phpfpm']['enabled'] == 1) {
|
||||||
|
$websrv .= '_fcgid';
|
||||||
if (is_dir($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 )
|
|
||||||
{
|
|
||||||
if ($it->isFile() && $it->getFilename() == 'php-fcgi-starter')
|
|
||||||
{
|
|
||||||
removeImmutable($its->getPathname());
|
|
||||||
}
|
}
|
||||||
|
} elseif ($settings['system']['webserver'] == "lighttpd") {
|
||||||
|
$websrv = 'lighttpd';
|
||||||
|
if ($settings['system']['mod_fcgid'] == 1 || $settings['phpfpm']['enabled'] == 1) {
|
||||||
|
$websrv .= '_fcgid';
|
||||||
}
|
}
|
||||||
// now get rid of old stuff
|
} elseif($settings['system']['webserver'] == "nginx") {
|
||||||
//(but append /* so we don't delete the directory)
|
$websrv = 'nginx';
|
||||||
$configdir.='/*';
|
if ($settings['phpfpm']['enabled'] == 1) {
|
||||||
safe_exec('rm -rf '. makeCorrectFile($configdir));
|
$websrv .= '_phpfpm';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear php-fpm-configurations prior to re-creation to keep it clean
|
$webserver = new $websrv($db, $cronlog, $debugHandler, $idna_convert, $settings);
|
||||||
if ($settings['phpfpm']['enabled'] == '1')
|
|
||||||
{
|
|
||||||
$configdir = makeCorrectDir($settings['phpfpm']['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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($webserver))
|
if (isset($webserver)) {
|
||||||
{
|
|
||||||
if($settings['system']['webserver'] == "apache2")
|
|
||||||
{
|
|
||||||
if($settings['system']['mod_fcgid'] == 1 || $settings['phpfpm']['enabled'] == 1)
|
|
||||||
{
|
|
||||||
$webserver = new apache_fcgid($db, $cronlog, $debugHandler, $idna_convert, $settings);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$webserver = new apache($db, $cronlog, $debugHandler, $idna_convert, $settings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elseif($settings['system']['webserver'] == "lighttpd")
|
|
||||||
{
|
|
||||||
if($settings['system']['mod_fcgid'] == 1 || $settings['phpfpm']['enabled'] == 1)
|
|
||||||
{
|
|
||||||
$webserver = new lighttpd_fcgid($db, $cronlog, $debugHandler, $idna_convert, $settings);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$webserver = new lighttpd($db, $cronlog, $debugHandler, $idna_convert, $settings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elseif($settings['system']['webserver'] == "nginx")
|
|
||||||
{
|
|
||||||
if($settings['phpfpm']['enabled'] == 1)
|
|
||||||
{
|
|
||||||
$webserver = new nginx_phpfpm($db, $cronlog, $debugHandler, $idna_convert, $settings);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$webserver = new nginx($db, $cronlog, $debugHandler, $idna_convert, $settings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isset($webserver))
|
|
||||||
{
|
|
||||||
$webserver->createIpPort();
|
$webserver->createIpPort();
|
||||||
$webserver->createVirtualHosts();
|
$webserver->createVirtualHosts();
|
||||||
$webserver->createFileDirOptions();
|
$webserver->createFileDirOptions();
|
||||||
$webserver->writeConfigs();
|
$webserver->writeConfigs();
|
||||||
$webserver->createOwnVhostStarter();
|
$webserver->createOwnVhostStarter();
|
||||||
$webserver->reload();
|
$webserver->reload();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
echo "Please check you Webserver settings\n";
|
echo "Please check you Webserver settings\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user