Update cron_tasks.inc.http.10.apache.php

This commit is contained in:
Axel Guckelsberger
2013-04-27 09:50:05 +03:00
parent 84d87adb9b
commit febb8e37bc

View File

@@ -82,8 +82,7 @@ class apache
private function _createStandardDirectoryEntry()
{
$vhosts_folder = '';
if(is_dir($this->settings['system']['apacheconf_vhost']))
{
if (is_dir($this->settings['system']['apacheconf_vhost'])) {
$vhosts_folder = makeCorrectDir($this->settings['system']['apacheconf_vhost']);
} else {
$vhosts_folder = makeCorrectDir(dirname($this->settings['system']['apacheconf_vhost']));
@@ -94,17 +93,13 @@ class apache
|| $this->settings['phpfpm']['enabled'] == '1'
) {
// if we use fcgid or php-fpm we don't need this file
if(file_exists($vhosts_filename))
{
if (file_exists($vhosts_filename)) {
fwrite($this->debugHandler, ' apache::_createStandardDirectoryEntry: unlinking ' . basename($vhosts_filename) . "\n");
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'unlinking ' . basename($vhosts_filename));
unlink(makeCorrectFile($vhosts_filename));
}
}
else
{
if(!isset($this->virtualhosts_data[$vhosts_filename]))
{
} else {
if (!isset($this->virtualhosts_data[$vhosts_filename])) {
$this->virtualhosts_data[$vhosts_filename] = '';
}
@@ -132,8 +127,7 @@ class apache
|| $this->settings['defaultwebsrverrhandler']['err500'] != '')
) {
$vhosts_folder = '';
if(is_dir($this->settings['system']['apacheconf_vhost']))
{
if (is_dir($this->settings['system']['apacheconf_vhost'])) {
$vhosts_folder = makeCorrectDir($this->settings['system']['apacheconf_vhost']);
} else {
$vhosts_folder = makeCorrectDir(dirname($this->settings['system']['apacheconf_vhost']));
@@ -141,43 +135,20 @@ class apache
$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] = '';
}
if ($this->settings['defaultwebsrverrhandler']['err401'] != '') {
$defhandler = $this->settings['defaultwebsrverrhandler']['err401'];
$statusCodes = array('401', '403', '404', '500');
foreach ($statusCodes as $statusCode) {
if ($this->settings['defaultwebsrverrhandler']['err' . $statusCode] != '') {
$defhandler = $this->settings['defaultwebsrverrhandler']['err' . $statusCode];
if (!validateUrl($defhandler)) {
$defhandler = makeCorrectFile($defhandler);
}
$this->virtualhosts_data[$vhosts_filename].= 'ErrorDocument 401 "' . $defhandler . '"'."\n";
$this->virtualhosts_data[$vhosts_filename] .= 'ErrorDocument ' . $statusCode . ' "' . $defhandler . '"'."\n";
}
if ($this->settings['defaultwebsrverrhandler']['err403'] != '') {
$defhandler = $this->settings['defaultwebsrverrhandler']['err403'];
if (!validateUrl($defhandler)) {
$defhandler = makeCorrectFile($defhandler);
}
$this->virtualhosts_data[$vhosts_filename].= 'ErrorDocument 403 "' . $defhandler . '"' . "\n";
}
if ($this->settings['defaultwebsrverrhandler']['err404'] != '') {
$defhandler = $this->settings['defaultwebsrverrhandler']['err404'];
if (!validateUrl($defhandler)) {
$defhandler = makeCorrectFile($defhandler);
}
$this->virtualhosts_data[$vhosts_filename].= 'ErrorDocument 404 "' . $defhandler . '"' . "\n";
}
if ($this->settings['defaultwebsrverrhandler']['err500'] != '') {
$defhandler = $this->settings['defaultwebsrverrhandler']['err500'];
if (!validateUrl($defhandler)) {
$defhandler = makeCorrectFile($defhandler);
}
$this->virtualhosts_data[$vhosts_filename].= 'ErrorDocument 500 "' . $defhandler . '"' . "\n";
}
}
}
@@ -185,14 +156,10 @@ class apache
{
$result_ipsandports = $this->db->query("SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` ORDER BY `ip` ASC, `port` ASC");
while($row_ipsandports = $this->db->fetch_array($result_ipsandports))
{
if(filter_var($row_ipsandports['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
{
while ($row_ipsandports = $this->db->fetch_array($result_ipsandports)) {
if (filter_var($row_ipsandports['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$ipport = '[' . $row_ipsandports['ip'] . ']:' . $row_ipsandports['port'];
}
else
{
} else {
$ipport = $row_ipsandports['ip'] . ':' . $row_ipsandports['port'];
}
@@ -200,19 +167,16 @@ class apache
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'creating ip/port settings for ' . $ipport);
$vhosts_filename = makeCorrectFile($this->settings['system']['apacheconf_vhost'] . '/10_froxlor_ipandport_' . trim(str_replace(':', '.', $row_ipsandports['ip']), '.') . '.' . $row_ipsandports['port'] . '.conf');
if(!isset($this->virtualhosts_data[$vhosts_filename]))
{
if (!isset($this->virtualhosts_data[$vhosts_filename])) {
$this->virtualhosts_data[$vhosts_filename] = '';
}
if($row_ipsandports['listen_statement'] == '1')
{
if ($row_ipsandports['listen_statement'] == '1') {
$this->virtualhosts_data[$vhosts_filename] .= 'Listen ' . $ipport . "\n";
$this->logger->logAction(CRON_ACTION, LOG_DEBUG, $ipport . ' :: inserted listen-statement');
}
if($row_ipsandports['namevirtualhost_statement'] == '1')
{
if ($row_ipsandports['namevirtualhost_statement'] == '1') {
// >=apache-2.4 enabled?
if ($this->settings['system']['apache24'] == '1') {
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, $ipport . ' :: namevirtualhost-statement no longer needed for apache-2.4');
@@ -222,52 +186,39 @@ class apache
}
}
if($row_ipsandports['vhostcontainer'] == '1')
{
if ($row_ipsandports['vhostcontainer'] == '1') {
$this->virtualhosts_data[$vhosts_filename] .= '<VirtualHost ' . $ipport . '>' . "\n";
if($row_ipsandports['docroot'] == '')
{
if ($row_ipsandports['docroot'] == '') {
/**
* add 'real'-vhost content here, like doc-root :)
*/
if($this->settings['system']['froxlordirectlyviahostname'])
{
if ($this->settings['system']['froxlordirectlyviahostname']) {
$mypath = makeCorrectDir(dirname(dirname(dirname(__FILE__))));
}
else
{
} else {
$mypath = makeCorrectDir(dirname(dirname(dirname(dirname(__FILE__)))));
}
}
else
{
} else {
// user-defined docroot, #417
$mypath = makeCorrectDir($row_ipsandports['docroot']);
}
$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";
}
// create fcgid <Directory>-Part (starter is created in apache_fcgid)
if ($this->settings['system']['mod_fcgid_ownvhost'] == '1'
&& $this->settings['system']['mod_fcgid'] == '1'
)
{
) {
$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";
if((int)$this->settings['system']['mod_fcgid_wrapper'] == 0)
{
if ((int)$this->settings['system']['mod_fcgid_wrapper'] == 0) {
$this->virtualhosts_data[$vhosts_filename] .= ' SuexecUserGroup "' . $this->settings['system']['mod_fcgid_httpuser'] . '" "' . $this->settings['system']['mod_fcgid_httpgroup'] . '"' . "\n";
$this->virtualhosts_data[$vhosts_filename] .= ' ScriptAlias /php/ ' . $configdir . "\n";
}
else
{
} else {
$starter_filename = makeCorrectFile($configdir . '/php-fcgi-starter');
$this->virtualhosts_data[$vhosts_filename] .= ' SuexecUserGroup "' . $this->settings['system']['mod_fcgid_httpuser'] . '" "' . $this->settings['system']['mod_fcgid_httpgroup'] . '"' . "\n";
$this->virtualhosts_data[$vhosts_filename] .= ' <Directory "' . $mypath . '">' . "\n";
@@ -285,8 +236,7 @@ class apache
}
}
// create php-fpm <Directory>-Part (config is created in apache_fcgid)
elseif($this->settings['phpfpm']['enabled'] == '1')
{
elseif ($this->settings['phpfpm']['enabled'] == '1') {
$domain = array(
'id' => 'none',
'domain' => $this->settings['system']['hostname'],
@@ -337,52 +287,42 @@ class apache
* end of dirprotection
*/
if($row_ipsandports['specialsettings'] != '')
{
if ($row_ipsandports['specialsettings'] != '') {
$this->virtualhosts_data[$vhosts_filename] .= $row_ipsandports['specialsettings'] . "\n";
}
if($row_ipsandports['ssl'] == '1' && $this->settings['system']['use_ssl'] == '1')
{
if($row_ipsandports['ssl_cert_file'] == '')
{
if ($row_ipsandports['ssl'] == '1' && $this->settings['system']['use_ssl'] == '1') {
if ($row_ipsandports['ssl_cert_file'] == '') {
$row_ipsandports['ssl_cert_file'] = $this->settings['system']['ssl_cert_file'];
}
if($row_ipsandports['ssl_key_file'] == '')
{
if ($row_ipsandports['ssl_key_file'] == '') {
$row_ipsandports['ssl_key_file'] = $this->settings['system']['ssl_key_file'];
}
if($row_ipsandports['ssl_ca_file'] == '')
{
if ($row_ipsandports['ssl_ca_file'] == '') {
$row_ipsandports['ssl_ca_file'] = $this->settings['system']['ssl_ca_file'];
}
// #418
if($row_ipsandports['ssl_cert_chainfile'] == '')
{
if ($row_ipsandports['ssl_cert_chainfile'] == '') {
$row_ipsandports['ssl_cert_chainfile'] = $this->settings['system']['ssl_cert_chainfile'];
}
if($row_ipsandports['ssl_cert_file'] != '')
{
if ($row_ipsandports['ssl_cert_file'] != '') {
$this->virtualhosts_data[$vhosts_filename] .= ' SSLEngine On' . "\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";
}
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";
}
// #418
if($row_ipsandports['ssl_cert_chainfile'] != '')
{
if ($row_ipsandports['ssl_cert_chainfile'] != '') {
$this->virtualhosts_data[$vhosts_filename] .= ' SSLCertificateChainFile ' . makeCorrectFile($row_ipsandports['ssl_cert_chainfile']) . "\n";
}
}
@@ -413,32 +353,20 @@ class apache
{
$php_options_text = '';
if($domain['phpenabled'] == '1')
{
if ($domain['phpenabled'] == '1') {
// This vHost has PHP enabled and we are using the regular mod_php
if($domain['openbasedir'] == '1')
{
if($domain['openbasedir_path'] == '1' || strstr($domain['documentroot'], ":") !== false)
{
if ($domain['openbasedir'] == '1') {
$_phpappendopenbasedir = appendOpenBasedirPath($domain['customerroot'], true);
}
else
{
$_phpappendopenbasedir = appendOpenBasedirPath($domain['documentroot'], true);
}
$_custom_openbasedir = explode(':', $this->settings['system']['phpappendopenbasedir']);
foreach($_custom_openbasedir as $cobd)
{
foreach ($_custom_openbasedir as $cobd) {
$_phpappendopenbasedir .= appendOpenBasedirPath($cobd);
}
$php_options_text .= ' php_admin_value open_basedir "' . $_phpappendopenbasedir . '"'."\n";
}
}
else
{
} else {
$php_options_text .= ' # PHP is disabled for this vHost' . "\n";
$php_options_text .= ' php_flag engine off' . "\n";
}
@@ -453,47 +381,30 @@ class apache
/*
* We collect all servernames and Aliases
*/
protected function getServerNames($domain)
{
$servernames_text = '';
$servernames_text.= ' ServerName ' . $domain['domain'] . "\n";
$servernames_text = ' ServerName ' . $domain['domain'] . "\n";
if($domain['iswildcarddomain'] == '1')
{
$server_alias = '';
if ($domain['iswildcarddomain'] == '1') {
$server_alias = '*.' . $domain['domain'];
}
else
{
if($domain['wwwserveralias'] == '1')
{
} elseif ($domain['wwwserveralias'] == '1') {
$server_alias = 'www.' . $domain['domain'];
}
else
{
$server_alias = '';
}
}
if(trim($server_alias) != '')
{
if (trim($server_alias) != '') {
$servernames_text .= ' ServerAlias ' . $server_alias . "\n";
}
$alias_domains = $this->db->query('SELECT `domain`, `iswildcarddomain`, `wwwserveralias` FROM `' . TABLE_PANEL_DOMAINS . '` WHERE `aliasdomain`=\'' . $domain['id'] . '\'');
while(($alias_domain = $this->db->fetch_array($alias_domains)) !== false)
{
while (($alias_domain = $this->db->fetch_array($alias_domains)) !== false) {
$server_alias = ' ServerAlias ' . $alias_domain['domain'];
if($alias_domain['iswildcarddomain'] == '1')
{
if ($alias_domain['iswildcarddomain'] == '1') {
$server_alias .= ' *.' . $alias_domain['domain'];
}
else
{
if($alias_domain['wwwserveralias'] == '1')
{
} else {
if ($alias_domain['wwwserveralias'] == '1') {
$server_alias .= ' www.' . $alias_domain['domain'];
}
}
@@ -508,7 +419,6 @@ class apache
/*
* Let's get the webroot
*/
protected function getWebroot($domain)
{
$webroot_text = '';
@@ -516,14 +426,12 @@ class apache
$domain['documentroot'] = makeCorrectDir($domain['documentroot']);
if ($domain['deactivated'] == '1'
&& $this->settings['system']['deactivateddocroot'] != '')
{
&& $this->settings['system']['deactivateddocroot'] != ''
) {
$webroot_text .= ' # Using docroot for deactivated users...' . "\n";
$webroot_text .= ' DocumentRoot "' . makeCorrectDir($this->settings['system']['deactivateddocroot']) . "\"\n";
$this->_deactivated = true;
}
else
{
} else {
$webroot_text .= ' DocumentRoot "' . $domain['documentroot'] . "\"\n";
$this->_deactivated = false;
}
@@ -534,29 +442,17 @@ class apache
/*
* Lets set the text part for the stats software
*/
protected function getStats($domain)
{
$stats_text = '';
if ($domain['speciallogfile'] == '1') {
if ($domain['parentdomainid'] == '0') {
$statDomain = ($domain['parentdomainid'] == '0') ? $domain['domain'] : $domain['parentdomain'];
if ($this->settings['system']['awstats_enabled'] == '1') {
$stats_text.= ' Alias /awstats "' . makeCorrectFile($domain['customerroot'] . '/awstats/' . $domain['domain']) . '"' . "\n";
$stats_text .= ' Alias /awstats "' . makeCorrectFile($domain['customerroot'] . '/awstats/' . $statDomain) . '"' . "\n";
$stats_text .= ' Alias /awstats-icon "' . makeCorrectDir($this->settings['system']['awstats_icons']) . '"' . "\n";
} else {
$stats_text.= ' Alias /webalizer "' . makeCorrectFile($domain['customerroot'] . '/webalizer/' . $domain['domain']) . '"' . "\n";
}
} else {
if ($this->settings['system']['awstats_enabled'] == '1') {
$stats_text.= ' Alias /awstats "' . makeCorrectFile($domain['customerroot'] . '/awstats/' . $domain['parentdomain']) . '"' . "\n";
$stats_text.= ' Alias /awstats-icon "' . makeCorrectDir($this->settings['system']['awstats_icons']) . '"' . "\n";
} else {
$stats_text.= ' Alias /webalizer "' . makeCorrectFile($domain['customerroot'] . '/webalizer/' . $domain['parentdomain']) . '"' . "\n";
}
$stats_text .= ' Alias /webalizer "' . makeCorrectFile($domain['customerroot'] . '/webalizer/' . $statDomain) . '"' . "\n";
}
} else {
if ($domain['customerroot'] != $domain['documentroot']) {
@@ -627,23 +523,16 @@ class apache
if ($alias_domain['iswildcarddomain'] == '1') {
$server_alias .= '*.' . $alias_domain['domain'];
} else {
if ($alias_domain['wwwserveralias'] == '1') {
} elseif ($alias_domain['wwwserveralias'] == '1') {
$server_alias .= 'www.' . $alias_domain['domain'];
} else {
$server_alias.= '';
}
}
}
$alias = '';
if ($domain['iswildcarddomain'] == '1') {
$alias = '*.' . $domain['domain'];
} else {
if ($domain['wwwserveralias'] == '1') {
} elseif ($domain['wwwserveralias'] == '1') {
$alias = 'www.' . $domain['domain'];
} else {
$alias = '';
}
}
// After inserting the AWStats information,
@@ -660,7 +549,6 @@ class apache
/*
* Get the filename for the virtualhost
*/
protected function getVhostFilename($domain, $ssl_vhost = false)
{
if ((int)$domain['parentdomainid'] == 0
@@ -669,24 +557,18 @@ class apache
|| domainMainToSubExists($domain['ismainbutsubto']) == false)
) {
$vhost_no = '22';
}
elseif((int)$domain['parentdomainid'] == 0
} elseif ((int)$domain['parentdomainid'] == 0
&& isCustomerStdSubdomain((int)$domain['id']) == false
&& (int)$domain['ismainbutsubto'] > 0
) {
$vhost_no = '21';
}
else
{
} else {
$vhost_no = '20';
}
if($ssl_vhost === true)
{
if ($ssl_vhost === true) {
$vhost_filename = makeCorrectFile($this->settings['system']['apacheconf_vhost'] . '/'.$vhost_no.'_froxlor_ssl_vhost_' . $domain['domain'] . '.conf');
}
else
{
} else {
$vhost_filename = makeCorrectFile($this->settings['system']['apacheconf_vhost'] . '/'.$vhost_no.'_froxlor_normal_vhost_' . $domain['domain'] . '.conf');
}
@@ -696,22 +578,19 @@ class apache
/*
* We compose the virtualhost entry for one domain
*/
protected function getVhostContent($domain, $ssl_vhost = false)
{
if ($ssl_vhost === true
&& $domain['ssl'] != '1')
{
&& $domain['ssl'] != '1'
) {
return '';
}
if ($ssl_vhost === true
&& $domain['ssl'] == '1')
{
&& $domain['ssl'] == '1'
) {
$query = "SELECT * FROM " . TABLE_PANEL_IPSANDPORTS . " WHERE `id`='" . $domain['ssl_ipandport'] . "'";
}
else
{
} else {
$query = "SELECT * FROM " . TABLE_PANEL_IPSANDPORTS . " WHERE `id`='" . $domain['ipandport'] . "'";
}
@@ -724,12 +603,9 @@ class apache
// #418
$domain['ssl_cert_chainfile'] = $ipandport['ssl_cert_chainfile'];
if(filter_var($domain['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
{
if (filter_var($domain['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$ipport = '[' . $domain['ip'] . ']:' . $domain['port'];
}
else
{
} else {
$ipport = $domain['ip'] . ':' . $domain['port'];
}
@@ -738,61 +614,52 @@ class apache
if ($ssl_vhost == false
&& $domain['ssl'] == '1'
&& $domain['ssl_redirect'] == '1')
{
&& $domain['ssl_redirect'] == '1'
) {
$domain['documentroot'] = 'https://' . $domain['domain'] . '/';
}
if ($ssl_vhost === true
&& $domain['ssl'] == '1'
&& $this->settings['system']['use_ssl'] == '1')
{
if($domain['ssl_cert_file'] == '')
{
&& $this->settings['system']['use_ssl'] == '1'
) {
if ($domain['ssl_cert_file'] == '') {
$domain['ssl_cert_file'] = $this->settings['system']['ssl_cert_file'];
}
if($domain['ssl_key_file'] == '')
{
if ($domain['ssl_key_file'] == '') {
$domain['ssl_key_file'] = $this->settings['system']['ssl_key_file'];
}
if($domain['ssl_ca_file'] == '')
{
if ($domain['ssl_ca_file'] == '') {
$domain['ssl_ca_file'] = $this->settings['system']['ssl_ca_file'];
}
// #418
if($domain['ssl_cert_chainfile'] == '')
{
if ($domain['ssl_cert_chainfile'] == '') {
$domain['ssl_cert_chainfile'] = $this->settings['system']['ssl_cert_chainfile'];
}
if($domain['ssl_cert_file'] != '')
{
if ($domain['ssl_cert_file'] != '') {
$vhost_content .= ' SSLEngine On' . "\n";
$vhost_content .= ' SSLCertificateFile ' . makeCorrectFile($domain['ssl_cert_file']) . "\n";
if($domain['ssl_key_file'] != '')
{
if ($domain['ssl_key_file'] != '') {
$vhost_content .= ' SSLCertificateKeyFile ' . makeCorrectFile($domain['ssl_key_file']) . "\n";
}
if($domain['ssl_ca_file'] != '')
{
if ($domain['ssl_ca_file'] != '') {
$vhost_content .= ' SSLCACertificateFile ' . makeCorrectFile($domain['ssl_ca_file']) . "\n";
}
// #418
if($domain['ssl_cert_chainfile'] != '')
{
if ($domain['ssl_cert_chainfile'] != '') {
$vhost_content .= ' SSLCertificateChainFile ' . makeCorrectFile($domain['ssl_cert_chainfile']) . "\n";
}
}
}
if(preg_match('/^https?\:\/\//', $domain['documentroot']))
{
if (preg_match('/^https?\:\/\//', $domain['documentroot'])) {
$corrected_docroot = $this->idnaConvert->encode($domain['documentroot']);
if (substr($corrected_docroot, -1) == '/') {
$corrected_docroot = substr($corrected_docroot, 0, -1);
@@ -814,9 +681,7 @@ class apache
$code = getDomainRedirectCode($domain['id']);
$vhost_content .= ' Redirect '.$code.' / ' . $this->idnaConvert->encode($domain['documentroot']) . "\n";
}
else
{
} else {
mkDirWithCorrectOwnership($domain['customerroot'], $domain['documentroot'], $domain['guid'], $domain['guid'], true, true);
$vhost_content .= $this->getWebroot($domain);
if ($this->_deactivated == false) {
@@ -845,37 +710,30 @@ class apache
/*
* We compose the virtualhost entries for the domains
*/
public function createVirtualHosts()
{
$result_domains = $this->db->query("SELECT `d`.*, `pd`.`domain` AS `parentdomain`, `c`.`loginname`, `d`.`phpsettingid`, `c`.`adminid`, `c`.`guid`, `c`.`email`, `c`.`documentroot` AS `customerroot`, `c`.`deactivated`, `c`.`phpenabled` AS `phpenabled`, `d`.`mod_fcgid_starter`, `d`.`mod_fcgid_maxrequests` FROM `" . TABLE_PANEL_DOMAINS . "` `d` 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");
while($domain = $this->db->fetch_array($result_domains))
{
while ($domain = $this->db->fetch_array($result_domains)) {
fwrite($this->debugHandler, ' apache::createVirtualHosts: creating vhost container for domain ' . $domain['id'] . ', customer ' . $domain['loginname'] . "\n");
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'creating vhost container for domain ' . $domain['id'] . ', customer ' . $domain['loginname']);
$vhosts_filename = $this->getVhostFilename($domain);
// Apply header
$this->virtualhosts_data[$vhosts_filename] = '# Domain ID: ' . $domain['id'] . ' - CustomerID: ' . $domain['customerid'] . ' - CustomerLogin: ' . $domain['loginname'] . "\n";
if ($domain['deactivated'] != '1'
|| $this->settings['system']['deactivateddocroot'] != '')
{
|| $this->settings['system']['deactivateddocroot'] != ''
) {
$this->virtualhosts_data[$vhosts_filename].= $this->getVhostContent($domain);
if($domain['ssl'] == '1')
{
if ($domain['ssl'] == '1') {
// Adding ssl stuff if enabled
$vhosts_filename_ssl = $this->getVhostFilename($domain, true);
$this->virtualhosts_data[$vhosts_filename_ssl] = '# Domain ID: ' . $domain['id'] . ' (SSL) - CustomerID: ' . $domain['customerid'] . ' - CustomerLogin: ' . $domain['loginname'] . "\n";
$this->virtualhosts_data[$vhosts_filename_ssl] .= $this->getVhostContent($domain, true);
}
}
else
{
} else {
$this->virtualhosts_data[$vhosts_filename] .= '# Customer deactivated and a docroot for deactivated users hasn\'t been set.' . "\n";
}
}
@@ -884,18 +742,16 @@ class apache
/*
* We compose the diroption entries for the paths
*/
public function createFileDirOptions()
{
$result = $this->db->query('SELECT `htac`.*, `c`.`guid`, `c`.`documentroot` AS `customerroot` FROM `' . TABLE_PANEL_HTACCESS . '` `htac` LEFT JOIN `' . TABLE_PANEL_CUSTOMERS . '` `c` USING (`customerid`) ORDER BY `htac`.`path`');
$diroptions = array();
while($row_diroptions = $this->db->fetch_array($result))
{
while ($row_diroptions = $this->db->fetch_array($result)) {
if ($row_diroptions['customerid'] != 0
&& isset($row_diroptions['customerroot'])
&& $row_diroptions['customerroot'] != '')
{
&& $row_diroptions['customerroot'] != ''
) {
$diroptions[$row_diroptions['path']] = $row_diroptions;
$diroptions[$row_diroptions['path']]['htpasswds'] = array();
}
@@ -903,14 +759,12 @@ class apache
$result = $this->db->query('SELECT `htpw`.*, `c`.`guid`, `c`.`documentroot` AS `customerroot` FROM `' . TABLE_PANEL_HTPASSWDS . '` `htpw` LEFT JOIN `' . TABLE_PANEL_CUSTOMERS . '` `c` USING (`customerid`) ORDER BY `htpw`.`path`, `htpw`.`username`');
while($row_htpasswds = $this->db->fetch_array($result))
{
while ($row_htpasswds = $this->db->fetch_array($result)) {
if ($row_htpasswds['customerid'] != 0
&& isset($row_htpasswds['customerroot'])
&& $row_htpasswds['customerroot'] != '')
{
if(!isset($diroptions[$row_htpasswds['path']]) || !is_array($diroptions[$row_htpasswds['path']]))
{
&& $row_htpasswds['customerroot'] != ''
) {
if (!isset($diroptions[$row_htpasswds['path']]) || !is_array($diroptions[$row_htpasswds['path']])) {
$diroptions[$row_htpasswds['path']] = array();
}
@@ -922,33 +776,30 @@ class apache
}
}
foreach($diroptions as $row_diroptions)
{
foreach ($diroptions as $row_diroptions) {
$row_diroptions['path'] = makeCorrectDir($row_diroptions['path']);
mkDirWithCorrectOwnership($row_diroptions['customerroot'], $row_diroptions['path'], $row_diroptions['guid'], $row_diroptions['guid']);
$diroptions_filename = makeCorrectFile($this->settings['system']['apacheconf_diroptions'] . '/40_froxlor_diroption_' . md5($row_diroptions['path']) . '.conf');
if(!isset($this->diroptions_data[$diroptions_filename]))
{
if (!isset($this->diroptions_data[$diroptions_filename])) {
$this->diroptions_data[$diroptions_filename] = '';
}
if(is_dir($row_diroptions['path']))
{
if (is_dir($row_diroptions['path'])) {
$cperlenabled = customerHasPerlEnabled($row_diroptions['customerid']);
$this->diroptions_data[$diroptions_filename] .= '<Directory "' . $row_diroptions['path'] . '">' . "\n";
if (isset($row_diroptions['options_indexes'])
&& $row_diroptions['options_indexes'] == '1')
{
&& $row_diroptions['options_indexes'] == '1'
) {
$this->diroptions_data[$diroptions_filename] .= ' Options +Indexes';
// add perl options if enabled
if ($cperlenabled
&& isset($row_diroptions['options_cgi'])
&& $row_diroptions['options_cgi'] == '1')
{
&& $row_diroptions['options_cgi'] == '1'
) {
$this->diroptions_data[$diroptions_filename] .= ' ExecCGI -MultiViews +SymLinksIfOwnerMatch +FollowSymLinks'."\n";
} else {
$this->diroptions_data[$diroptions_filename] .= "\n";
@@ -957,15 +808,15 @@ class apache
}
if (isset($row_diroptions['options_indexes'])
&& $row_diroptions['options_indexes'] == '0')
{
&& $row_diroptions['options_indexes'] == '0'
) {
$this->diroptions_data[$diroptions_filename] .= ' Options -Indexes';
// add perl options if enabled
if ($cperlenabled
&& isset($row_diroptions['options_cgi'])
&& $row_diroptions['options_cgi'] == '1')
{
&& $row_diroptions['options_cgi'] == '1'
) {
$this->diroptions_data[$diroptions_filename] .= ' ExecCGI -MultiViews +SymLinksIfOwnerMatch +FollowSymLinks'."\n";
} else {
$this->diroptions_data[$diroptions_filename] .= "\n";
@@ -973,40 +824,23 @@ class apache
fwrite($this->debugHandler, ' cron_tasks: Task3 - Setting Options -Indexes' . "\n");
}
if (isset($row_diroptions['error404path'])
&& $row_diroptions['error404path'] != ''
$statusCodes = array('404', '403', '500');
foreach ($statusCodes as $statusCode) {
if (isset($row_diroptions['error' . $statusCode . 'path'])
&& $row_diroptions['error' . $statusCode . 'path'] != ''
) {
$defhandler = $row_diroptions['error404path'];
$defhandler = $row_diroptions['error' . $statusCode . 'path'];
if (!validateUrl($defhandler)) {
$defhandler = makeCorrectFile($defhandler);
}
$this->diroptions_data[$diroptions_filename].= ' ErrorDocument 404 "' . $defhandler. '"' . "\n";
$this->diroptions_data[$diroptions_filename].= ' ErrorDocument ' . $statusCode . ' "' . $defhandler. '"' . "\n";
}
if (isset($row_diroptions['error403path'])
&& $row_diroptions['error403path'] != ''
) {
$defhandler = $row_diroptions['error403path'];
if (!validateUrl($defhandler)) {
$defhandler = makeCorrectFile($defhandler);
}
$this->diroptions_data[$diroptions_filename].= ' ErrorDocument 403 "' . $defhandler . '"' . "\n";
}
if (isset($row_diroptions['error500path'])
&& $row_diroptions['error500path'] != ''
) {
$defhandler = $row_diroptions['error500path'];
if (!validateUrl($defhandler)) {
$defhandler = makeCorrectFile($defhandler);
}
$this->diroptions_data[$diroptions_filename].= ' ErrorDocument 500 "' . $defhandler . '"' . "\n";
}
if ($cperlenabled
&& isset($row_diroptions['options_cgi'])
&& $row_diroptions['options_cgi'] == '1')
{
&& $row_diroptions['options_cgi'] == '1'
) {
$this->diroptions_data[$diroptions_filename] .= ' AllowOverride None' . "\n";
$this->diroptions_data[$diroptions_filename] .= ' AddHandler cgi-script .cgi .pl' . "\n";
// >=apache-2.4 enabled?
@@ -1019,14 +853,12 @@ class apache
fwrite($this->debugHandler, ' cron_tasks: Task3 - Enabling perl execution' . "\n");
// check for suexec-workaround, #319
if((int)$this->settings['perl']['suexecworkaround'] == 1)
{
if ((int)$this->settings['perl']['suexecworkaround'] == 1) {
// symlink this directory to suexec-safe-path
$loginname = getCustomerDetail($row_diroptions['customerid'], 'loginname');
$suexecpath = makeCorrectDir($this->settings['perl']['suexecpath'].'/'.$loginname.'/'.md5($row_diroptions['path']).'/');
if(!file_exists($suexecpath))
{
if (!file_exists($suexecpath)) {
safe_exec('mkdir -p '.escapeshellarg($suexecpath));
safe_exec('chown -R '.escapeshellarg($row_diroptions['guid']).':'.escapeshellarg($row_diroptions['guid']).' '.escapeshellarg($suexecpath));
}
@@ -1034,47 +866,38 @@ class apache
// symlink to {$givenpath}/cgi-bin
// NOTE: symlinks are FILES, so do not append a / here
$perlsymlink = makeCorrectFile($row_diroptions['path'].'/cgi-bin');
if(!file_exists($perlsymlink))
{
if (!file_exists($perlsymlink)) {
safe_exec('ln -s '.escapeshellarg($suexecpath).' '.escapeshellarg($perlsymlink));
}
safe_exec('chown '.escapeshellarg($row_diroptions['guid']).':'.escapeshellarg($row_diroptions['guid']).' '.escapeshellarg($perlsymlink));
}
}
else
{
} else {
// if no perl-execution is enabled but the workaround is,
// we have to remove the symlink and folder in suexecpath
if((int)$this->settings['perl']['suexecworkaround'] == 1)
{
if ((int)$this->settings['perl']['suexecworkaround'] == 1) {
$loginname = getCustomerDetail($row_diroptions['customerid'], 'loginname');
$suexecpath = makeCorrectDir($this->settings['perl']['suexecpath'].'/'.$loginname.'/'.md5($row_diroptions['path']).'/');
$perlsymlink = makeCorrectFile($row_diroptions['path'].'/cgi-bin');
// remove symlink
if(file_exists($perlsymlink))
{
if (file_exists($perlsymlink)) {
safe_exec('rm -f '.escapeshellarg($perlsymlink));
}
// remove folder in suexec-path
if(file_exists($suexecpath))
{
if (file_exists($suexecpath)) {
safe_exec('rm -rf '.escapeshellarg($suexecpath));
}
}
}
if(count($row_diroptions['htpasswds']) > 0)
{
if (count($row_diroptions['htpasswds']) > 0) {
$htpasswd_filename = makeCorrectFile($this->settings['system']['apacheconf_htpasswddir'] . '/' . $row_diroptions['customerid'] . '-' . md5($row_diroptions['path']) . '.htpasswd');
if(!isset($this->htpasswds_data[$htpasswd_filename]))
{
if (!isset($this->htpasswds_data[$htpasswd_filename])) {
$this->htpasswds_data[$htpasswd_filename] = '';
}
foreach($row_diroptions['htpasswds'] as $row_htpasswd)
{
foreach ($row_diroptions['htpasswds'] as $row_htpasswd) {
$this->htpasswds_data[$htpasswd_filename] .= $row_htpasswd['username'] . ':' . $row_htpasswd['password'] . "\n";
}
@@ -1092,7 +915,6 @@ class apache
/*
* We write the configs
*/
public function writeConfigs()
{
// Write diroptions
@@ -1100,16 +922,13 @@ class apache
fwrite($this->debugHandler, ' apache::writeConfigs: rebuilding ' . $this->settings['system']['apacheconf_diroptions'] . "\n");
$this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . $this->settings['system']['apacheconf_diroptions']);
if(count($this->diroptions_data) > 0)
{
if(!isConfigDir($this->settings['system']['apacheconf_diroptions']))
{
if (count($this->diroptions_data) > 0) {
if (!isConfigDir($this->settings['system']['apacheconf_diroptions'])) {
// Save one big file
$diroptions_file = '';
foreach($this->diroptions_data as $diroptions_filename => $diroptions_content)
{
foreach ($this->diroptions_data as $diroptions_filename => $diroptions_content) {
$diroptions_file.= $diroptions_content . "\n\n";
}
@@ -1121,11 +940,8 @@ class apache
$diroptions_file_handler = fopen($diroptions_filename, 'w');
fwrite($diroptions_file_handler, $diroptions_file);
fclose($diroptions_file_handler);
}
else
{
if(!file_exists($this->settings['system']['apacheconf_diroptions']))
{
} else {
if (!file_exists($this->settings['system']['apacheconf_diroptions'])) {
fwrite($this->debugHandler, ' apache::writeConfigs: mkdir ' . escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_diroptions'])) . "\n");
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'mkdir ' . escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_diroptions'])));
safe_exec('mkdir ' . escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_diroptions'])));
@@ -1133,12 +949,10 @@ class apache
// Write a single file for every diroption
foreach($this->diroptions_data as $diroptions_filename => $diroptions_file)
{
foreach ($this->diroptions_data as $diroptions_filename => $diroptions_file) {
$this->known_diroptionsfilenames[] = basename($diroptions_filename);
// Apply header
$diroptions_file = '# ' . basename($diroptions_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $diroptions_file;
$diroptions_file_handler = fopen($diroptions_filename, 'w');
fwrite($diroptions_file_handler, $diroptions_file);
@@ -1152,28 +966,22 @@ class apache
fwrite($this->debugHandler, ' apache::writeConfigs: rebuilding ' . $this->settings['system']['apacheconf_htpasswddir'] . "\n");
$this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . $this->settings['system']['apacheconf_htpasswddir']);
if(count($this->htpasswds_data) > 0)
{
if(!file_exists($this->settings['system']['apacheconf_htpasswddir']))
{
if (count($this->htpasswds_data) > 0) {
if (!file_exists($this->settings['system']['apacheconf_htpasswddir'])) {
$umask = umask();
umask(0000);
mkdir($this->settings['system']['apacheconf_htpasswddir'], 0751);
umask($umask);
}
if(isConfigDir($this->settings['system']['apacheconf_htpasswddir'], true))
{
foreach($this->htpasswds_data as $htpasswd_filename => $htpasswd_file)
{
if (isConfigDir($this->settings['system']['apacheconf_htpasswddir'], true)) {
foreach ($this->htpasswds_data as $htpasswd_filename => $htpasswd_file) {
$this->known_htpasswdsfilenames[] = basename($htpasswd_filename);
$htpasswd_file_handler = fopen($htpasswd_filename, 'w');
fwrite($htpasswd_file_handler, $htpasswd_file);
fclose($htpasswd_file_handler);
}
}
else
{
} else {
fwrite($this->debugHandler, ' cron_tasks: WARNING!!! ' . $this->settings['system']['apacheconf_htpasswddir'] . ' is not a directory. htpasswd directory protection is disabled!!!' . "\n");
echo '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!!!');
@@ -1185,10 +993,8 @@ class apache
fwrite($this->debugHandler, ' apache::writeConfigs: rebuilding ' . $this->settings['system']['apacheconf_vhost'] . "\n");
$this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . $this->settings['system']['apacheconf_vhost']);
if(count($this->virtualhosts_data) > 0)
{
if(!isConfigDir($this->settings['system']['apacheconf_vhost']))
{
if (count($this->virtualhosts_data) > 0) {
if (!isConfigDir($this->settings['system']['apacheconf_vhost'])) {
// Save one big file
$vhosts_file = '';
@@ -1199,44 +1005,35 @@ class apache
// #437
ksort($this->virtualhosts_data);
foreach($this->virtualhosts_data as $vhosts_filename => $vhost_content)
{
foreach ($this->virtualhosts_data as $vhosts_filename => $vhost_content) {
$vhosts_file.= $vhost_content . "\n\n";
}
// Include diroptions file in case it exists
if(file_exists($this->settings['system']['apacheconf_diroptions']))
{
if (file_exists($this->settings['system']['apacheconf_diroptions'])) {
$vhosts_file.= "\n" . 'Include ' . $this->settings['system']['apacheconf_diroptions'] . "\n\n";
}
$vhosts_filename = $this->settings['system']['apacheconf_vhost'];
// Apply header
$vhosts_file = '# ' . basename($vhosts_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $vhosts_file;
$vhosts_file_handler = fopen($vhosts_filename, 'w');
fwrite($vhosts_file_handler, $vhosts_file);
fclose($vhosts_file_handler);
}
else
{
if(!file_exists($this->settings['system']['apacheconf_vhost']))
{
} else {
if (!file_exists($this->settings['system']['apacheconf_vhost'])) {
fwrite($this->debugHandler, ' apache::writeConfigs: mkdir ' . escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_vhost'])) . "\n");
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'mkdir ' . escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_vhost'])));
safe_exec('mkdir ' . escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_vhost'])));
}
// Write a single file for every vhost
foreach($this->virtualhosts_data as $vhosts_filename => $vhosts_file)
{
foreach ($this->virtualhosts_data as $vhosts_filename => $vhosts_file) {
$this->known_vhostfilenames[] = basename($vhosts_filename);
// Apply header
$vhosts_file = '# ' . basename($vhosts_filename) . "\n" . '# Created ' . date('d.m.Y H:i') . "\n" . '# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.' . "\n" . "\n" . $vhosts_file;
$vhosts_file_handler = fopen($vhosts_filename, 'w');
fwrite($vhosts_file_handler, $vhosts_file);