Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
Minor code fixes
  • Loading branch information
QROkes committed Jun 27, 2020
1 parent 23875eb commit a7e137e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/general
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ is_domain() {

is_url_path() {
# Should start with / and after that all should be valid characters.
if [[ -n $1 && $1 =~ ^\/([\]A-Za-z0-9_\/\.-:\!\*\'\[\(\)\;@\&\=\+\$\,\?#\~\%]+)?$ ]]; then
if [[ -n $1 && $1 =~ ^\/([\]A-Za-z0-9_\/\.:\!\*\'\[\(\)\;@\&\=\+\$\,\?#\~\%\-]+)?$ ]]; then
echo "true"
else
echo "false"
Expand Down
19 changes: 9 additions & 10 deletions lib/webin
Original file line number Diff line number Diff line change
Expand Up @@ -1886,6 +1886,9 @@ custom_cache_global() {
if [[ -z $query_string_cache && -z $query_string_never_cache && -z $skip_cache ]]; then
echo "${red}[ERROR] Please, enter a valid value!${end}"
exit 1
elif [[ -n $regex && ( -n $query_string_cache || -n $query_string_never_cache ) ]]; then
echo "${red}[ERROR] Regex not allowed for Query-String custom rules!${end}"
exit 1
elif [[ $skip_cache == "/" && -z $regex ]]; then
echo "${red}[ERROR] Root folder not allowed, use regex or disable site cache!${end}"
exit 1
Expand All @@ -1895,10 +1898,10 @@ custom_cache_global() {
elif [[ -n $skip_cache && $(is_url_path $skip_cache) != "true" ]]; then
echo "${red}[ERROR] Invalid URL!${end}"
exit 1
elif [[ -z $regex && -n $query_string_cache ]] && ! [[ $query_string_cache =~ ^([\]A-Za-z0-9_\/\.-:\!\*\'\[\(\)\;@\&\=\+\$\,\?#\~\%]+)?$ ]]; then
elif [[ -z $regex && -n $query_string_cache ]] && ! [[ $query_string_cache =~ ^([\]A-Za-z0-9_\/\.:\!\*\'\[\(\)\;@\&\=\+\$\,\?#\~\%\-]+)?$ ]]; then
echo "${red}[ERROR] Invalid Query String!${end}"
exit 1
elif [[ -z $regex && -n $query_string_never_cache ]] && ! [[ $query_string_never_cache =~ ^([\]A-Za-z0-9_\/\.-:\!\*\'\[\(\)\;@\&\=\+\$\,\?#\~\%]+)?$ ]]; then
elif [[ -z $regex && -n $query_string_never_cache ]] && ! [[ $query_string_never_cache =~ ^([\]A-Za-z0-9_\/\.:\!\*\'\[\(\)\;@\&\=\+\$\,\?#\~\%\-]+)?$ ]]; then
echo "${red}[ERROR] Invalid Query String!${end}"
exit 1
fi
Expand Down Expand Up @@ -1933,21 +1936,17 @@ custom_cache_global() {
if [[ -n $query_string_never_cache ]]; then
echo "# Value: $code
# NeverCacheQueryString
if (\$query_string $sign $value) {
if (\$arg_${value}) {
set \$skip_cache 1;
}
# CacheRuleEnd" >> /etc/nginx/apps.d/global_custom_cache.conf
elif [[ -n $query_string_cache ]]; then
# Sed can not write when file is empty
[[ ! -s /etc/nginx/apps.d/global_custom_cache.conf ]] && echo ' ' >> /etc/nginx/apps.d/global_custom_cache.conf
sudo sed -i "1i # Value: $code\n# CacheQueryString\nif (\$query_string $sign $value) {\n set \$skip_cache 0;\n}\n# CacheRuleEnd" /etc/nginx/apps.d/global_custom_cache.conf
sudo sed -i "1i # Value: $code\n# CacheQueryString\nif (\$arg_${value}) {\n set \$skip_cache 0;\n}\n# CacheRuleEnd" /etc/nginx/apps.d/global_custom_cache.conf
elif [[ -n $skip_cache ]]; then
echo "# Value: $code
# CacheSkipURL
if (\$request_uri $sign $value) {
set \$skip_cache 1;
}
# CacheRuleEnd" >> /etc/nginx/apps.d/global_custom_cache.conf
[[ ! -s /etc/nginx/apps.d/global_custom_cache.conf ]] && echo ' ' >> /etc/nginx/apps.d/global_custom_cache.conf
sudo sed -i "1i # Value: $code\n# CacheSkipURL\nif (\$request_uri $sign $value) {\n set \$skip_cache 1;\n}\n# CacheRuleEnd" /etc/nginx/apps.d/global_custom_cache.conf
fi

# Last verification
Expand Down
9 changes: 3 additions & 6 deletions plugins/httpauth
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,12 @@ elif [[ -n $whitelist ]]; then
if [[ ! -f /etc/nginx/apps.d/whitelist-acl.conf ]]; then
sudo touch /etc/nginx/apps.d/whitelist-acl.conf
sudo chmod 644 /etc/nginx/apps.d/whitelist-acl.conf
sudo chown -R root:root /etc/nginx/apps.d/whitelist-acl.conf
echo "
allow 127.0.0.1;
deny all;" >> /etc/nginx/apps.d/whitelist-acl.conf
sudo chown -R root:root /etc/nginx/apps.d/whitelist-acl.conf
fi

exist=$( grep -E "^allow $whitelist;$" /etc/nginx/apps.d/whitelist-acl.conf )
if [[ -z $exist ]]; then
sudo sed -i "1i allow ${whitelist};" /etc/nginx/apps.d/whitelist-acl.conf
echo "allow ${whitelist};" >> /etc/nginx/apps.d/whitelist-acl.conf
echo "${gre}The IP address ${blu}'$whitelist'${gre} was successfully whitelisted!${end}"
else
echo "${gre}IP '$whitelist' is already whitelisted!${end}"
Expand Down Expand Up @@ -256,7 +253,7 @@ location $sign$path {
}
# PathEnd" >> /etc/nginx/apps.d/$domain-nginx.conf

if [[ $(is_php $domain) == "false" && $(is_wp $domain $subfolder) == "false" ]]; then
if [[ $(is_php $domain $subfolder) == "false" && $(is_wp $domain $subfolder) == "false" ]]; then
sudo sed -i "/^# Path: $(echo $path | sed "s#/#\\\/#g")/,/^# PathEnd/{/try_files/d}" /etc/nginx/apps.d/$domain-nginx.conf
fi

Expand Down
1 change: 1 addition & 0 deletions plugins/site
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ elif [[ -n $mysql || ( -n $php && -n $domain ) ]]; then
echo "${red}[ERROR] Subfolder${blu} $subfolder ${red}already exists!${end}"
exit 1
elif [[ -n $subfolder ]]; then
[[ ! -f /etc/nginx/sites-available/$domain ]] && create_empty_site
php_subfolder
sudo mkdir -p /var/www/$domain/htdocs$subfolder
sudo chown -R www-data:www-data /var/www
Expand Down
2 changes: 2 additions & 0 deletions templates/nginx/common/acl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ auth_basic_user_file $authfile;

# Whitelist (Allowed IP Address List)
include apps.d/*-acl.conf;
allow 127.0.0.1;
deny all;

0 comments on commit a7e137e

Please sign in to comment.