Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
- Certbot instructions updated.
- Empty blank site option included.
- Fixed issue when parked site is created and main site have cache enabled.
  • Loading branch information
QROkes committed Mar 24, 2021
1 parent 6f3b7d7 commit 66d365d
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 27 deletions.
26 changes: 14 additions & 12 deletions lib/general
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/install
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions lib/site-ssl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
}
Expand Down
27 changes: 21 additions & 6 deletions lib/sites
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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}"
Expand All @@ -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
Expand All @@ -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
}

Expand Down
6 changes: 4 additions & 2 deletions lib/webin
Original file line number Diff line number Diff line change
Expand Up @@ -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 {} \;
Expand Down
2 changes: 1 addition & 1 deletion plugins/site
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 66d365d

Please sign in to comment.