diff --git a/scripts/jobs/cron_tasks.inc.http.30.nginx.php b/scripts/jobs/cron_tasks.inc.http.30.nginx.php index 0d5d74bf..9c82d593 100644 --- a/scripts/jobs/cron_tasks.inc.http.30.nginx.php +++ b/scripts/jobs/cron_tasks.inc.http.30.nginx.php @@ -28,6 +28,7 @@ class nginx private $logger = false; private $debugHandler = false; private $idnaConvert = false; + private $nginx_server = array(); // protected @@ -40,7 +41,6 @@ class nginx protected $mod_accesslog_loaded = "0"; protected $vhost_root_autoindex = false; protected $known_vhostfilenames = array(); - /** * indicator whether a customer is deactivated or not * if yes, only the webroot will be generated @@ -49,13 +49,14 @@ class nginx */ private $_deactivated = false; - public function __construct($db, $logger, $debugHandler, $idnaConvert, $settings) + public function __construct($db, $logger, $debugHandler, $idnaConvert, $settings, $nginx_server=array()) { $this->db = $db; $this->logger = $logger; $this->debugHandler = $debugHandler; $this->idnaConvert = $idnaConvert; $this->settings = $settings; + $this->nginx_server = $nginx_server; } protected function getDB() @@ -87,13 +88,6 @@ class nginx } } - public function createVirtualHosts() - { - } - - public function createFileDirOptions() - { - } /** * define a default ErrorDocument-statement, bug #unknown-yet @@ -143,7 +137,10 @@ class nginx } } - + public function createVirtualHosts(){ + } + public function createFileDirOptions(){ + } public function createIpPort() { $query = "SELECT * FROM `" . TABLE_PANEL_IPSANDPORTS . "` ORDER BY `ip` ASC, `port` ASC"; @@ -233,14 +230,14 @@ class nginx } } } - + $this->nginx_data[$vhost_filename].= "\t".'location ~ \.php$ {'."\n"; $this->nginx_data[$vhost_filename].= "\t\t".'fastcgi_index index.php;'."\n"; $this->nginx_data[$vhost_filename].= "\t\t".'include /etc/nginx/fastcgi_params;'."\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"; } - $this->nginx_data[$vhost_filename].= "\t\t".'fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;'."\n"; if((int)$this->settings['phpfpm']['enabled'] == 1 && (int)$this->settings['phpfpm']['enabled_ownvhost'] == 1 ) { @@ -255,7 +252,7 @@ class nginx 'safemode' => '0', 'email' => $this->settings['panel']['adminmail'], 'loginname' => 'froxlor.panel', - 'documentroot' => $mypath + 'documentroot' => $mypath, ); $php = new phpinterface($this->getDB(), $this->settings, $domain); @@ -425,10 +422,20 @@ class nginx if ($this->_deactivated == false) { $vhost_content.= $this->create_pathOptions($domain); - // $vhost_content.= $this->create_htaccess($domain); $vhost_content.= $this->composePhpOptions($domain, $ssl_vhost); - $vhost_content.= $this->getStats($domain); + $l_regex1="/(location\ \/\ \{)(.*)(\})/smU"; + $l_regex2="/(location\ \/\ \{.*\})/smU"; + $replace_by=""; + $replacements=preg_match_all($l_regex1,$vhost_content,$out); + if ($replacements>1){ + foreach ($out[2] as $val) { + $replace_by.=$val."\n"; + } + $vhost_content=preg_replace($l_regex2,"",$vhost_content,$replacements-1); + $vhost_content=preg_replace($l_regex2,"location / {"."\n\t\t". $replace_by ."\t}"."\n",$vhost_content); + } + if ($domain['specialsettings'] != "") { $vhost_content.= $domain['specialsettings'] . "\n"; } @@ -467,19 +474,22 @@ class nginx $path_options.= "\t".'error_page 502 503 504 ' . $row['error500path'] . ';' . "\n"; } - if($row['options_indexes'] != '0') - { +// if($row['options_indexes'] != '0') +// { $path = makeCorrectDir(substr($row['path'], strlen($domain['documentroot']) - 1)); mkDirWithCorrectOwnership($domain['documentroot'], $row['path'], $domain['guid'], $domain['guid']); - if (trim($path) == '/') { + $path_options.= "\t".'# '.$path."\n"; + if ($path == '/') { $this->vhost_root_autoindex = true; - } - else - { $path_options.= "\t".'location ' . $path . ' {' . "\n"; - $path_options.= "\t\t" . 'autoindex on;' . "\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) @@ -487,12 +497,17 @@ class nginx { foreach($htpasswds as $idx => $single) { - if($path == $single['path']) - { - $path_options.= "\t\t" . 'auth_basic "Restricted Area";' . "\n"; - $path_options.= "\t\t" . 'auth_basic_user_file ' . $single['usrf'] . ';'."\n"; - // remove already used entries so we do not have doubles - unset($htpasswds[$idx]); + switch($single['path']){ + case '/awstats/': + case '/webalizer/': + break; + default: + if ($single['path']=='/'){ + $path_options.= "\t\t" . 'auth_basic "Restricted Area";' . "\n"; + $path_options.= "\t\t" . 'auth_basic_user_file ' . $single['usrf'] . ';'."\n"; + // remove already used entries so we do not have doubles + unset($htpasswds[$idx]); + } } } } @@ -500,10 +515,19 @@ class nginx $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"; + } +// } /** - * Perl suport + * Perl support * required the fastCGI wrapper to be running to receive the CGI requests. */ if(customerHasPerlEnabled($domain['customerid']) @@ -518,7 +542,7 @@ 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_pass '. $this->settings['system']['perl_server'] . ';' . "\n"; $path_options.= "\t\t" . 'fastcgi_index index.cgi;' . "\n"; $path_options.= "\t\t" . 'include /etc/nginx/fastcgi_params;'."\n"; $path_options.= "\t" . '}' . "\n"; @@ -533,10 +557,23 @@ class nginx { foreach($htpasswds as $idx => $single) { - $path_options.= "\t" . 'location ' . $single['path'] . ' {' . "\n"; - $path_options.= "\t\t" . 'auth_basic "Restricted Area";' . "\n"; - $path_options.= "\t\t" . 'auth_basic_user_file ' . $single['usrf'] . ';'."\n"; - $path_options.= "\t".'}' . "\n"; + //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 ' . $single['path'] . ' {' . "\n"; + $path_options.= "\t\t" . 'auth_basic "Restricted Area";' . "\n"; + $path_options.= "\t\t" . 'auth_basic_user_file ' . $single['usrf'] . ';'."\n"; + $path_options.= "\t".'}' . "\n"; + } + //} + unset($htpasswds[$idx]); } } @@ -545,7 +582,9 @@ class nginx protected function getHtpasswds($domain) { - $query = "SELECT * FROM " . TABLE_PANEL_HTPASSWDS . " WHERE `customerid`='" . $domain['customerid'] . "'"; + //$query = "SELECT * FROM " . TABLE_PANEL_HTPASSWDS . " WHERE `customerid`='" . $domain['customerid'] . "'"; + $query = "SELECT DISTINCT * FROM " . TABLE_PANEL_HTPASSWDS . " AS a JOIN " . TABLE_PANEL_DOMAINS . " AS b ON a.customerid=b.customerid WHERE b.customerid='" . $domain['customerid'] . "' AND a.path LIKE CONCAT(b.documentroot,'%') AND b.domain='" . $domain['domain'] . "'" ; + $result = $this->db->query($query); $returnval = array(); @@ -581,12 +620,12 @@ class nginx { $phpopts = "\t".'location ~ \.php$ {'."\n"; $phpopts.= "\t\t".'fastcgi_index index.php;'."\n"; - $phpopts.= "\t\t".'include /etc/nginx/fastcgi_params;'."\n"; + //$phpopts.= "\t\t".'fastcgi_pass ' . $this->settings['system']['nginx_php_backend'] . ';' . "\n"; + //$phpopts.= "\t\t".'fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;'."\n"; + //$phpopts.= "\t\t".'include /etc/nginx/fastcgi_params;'."\n"; if ($domain['ssl'] == '1' && $ssl_vhost) { $phpopts.= "\t\t".'fastcgi_param HTTPS on;'."\n"; } - $phpopts.= "\t\t".'fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;'."\n"; - $phpopts.= "\t\t".'fastcgi_pass ' . $this->settings['system']['nginx_php_backend'] . ';' . "\n"; $phpopts.= "\t".'}'."\n"; } return $phpopts; @@ -611,18 +650,22 @@ class nginx $webroot_text.= "\t".'location / {'."\n"; $webroot_text.= "\t\t".'index index.php index.html index.htm;'."\n"; + $webroot_text.= "\t\t" . 'try_files $uri $uri/ @rewrites;'."\n"; if($this->vhost_root_autoindex) { $webroot_text.= "\t\t".'autoindex on;'."\n"; $this->vhost_root_autoindex = false; } - $webroot_text.= "\t".'}'."\n"; + $webroot_text.= "\t".'}'."\n\n"; + $webroot_text.= "\tlocation @rewrites {\n"; + $webroot_text.= "rewrite ^ /index.php last;\n"; + $webroot_text.= "}\n\n"; return $webroot_text; } - protected function getStats($domain) + protected function getStats($domain,$single=array()) { $stats_text = ''; @@ -635,17 +678,20 @@ class nginx { $stats_text.= "\t" . 'location /awstats {' . "\n"; $stats_text.= "\t\t" . 'alias ' . makeCorrectFile($domain['customerroot'] . '/awstats/' . $domain['domain']) . ';' . "\n"; + $stats_text.= "\t\t" . 'auth_basic "Restricted Area";' . "\n"; + $stats_text.= "\t\t" . 'auth_basic_user_file ' . $single['usrf'] . ';'."\n"; $stats_text.= "\t" . '}' . "\n"; $stats_text.= "\t" . 'location /awstats-icon {' . "\n"; $stats_text.= "\t\t" . 'alias ' . makeCorrectDir($this->settings['system']['awstats_icons']) . ';' . "\n"; - $stats_text.= "\t\t" . '}' . "\n"; + $stats_text.= "\t" . '}' . "\n"; } else { $stats_text.= "\t" . 'location /webalizer {' . "\n"; $stats_text.= "\t\t" . 'alias ' . makeCorrectFile($domain['customerroot'] . '/webalizer/' . $domain['domain']) . ';' . "\n"; + $stats_text.= "\t\t" . 'auth_basic "Restricted Area";' . "\n"; + $stats_text.= "\t\t" . 'auth_basic_user_file ' . $single['usrf'] . ';'."\n"; $stats_text.= "\t" . '}' . "\n"; - } } else @@ -654,15 +700,19 @@ class nginx { $stats_text.= "\t" . 'location /awstats {' . "\n"; $stats_text.= "\t\t" . 'alias ' . makeCorrectFile($domain['customerroot'] . '/awstats/' . $domain['parentdomain']) . ';' . "\n"; + $stats_text.= "\t\t" . 'auth_basic "Restricted Area";' . "\n"; + $stats_text.= "\t\t" . 'auth_basic_user_file ' . $single['usrf'] . ';'."\n"; $stats_text.= "\t" . '}' . "\n"; $stats_text.= "\t" . 'location /awstats-icon {' . "\n"; $stats_text.= "\t\t" . 'alias ' . makeCorrectDir($this->settings['system']['awstats_icons']) . ';' . "\n"; - $stats_text.= "\t\t" . '}' . "\n"; + $stats_text.= "\t" . '}' . "\n"; } else { $stats_text.= "\t" . 'location /webalizer {' . "\n"; $stats_text.= "\t\t" . 'alias ' . makeCorrectFile($domain['customerroot'] . '/webalizer/' . $domain['parentdomain']) . ';' . "\n"; + $stats_text.= "\t\t" . 'auth_basic "Restricted Area";' . "\n"; + $stats_text.= "\t\t" . 'auth_basic_user_file ' . $single['usrf'] . ';'."\n"; $stats_text.= "\t" . '}' . "\n"; } @@ -676,6 +726,8 @@ class nginx { $stats_text.= "\t" . 'location /awstats {' . "\n"; $stats_text.= "\t\t" . 'alias ' . makeCorrectFile($domain['customerroot'] . '/awstats/' . $domain['domain']) . ';' . "\n"; + $stats_text.= "\t\t" . 'auth_basic "Restricted Area";' . "\n"; + $stats_text.= "\t\t" . 'auth_basic_user_file ' . $single['usrf'] . ';'."\n"; $stats_text.= "\t" . '}' . "\n"; $stats_text.= "\t" . 'location /awstats-icon {' . "\n"; $stats_text.= "\t\t" . 'alias ' . makeCorrectDir($this->settings['system']['awstats_icons']) . ';' . "\n"; @@ -685,6 +737,8 @@ class nginx { $stats_text.= "\t" . 'location /webalizer {' . "\n"; $stats_text.= "\t\t" . 'root ' . makeCorrectFile($domain['customerroot'] . '/webalizer/' . $domain['domain']) . ';' . "\n"; + $stats_text.= "\t\t" . 'auth_basic "Restricted Area";' . "\n"; + $stats_text.= "\t\t" . 'auth_basic_user_file ' . $single['usrf'] . ';'."\n"; $stats_text.= "\t" . '}' . "\n"; } @@ -697,10 +751,12 @@ class nginx { $stats_text.= "\t" . 'location /awstats {' . "\n"; $stats_text.= "\t\t" . 'alias ' . makeCorrectFile($domain['documentroot'] . '/awstats/' . $domain['domain']) . ';' . "\n"; + $stats_text.= "\t\t" . 'auth_basic "Restricted Area";' . "\n"; + $stats_text.= "\t\t" . 'auth_basic_user_file ' . $single['usrf'] . ';'."\n"; $stats_text.= "\t" . '}' . "\n"; $stats_text.= "\t" . 'location /awstats-icon {' . "\n"; $stats_text.= "\t\t" . 'alias ' . makeCorrectDir($this->settings['system']['awstats_icons']) . ';' . "\n"; - $stats_text.= "\t\t" . '}' . "\n"; + $stats_text.= "\t" . '}' . "\n"; } } diff --git a/scripts/jobs/cron_tasks.inc.http.35.nginx_phpfpm.php b/scripts/jobs/cron_tasks.inc.http.35.nginx_phpfpm.php index 90def257..84fbe8f2 100644 --- a/scripts/jobs/cron_tasks.inc.http.35.nginx_phpfpm.php +++ b/scripts/jobs/cron_tasks.inc.http.35.nginx_phpfpm.php @@ -38,13 +38,13 @@ class nginx_phpfpm extends nginx $phpconfig = $php->getPhpConfig((int)$domain['phpsettingid']); $php_options_text = "\t".'location ~ \.php$ {'."\n"; -// $php_options_text.= "\t\t".'fastcgi_index index.php;'."\n"; -// $php_options_text.= "\t\t".'include /etc/nginx/fastcgi_params;'."\n"; + $php_options_text.= "\t\t".'fastcgi_pass unix:' . $php->getInterface()->getSocketFile() . ';' . "\n"; + $php_options_text.= "\t\t".'fastcgi_index index.php;'."\n"; + $php_options_text.= "\t\t".'fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;'."\n"; + $php_options_text.= "\t\t".'include /etc/nginx/fastcgi_params;'."\n"; if ($domain['ssl'] == '1' && $ssl_vhost) { $php_options_text.= "\t\t".'fastcgi_param HTTPS on;'."\n"; } - $php_options_text.= "\t\t".'fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;'."\n"; - $php_options_text.= "\t\t".'fastcgi_pass unix:' . $php->getInterface()->getSocketFile() . ';' . "\n"; $php_options_text.= "\t".'}'."\n"; // create starter-file | config-file