From 93f24e172a9fae36cc6fb27ffee4029b265a8f77 Mon Sep 17 00:00:00 2001
From: ftimme <ft@falkotimme.com>
Date: Tue, 03 Apr 2012 11:55:49 -0400
Subject: [PATCH] - Fixed FS#2139.
---
server/conf/nginx_vhost.conf.master | 3
interface/web/sites/web_domain_edit.php | 5 +
server/plugins-available/nginx_plugin.inc.php | 167 +++++++++++++++++++++++++++++++++++++++++++++++++++----
3 files changed, 160 insertions(+), 15 deletions(-)
diff --git a/interface/web/sites/web_domain_edit.php b/interface/web/sites/web_domain_edit.php
index d74fae3..e5a0129 100644
--- a/interface/web/sites/web_domain_edit.php
+++ b/interface/web/sites/web_domain_edit.php
@@ -242,6 +242,11 @@
// The user is admin, so we fill in all IP addresses of the server
if($this->id > 0) {
+ if(!isset($this->dataRecord["server_id"])){
+ $tmp = $app->db->queryOneRecord("SELECT server_id FROM web_domain WHERE domain_id = ".intval($this->id));
+ $this->dataRecord["server_id"] = $tmp["server_id"];
+ unset($tmp);
+ }
$server_id = @$this->dataRecord["server_id"];
} else {
// Get the first server ID
diff --git a/server/conf/nginx_vhost.conf.master b/server/conf/nginx_vhost.conf.master
index 3ef9f00..47b08de 100644
--- a/server/conf/nginx_vhost.conf.master
+++ b/server/conf/nginx_vhost.conf.master
@@ -25,7 +25,8 @@
<tmpl_loop name="redirects">
if ($http_host ~* "<tmpl_var name='rewrite_domain'>$") {
- rewrite ^/(.+)$ <tmpl_var name='rewrite_target'>$1 <tmpl_var name='rewrite_type'>;
+ #rewrite ^/(.+)$ <tmpl_var name='rewrite_target'>$1 <tmpl_var name='rewrite_type'>;
+ rewrite ^<tmpl_var name='rewrite_exclude'>/(.+)$ <tmpl_var name='rewrite_target'>$2 <tmpl_var name='rewrite_type'>;
}
</tmpl_loop>
diff --git a/server/plugins-available/nginx_plugin.inc.php b/server/plugins-available/nginx_plugin.inc.php
index ffd5ff7..0f3b034 100644
--- a/server/plugins-available/nginx_plugin.inc.php
+++ b/server/plugins-available/nginx_plugin.inc.php
@@ -794,6 +794,7 @@
if($data['new']['redirect_type'] != '') {
if(substr($data['new']['redirect_path'],-1) != '/') $data['new']['redirect_path'] .= '/';
if(substr($data['new']['redirect_path'],0,8) == '[scheme]') $data['new']['redirect_path'] = '$scheme'.substr($data['new']['redirect_path'],8);
+
/* Disabled path extension
if($data['new']['redirect_type'] == 'no' && substr($data['new']['redirect_path'],0,4) != 'http') {
$data['new']['redirect_path'] = $data['new']['document_root'].'/web'.realpath($data['new']['redirect_path']).'/';
@@ -802,22 +803,91 @@
switch($data['new']['subdomain']) {
case 'www':
+ if(substr($data['new']['redirect_path'],0,1) == '/'){ // relative path
+ $rewrite_exclude = '(?!'.substr($data['new']['redirect_path'],0,-1).')';
+ } else { // URL - check if URL is local
+ $tmp_redirect_path = $data['new']['redirect_path'];
+ if(substr($tmp_redirect_path,0,7) == '$scheme') $tmp_redirect_path = 'http'.substr($tmp_redirect_path,7);
+ $tmp_redirect_path_parts = parse_url($tmp_redirect_path);
+ if($tmp_redirect_path_parts['host'] == $data['new']['domain'] && ($tmp_redirect_path_parts['port'] == '80' || $tmp_redirect_path_parts['port'] == '443' || !isset($tmp_redirect_path_parts['port']))){
+ if(substr($tmp_redirect_path_parts['path'],-1) == '/') $tmp_redirect_path_parts['path'] = substr($tmp_redirect_path_parts['path'],0,-1);
+ if(substr($tmp_redirect_path_parts['path'],0,1) != '/') $tmp_redirect_path_parts['path'] = '/'.$tmp_redirect_path_parts['path'];
+ $rewrite_exclude = '(?!'.$tmp_redirect_path_parts['path'].')';
+ } else {
+ $rewrite_exclude = '(.?)';
+ }
+ unset($tmp_redirect_path);
+ unset($tmp_redirect_path_parts);
+ }
$rewrite_rules[] = array( 'rewrite_domain' => '^'.$data['new']['domain'],
'rewrite_type' => ($data['new']['redirect_type'] == 'no')?'':$data['new']['redirect_type'],
- 'rewrite_target' => $data['new']['redirect_path']);
+ 'rewrite_target' => $data['new']['redirect_path'],
+ 'rewrite_exclude' => $rewrite_exclude);
+
+ if(substr($data['new']['redirect_path'],0,1) == '/'){ // relative path
+ $rewrite_exclude = '(?!'.substr($data['new']['redirect_path'],0,-1).')';
+ } else { // URL - check if URL is local
+ $tmp_redirect_path = $data['new']['redirect_path'];
+ if(substr($tmp_redirect_path,0,7) == '$scheme') $tmp_redirect_path = 'http'.substr($tmp_redirect_path,7);
+ $tmp_redirect_path_parts = parse_url($tmp_redirect_path);
+ if($tmp_redirect_path_parts['host'] == 'www.'.$data['new']['domain'] && ($tmp_redirect_path_parts['port'] == '80' || $tmp_redirect_path_parts['port'] == '443' || !isset($tmp_redirect_path_parts['port']))){
+ if(substr($tmp_redirect_path_parts['path'],-1) == '/') $tmp_redirect_path_parts['path'] = substr($tmp_redirect_path_parts['path'],0,-1);
+ if(substr($tmp_redirect_path_parts['path'],0,1) != '/') $tmp_redirect_path_parts['path'] = '/'.$tmp_redirect_path_parts['path'];
+ $rewrite_exclude = '(?!'.$tmp_redirect_path_parts['path'].')';
+ } else {
+ $rewrite_exclude = '(.?)';
+ }
+ unset($tmp_redirect_path);
+ unset($tmp_redirect_path_parts);
+ }
$rewrite_rules[] = array( 'rewrite_domain' => '^www.'.$data['new']['domain'],
'rewrite_type' => ($data['new']['redirect_type'] == 'no')?'':$data['new']['redirect_type'],
- 'rewrite_target' => $data['new']['redirect_path']);
+ 'rewrite_target' => $data['new']['redirect_path'],
+ 'rewrite_exclude' => $rewrite_exclude);
break;
case '*':
+ if(substr($data['new']['redirect_path'],0,1) == '/'){ // relative path
+ $rewrite_exclude = '(?!'.substr($data['new']['redirect_path'],0,-1).')';
+ } else { // URL - check if URL is local
+ $tmp_redirect_path = $data['new']['redirect_path'];
+ if(substr($tmp_redirect_path,0,7) == '$scheme') $tmp_redirect_path = 'http'.substr($tmp_redirect_path,7);
+ $tmp_redirect_path_parts = parse_url($tmp_redirect_path);
+ if(substr($tmp_redirect_path_parts['host'],-strlen($data['new']['domain'])) == $data['new']['domain'] && ($tmp_redirect_path_parts['port'] == '80' || $tmp_redirect_path_parts['port'] == '443' || !isset($tmp_redirect_path_parts['port']))){
+ if(substr($tmp_redirect_path_parts['path'],-1) == '/') $tmp_redirect_path_parts['path'] = substr($tmp_redirect_path_parts['path'],0,-1);
+ if(substr($tmp_redirect_path_parts['path'],0,1) != '/') $tmp_redirect_path_parts['path'] = '/'.$tmp_redirect_path_parts['path'];
+ $rewrite_exclude = '(?!'.$tmp_redirect_path_parts['path'].')';
+ } else {
+ $rewrite_exclude = '(.?)';
+ }
+ unset($tmp_redirect_path);
+ unset($tmp_redirect_path_parts);
+ }
$rewrite_rules[] = array( 'rewrite_domain' => $data['new']['domain'],
'rewrite_type' => ($data['new']['redirect_type'] == 'no')?'':$data['new']['redirect_type'],
- 'rewrite_target' => $data['new']['redirect_path']);
+ 'rewrite_target' => $data['new']['redirect_path'],
+ 'rewrite_exclude' => $rewrite_exclude);
break;
default:
+ if(substr($data['new']['redirect_path'],0,1) == '/'){ // relative path
+ $rewrite_exclude = '(?!'.substr($data['new']['redirect_path'],0,-1).')';
+ } else { // URL - check if URL is local
+ $tmp_redirect_path = $data['new']['redirect_path'];
+ if(substr($tmp_redirect_path,0,7) == '$scheme') $tmp_redirect_path = 'http'.substr($tmp_redirect_path,7);
+ $tmp_redirect_path_parts = parse_url($tmp_redirect_path);
+ if($tmp_redirect_path_parts['host'] == $data['new']['domain'] && ($tmp_redirect_path_parts['port'] == '80' || $tmp_redirect_path_parts['port'] == '443' || !isset($tmp_redirect_path_parts['port']))){
+ if(substr($tmp_redirect_path_parts['path'],-1) == '/') $tmp_redirect_path_parts['path'] = substr($tmp_redirect_path_parts['path'],0,-1);
+ if(substr($tmp_redirect_path_parts['path'],0,1) != '/') $tmp_redirect_path_parts['path'] = '/'.$tmp_redirect_path_parts['path'];
+ $rewrite_exclude = '(?!'.$tmp_redirect_path_parts['path'].')';
+ } else {
+ $rewrite_exclude = '(.?)';
+ }
+ unset($tmp_redirect_path);
+ unset($tmp_redirect_path_parts);
+ }
$rewrite_rules[] = array( 'rewrite_domain' => '^'.$data['new']['domain'],
'rewrite_type' => ($data['new']['redirect_type'] == 'no')?'':$data['new']['redirect_type'],
- 'rewrite_target' => $data['new']['redirect_path']);
+ 'rewrite_target' => $data['new']['redirect_path'],
+ 'rewrite_exclude' => $rewrite_exclude);
}
}
@@ -826,30 +896,30 @@
$server_alias = array();
switch($data['new']['subdomain']) {
case 'www':
- $server_alias[] .= 'www.'.$data['new']['domain'].' ';
+ $server_alias[] = 'www.'.$data['new']['domain'].' ';
break;
case '*':
- $server_alias[] .= '*.'.$data['new']['domain'].' ';
+ $server_alias[] = '*.'.$data['new']['domain'].' ';
break;
}
if(is_array($aliases)) {
foreach($aliases as $alias) {
switch($alias['subdomain']) {
case 'www':
- $server_alias[] .= 'www.'.$alias['domain'].' '.$alias['domain'].' ';
+ $server_alias[] = 'www.'.$alias['domain'].' '.$alias['domain'].' ';
break;
case '*':
- $server_alias[] .= '*.'.$alias['domain'].' '.$alias['domain'].' ';
+ $server_alias[] = '*.'.$alias['domain'].' '.$alias['domain'].' ';
break;
default:
- $server_alias[] .= $alias['domain'].' ';
+ $server_alias[] = $alias['domain'].' ';
break;
}
$app->log('Add server alias: '.$alias['domain'],LOGLEVEL_DEBUG);
// Rewriting
if($alias['redirect_type'] != '') {
if(substr($alias['redirect_path'],-1) != '/') $alias['redirect_path'] .= '/';
- if(substr($alias['redirect_path'],0,8) == '[scheme]') $alias['redirect_path'] = '$scheme'.substr($alias['redirect_path'],8);
+ if(substr($alias['redirect_path'],0,8) == '[scheme]') $alias['redirect_path'] = '$scheme'.substr($alias['redirect_path'],8);
/* Disabled the path extension
if($data['new']['redirect_type'] == 'no' && substr($data['new']['redirect_path'],0,4) != 'http') {
@@ -859,22 +929,91 @@
switch($alias['subdomain']) {
case 'www':
+ if(substr($alias['redirect_path'],0,1) == '/'){ // relative path
+ $rewrite_exclude = '(?!'.substr($alias['redirect_path'],0,-1).')';
+ } else { // URL - check if URL is local
+ $tmp_redirect_path = $alias['redirect_path'];
+ if(substr($tmp_redirect_path,0,7) == '$scheme') $tmp_redirect_path = 'http'.substr($tmp_redirect_path,7);
+ $tmp_redirect_path_parts = parse_url($tmp_redirect_path);
+ if($tmp_redirect_path_parts['host'] == $alias['domain'] && ($tmp_redirect_path_parts['port'] == '80' || $tmp_redirect_path_parts['port'] == '443' || !isset($tmp_redirect_path_parts['port']))){
+ if(substr($tmp_redirect_path_parts['path'],-1) == '/') $tmp_redirect_path_parts['path'] = substr($tmp_redirect_path_parts['path'],0,-1);
+ if(substr($tmp_redirect_path_parts['path'],0,1) != '/') $tmp_redirect_path_parts['path'] = '/'.$tmp_redirect_path_parts['path'];
+ $rewrite_exclude = '(?!'.$tmp_redirect_path_parts['path'].')';
+ } else {
+ $rewrite_exclude = '(.?)';
+ }
+ unset($tmp_redirect_path);
+ unset($tmp_redirect_path_parts);
+ }
$rewrite_rules[] = array( 'rewrite_domain' => '^'.$alias['domain'],
'rewrite_type' => ($alias['redirect_type'] == 'no')?'':$alias['redirect_type'],
- 'rewrite_target' => $alias['redirect_path']);
+ 'rewrite_target' => $alias['redirect_path'],
+ 'rewrite_exclude' => $rewrite_exclude);
+
+ if(substr($alias['redirect_path'],0,1) == '/'){ // relative path
+ $rewrite_exclude = '(?!'.substr($alias['redirect_path'],0,-1).')';
+ } else { // URL - check if URL is local
+ $tmp_redirect_path = $alias['redirect_path'];
+ if(substr($tmp_redirect_path,0,7) == '$scheme') $tmp_redirect_path = 'http'.substr($tmp_redirect_path,7);
+ $tmp_redirect_path_parts = parse_url($tmp_redirect_path);
+ if($tmp_redirect_path_parts['host'] == 'www.'.$alias['domain'] && ($tmp_redirect_path_parts['port'] == '80' || $tmp_redirect_path_parts['port'] == '443' || !isset($tmp_redirect_path_parts['port']))){
+ if(substr($tmp_redirect_path_parts['path'],-1) == '/') $tmp_redirect_path_parts['path'] = substr($tmp_redirect_path_parts['path'],0,-1);
+ if(substr($tmp_redirect_path_parts['path'],0,1) != '/') $tmp_redirect_path_parts['path'] = '/'.$tmp_redirect_path_parts['path'];
+ $rewrite_exclude = '(?!'.$tmp_redirect_path_parts['path'].')';
+ } else {
+ $rewrite_exclude = '(.?)';
+ }
+ unset($tmp_redirect_path);
+ unset($tmp_redirect_path_parts);
+ }
$rewrite_rules[] = array( 'rewrite_domain' => '^www.'.$alias['domain'],
'rewrite_type' => ($alias['redirect_type'] == 'no')?'':$alias['redirect_type'],
- 'rewrite_target' => $alias['redirect_path']);
+ 'rewrite_target' => $alias['redirect_path'],
+ 'rewrite_exclude' => $rewrite_exclude);
break;
case '*':
+ if(substr($alias['redirect_path'],0,1) == '/'){ // relative path
+ $rewrite_exclude = '(?!'.substr($alias['redirect_path'],0,-1).')';
+ } else { // URL - check if URL is local
+ $tmp_redirect_path = $alias['redirect_path'];
+ if(substr($tmp_redirect_path,0,7) == '$scheme') $tmp_redirect_path = 'http'.substr($tmp_redirect_path,7);
+ $tmp_redirect_path_parts = parse_url($tmp_redirect_path);
+ if(substr($tmp_redirect_path_parts['host'],-strlen($alias['domain'])) == $alias['domain'] && ($tmp_redirect_path_parts['port'] == '80' || $tmp_redirect_path_parts['port'] == '443' || !isset($tmp_redirect_path_parts['port']))){
+ if(substr($tmp_redirect_path_parts['path'],-1) == '/') $tmp_redirect_path_parts['path'] = substr($tmp_redirect_path_parts['path'],0,-1);
+ if(substr($tmp_redirect_path_parts['path'],0,1) != '/') $tmp_redirect_path_parts['path'] = '/'.$tmp_redirect_path_parts['path'];
+ $rewrite_exclude = '(?!'.$tmp_redirect_path_parts['path'].')';
+ } else {
+ $rewrite_exclude = '(.?)';
+ }
+ unset($tmp_redirect_path);
+ unset($tmp_redirect_path_parts);
+ }
$rewrite_rules[] = array( 'rewrite_domain' => $alias['domain'],
'rewrite_type' => ($alias['redirect_type'] == 'no')?'':$alias['redirect_type'],
- 'rewrite_target' => $alias['redirect_path']);
+ 'rewrite_target' => $alias['redirect_path'],
+ 'rewrite_exclude' => $rewrite_exclude);
break;
default:
+ if(substr($alias['redirect_path'],0,1) == '/'){ // relative path
+ $rewrite_exclude = '(?!'.substr($alias['redirect_path'],0,-1).')';
+ } else { // URL - check if URL is local
+ $tmp_redirect_path = $alias['redirect_path'];
+ if(substr($tmp_redirect_path,0,7) == '$scheme') $tmp_redirect_path = 'http'.substr($tmp_redirect_path,7);
+ $tmp_redirect_path_parts = parse_url($tmp_redirect_path);
+ if($tmp_redirect_path_parts['host'] == $alias['domain'] && ($tmp_redirect_path_parts['port'] == '80' || $tmp_redirect_path_parts['port'] == '443' || !isset($tmp_redirect_path_parts['port']))){
+ if(substr($tmp_redirect_path_parts['path'],-1) == '/') $tmp_redirect_path_parts['path'] = substr($tmp_redirect_path_parts['path'],0,-1);
+ if(substr($tmp_redirect_path_parts['path'],0,1) != '/') $tmp_redirect_path_parts['path'] = '/'.$tmp_redirect_path_parts['path'];
+ $rewrite_exclude = '(?!'.$tmp_redirect_path_parts['path'].')';
+ } else {
+ $rewrite_exclude = '(.?)';
+ }
+ unset($tmp_redirect_path);
+ unset($tmp_redirect_path_parts);
+ }
$rewrite_rules[] = array( 'rewrite_domain' => '^'.$alias['domain'],
'rewrite_type' => ($alias['redirect_type'] == 'no')?'':$alias['redirect_type'],
- 'rewrite_target' => $alias['redirect_path']);
+ 'rewrite_target' => $alias['redirect_path'],
+ 'rewrite_exclude' => $rewrite_exclude);
}
}
}
--
Gitblit v1.9.1