migrating more files to new Settings-class makes me dance, refs #1325
Signed-off-by: Roman Schmerold (BNoiZe) <bnoize@froxlor.org>
This commit is contained in:
@@ -15,15 +15,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
class nginx
|
||||
{
|
||||
class nginx {
|
||||
private $logger = false;
|
||||
private $debugHandler = false;
|
||||
private $idnaConvert = false;
|
||||
private $nginx_server = array();
|
||||
|
||||
// protected
|
||||
protected $settings = array();
|
||||
// protected
|
||||
protected $nginx_data = array();
|
||||
protected $needed_htpasswds = array();
|
||||
protected $auth_backend_loaded = false;
|
||||
@@ -40,34 +38,32 @@ class nginx
|
||||
*/
|
||||
private $_deactivated = false;
|
||||
|
||||
public function __construct($logger, $debugHandler, $idnaConvert, $settings, $nginx_server=array())
|
||||
{
|
||||
public function __construct($logger, $debugHandler, $idnaConvert, $nginx_server=array()) {
|
||||
$this->logger = $logger;
|
||||
$this->debugHandler = $debugHandler;
|
||||
$this->idnaConvert = $idnaConvert;
|
||||
$this->settings = $settings;
|
||||
$this->nginx_server = $nginx_server;
|
||||
}
|
||||
|
||||
public function reload()
|
||||
{
|
||||
|
||||
public function reload() {
|
||||
fwrite($this->debugHandler, ' nginx::reload: reloading nginx' . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'reloading nginx');
|
||||
safe_exec($this->settings['system']['apachereload_command']);
|
||||
safe_exec(Settings::Get('system.apachereload_command'));
|
||||
|
||||
/**
|
||||
* nginx does not auto-spawn fcgi-processes
|
||||
*/
|
||||
if ($this->settings['system']['phpreload_command'] != ''
|
||||
&& (int)$this->settings['phpfpm']['enabled'] == 0
|
||||
if (Settings::Get('system.phpreload_command') != ''
|
||||
&& (int)Settings::Get('phpfpm.enabled') == 0
|
||||
) {
|
||||
fwrite($this->debugHandler, ' nginx::reload: restarting php processes' . "\n");
|
||||
fwrite($this->debugHandler, ' nginx::reload: restarting php processes' . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'restarting php processes');
|
||||
safe_exec($this->settings['system']['phpreload_command']);
|
||||
} elseif ((int)$this->settings['phpfpm']['enabled'] == 1) {
|
||||
safe_exec(Settings::Get('system.phpreload_command'));
|
||||
} elseif ((int)Settings::Get('phpfpm.enabled') == 1) {
|
||||
fwrite($this->debugHandler, ' nginx::reload: reloading php-fpm' . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'reloading php-fpm');
|
||||
safe_exec(escapeshellcmd($this->settings['phpfpm']['reload']));
|
||||
safe_exec(escapeshellcmd(Settings::Get('phpfpm.reload')));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,19 +71,18 @@ class nginx
|
||||
/**
|
||||
* define a default ErrorDocument-statement, bug #unknown-yet
|
||||
*/
|
||||
private function _createStandardErrorHandler()
|
||||
{
|
||||
if ($this->settings['defaultwebsrverrhandler']['enabled'] == '1'
|
||||
&& ($this->settings['defaultwebsrverrhandler']['err401'] != ''
|
||||
|| $this->settings['defaultwebsrverrhandler']['err403'] != ''
|
||||
|| $this->settings['defaultwebsrverrhandler']['err404'] != ''
|
||||
|| $this->settings['defaultwebsrverrhandler']['err500'] != '')
|
||||
private function _createStandardErrorHandler() {
|
||||
if (Settings::Get('defaultwebsrverrhandler.enabled') == '1'
|
||||
&& (Settings::Get('defaultwebsrverrhandler.err401') != ''
|
||||
|| Settings::Get('defaultwebsrverrhandler.err403') != ''
|
||||
|| Settings::Get('defaultwebsrverrhandler.err404') != ''
|
||||
|| Settings::Get('defaultwebsrverrhandler.err500') != '')
|
||||
) {
|
||||
$vhosts_folder = '';
|
||||
if (is_dir($this->settings['system']['apacheconf_vhost'])) {
|
||||
$vhosts_folder = makeCorrectDir($this->settings['system']['apacheconf_vhost']);
|
||||
if (is_dir(Settings::Get('system.apacheconf_vhost'))) {
|
||||
$vhosts_folder = makeCorrectDir(Settings::Get('system.apacheconf_vhost'));
|
||||
} else {
|
||||
$vhosts_folder = makeCorrectDir(dirname($this->settings['system']['apacheconf_vhost']));
|
||||
$vhosts_folder = makeCorrectDir(dirname(Settings::Get('system.apacheconf_vhost')));
|
||||
}
|
||||
|
||||
$vhosts_filename = makeCorrectFile($vhosts_folder . '/05_froxlor_default_errorhandler.conf');
|
||||
@@ -98,8 +93,8 @@ class nginx
|
||||
|
||||
$statusCodes = array('401', '403', '404', '500');
|
||||
foreach ($statusCodes as $statusCode) {
|
||||
if ($this->settings['defaultwebsrverrhandler']['err' . $statusCode] != '') {
|
||||
$defhandler = $this->settings['defaultwebsrverrhandler']['err' . $statusCode];
|
||||
if (Settings::Get('defaultwebsrverrhandler.err' . $statusCode) != '') {
|
||||
$defhandler = Settings::Get('defaultwebsrverrhandler.err' . $statusCode);
|
||||
if (!validateUrl($defhandler)) {
|
||||
$defhandler = makeCorrectFile($defhandler);
|
||||
}
|
||||
@@ -109,16 +104,16 @@ class nginx
|
||||
}
|
||||
}
|
||||
|
||||
public function createVirtualHosts()
|
||||
{
|
||||
|
||||
public function createVirtualHosts() {
|
||||
}
|
||||
|
||||
public function createFileDirOptions()
|
||||
{
|
||||
|
||||
public function createFileDirOptions() {
|
||||
}
|
||||
|
||||
public function createIpPort()
|
||||
{
|
||||
|
||||
public function createIpPort() {
|
||||
$result_ipsandports_stmt = Database::query("
|
||||
SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` ORDER BY `ip` ASC, `port` ASC
|
||||
");
|
||||
@@ -133,7 +128,7 @@ class nginx
|
||||
|
||||
fwrite($this->debugHandler, ' nginx::createIpPort: creating ip/port settings for ' . $ip . ":" . $port . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, 'creating ip/port settings for ' . $ip . ":" . $port);
|
||||
$vhost_filename = makeCorrectFile($this->settings['system']['apacheconf_vhost'] . '/10_froxlor_ipandport_' . trim(str_replace(':', '.', $row_ipsandports['ip']), '.') . '.' . $row_ipsandports['port'] . '.conf');
|
||||
$vhost_filename = makeCorrectFile(Settings::Get('system.apacheconf_vhost') . '/10_froxlor_ipandport_' . trim(str_replace(':', '.', $row_ipsandports['ip']), '.') . '.' . $row_ipsandports['port'] . '.conf');
|
||||
|
||||
if (!isset($this->nginx_data[$vhost_filename])) {
|
||||
$this->nginx_data[$vhost_filename] = '';
|
||||
@@ -148,13 +143,13 @@ class nginx
|
||||
$ssl_vhost = false;
|
||||
if ($row_ipsandports['ssl'] == '1') {
|
||||
if ($row_ipsandports['ssl_cert_file'] == '') {
|
||||
$row_ipsandports['ssl_cert_file'] = $this->settings['system']['ssl_cert_file'];
|
||||
$row_ipsandports['ssl_cert_file'] = Settings::Get('system.ssl_cert_file');
|
||||
}
|
||||
if ($row_ipsandports['ssl_key_file'] == '') {
|
||||
$row_ipsandports['ssl_key_file'] = $this->settings['system']['ssl_key_file'];
|
||||
$row_ipsandports['ssl_key_file'] = Settings::Get('system.ssl_key_file');
|
||||
}
|
||||
if ($row_ipsandports['ssl_ca_file'] == '') {
|
||||
$row_ipsandports['ssl_ca_file'] = $this->settings['system']['ssl_ca_file'];
|
||||
$row_ipsandports['ssl_ca_file'] = Settings::Get('system.ssl_ca_file');
|
||||
}
|
||||
if ($row_ipsandports['ssl_cert_file'] != '') {
|
||||
$ssl_vhost = true;
|
||||
@@ -167,7 +162,7 @@ class nginx
|
||||
$this->nginx_data[$vhost_filename] .= "\t". 'listen ' . $ip . ':' . $port . ' default'. ($ssl_vhost == true ? ' ssl' : '') . ';' . "\n";
|
||||
|
||||
$this->nginx_data[$vhost_filename] .= "\t".'# Froxlor default vhost' . "\n";
|
||||
$this->nginx_data[$vhost_filename] .= "\t".'server_name ' . $this->settings['system']['hostname'] . ';' . "\n";
|
||||
$this->nginx_data[$vhost_filename] .= "\t".'server_name ' . Settings::Get('system.hostname') . ';' . "\n";
|
||||
$this->nginx_data[$vhost_filename] .= "\t".'access_log /var/log/nginx/access.log;' . "\n";
|
||||
|
||||
$mypath = '';
|
||||
@@ -176,7 +171,7 @@ class nginx
|
||||
if ($row_ipsandports['docroot'] == '') {
|
||||
// check whether the hostname should directly point to
|
||||
// the froxlor-installation or not
|
||||
if ($this->settings['system']['froxlordirectlyviahostname']) {
|
||||
if (Settings::Get('system.froxlordirectlyviahostname')) {
|
||||
$mypath = makeCorrectDir(dirname(dirname(dirname(__FILE__))));
|
||||
} else {
|
||||
$mypath = makeCorrectDir(dirname(dirname(dirname(dirname(__FILE__)))));
|
||||
@@ -207,23 +202,23 @@ class nginx
|
||||
$this->nginx_data[$vhost_filename] .= "\t\t\t".'return 404;'."\n";
|
||||
$this->nginx_data[$vhost_filename] .= "\t\t".'}'."\n";
|
||||
$this->nginx_data[$vhost_filename] .= "\t\t".'fastcgi_index index.php;'."\n";
|
||||
$this->nginx_data[$vhost_filename] .= "\t\t".'include '.$this->settings['nginx']['fastcgiparams'].';'."\n";
|
||||
$this->nginx_data[$vhost_filename] .= "\t\t".'include '.Settings::Get('nginx.fastcgiparams').';'."\n";
|
||||
$this->nginx_data[$vhost_filename] .= "\t\t".'fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;'."\n";
|
||||
if ($row_ipsandports['ssl'] == '1') {
|
||||
$this->nginx_data[$vhost_filename] .= "\t\t".'fastcgi_param HTTPS on;'."\n";
|
||||
}
|
||||
if ((int)$this->settings['phpfpm']['enabled'] == 1
|
||||
&& (int)$this->settings['phpfpm']['enabled_ownvhost'] == 1
|
||||
if ((int)Settings::Get('phpfpm.enabled') == 1
|
||||
&& (int)Settings::Get('phpfpm.enabled_ownvhost') == 1
|
||||
) {
|
||||
$domain = array(
|
||||
'id' => 'none',
|
||||
'domain' => $this->settings['system']['hostname'],
|
||||
'domain' => Settings::Get('system.hostname'),
|
||||
'adminid' => 1, /* first admin-user (superadmin) */
|
||||
'mod_fcgid_starter' => -1,
|
||||
'mod_fcgid_maxrequests' => -1,
|
||||
'guid' => $this->settings['phpfpm']['vhost_httpuser'],
|
||||
'guid' => Settings::Get('phpfpm.vhost_httpuser'),
|
||||
'openbasedir' => 0,
|
||||
'email' => $this->settings['panel']['adminmail'],
|
||||
'email' => Settings::Get('panel.adminmail'),
|
||||
'loginname' => 'froxlor.panel',
|
||||
'documentroot' => $mypath,
|
||||
);
|
||||
@@ -231,7 +226,7 @@ class nginx
|
||||
$php = new phpinterface($domain);
|
||||
$this->nginx_data[$vhost_filename] .= "\t\t".'fastcgi_pass unix:' . $php->getInterface()->getSocketFile() . ';' . "\n";
|
||||
} else {
|
||||
$this->nginx_data[$vhost_filename] .= "\t\t".'fastcgi_pass ' . $this->settings['system']['nginx_php_backend'] . ';' . "\n";
|
||||
$this->nginx_data[$vhost_filename] .= "\t\t".'fastcgi_pass ' . Settings::Get('system.nginx_php_backend') . ';' . "\n";
|
||||
}
|
||||
$this->nginx_data[$vhost_filename] .= "\t".'}'."\n";
|
||||
$this->nginx_data[$vhost_filename] .= '}' . "\n\n";
|
||||
@@ -247,6 +242,7 @@ class nginx
|
||||
$this->_createStandardErrorHandler();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* create vhosts
|
||||
*/
|
||||
@@ -255,8 +251,8 @@ class nginx
|
||||
$domains = WebserverBase::getVhostsToCreate();
|
||||
foreach ($domains as $domain) {
|
||||
|
||||
if (is_dir($this->settings['system']['apacheconf_vhost'])) {
|
||||
safe_exec('mkdir -p '.escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_vhost'])));
|
||||
if (is_dir(Settings::Get('system.apacheconf_vhost'))) {
|
||||
safe_exec('mkdir -p '.escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_vhost'))));
|
||||
}
|
||||
|
||||
$vhost_filename = $this->getVhostFilename($domain);
|
||||
@@ -265,9 +261,9 @@ class nginx
|
||||
$this->nginx_data[$vhost_filename] = '';
|
||||
}
|
||||
|
||||
if ((!empty($this->nginx_data[$vhost_filename])
|
||||
&& !is_dir($this->settings['system']['apacheconf_vhost']))
|
||||
|| is_dir($this->settings['system']['apacheconf_vhost'])
|
||||
if ((!empty($this->nginx_data[$vhost_filename])
|
||||
&& !is_dir(Settings::Get('system.apacheconf_vhost')))
|
||||
|| is_dir(Settings::Get('system.apacheconf_vhost'))
|
||||
) {
|
||||
// Create non-ssl host
|
||||
$this->nginx_data[$vhost_filename].= $this->getVhostContent($domain, false);
|
||||
@@ -283,8 +279,8 @@ class nginx
|
||||
}
|
||||
}
|
||||
|
||||
protected function getVhostFilename($domain, $ssl_vhost = false)
|
||||
{
|
||||
|
||||
protected function getVhostFilename($domain, $ssl_vhost = false) {
|
||||
if ((int)$domain['parentdomainid'] == 0
|
||||
&& isCustomerStdSubdomain((int)$domain['id']) == false
|
||||
&& ((int)$domain['ismainbutsubto'] == 0
|
||||
@@ -301,16 +297,16 @@ class nginx
|
||||
}
|
||||
|
||||
if ($ssl_vhost === true) {
|
||||
$vhost_filename = makeCorrectFile($this->settings['system']['apacheconf_vhost'] . '/'.$vhost_no.'_froxlor_ssl_vhost_' . $domain['domain'] . '.conf');
|
||||
$vhost_filename = makeCorrectFile(Settings::Get('system.apacheconf_vhost') . '/'.$vhost_no.'_froxlor_ssl_vhost_' . $domain['domain'] . '.conf');
|
||||
} else {
|
||||
$vhost_filename = makeCorrectFile($this->settings['system']['apacheconf_vhost'] . '/'.$vhost_no.'_froxlor_normal_vhost_' . $domain['domain'] . '.conf');
|
||||
$vhost_filename = makeCorrectFile(Settings::Get('system.apacheconf_vhost') . '/'.$vhost_no.'_froxlor_normal_vhost_' . $domain['domain'] . '.conf');
|
||||
}
|
||||
|
||||
return $vhost_filename;
|
||||
}
|
||||
|
||||
protected function getVhostContent($domain, $ssl_vhost = false)
|
||||
{
|
||||
|
||||
protected function getVhostContent($domain, $ssl_vhost = false) {
|
||||
if ($ssl_vhost === true
|
||||
&& $domain['ssl'] != '1'
|
||||
&& $domain['ssl_redirect'] != '1'
|
||||
@@ -324,10 +320,10 @@ class nginx
|
||||
$query = "SELECT * FROM `".TABLE_PANEL_IPSANDPORTS."` `i`, `".TABLE_DOMAINTOIP."` `dip`
|
||||
WHERE dip.id_domain = :domainid AND i.id = dip.id_ipandports ";
|
||||
|
||||
if ($ssl_vhost === true
|
||||
&& ($domain['ssl'] == '1' || $domain['ssl_redirect'] == '1')
|
||||
if ($ssl_vhost === true
|
||||
&& ($domain['ssl'] == '1' || $domain['ssl_redirect'] == '1')
|
||||
) {
|
||||
// by ordering by cert-file the row with filled out SSL-Fields will be shown last,
|
||||
// by ordering by cert-file the row with filled out SSL-Fields will be shown last,
|
||||
// thus it is enough to fill out 1 set of SSL-Fields
|
||||
$query .= "AND i.ssl = 1 ORDER BY i.ssl_cert_file ASC;";
|
||||
} else {
|
||||
@@ -356,7 +352,7 @@ class nginx
|
||||
// if the domain has customer-defined ssl-certificates
|
||||
$dssl->setDomainSSLFilesArray($domain);
|
||||
}
|
||||
|
||||
|
||||
if (filter_var($domain['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
||||
$ipport = '[' . $domain['ip'] . ']:' . $domain['port'];
|
||||
} else {
|
||||
@@ -376,8 +372,7 @@ class nginx
|
||||
// respect ssl_redirect settings, #542
|
||||
if ($ssl_vhost == false
|
||||
&& $domain['ssl'] == '1'
|
||||
&& $domain['ssl_redirect'] == '1')
|
||||
{
|
||||
&& $domain['ssl_redirect'] == '1') {
|
||||
// We must not check if our port differs from port 443,
|
||||
// but if there is a destination-port != 443
|
||||
$_sslport = '';
|
||||
@@ -412,8 +407,8 @@ class nginx
|
||||
if ($this->_deactivated == false) {
|
||||
|
||||
if ($ssl_vhost === true
|
||||
&& $domain['ssl'] == '1'
|
||||
&& $this->settings['system']['use_ssl'] == '1'
|
||||
&& $domain['ssl'] == '1'
|
||||
&& Settings::Get('system.use_ssl') == '1'
|
||||
) {
|
||||
$vhost_content.= $this->composeSslSettings($domain);
|
||||
}
|
||||
@@ -430,8 +425,8 @@ class nginx
|
||||
$vhost_content .= $_vhost_content;
|
||||
}
|
||||
|
||||
if ($this->settings['system']['default_vhostconf'] != '') {
|
||||
$vhost_content .= $this->settings['system']['default_vhostconf'] . "\n";
|
||||
if (Settings::Get('system.default_vhostconf') != '') {
|
||||
$vhost_content .= Settings::Get('system.default_vhostconf') . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -439,11 +434,12 @@ class nginx
|
||||
|
||||
return $this->mergeVhostBlocks($vhost_content);
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected function mergeVhostBlocks($vhost_content) {
|
||||
$vhost_content = explode("\n", preg_replace('/[ \t]+/', ' ', trim(preg_replace('/\t+/', '', $vhost_content))));
|
||||
$vhost_content = array_filter($vhost_content, create_function('$a','return preg_match("#\S#", $a);'));
|
||||
|
||||
|
||||
// Merge similar blocks
|
||||
$new_vhost_content = array();
|
||||
$isOpen = false;
|
||||
@@ -480,7 +476,7 @@ class nginx
|
||||
$new_vhost_content[] = $line;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Fix idention
|
||||
$nextLevel = 0;
|
||||
for ($i = 0; $i < count($new_vhost_content); $i++) {
|
||||
@@ -496,36 +492,37 @@ class nginx
|
||||
$nextLevel += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return implode("\n", $new_vhost_content);
|
||||
}
|
||||
|
||||
|
||||
protected function composeSslSettings($domain) {
|
||||
|
||||
|
||||
$sslsettings = '';
|
||||
|
||||
if ($domain['ssl_cert_file'] == '') {
|
||||
$domain['ssl_cert_file'] = $this->settings['system']['ssl_cert_file'];
|
||||
$domain['ssl_cert_file'] = Settings::Get('system.ssl_cert_file');
|
||||
}
|
||||
|
||||
if ($domain['ssl_key_file'] == '') {
|
||||
$domain['ssl_key_file'] = $this->settings['system']['ssl_key_file'];
|
||||
$domain['ssl_key_file'] = Settings::Get('system.ssl_key_file');
|
||||
}
|
||||
|
||||
if ($domain['ssl_ca_file'] == '') {
|
||||
$domain['ssl_ca_file'] = $this->settings['system']['ssl_ca_file'];
|
||||
$domain['ssl_ca_file'] = Settings::Get('system.ssl_ca_file');
|
||||
}
|
||||
|
||||
// #418
|
||||
if ($domain['ssl_cert_chainfile'] == '') {
|
||||
$domain['ssl_cert_chainfile'] = $this->settings['system']['ssl_cert_chainfile'];
|
||||
$domain['ssl_cert_chainfile'] = Settings::Get('system.ssl_cert_chainfile');
|
||||
}
|
||||
|
||||
if ($domain['ssl_cert_file'] != '') {
|
||||
// obsolete: ssl on now belongs to the listen block as 'ssl' at the end
|
||||
//$sslsettings .= "\t" . 'ssl on;' . "\n";
|
||||
$sslsettings .= "\t" . 'ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;' . "\n";
|
||||
$sslsettings .= "\t" . 'ssl_ciphers ' . $this->settings['system']['ssl_cipher_list'] . ';' . "\n";
|
||||
$sslsettings .= "\t" . 'ssl_ciphers ' . Settings::Get('system.ssl_cipher_list') . ';' . "\n";
|
||||
$sslsettings .= "\t" . 'ssl_prefer_server_ciphers on;' . "\n";
|
||||
$sslsettings .= "\t" . 'ssl_certificate ' . makeCorrectFile($domain['ssl_cert_file']) . ';' . "\n";
|
||||
|
||||
@@ -541,8 +538,8 @@ class nginx
|
||||
return $sslsettings;
|
||||
}
|
||||
|
||||
protected function create_pathOptions($domain)
|
||||
{
|
||||
|
||||
protected function create_pathOptions($domain) {
|
||||
$has_location = false;
|
||||
|
||||
$result_stmt = Database::prepare("
|
||||
@@ -580,55 +577,55 @@ class nginx
|
||||
$path_options .= "\t".'error_page 500 502 503 504 ' . $defhandler . ';' . "\n";
|
||||
}
|
||||
|
||||
// if ($row['options_indexes'] != '0') {
|
||||
$path = makeCorrectDir(substr($row['path'], strlen($domain['documentroot']) - 1));
|
||||
// if ($row['options_indexes'] != '0') {
|
||||
$path = makeCorrectDir(substr($row['path'], strlen($domain['documentroot']) - 1));
|
||||
|
||||
mkDirWithCorrectOwnership($domain['documentroot'], $row['path'], $domain['guid'], $domain['guid']);
|
||||
mkDirWithCorrectOwnership($domain['documentroot'], $row['path'], $domain['guid'], $domain['guid']);
|
||||
|
||||
$path_options .= "\t".'# '.$path."\n";
|
||||
if ($path == '/') {
|
||||
$this->vhost_root_autoindex = true;
|
||||
$path_options .= "\t".'location ' . $path . ' {' . "\n";
|
||||
if($this->vhost_root_autoindex) {
|
||||
$path_options .= "\t\t" . 'autoindex on;' . "\n";
|
||||
$this->vhost_root_autoindex = false;
|
||||
}
|
||||
$path_options.= "\t\t" . 'index index.php index.html index.htm;'."\n";
|
||||
// $path_options.= "\t\t" . 'try_files $uri $uri/ @rewrites;'."\n";
|
||||
// check if we have a htpasswd for this path
|
||||
// (damn nginx does not like more than one
|
||||
// 'location'-part with the same path)
|
||||
if (count($htpasswds) > 0) {
|
||||
foreach ($htpasswds as $idx => $single) {
|
||||
switch ($single['path']) {
|
||||
case '/awstats/':
|
||||
case '/webalizer/':
|
||||
// no stats-alias in "location /"-context
|
||||
break;
|
||||
default:
|
||||
if ($single['path'] == '/') {
|
||||
$path_options .= "\t\t" . 'auth_basic "Restricted Area";' . "\n";
|
||||
$path_options .= "\t\t" . 'auth_basic_user_file ' . makeCorrectFile($single['usrf']) . ';'."\n";
|
||||
// remove already used entries so we do not have doubles
|
||||
unset($htpasswds[$idx]);
|
||||
}
|
||||
$path_options .= "\t".'# '.$path."\n";
|
||||
if ($path == '/') {
|
||||
$this->vhost_root_autoindex = true;
|
||||
$path_options .= "\t".'location ' . $path . ' {' . "\n";
|
||||
if ($this->vhost_root_autoindex) {
|
||||
$path_options .= "\t\t" . 'autoindex on;' . "\n";
|
||||
$this->vhost_root_autoindex = false;
|
||||
}
|
||||
$path_options.= "\t\t" . 'index index.php index.html index.htm;'."\n";
|
||||
// $path_options.= "\t\t" . 'try_files $uri $uri/ @rewrites;'."\n";
|
||||
// check if we have a htpasswd for this path
|
||||
// (damn nginx does not like more than one
|
||||
// 'location'-part with the same path)
|
||||
if (count($htpasswds) > 0) {
|
||||
foreach ($htpasswds as $idx => $single) {
|
||||
switch ($single['path']) {
|
||||
case '/awstats/':
|
||||
case '/webalizer/':
|
||||
// no stats-alias in "location /"-context
|
||||
break;
|
||||
default:
|
||||
if ($single['path'] == '/') {
|
||||
$path_options .= "\t\t" . 'auth_basic "Restricted Area";' . "\n";
|
||||
$path_options .= "\t\t" . 'auth_basic_user_file ' . makeCorrectFile($single['usrf']) . ';'."\n";
|
||||
// remove already used entries so we do not have doubles
|
||||
unset($htpasswds[$idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$path_options .= "\t".'}' . "\n";
|
||||
|
||||
$this->vhost_root_autoindex = false;
|
||||
} else {
|
||||
$path_options .= "\t".'location ' . $path . ' {' . "\n";
|
||||
if ($this->vhost_root_autoindex) {
|
||||
$path_options .= "\t\t" . 'autoindex on;' . "\n";
|
||||
$this->vhost_root_autoindex = false;
|
||||
}
|
||||
$path_options .= "\t\t" . 'index index.php index.html index.htm;'."\n";
|
||||
$path_options .= "\t".'} ' . "\n";
|
||||
}
|
||||
// }
|
||||
|
||||
$path_options .= "\t".'}' . "\n";
|
||||
|
||||
$this->vhost_root_autoindex = false;
|
||||
} else {
|
||||
$path_options .= "\t".'location ' . $path . ' {' . "\n";
|
||||
if ($this->vhost_root_autoindex) {
|
||||
$path_options .= "\t\t" . 'autoindex on;' . "\n";
|
||||
$this->vhost_root_autoindex = false;
|
||||
}
|
||||
$path_options .= "\t\t" . 'index index.php index.html index.htm;'."\n";
|
||||
$path_options .= "\t".'} ' . "\n";
|
||||
}
|
||||
// }
|
||||
|
||||
/**
|
||||
* Perl support
|
||||
* required the fastCGI wrapper to be running to receive the CGI requests.
|
||||
@@ -645,30 +642,30 @@ class nginx
|
||||
}
|
||||
$path_options .= "\t" . 'location ~ \(.pl|.cgi)$ {' . "\n";
|
||||
$path_options .= "\t\t" . 'gzip off; #gzip makes scripts feel slower since they have to complete before getting gzipped' . "\n";
|
||||
$path_options .= "\t\t" . 'fastcgi_pass '. $this->settings['system']['perl_server'] . ';' . "\n";
|
||||
$path_options .= "\t\t" . 'fastcgi_index index.cgi;' . "\n";
|
||||
$path_options .= "\t\t" . 'include '.$this->settings['nginx']['fastcgiparams'].';'."\n";
|
||||
$path_options .= "\t\t" . 'fastcgi_pass '. Settings::Get('system.perl_server') . ';' . "\n";
|
||||
$path_options .= "\t\t" . 'fastcgi_index index.cgi;' . "\n";
|
||||
$path_options .= "\t\t" . 'include '.Settings::Get('nginx.fastcgiparams').';'."\n";
|
||||
$path_options .= "\t" . '}' . "\n";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// now the rest of the htpasswds
|
||||
if (count($htpasswds) > 0) {
|
||||
foreach ($htpasswds as $idx => $single) {
|
||||
//if ($single['path'] != '/') {
|
||||
switch ($single['path']) {
|
||||
case '/awstats/':
|
||||
case '/webalizer/':
|
||||
$path_options .= $this->getStats($domain,$single);
|
||||
unset($htpasswds[$idx]);
|
||||
break;
|
||||
default:
|
||||
$path_options .= "\t" . 'location ' . makeCorrectDir($single['path']) . ' {' . "\n";
|
||||
$path_options .= "\t\t" . 'auth_basic "Restricted Area";' . "\n";
|
||||
$path_options .= "\t\t" . 'auth_basic_user_file ' . makeCorrectFile($single['usrf']) . ';'."\n";
|
||||
$path_options .= "\t".'}' . "\n";
|
||||
}
|
||||
switch ($single['path']) {
|
||||
case '/awstats/':
|
||||
case '/webalizer/':
|
||||
$path_options .= $this->getStats($domain,$single);
|
||||
unset($htpasswds[$idx]);
|
||||
break;
|
||||
default:
|
||||
$path_options .= "\t" . 'location ' . makeCorrectDir($single['path']) . ' {' . "\n";
|
||||
$path_options .= "\t\t" . 'auth_basic "Restricted Area";' . "\n";
|
||||
$path_options .= "\t\t" . 'auth_basic_user_file ' . makeCorrectFile($single['usrf']) . ';'."\n";
|
||||
$path_options .= "\t".'}' . "\n";
|
||||
}
|
||||
//}
|
||||
unset($htpasswds[$idx]);
|
||||
}
|
||||
@@ -677,6 +674,7 @@ class nginx
|
||||
return $path_options;
|
||||
}
|
||||
|
||||
|
||||
protected function getHtpasswds($domain) {
|
||||
|
||||
$result_stmt = Database::prepare("
|
||||
@@ -691,7 +689,7 @@ class nginx
|
||||
$x = 0;
|
||||
while ($row_htpasswds = $result_stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
if (count($row_htpasswds) > 0) {
|
||||
$htpasswd_filename = makeCorrectFile($this->settings['system']['apacheconf_htpasswddir'] . '/' . $row_htpasswds['customerid'] . '-' . md5($row_htpasswds['path']) . '.htpasswd');
|
||||
$htpasswd_filename = makeCorrectFile(Settings::Get('system.apacheconf_htpasswddir') . '/' . $row_htpasswds['customerid'] . '-' . md5($row_htpasswds['path']) . '.htpasswd');
|
||||
|
||||
// ensure we can write to the array with index $htpasswd_filename
|
||||
if (!isset($this->htpasswds_data[$htpasswd_filename])) {
|
||||
@@ -720,17 +718,17 @@ class nginx
|
||||
return $returnval;
|
||||
}
|
||||
|
||||
protected function composePhpOptions($domain, $ssl_vhost = false)
|
||||
{
|
||||
|
||||
protected function composePhpOptions($domain, $ssl_vhost = false) {
|
||||
$phpopts = '';
|
||||
if ($domain['phpenabled'] == '1') {
|
||||
$phpopts = "\t".'location ~ \.php$ {'."\n";
|
||||
$phpopts.= "\t\t".'try_files $uri =404;'."\n";
|
||||
$phpopts.= "\t\t".'fastcgi_split_path_info ^(.+\.php)(/.+)$;'."\n";
|
||||
$phpopts.= "\t\t".'fastcgi_index index.php;'."\n";
|
||||
$phpopts.= "\t\t".'fastcgi_pass ' . $this->settings['system']['nginx_php_backend'] . ';' . "\n";
|
||||
$phpopts.= "\t\t".'fastcgi_pass ' . Settings::Get('system.nginx_php_backend') . ';' . "\n";
|
||||
$phpopts.= "\t\t".'fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;'."\n";
|
||||
$phpopts.= "\t\t".'include '.$this->settings['nginx']['fastcgiparams'].';'."\n";
|
||||
$phpopts.= "\t\t".'include '.Settings::Get('nginx.fastcgiparams').';'."\n";
|
||||
if ($domain['ssl'] == '1' && $ssl_vhost) {
|
||||
$phpopts.= "\t\t".'fastcgi_param HTTPS on;'."\n";
|
||||
}
|
||||
@@ -739,15 +737,15 @@ class nginx
|
||||
return $phpopts;
|
||||
}
|
||||
|
||||
protected function getWebroot($domain, $ssl)
|
||||
{
|
||||
|
||||
protected function getWebroot($domain, $ssl) {
|
||||
$webroot_text = '';
|
||||
|
||||
if ($domain['deactivated'] == '1'
|
||||
&& $this->settings['system']['deactivateddocroot'] != ''
|
||||
&& Settings::Get('system.deactivateddocroot') != ''
|
||||
) {
|
||||
$webroot_text .= "\t".'# Using docroot for deactivated users...' . "\n";
|
||||
$webroot_text .= "\t".'root '.makeCorrectDir($this->settings['system']['deactivateddocroot']).';'."\n";
|
||||
$webroot_text .= "\t".'root '.makeCorrectDir(Settings::Get('system.deactivateddocroot')).';'."\n";
|
||||
$this->_deactivated = true;
|
||||
} else {
|
||||
$webroot_text .= "\t".'root '.makeCorrectDir($domain['documentroot']).';'."\n";
|
||||
@@ -771,12 +769,12 @@ class nginx
|
||||
return $webroot_text;
|
||||
}
|
||||
|
||||
protected function getStats($domain, $single)
|
||||
{
|
||||
|
||||
protected function getStats($domain, $single) {
|
||||
$stats_text = '';
|
||||
|
||||
// define basic path to the stats
|
||||
if ($this->settings['system']['awstats_enabled'] == '1') {
|
||||
if (Settings::Get('system.awstats_enabled') == '1') {
|
||||
$alias_dir = makeCorrectFile($domain['customerroot'] . '/awstats/');
|
||||
} else {
|
||||
$alias_dir = makeCorrectFile($domain['customerroot'] . '/webalizer/');
|
||||
@@ -789,7 +787,7 @@ class nginx
|
||||
$alias_dir = makeCorrectDir($alias_dir.'/'.$domain['parentdomain']);
|
||||
}
|
||||
|
||||
if ($this->settings['system']['awstats_enabled'] == '1') {
|
||||
if (Settings::Get('system.awstats_enabled') == '1') {
|
||||
// awstats
|
||||
$stats_text .= "\t" . 'location /awstats {' . "\n";
|
||||
} else {
|
||||
@@ -802,18 +800,18 @@ class nginx
|
||||
$stats_text .= "\t\t" . 'auth_basic_user_file ' . makeCorrectFile($single['usrf']) . ';'."\n";
|
||||
$stats_text .= "\t" . '}' . "\n\n";
|
||||
|
||||
// awstats icons
|
||||
if ($this->settings['system']['awstats_enabled'] == '1') {
|
||||
$stats_text .= "\t" . 'location ~ ^/awstats-icon/(.*)$ {' . "\n";
|
||||
$stats_text .= "\t\t" . 'alias ' . makeCorrectDir($this->settings['system']['awstats_icons']) . '$1;' . "\n";
|
||||
$stats_text .= "\t" . '}' . "\n\n";
|
||||
}
|
||||
|
||||
// awstats icons
|
||||
if (Settings::Get('system.awstats_enabled') == '1') {
|
||||
$stats_text .= "\t" . 'location ~ ^/awstats-icon/(.*)$ {' . "\n";
|
||||
$stats_text .= "\t\t" . 'alias ' . makeCorrectDir(Settings::Get('system.awstats_icons')) . '$1;' . "\n";
|
||||
$stats_text .= "\t" . '}' . "\n\n";
|
||||
}
|
||||
|
||||
return $stats_text;
|
||||
}
|
||||
|
||||
protected function getLogFiles($domain)
|
||||
{
|
||||
|
||||
protected function getLogFiles($domain) {
|
||||
$logfiles_text = '';
|
||||
|
||||
$speciallogfile = '';
|
||||
@@ -826,22 +824,22 @@ class nginx
|
||||
}
|
||||
|
||||
// The normal access/error - logging is enabled
|
||||
$error_log = makeCorrectFile($this->settings['system']['logfiles_directory'] . $domain['loginname'] . $speciallogfile . '-error.log');
|
||||
$error_log = makeCorrectFile(Settings::Get('system.logfiles_directory') . $domain['loginname'] . $speciallogfile . '-error.log');
|
||||
// Create the logfile if it does not exist (fixes #46)
|
||||
touch($error_log);
|
||||
chown($error_log, $this->settings['system']['httpuser']);
|
||||
chgrp($error_log, $this->settings['system']['httpgroup']);
|
||||
chown($error_log, Settings::Get('system.httpuser'));
|
||||
chgrp($error_log, Settings::Get('system.httpgroup'));
|
||||
|
||||
$access_log = makeCorrectFile($this->settings['system']['logfiles_directory'] . $domain['loginname'] . $speciallogfile . '-access.log');
|
||||
$access_log = makeCorrectFile(Settings::Get('system.logfiles_directory') . $domain['loginname'] . $speciallogfile . '-access.log');
|
||||
// Create the logfile if it does not exist (fixes #46)
|
||||
touch($access_log);
|
||||
chown($access_log, $this->settings['system']['httpuser']);
|
||||
chgrp($access_log, $this->settings['system']['httpgroup']);
|
||||
chown($access_log, Settings::Get('system.httpuser'));
|
||||
chgrp($access_log, Settings::Get('system.httpgroup'));
|
||||
|
||||
$logfiles_text .= "\t".'access_log ' . $access_log . ' combined;' . "\n";
|
||||
$logfiles_text .= "\t".'error_log ' . $error_log . ' error;' . "\n";
|
||||
|
||||
if ($this->settings['system']['awstats_enabled'] == '1') {
|
||||
if (Settings::Get('system.awstats_enabled') == '1') {
|
||||
if ((int)$domain['parentdomainid'] == 0) {
|
||||
// prepare the aliases and subdomains for stats config files
|
||||
$server_alias = '';
|
||||
@@ -877,19 +875,19 @@ class nginx
|
||||
// be sure to build the awstats conf file as well
|
||||
// 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
|
||||
createAWStatsConf($this->settings['system']['logfiles_directory'] . $domain['loginname'] . $speciallogfile . '-access.log', $domain['domain'], $alias . $server_alias, $domain['customerroot'], $domain);
|
||||
createAWStatsConf(Settings::Get('system.logfiles_directory') . $domain['loginname'] . $speciallogfile . '-access.log', $domain['domain'], $alias . $server_alias, $domain['customerroot'], $domain);
|
||||
}
|
||||
}
|
||||
|
||||
return $logfiles_text;
|
||||
}
|
||||
|
||||
public function createOwnVhostStarter()
|
||||
{
|
||||
|
||||
public function createOwnVhostStarter() {
|
||||
}
|
||||
|
||||
protected function getServerNames($domain)
|
||||
{
|
||||
|
||||
protected function getServerNames($domain) {
|
||||
$server_alias = '';
|
||||
|
||||
if ($domain['iswildcarddomain'] == '1') {
|
||||
@@ -924,26 +922,26 @@ class nginx
|
||||
return $servernames_text;
|
||||
}
|
||||
|
||||
public function writeConfigs()
|
||||
{
|
||||
fwrite($this->debugHandler, ' nginx::writeConfigs: rebuilding ' . $this->settings['system']['apacheconf_vhost'] . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . $this->settings['system']['apacheconf_vhost']);
|
||||
|
||||
if (!isConfigDir($this->settings['system']['apacheconf_vhost'])) {
|
||||
public function writeConfigs() {
|
||||
fwrite($this->debugHandler, ' nginx::writeConfigs: rebuilding ' . Settings::Get('system.apacheconf_vhost') . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_INFO, "rebuilding " . Settings::Get('system.apacheconf_vhost'));
|
||||
|
||||
if (!isConfigDir(Settings::Get('system.apacheconf_vhost'))) {
|
||||
// Save one big file
|
||||
$vhosts_file = '';
|
||||
|
||||
|
||||
// sort by filename so the order is:
|
||||
// 1. subdomains
|
||||
// 2. subdomains as main-domains
|
||||
// 3. main-domains
|
||||
ksort($this->nginx_data);
|
||||
|
||||
|
||||
foreach ($this->nginx_data as $vhosts_filename => $vhost_content) {
|
||||
$vhosts_file.= $vhost_content . "\n\n";
|
||||
}
|
||||
|
||||
$vhosts_filename = $this->settings['system']['apacheconf_vhost'];
|
||||
$vhosts_filename = Settings::Get('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;
|
||||
@@ -951,10 +949,10 @@ class nginx
|
||||
fwrite($vhosts_file_handler, $vhosts_file);
|
||||
fclose($vhosts_file_handler);
|
||||
} else {
|
||||
if (!file_exists($this->settings['system']['apacheconf_vhost'])) {
|
||||
fwrite($this->debugHandler, ' nginx::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 -p ' . escapeshellarg(makeCorrectDir($this->settings['system']['apacheconf_vhost'])));
|
||||
if (!file_exists(Settings::Get('system.apacheconf_vhost'))) {
|
||||
fwrite($this->debugHandler, ' nginx::writeConfigs: mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_vhost'))) . "\n");
|
||||
$this->logger->logAction(CRON_ACTION, LOG_NOTICE, 'mkdir ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_vhost'))));
|
||||
safe_exec('mkdir -p ' . escapeshellarg(makeCorrectDir(Settings::Get('system.apacheconf_vhost'))));
|
||||
}
|
||||
|
||||
// Write a single file for every vhost
|
||||
@@ -975,18 +973,18 @@ class nginx
|
||||
|
||||
// htaccess stuff
|
||||
if (count($this->htpasswds_data) > 0) {
|
||||
if (!file_exists($this->settings['system']['apacheconf_htpasswddir'])) {
|
||||
if (!file_exists(Settings::Get('system.apacheconf_htpasswddir'))) {
|
||||
$umask = umask();
|
||||
umask(0000);
|
||||
mkdir($this->settings['system']['apacheconf_htpasswddir'], 0751);
|
||||
mkdir(Settings::Get('system.apacheconf_htpasswddir'), 0751);
|
||||
umask($umask);
|
||||
} elseif (!is_dir($this->settings['system']['apacheconf_htpasswddir'])) {
|
||||
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!!!');
|
||||
} elseif (!is_dir(Settings::Get('system.apacheconf_htpasswddir'))) {
|
||||
fwrite($this->debugHandler, ' cron_tasks: WARNING!!! ' . Settings::Get('system.apacheconf_htpasswddir') . ' is not a directory. htpasswd directory protection is disabled!!!' . "\n");
|
||||
echo 'WARNING!!! ' . Settings::Get('system.apacheconf_htpasswddir') . ' is not a directory. htpasswd directory protection is disabled!!!';
|
||||
$this->logger->logAction(CRON_ACTION, LOG_WARNING, 'WARNING!!! ' . Settings::Get('system.apacheconf_htpasswddir') . ' is not a directory. htpasswd directory protection is disabled!!!');
|
||||
}
|
||||
|
||||
if (is_dir($this->settings['system']['apacheconf_htpasswddir'])) {
|
||||
if (is_dir(Settings::Get('system.apacheconf_htpasswddir'))) {
|
||||
foreach ($this->htpasswds_data as $htpasswd_filename => $htpasswd_file) {
|
||||
$this->known_htpasswdsfilenames[] = basename($htpasswd_filename);
|
||||
$htpasswd_file_handler = fopen($htpasswd_filename, 'w');
|
||||
|
||||
Reference in New Issue
Block a user