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:
@@ -1120,15 +1120,8 @@ class apache
|
||||
fwrite($diroptions_file_handler, $diroptions_file);
|
||||
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
|
||||
|
||||
@@ -1154,8 +1147,6 @@ class apache
|
||||
fwrite($htpasswd_file_handler, $htpasswd_file);
|
||||
fclose($htpasswd_file_handler);
|
||||
}
|
||||
|
||||
$this->wipeOutOldHtpasswdConfigs();
|
||||
}
|
||||
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!!!');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// no more htpasswds, but there might be some file-corpses which have to be removed
|
||||
$this->wipeOutOldHtpasswdConfigs();
|
||||
}
|
||||
|
||||
// Write virtualhosts
|
||||
|
||||
@@ -1233,93 +1219,6 @@ class apache
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
$this->wipeOutOldConfigs();
|
||||
}
|
||||
|
||||
// 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);
|
||||
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");
|
||||
$resultIDs = array();
|
||||
|
||||
while($row = $db->fetch_array($result_tasks))
|
||||
{
|
||||
while ($row = $db->fetch_array($result_tasks)) {
|
||||
|
||||
$resultIDs[] = $row['id'];
|
||||
|
||||
if($row['data'] != '')
|
||||
{
|
||||
if ($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
|
||||
*/
|
||||
|
||||
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'];
|
||||
if ($row['type'] == '1') {
|
||||
|
||||
/**
|
||||
* dont do anyting if the directory not exists
|
||||
* (e.g. awstats not installed yet or whatever)
|
||||
* fixes #45
|
||||
*/
|
||||
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");
|
||||
}
|
||||
// get configuration-I/O object
|
||||
$configio = new ConfigIO($settings);
|
||||
// clean up old configs
|
||||
$configio->cleanUp();
|
||||
|
||||
if (!isset($webserver)) {
|
||||
if ($settings['system']['webserver'] == "apache2") {
|
||||
$websrv = 'apache';
|
||||
if ($settings['system']['mod_fcgid'] == 1 || $settings['phpfpm']['enabled'] == 1) {
|
||||
$websrv .= '_fcgid';
|
||||
}
|
||||
} elseif ($settings['system']['webserver'] == "lighttpd") {
|
||||
$websrv = 'lighttpd';
|
||||
if ($settings['system']['mod_fcgid'] == 1 || $settings['phpfpm']['enabled'] == 1) {
|
||||
$websrv .= '_fcgid';
|
||||
}
|
||||
} elseif($settings['system']['webserver'] == "nginx") {
|
||||
$websrv = 'nginx';
|
||||
if ($settings['phpfpm']['enabled'] == 1) {
|
||||
$websrv .= '_phpfpm';
|
||||
}
|
||||
}
|
||||
unset($awstatsclean);
|
||||
}
|
||||
//end dhr
|
||||
|
||||
// clear fcgid - starter files prior to re-creation to keep it clean, #367
|
||||
if ($settings['system']['mod_fcgid'] == '1')
|
||||
{
|
||||
$configdir = makeCorrectDir($settings['system']['mod_fcgid_configdir']);
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
// now get rid of old stuff
|
||||
//(but append /* so we don't delete the directory)
|
||||
$configdir.='/*';
|
||||
safe_exec('rm -rf '. makeCorrectFile($configdir));
|
||||
}
|
||||
$webserver = new $websrv($db, $cronlog, $debugHandler, $idna_convert, $settings);
|
||||
}
|
||||
|
||||
// clear php-fpm-configurations prior to re-creation to keep it clean
|
||||
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($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))
|
||||
{
|
||||
if (isset($webserver)) {
|
||||
$webserver->createIpPort();
|
||||
$webserver->createVirtualHosts();
|
||||
$webserver->createFileDirOptions();
|
||||
$webserver->writeConfigs();
|
||||
$webserver->createOwnVhostStarter();
|
||||
$webserver->reload();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
echo "Please check you Webserver settings\n";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user