diff --git a/lib/general b/lib/general index 234c448..a981a9b 100644 --- a/lib/general +++ b/lib/general @@ -648,12 +648,14 @@ is_proxy() { [[ -n $2 ]] && local subn=$(echo $2 | sed "s/\//_/g") [[ -f /etc/nginx/sites-available/$1 && -n $(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$1 | grep -F " apps.d/$1$subn-proxy.conf;") ]] && echo "true" || echo "false" } - - is_dedicated_proxy() { - # $1 = domain, ($2 = subfolder)* - # Any site full-empty will be considered as "dedicated" - [[ -f /etc/nginx/sites-available/$1 && -z $(grep -F " common/locations.conf;" /etc/nginx/sites-available/$1) && -z $(grep -E "include common/headers-.*.conf;" /etc/nginx/sites-available/$1) ]] && echo "true" || echo "false" + # $1 = domain, $2 = subfolder + [[ -n $2 ]] && local subn=$(echo $2 | sed "s/\//_/g") + [[ -f /etc/nginx/sites-available/$1 && -z $(grep -F " common/locations.conf;" /etc/nginx/sites-available/$1) && -z $(grep -E "include common/headers-.*.conf;" /etc/nginx/sites-available/$1) && -n $(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$1 | grep -F " apps.d/$1$subn-proxy.conf;") ]] && echo "true" || echo "false" +} +is_dedicated_proxy_domain() { + # $1 = domain + [[ -f /etc/nginx/sites-available/$1 && -z $(grep -F " common/locations.conf;" /etc/nginx/sites-available/$1) && -z $(grep -E "include common/headers-.*.conf;" /etc/nginx/sites-available/$1) && -n $(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$1 | grep -E " apps.d/${1}.*-proxy.conf;") ]] && echo "true" || echo "false" } @@ -811,14 +813,12 @@ is_subfolder() { is_empty_root_site() { # $1 = domain if [[ -n $1 ]]; then - if [[ $(is_wp $1) == "true" || $(is_php $1) == "true" || $(is_proxy $1) == "true" || $(is_html $1) == "true" || $(is_parked $1) == "true" || $(is_forward $1) == "true" ]]; then + if [[ -f /etc/nginx/sites-available/$1 && -z $(grep -F " common/locations.conf;" /etc/nginx/sites-available/$1) && -z $(grep -E "include common/headers-.*.conf;" /etc/nginx/sites-available/$1) ]]; then + echo "full" + elif [[ $(is_wp $1) == "true" || $(is_php $1) == "true" || $(is_proxy $1) == "true" || $(is_html $1) == "true" || $(is_parked $1) == "true" || $(is_forward $1) == "true" ]]; then echo "false" elif [[ -f /etc/nginx/sites-available/$1 ]]; then - if [[ -z $(grep -F " common/locations.conf;" /etc/nginx/sites-available/$1) && -z $(grep -E "include common/headers-.*.conf;" /etc/nginx/sites-available/$1) ]]; then - echo "full" - else - echo "true" - fi + echo "true" else echo "false" fi @@ -869,12 +869,14 @@ site_type() { echo "PHP" elif [[ $(is_html $1) == "true" ]]; then echo "HTML" - elif [[ $(is_dedicated_proxy $1) == "true" ]]; then + elif [[ $(is_dedicated_proxy_domain $1) == "true" ]]; then echo "Dedicated Reverse Proxy" elif [[ $(is_proxy $1) == "true" ]]; then echo "Reverse Proxy" elif [[ $(is_forward $1) == "true" ]]; then echo "Forward" + elif [[ $(is_empty_root_site $1) == "full" ]]; then + echo "Empty Blank" elif [[ $(is_empty_root_site $1) == "true" ]]; then echo "Subfolders" else diff --git a/lib/install b/lib/install index 43b16f2..2c26fcc 100644 --- a/lib/install +++ b/lib/install @@ -301,6 +301,10 @@ nginx_optim() { sudo cp -R /opt/webinoly/templates/nginx/conf.d/* /etc/nginx/conf.d/ sudo cat /opt/webinoly/templates/nginx/nginx.conf > /etc/nginx/nginx.conf + # This files are backedup by server-reset (needs to be here to avoid nginx errors) + [[ -f /tmp/webinoly_blockips_backup ]] && sudo mv /tmp/webinoly_blockips_backup /etc/nginx/conf.d/blockips.conf + [[ -f /tmp/webinoly_backup ]] && sudo mv /tmp/webinoly_backup /etc/nginx/conf.d/webinoly.conf + # Remove it, then add it again to prevent multiple # for each server-reset sudo sed -i '/ SERVER_NAME /s/#//' /etc/nginx/fastcgi_params sudo sed -i '/ SERVER_NAME /s/^/#/' /etc/nginx/fastcgi_params diff --git a/lib/site-ssl b/lib/site-ssl index e93af04..52760db 100644 --- a/lib/site-ssl +++ b/lib/site-ssl @@ -121,20 +121,21 @@ site_ssl_on() { local manual="dns" fi - # Manual mode for Reverse Proxy sites + # Custom Root-Path mode for local Reverse Proxy sites if [[ ( ! -f /etc/letsencrypt/live/$domain/fullchain.pem || $ssl == "force-renewal" ) && -n $root_path ]]; then conf_write temp-path $root_path - sudo certbot certonly --manual --preferred-challenges=http --manual-auth-hook /opt/webinoly/lib/ex-ssl-authentication --manual-cleanup-hook /opt/webinoly/lib/ex-ssl-cleanup --manual-public-ip-logging-ok $domset $param + sudo certbot certonly --manual --preferred-challenges=http --manual-auth-hook /opt/webinoly/lib/ex-ssl-authentication --manual-cleanup-hook /opt/webinoly/lib/ex-ssl-cleanup $domset $param conf_delete temp-path - # Single cert + # Normal and manual certs elif [[ ! -f /etc/letsencrypt/live/$domain/fullchain.pem || $ssl == "force-renewal" ]]; then if [[ -n $manual ]]; then - sudo certbot certonly --manual --preferred-challenges=$manual --manual-public-ip-logging-ok $domset $param + sudo certbot certonly --manual --preferred-challenges=$manual $domset $param else sudo certbot certonly --webroot -w /var/www/$path/htdocs/ $domset $param fi + # Existing cert elif [[ -f /etc/letsencrypt/live/$domain/fullchain.pem ]]; then echo "${blu}Certificate for${end} $domain ${blu}already exist and found, wait while we configure your server to use it!${end}" fi @@ -167,13 +168,13 @@ site_ssl_on() { echo "${end}" exit 1 fi - [[ $(conf_read debug) == "true" ]] && echo "${red}Debug Mode is enabled, this SSL Cert is just for testing purpose and should not be used in production enviroments.${end}" + [[ $(conf_read debug) == "true" ]] && echo "${red}[WARNING] Debug Mode is enabled, this SSL Cert is just for testing purpose and should not be used in production enviroments.${end}" } ssl_revoke() { [[ $(conf_read debug) == "true" ]] && local param="--test-cert" || local param="" - sudo certbot revoke --cert-path /etc/letsencrypt/live/$domain/cert.pem --delete-after-revoke $param + sudo certbot revoke --cert-path /etc/letsencrypt/live/$domain/cert.pem --delete-after-revoke --non-interactive $param echo "${gre}" echo "SSL Cert for your site${blu} $domain ${gre}has been completely removed and revoked!${end}" } diff --git a/lib/sites b/lib/sites index be95343..3527168 100644 --- a/lib/sites +++ b/lib/sites @@ -1076,7 +1076,7 @@ parked_domain() { elif [[ $(is_parked $parked) == "true" ]]; then echo "${red}[ERROR] Parking a site using a parked site as main site is not allowed! ${end}" exit 1 - elif [[ $(is_empty_root_site $parked) == "true" ]]; then + elif [[ $(is_empty_root_site $parked) =~ ^(true|full)$ ]]; then echo "${red}[ERROR] Invalid main site!${end}" exit 1 fi @@ -1101,7 +1101,13 @@ parked_domain() { sudo sed -i "/root/c \ root /var/www/$parked/htdocs;" /etc/nginx/sites-available/$domain # Remove any conf file, this means we will not have subfolder support for parked sites, Should it be supported? - sudo sed -i "/WebinolyCustom/,/WebinolyCustomEnd/ {/include apps.d\/${domain}.*conf;/d}" /etc/nginx/sites-enabled/$domain + sudo sed -i "/WebinolyCustom/,/WebinolyCustomEnd/ {/include apps.d\/${domain}.*conf;/d}" /etc/nginx/sites-available/$domain + + # In case of WP cache, should be disabled in the new parked conf + sudo sed -i "/include common\/wpfc.conf;/c \ include common\/php.conf;" /etc/nginx/sites-available/$domain + sudo sed -i "/include apps.d\/${domain}-wpcache.conf;/c \ include common\/php.conf;" /etc/nginx/sites-available/$domain + [[ $(conf_read php-info) != "false" ]] && sudo sed -i "/include apps.d\/${domain}-phpcache.conf;/c \ include common\/phpx.conf;" /etc/nginx/sites-available/$domain + [[ $(conf_read php-info) == "false" ]] && sudo sed -i "/include apps.d\/${domain}-phpcache.conf;/c \ include common\/php.conf;" /etc/nginx/sites-available/$domain cusconl=$( grep -o "include /var/www/$domain/.*" /etc/nginx/sites-available/$domain | sed "s/$domain/$parked/" ) sed -i "/include \/var\/www\/$domain/c \ ${cusconl}" /etc/nginx/sites-available/$domain @@ -1155,17 +1161,23 @@ reverse_proxy() { if ! [[ -n $proxydata && $(is_url $proxydata) =~ ^(http|https|ip|true)$ ]]; then echo "${red}[ERROR] Please, enter a valid host and port!${end}" exit 1 + elif [[ -f /etc/nginx/sites-available/$domain && -z $subfolder && (($(is_empty_root_site $domain) == "full" && $(is_proxy $domain) != "false") || $(is_empty_root_site $domain) == "false") ]]; then + echo "${red}[ERROR] Site${blu} $domain ${red}already exists!${end}" + exit 1 elif [[ -f /etc/nginx/sites-available/$domain && -n $subfolder && $(is_subfolder $domain $subfolder) != "false" ]]; then echo "${red}[ERROR] Subfolder${blu} $subfolder ${red}already exists!${end}" exit 1 - elif [[ -n $dedicated_reverse_proxy && $(is_empty_root_site $domain) == "true" ]]; then + elif [[ -f /etc/nginx/sites-available/$domain && -n $dedicated_reverse_proxy && $(is_empty_root_site $domain) != "full" && $(is_dedicated_proxy_domain $domain) != "true" ]]; then echo "${red}[ERROR] Main site is not a Dedicated Reverse Proxy site!${end}" exit 1 + elif [[ $(is_empty_root_site $domain) == "full" && $(is_dedicated_proxy_domain $domain) == "false" ]]; then + echo "${red}[ERROR] This domain is currently set as Empty (blank), to create a site you need to add your own NGINX configuration. ${dim}(/var/www/example.com/*-nginx.conf)!${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" ]]; then + elif [[ -z $subfolder && $(is_empty_root_site $domain) == "full" && $(is_dedicated_proxy $domain) == "false" ]]; then echo "${gre}Site configuration found: Main site at${blu} $domain ${gre}root has been successfully set as Dedicated Reverse-Proxy!${end}" elif [[ -z $subfolder && $(is_empty_root_site $domain) == "true" ]]; then echo "${gre}Site configuration found: Main site at${blu} $domain ${gre}root has been successfully set as Reverse-Proxy!${end}" @@ -1179,7 +1191,7 @@ reverse_proxy() { 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 - if [[ -n $dedicated_reverse_proxy || $(is_dedicated_proxy $domain) == "true" ]]; then + if [[ -n $dedicated_reverse_proxy || $(is_dedicated_proxy_domain $domain) == "true" ]]; then sudo sed -i '/CacheStaticFiles/,/BasicLocEnd/{/.*/d}' /etc/nginx/apps.d/$domain$subname-proxy.conf echo "${blu}${bol}This site is set as Dedicated Reverse Proxy!${end}" fi @@ -1202,9 +1214,12 @@ reverse_proxy() { full_empty_not_allowed() { # Full Empty sites are only for Dedicated Reverse Proxy sites - if [[ $(is_dedicated_proxy $domain) == "true" ]]; then + if [[ $(is_dedicated_proxy_domain $domain) == "true" ]]; then echo "${red}[ERROR] This domain is currently set as Dedicated Reverse Proxy!${end}" exit 1 + elif [[ $(is_empty_root_site $domain) == "full" ]]; then + echo "${red}[ERROR] This domain is currently set as Empty (blank), to create a site you need to add your own NGINX configuration. ${dim}(/var/www/example.com/*-nginx.conf)!${end}" + exit 1 fi } diff --git a/lib/webin b/lib/webin index 063233e..3000ca4 100644 --- a/lib/webin +++ b/lib/webin @@ -757,14 +757,16 @@ webinoly_update() { server_reset() { # Regenerate NGINX conf files - if [[ $(conf_read nginx-optim) == "true" && $server_reset =~ ^(nginx|all)$ ]]; then + if [[ $(conf_read nginx-optim) == "true" && $server_reset =~ ^(nginx|all)$ ]]; then + # Backup files will be restored in nginx_optim function [[ -f /etc/nginx/conf.d/blockips.conf ]] && sudo cp -p /etc/nginx/conf.d/blockips.conf /tmp/webinoly_blockips_backup + [[ -f /etc/nginx/conf.d/webinoly.conf ]] && sudo cp -p /etc/nginx/conf.d/webinoly.conf /tmp/webinoly_backup + sudo sed -i '/WebinolyCustom/,/WebinolyCustomEnd/{/.*/d}' /etc/nginx/fastcgi_params sudo rm -rf /etc/nginx/common sudo rm -rf /etc/nginx/conf.d/* linux_purge nginx_optim - [[ -f /tmp/webinoly_blockips_backup ]] && sudo mv /tmp/webinoly_blockips_backup /etc/nginx/conf.d/blockips.conf # Fix permissions sudo find /var/www -type d -exec chmod 755 {} \; diff --git a/plugins/site b/plugins/site index 648cdd8..9409b76 100644 --- a/plugins/site +++ b/plugins/site @@ -154,7 +154,7 @@ elif [[ -n $mysql || ( -n $php && -n $domain ) ]]; then elif [[ -n $empty && -n $domain ]]; then full_empty_not_allowed echo "${blu}You've created an EMPTY site, which means that you need to add your own NGINX configuration. ${dim}(/var/www/example.com/*-nginx.conf)${end}" - create_empty_site + [[ $empty == "blank" ]] && create_empty_site -full || create_empty_site # Create HTML site