Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
FIX: Reverse proxy site issue with subfolders.
FIX: Redirection manager allowing duplicate regex.
  • Loading branch information
QROkes committed Apr 29, 2022
1 parent 2199c2a commit 5d87597
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
9 changes: 7 additions & 2 deletions lib/general
Original file line number Diff line number Diff line change
Expand Up @@ -990,8 +990,13 @@ is_log() {


escaped_string() {
# Escaped characters: Put a backslash before $.*/[\]^()+
echo $(echo $1 | sed "s#/#\\\/#g" | sed "s/\./\\\./g" | sed "s/\\$/\\\\$/g" | sed "s/\*/\\\*/g" | sed "s/\\\/\\\\/g" | sed "s/\[/\\\[/g" | sed "s/\]/\\\]/g" | sed "s/\^/\\\^/g" | sed -E "s/\(/\\\(/g" | sed -E "s/\)/\\\)/g" | sed "s/\+/\\\+/g")
if [[ $2 == "-grep" ]]; then
# Escaped characters: Put a backslash before $.*/[\]^()+
echo $(echo $1 | sed "s#/#\\\/#g" | sed "s/\./\\\./g" | sed "s/\\$/\\\\$/g" | sed "s/\*/\\\*/g" | sed "s/\\\/\\\\/g" | sed "s/\[/\\\[/g" | sed "s/\]/\\\]/g" | sed "s/\^/\\\^/g")
else
# Escaped characters: Put a backslash before $.*/[\]^
echo $(echo $1 | sed "s#/#\\\/#g" | sed "s/\./\\\./g" | sed "s/\\$/\\\\$/g" | sed "s/\*/\\\*/g" | sed "s/\\\/\\\\/g" | sed "s/\[/\\\[/g" | sed "s/\]/\\\]/g" | sed "s/\^/\\\^/g" | sed -E "s/\(/\\\(/g" | sed -E "s/\)/\\\)/g" | sed "s/\+/\\\+/g")
fi
}


Expand Down
27 changes: 18 additions & 9 deletions lib/sites
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ create_empty_site() {

if [[ $1 == "-full" ]]; then
sudo sed -i "/locations.conf;/d" /etc/nginx/sites-available/$domain
sudo sed -i "/include .*header.*.conf;/d" /etc/nginx/sites-available/$domain
sudo sed -i "/include .*headers-.*.conf;/d" /etc/nginx/sites-available/$domain
fi
}
Expand Down Expand Up @@ -945,9 +946,9 @@ redirection_manager() {
sudo chown -R root:root /etc/nginx/apps.d/$domain-nginx.conf
fi

local exisa=$( grep -G "^# RedirectFrom: $(escaped_string $from)$" /etc/nginx/apps.d/$domain-nginx.conf )
local exisb=$( grep -G "^# RedirectFrom: $(escaped_string $from) (Regex)$" /etc/nginx/apps.d/$domain-nginx.conf )
local exisc=$( grep -G "^# RedirectFrom: $(escaped_string $from) (Exact)$" /etc/nginx/apps.d/$domain-nginx.conf )
local exisa=$( grep -G "^# RedirectFrom: $(escaped_string $from -grep)$" /etc/nginx/apps.d/$domain-nginx.conf )
local exisb=$( grep -G "^# RedirectFrom: $(escaped_string $from -grep) (Regex)$" /etc/nginx/apps.d/$domain-nginx.conf )
local exisc=$( grep -G "^# RedirectFrom: $(escaped_string $from -grep) (Exact)$" /etc/nginx/apps.d/$domain-nginx.conf )

# Can have both at the same time, one exact and another.
if [[ ( -z $exisc && $exact == "true" ) || ( -z $exisa && -z $exisb && -z $exact ) ]]; then
Expand Down Expand Up @@ -1254,6 +1255,19 @@ reverse_proxy() {
exit 1
fi
is_url $proxydata -split
[[ -n $url_scheme ]] && url_scheme="$url_scheme://" || url_scheme="http://"
[[ -n $url_port ]] && url_port=":$url_port"
rpurl="$url_host$url_port$url_path"
# URI part (subfolders) are not allowed because the proxy configuration we are using includes the static files location
# This location block is using regex which is not allowed, dedicated reverse proxy are not affected because they don't have static file location block.
# nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except" block in /etc/nginx/apps.d/testa.qrokes.com-proxy.conf:31
if [[ -z $dedicated_reverse_proxy && -n $url_path ]]; then
echo "${red}[ERROR] Subfolders in your endpoint are not allowed in Reverse Proxy sites configured as websites!${end}"
exit 1
fi
if [[ ( -z $subfolder || ( -n $subfolder && ! -f /etc/nginx/sites-available/$domain )) && $(is_empty_root_site $domain) == "false" ]]; then
[[ -n $dedicated_reverse_proxy ]] && create_empty_site -full || create_empty_site
elif [[ -z $subfolder && $(is_empty_root_site $domain) == "full" && $(is_dedicated_proxy $domain) == "false" ]]; then
Expand All @@ -1262,11 +1276,6 @@ reverse_proxy() {
echo "${gre}Site configuration found: Main site at${blu} $domain ${gre}root has been successfully set as Reverse-Proxy!${end}"
fi

is_url $proxydata -split
[[ -n $url_scheme ]] && url_scheme="$url_scheme://" || url_scheme="http://"
[[ -n $url_port ]] && url_port=":$url_port"
rpurl="$url_host$url_port$url_path"

sudo cp /opt/webinoly/templates/template-site-proxy /etc/nginx/apps.d/$domain$subname-proxy.conf
sudo sed -i "/# WebinolyCustom$/a \ include apps.d/$domain$subname-proxy.conf;" /etc/nginx/sites-available/$domain

Expand All @@ -1284,7 +1293,7 @@ reverse_proxy() {
[[ $(is_ssl $domain) != "true" ]] && sudo sed -i '/CacheStaticFiles/,/expires max;/{/headers-https.conf;/d}' /etc/nginx/apps.d/$domain$subname-proxy.conf

# Suggest / at the end of the url to pass
if [[ $(echo "${rpurl}" | rev | cut -c-1) != "/" ]]; then
if [[ -n $dedicated_reverse_proxy && $(echo "${rpurl}" | rev | cut -c-1) != "/" ]]; then
echo "${dim}[INFO] Your endpoint URL doesn't have a / at the end! You should note that it can have a different behavior."
echo "Read: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass ${end}"
fi
Expand Down

0 comments on commit 5d87597

Please sign in to comment.