fixes fpm and redirect loop fpm alias cannot be in docroot

This commit is contained in:
blackice2999
2012-05-08 16:27:32 +02:00
parent 89fdbbc436
commit 6d79b81a89

View File

@@ -30,21 +30,21 @@ class apache
private $logger = false; private $logger = false;
private $debugHandler = false; private $debugHandler = false;
private $idnaConvert = false; private $idnaConvert = false;
// protected // protected
protected $settings = array(); protected $settings = array();
protected $known_vhostfilenames = array(); protected $known_vhostfilenames = array();
protected $known_diroptionsfilenames = array(); protected $known_diroptionsfilenames = array();
protected $known_htpasswdsfilenames = array(); protected $known_htpasswdsfilenames = array();
protected $virtualhosts_data = array(); protected $virtualhosts_data = array();
protected $diroptions_data = array(); protected $diroptions_data = array();
protected $htpasswds_data = array(); protected $htpasswds_data = array();
/** /**
* indicator whether a customer is deactivated or not * indicator whether a customer is deactivated or not
* if yes, only the webroot will be generated * if yes, only the webroot will be generated
* *
* @var bool * @var bool
*/ */
private $_deactivated = false; private $_deactivated = false;
@@ -57,7 +57,7 @@ class apache
$this->idnaConvert = $idnaConvert; $this->idnaConvert = $idnaConvert;
$this->settings = $settings; $this->settings = $settings;
} }
protected function getDB() protected function getDB()
{ {
return $this->db; return $this->db;
@@ -75,7 +75,7 @@ class apache
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'reloading apache'); $this->logger->logAction(CRON_ACTION, LOG_INFO, 'reloading apache');
safe_exec(escapeshellcmd($this->settings['system']['apachereload_command'])); safe_exec(escapeshellcmd($this->settings['system']['apachereload_command']));
} }
/** /**
* define a standard <Directory>-statement, bug #32 * define a standard <Directory>-statement, bug #32
*/ */
@@ -99,7 +99,7 @@ class apache
fwrite($this->debugHandler, ' apache::_createStandardDirectoryEntry: unlinking ' . basename($vhosts_filename) . "\n"); fwrite($this->debugHandler, ' apache::_createStandardDirectoryEntry: unlinking ' . basename($vhosts_filename) . "\n");
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'unlinking ' . basename($vhosts_filename)); $this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'unlinking ' . basename($vhosts_filename));
unlink(makeCorrectFile($vhosts_filename)); unlink(makeCorrectFile($vhosts_filename));
} }
} }
else else
{ {
@@ -133,14 +133,14 @@ class apache
} else { } else {
$vhosts_folder = makeCorrectDir(dirname($this->settings['system']['apacheconf_vhost'])); $vhosts_folder = makeCorrectDir(dirname($this->settings['system']['apacheconf_vhost']));
} }
$vhosts_filename = makeCorrectFile($vhosts_folder . '/05_froxlor_default_errorhandler.conf'); $vhosts_filename = makeCorrectFile($vhosts_folder . '/05_froxlor_default_errorhandler.conf');
if(!isset($this->virtualhosts_data[$vhosts_filename])) if(!isset($this->virtualhosts_data[$vhosts_filename]))
{ {
$this->virtualhosts_data[$vhosts_filename] = ''; $this->virtualhosts_data[$vhosts_filename] = '';
} }
if($this->settings['defaultwebsrverrhandler']['err401'] != '') if($this->settings['defaultwebsrverrhandler']['err401'] != '')
{ {
$this->virtualhosts_data[$vhosts_filename].= 'ErrorDocument 401 ' . $this->settings['defaultwebsrverrhandler']['err401'] . "\n"; $this->virtualhosts_data[$vhosts_filename].= 'ErrorDocument 401 ' . $this->settings['defaultwebsrverrhandler']['err401'] . "\n";
@@ -155,7 +155,7 @@ class apache
{ {
$this->virtualhosts_data[$vhosts_filename].= 'ErrorDocument 404 ' . $this->settings['defaultwebsrverrhandler']['err404'] . "\n"; $this->virtualhosts_data[$vhosts_filename].= 'ErrorDocument 404 ' . $this->settings['defaultwebsrverrhandler']['err404'] . "\n";
} }
if($this->settings['defaultwebsrverrhandler']['err500'] != '') if($this->settings['defaultwebsrverrhandler']['err500'] != '')
{ {
$this->virtualhosts_data[$vhosts_filename].= 'ErrorDocument 500 ' . $this->settings['defaultwebsrverrhandler']['err500'] . "\n"; $this->virtualhosts_data[$vhosts_filename].= 'ErrorDocument 500 ' . $this->settings['defaultwebsrverrhandler']['err500'] . "\n";
@@ -213,7 +213,7 @@ class apache
{ {
$mypath = makeCorrectDir(dirname(dirname(dirname(__FILE__)))); $mypath = makeCorrectDir(dirname(dirname(dirname(__FILE__))));
} }
else else
{ {
$mypath = makeCorrectDir(dirname(dirname(dirname(dirname(__FILE__))))); $mypath = makeCorrectDir(dirname(dirname(dirname(dirname(__FILE__)))));
} }
@@ -225,7 +225,7 @@ class apache
} }
$this->virtualhosts_data[$vhosts_filename].= 'DocumentRoot "'.$mypath.'"'."\n"; $this->virtualhosts_data[$vhosts_filename].= 'DocumentRoot "'.$mypath.'"'."\n";
if($row_ipsandports['vhostcontainer_servername_statement'] == '1') if($row_ipsandports['vhostcontainer_servername_statement'] == '1')
{ {
$this->virtualhosts_data[$vhosts_filename].= ' ServerName ' . $this->settings['system']['hostname'] . "\n"; $this->virtualhosts_data[$vhosts_filename].= ' ServerName ' . $this->settings['system']['hostname'] . "\n";
@@ -236,7 +236,7 @@ class apache
&& $this->settings['system']['mod_fcgid'] == '1' && $this->settings['system']['mod_fcgid'] == '1'
) )
{ {
$configdir = makeCorrectDir($this->settings['system']['mod_fcgid_configdir'] . '/froxlor.panel/' . $this->settings['system']['hostname']); $configdir = makeCorrectDir($this->settings['system']['mod_fcgid_configdir'] . '/froxlor.panel/' . $this->settings['system']['hostname']);
$this->virtualhosts_data[$vhosts_filename].= ' FcgidIdleTimeout ' . $this->settings['system']['mod_fcgid_idle_timeout'] . "\n"; $this->virtualhosts_data[$vhosts_filename].= ' FcgidIdleTimeout ' . $this->settings['system']['mod_fcgid_idle_timeout'] . "\n";
if((int)$this->settings['system']['mod_fcgid_wrapper'] == 0) if((int)$this->settings['system']['mod_fcgid_wrapper'] == 0)
@@ -271,12 +271,15 @@ class apache
'safemode' => '0', 'safemode' => '0',
'email' => $this->settings['panel']['adminmail'], 'email' => $this->settings['panel']['adminmail'],
'loginname' => 'froxlor.panel', 'loginname' => 'froxlor.panel',
'documentroot' => $mypath 'documentroot' => $mypath,
); );
/**
* @var $php phpinterface_fpm
*/
$php = new phpinterface($this->getDB(), $this->settings, $domain); $php = new phpinterface($this->getDB(), $this->settings, $domain);
$this->virtualhosts_data[$vhosts_filename].= ' SuexecUserGroup "' . $this->settings['system']['mod_fcgid_httpuser'] . '" "' . $this->settings['system']['mod_fcgid_httpgroup'] . '"' . "\n"; $this->virtualhosts_data[$vhosts_filename].= ' SuexecUserGroup "' . $this->settings['system']['mod_fcgid_httpuser'] . '" "' . $this->settings['system']['mod_fcgid_httpgroup'] . '"' . "\n";
$this->virtualhosts_data[$vhosts_filename].= ' FastCgiExternalServer ' . $mypath . $domain['domain'] . "." . 'fpm.external -socket ' . $php->getInterface()->getSocketFile() . ' -user ' . $this->settings['system']['mod_fcgid_httpuser'] . ' -group ' . $this->settings['system']['mod_fcgid_httpuser'] . " -idle-timeout " . $this->settings['phpfpm']['idle_timeout'] . "\n"; $this->virtualhosts_data[$vhosts_filename].= ' FastCgiExternalServer ' . $php->getTempDir() . $domain['domain'] . "." . 'fpm.external -socket ' . $php->getInterface()->getSocketFile() . ' -user ' . $this->settings['system']['mod_fcgid_httpuser'] . ' -group ' . $this->settings['system']['mod_fcgid_httpuser'] . " -idle-timeout " . $this->settings['phpfpm']['idle_timeout'] . "\n";
$this->virtualhosts_data[$vhosts_filename].= ' <Directory "' . $mypath . '">' . "\n"; $this->virtualhosts_data[$vhosts_filename].= ' <Directory "' . $mypath . '">' . "\n";
$this->virtualhosts_data[$vhosts_filename].= ' AddHandler php5-fastcgi .php'. "\n"; $this->virtualhosts_data[$vhosts_filename].= ' AddHandler php5-fastcgi .php'. "\n";
$this->virtualhosts_data[$vhosts_filename].= ' Action php5-fastcgi /fastcgiphp' . "\n"; $this->virtualhosts_data[$vhosts_filename].= ' Action php5-fastcgi /fastcgiphp' . "\n";
@@ -284,7 +287,7 @@ class apache
$this->virtualhosts_data[$vhosts_filename].= ' Order allow,deny' . "\n"; $this->virtualhosts_data[$vhosts_filename].= ' Order allow,deny' . "\n";
$this->virtualhosts_data[$vhosts_filename].= ' allow from all' . "\n"; $this->virtualhosts_data[$vhosts_filename].= ' allow from all' . "\n";
$this->virtualhosts_data[$vhosts_filename].= ' </Directory>' . "\n"; $this->virtualhosts_data[$vhosts_filename].= ' </Directory>' . "\n";
$this->virtualhosts_data[$vhosts_filename].= ' Alias /fastcgiphp ' . $mypath . $domain['domain'] . "." . 'fpm.external' . "\n"; $this->virtualhosts_data[$vhosts_filename].= ' Alias /fastcgiphp ' . $php->getTempDir() . $domain['domain'] . "." . 'fpm.external' . "\n";
} }
/** /**
@@ -294,7 +297,7 @@ class apache
$this->virtualhosts_data[$vhosts_filename].= "\t\tAllow from all\n"; $this->virtualhosts_data[$vhosts_filename].= "\t\tAllow from all\n";
$this->virtualhosts_data[$vhosts_filename].= "\t\tOptions -Indexes\n"; $this->virtualhosts_data[$vhosts_filename].= "\t\tOptions -Indexes\n";
$this->virtualhosts_data[$vhosts_filename].= "\t</Directory>\n"; $this->virtualhosts_data[$vhosts_filename].= "\t</Directory>\n";
$this->virtualhosts_data[$vhosts_filename].= "\t<Directory \"'.$mypath.'*\">\n"; $this->virtualhosts_data[$vhosts_filename].= "\t<Directory \"'.$mypath.'*\">\n";
$this->virtualhosts_data[$vhosts_filename].= "\t\tOrder Deny,Allow\n"; $this->virtualhosts_data[$vhosts_filename].= "\t\tOrder Deny,Allow\n";
$this->virtualhosts_data[$vhosts_filename].= "\t\tDeny from All\n"; $this->virtualhosts_data[$vhosts_filename].= "\t\tDeny from All\n";
@@ -334,12 +337,12 @@ class apache
{ {
$this->virtualhosts_data[$vhosts_filename].= ' SSLEngine On' . "\n"; $this->virtualhosts_data[$vhosts_filename].= ' SSLEngine On' . "\n";
$this->virtualhosts_data[$vhosts_filename].= ' SSLCertificateFile ' . makeCorrectFile($row_ipsandports['ssl_cert_file']) . "\n"; $this->virtualhosts_data[$vhosts_filename].= ' SSLCertificateFile ' . makeCorrectFile($row_ipsandports['ssl_cert_file']) . "\n";
if($row_ipsandports['ssl_key_file'] != '') if($row_ipsandports['ssl_key_file'] != '')
{ {
$this->virtualhosts_data[$vhosts_filename].= ' SSLCertificateKeyFile ' . makeCorrectFile($row_ipsandports['ssl_key_file']) . "\n"; $this->virtualhosts_data[$vhosts_filename].= ' SSLCertificateKeyFile ' . makeCorrectFile($row_ipsandports['ssl_key_file']) . "\n";
} }
if($row_ipsandports['ssl_ca_file'] != '') if($row_ipsandports['ssl_ca_file'] != '')
{ {
$this->virtualhosts_data[$vhosts_filename].= ' SSLCACertificateFile ' . makeCorrectFile($row_ipsandports['ssl_ca_file']) . "\n"; $this->virtualhosts_data[$vhosts_filename].= ' SSLCACertificateFile ' . makeCorrectFile($row_ipsandports['ssl_ca_file']) . "\n";
@@ -358,7 +361,7 @@ class apache
} }
unset($vhosts_filename); unset($vhosts_filename);
} }
/** /**
* bug #32 * bug #32
*/ */
@@ -392,7 +395,7 @@ class apache
{ {
$_phpappendopenbasedir = appendOpenBasedirPath($domain['documentroot'], true); $_phpappendopenbasedir = appendOpenBasedirPath($domain['documentroot'], true);
} }
$_custom_openbasedir = explode(':', $this->settings['system']['phpappendopenbasedir']); $_custom_openbasedir = explode(':', $this->settings['system']['phpappendopenbasedir']);
foreach($_custom_openbasedir as $cobd) foreach($_custom_openbasedir as $cobd)
{ {
@@ -419,7 +422,7 @@ class apache
return $php_options_text; return $php_options_text;
} }
public function createOwnVhostStarter() public function createOwnVhostStarter()
{ {
} }
@@ -525,7 +528,7 @@ class apache
} }
else else
{ {
$stats_text.= ' Alias /webalizer "' . makeCorrectFile($domain['customerroot'] . '/webalizer/' . $domain['domain']) . '"' . "\n"; $stats_text.= ' Alias /webalizer "' . makeCorrectFile($domain['customerroot'] . '/webalizer/' . $domain['domain']) . '"' . "\n";
} }
} }
else else
@@ -549,7 +552,7 @@ class apache
{ {
$stats_text.= ' Alias /awstats "' . makeCorrectFile($domain['customerroot'] . '/awstats/' . $domain['domain']) . '"' . "\n"; $stats_text.= ' Alias /awstats "' . makeCorrectFile($domain['customerroot'] . '/awstats/' . $domain['domain']) . '"' . "\n";
$stats_text.= ' Alias /awstats-icon "' . makeCorrectDir($this->settings['system']['awstats_icons']) . '"' . "\n"; $stats_text.= ' Alias /awstats-icon "' . makeCorrectDir($this->settings['system']['awstats_icons']) . '"' . "\n";
} }
else else
{ {
$stats_text.= ' Alias /webalizer "' . makeCorrectFile($domain['customerroot'] . '/webalizer') . '"' . "\n"; $stats_text.= ' Alias /webalizer "' . makeCorrectFile($domain['customerroot'] . '/webalizer') . '"' . "\n";
@@ -609,13 +612,13 @@ class apache
touch($error_log); touch($error_log);
chown($error_log, $this->settings['system']['httpuser']); chown($error_log, $this->settings['system']['httpuser']);
chgrp($error_log, $this->settings['system']['httpgroup']); chgrp($error_log, $this->settings['system']['httpgroup']);
$access_log = makeCorrectFile($this->settings['system']['logfiles_directory'] . $domain['loginname'] . $speciallogfile . '-access.log'); $access_log = makeCorrectFile($this->settings['system']['logfiles_directory'] . $domain['loginname'] . $speciallogfile . '-access.log');
// Create the logfile if it does not exist (fixes #46) // Create the logfile if it does not exist (fixes #46)
touch($access_log); touch($access_log);
chown($access_log, $this->settings['system']['httpuser']); chown($access_log, $this->settings['system']['httpuser']);
chgrp($access_log, $this->settings['system']['httpgroup']); chgrp($access_log, $this->settings['system']['httpgroup']);
$logfiles_text.= ' ErrorLog "' . $error_log . "\"\n"; $logfiles_text.= ' ErrorLog "' . $error_log . "\"\n";
$logfiles_text.= ' CustomLog "' . $access_log .'" combined' . "\n"; $logfiles_text.= ' CustomLog "' . $access_log .'" combined' . "\n";
@@ -623,19 +626,19 @@ class apache
if($this->settings['system']['awstats_enabled'] == '1') if($this->settings['system']['awstats_enabled'] == '1')
{ {
if((int)$domain['parentdomainid'] == 0) if((int)$domain['parentdomainid'] == 0)
{ {
// prepare the aliases and subdomains for stats config files // prepare the aliases and subdomains for stats config files
$server_alias = ''; $server_alias = '';
$alias_domains = $this->db->query('SELECT `domain`, `iswildcarddomain`, `wwwserveralias` FROM `' . TABLE_PANEL_DOMAINS . '` $alias_domains = $this->db->query('SELECT `domain`, `iswildcarddomain`, `wwwserveralias` FROM `' . TABLE_PANEL_DOMAINS . '`
WHERE `aliasdomain`=\'' . $domain['id'] . '\' WHERE `aliasdomain`=\'' . $domain['id'] . '\'
OR `parentdomainid` =\''. $domain['id']. '\''); OR `parentdomainid` =\''. $domain['id']. '\'');
while(($alias_domain = $this->db->fetch_array($alias_domains)) !== false) while(($alias_domain = $this->db->fetch_array($alias_domains)) !== false)
{ {
$server_alias.= ' ' . $alias_domain['domain'] . ' '; $server_alias.= ' ' . $alias_domain['domain'] . ' ';
if($alias_domain['iswildcarddomain'] == '1') if($alias_domain['iswildcarddomain'] == '1')
{ {
$server_alias.= '*.' . $alias_domain['domain']; $server_alias.= '*.' . $alias_domain['domain'];
@@ -652,7 +655,7 @@ class apache
} }
} }
} }
if($domain['iswildcarddomain'] == '1') if($domain['iswildcarddomain'] == '1')
{ {
$alias = '*.' . $domain['domain']; $alias = '*.' . $domain['domain'];
@@ -668,8 +671,8 @@ class apache
$alias = ''; $alias = '';
} }
} }
// After inserting the AWStats information, // After inserting the AWStats information,
// be sure to build the awstats conf file as well // be sure to build the awstats conf file as well
// and chown it using $awstats_params, #258 // and chown it using $awstats_params, #258
// Bug 960 + Bug 970 : Use full $domain instead of custom $awstats_params as following classes depend on the informations // Bug 960 + Bug 970 : Use full $domain instead of custom $awstats_params as following classes depend on the informations
@@ -686,14 +689,14 @@ class apache
protected function getVhostFilename($domain, $ssl_vhost = false) protected function getVhostFilename($domain, $ssl_vhost = false)
{ {
if((int)$domain['parentdomainid'] == 0 if((int)$domain['parentdomainid'] == 0
&& isCustomerStdSubdomain((int)$domain['id']) == false && isCustomerStdSubdomain((int)$domain['id']) == false
&& ((int)$domain['ismainbutsubto'] == 0 && ((int)$domain['ismainbutsubto'] == 0
|| domainMainToSubExists($domain['ismainbutsubto']) == false) || domainMainToSubExists($domain['ismainbutsubto']) == false)
) { ) {
$vhost_no = '22'; $vhost_no = '22';
} }
elseif((int)$domain['parentdomainid'] == 0 elseif((int)$domain['parentdomainid'] == 0
&& isCustomerStdSubdomain((int)$domain['id']) == false && isCustomerStdSubdomain((int)$domain['id']) == false
&& (int)$domain['ismainbutsubto'] > 0 && (int)$domain['ismainbutsubto'] > 0
) { ) {
@@ -772,14 +775,14 @@ class apache
if(substr($corrected_docroot, -1) == '/') { if(substr($corrected_docroot, -1) == '/') {
$corrected_docroot = substr($corrected_docroot, 0, -1); $corrected_docroot = substr($corrected_docroot, 0, -1);
} }
/* Get domain's redirect code */ /* Get domain's redirect code */
$code = getDomainRedirectCode($domain['id']); $code = getDomainRedirectCode($domain['id']);
$modrew_red = ''; $modrew_red = '';
if ($code != '') { if ($code != '') {
$modrew_red = '[R='. $code . ';L]'; $modrew_red = '[R='. $code . ';L]';
} }
// redirect everything, not only root-directory, #541 // redirect everything, not only root-directory, #541
$vhost_content.= ' <IfModule mod_rewrite.c>'."\n"; $vhost_content.= ' <IfModule mod_rewrite.c>'."\n";
$vhost_content.= ' RewriteEngine On' . "\n"; $vhost_content.= ' RewriteEngine On' . "\n";
@@ -1308,10 +1311,10 @@ class apache
foreach($this->known_vhostfilenames as $vhostfilename){ foreach($this->known_vhostfilenames as $vhostfilename){
$known_phpfpm_files[]=preg_replace('/^(05|10|20|21|22|30|50|51)_(froxlor|syscp)_(dirfix|ipandport|normal_vhost|wildcard_vhost|ssl_vhost)_/', '', $vhostfilename); $known_phpfpm_files[]=preg_replace('/^(05|10|20|21|22|30|50|51)_(froxlor|syscp)_(dirfix|ipandport|normal_vhost|wildcard_vhost|ssl_vhost)_/', '', $vhostfilename);
} }
$configdir = $this->settings['phpfpm']['configdir']; $configdir = $this->settings['phpfpm']['configdir'];
$phpfpm_file_dirhandle = opendir($this->settings['phpfpm']['configdir']); $phpfpm_file_dirhandle = opendir($this->settings['phpfpm']['configdir']);
while(false !== ($phpfpm_filename = readdir($phpfpm_file_dirhandle))) while(false !== ($phpfpm_filename = readdir($phpfpm_file_dirhandle)))
{ {
if($phpfpm_filename != '.' if($phpfpm_filename != '.'
@@ -1364,10 +1367,10 @@ class apache
foreach($this->known_vhostfilenames as $vhostfilename){ foreach($this->known_vhostfilenames as $vhostfilename){
$known_phpfpm_files[]=preg_replace('/^(05|10|20|21|22|30|50|51)_(froxlor|syscp)_(dirfix|ipandport|normal_vhost|wildcard_vhost|ssl_vhost)_/', '', $vhostfilename); $known_phpfpm_files[]=preg_replace('/^(05|10|20|21|22|30|50|51)_(froxlor|syscp)_(dirfix|ipandport|normal_vhost|wildcard_vhost|ssl_vhost)_/', '', $vhostfilename);
} }
$configdir = $this->settings['phpfpm']['configdir']; $configdir = $this->settings['phpfpm']['configdir'];
$phpfpm_file_dirhandle = opendir($this->settings['phpfpm']['configdir']); $phpfpm_file_dirhandle = opendir($this->settings['phpfpm']['configdir']);
while(false !== ($phpfpm_filename = readdir($phpfpm_file_dirhandle))) while(false !== ($phpfpm_filename = readdir($phpfpm_file_dirhandle)))
{ {
if(is_array($known_phpfpm_files) if(is_array($known_phpfpm_files)
@@ -1404,7 +1407,7 @@ class apache
while(false !== ($htpasswd_filename = readdir($htpasswds_file_dirhandle))) while(false !== ($htpasswd_filename = readdir($htpasswds_file_dirhandle)))
{ {
if($htpasswd_filename != '.' if($htpasswd_filename != '.'
&& $htpasswd_filename != '..' && $htpasswd_filename != '..'
&& !in_array($htpasswd_filename, $this->known_htpasswdsfilenames) && !in_array($htpasswd_filename, $this->known_htpasswdsfilenames)
&& file_exists(makeCorrectFile($this->settings['system']['apacheconf_htpasswddir'] . '/' . $htpasswd_filename))) && file_exists(makeCorrectFile($this->settings['system']['apacheconf_htpasswddir'] . '/' . $htpasswd_filename)))
{ {