Skip to content

Commit 08401fa

Browse files
committed
site
Full revision done!
1 parent 6463e7e commit 08401fa

File tree

3 files changed

+75
-42
lines changed

3 files changed

+75
-42
lines changed

lib/general

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,14 +1228,14 @@ is_subfolder() {
12281228
is_empty_root_site() {
12291229
# $1 = domain
12301230
if [[ -n $1 ]]; then
1231-
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
1231+
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
1232+
echo "false"
1233+
elif [[ -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
12321234
echo "full"
1233-
elif [[ -f /etc/nginx/sites-available/$1 && -n $(grep -E "include apps.d/${1}_.*.conf;" /etc/nginx/sites-available/$1) ]]; then
1235+
elif [[ -f /etc/nginx/sites-available/$1 && ( -n $(grep -E "include apps.d/${1}_.*.conf;" /etc/nginx/sites-available/$1) || -n $(sed -n -e '/WebinolyNginxServerStart/,$p' /etc/nginx/sites-available/$1 | grep -E "location /.* { try_files ")) ]]; then
12341236
echo "subfolders"
1235-
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
1236-
echo "false"
12371237
elif [[ -f /etc/nginx/sites-available/$1 ]]; then
1238-
echo "true"
1238+
echo "true"
12391239
else
12401240
echo "false"
12411241
fi
@@ -1330,7 +1330,7 @@ email_update() {
13301330

13311331
echo "${gre}Email address has been successfuly validated, updated and saved!"
13321332
else
1333-
echo "${red}Please enter a valid email address!"
1333+
echo "${red}Please, enter a valid email address!"
13341334
fi
13351335
echo "${end}"
13361336
}
@@ -1792,22 +1792,22 @@ config_fastcgi_cache() {
17921792

17931793

17941794
if [[ $cache_valid == true ]]; then
1795-
echo "${gre}"
1795+
echo "${blu}"
17961796
echo "**********************************************************************"
1797-
echo "************* Set Nginx Cache new time values **************"
1797+
echo "************* ${bol}Set Nginx Cache new time values${end}${blu} **************"
17981798
echo "***** Example: 30d = 30days | 3h = 3hours | 5m = 5minutes ******"
17991799
echo "**********************************************************************"
1800-
echo "${blu}"
1801-
echo "Nginx Cache Valid for Pages (HttpCode: 200) actual value is: $hitval"
1802-
read -p " Set new value: " hit
1800+
echo "${dim}"
1801+
echo "Nginx Cache Valid for Pages (HttpCode: 200) actual value is: $hitval ${end}"
1802+
read -p " ${blu}Set new value:${end} " hit
18031803
hit=${hit:-$hitval}
18041804
echo ""
1805-
echo "Purge Cache for inactive pages actual value is: $inaval"
1806-
read -p " Set new value: " ina
1805+
echo "${blu}${dim}Purge Cache for inactive pages actual value is: $inaval ${end}"
1806+
read -p " ${blu}Set new value: ${end}" ina
18071807
ina=${ina:-$inaval}
18081808
echo ""
1809-
echo "Nginx Cache Valid for Errors and Redirections (301 302 303 307 308 404 410 451) actual value is: $othval"
1810-
read -p " Set new value: " oth
1809+
echo "${blu}${dim}Nginx Cache Valid for Errors and Redirections (301 302 303 307 308 404 410 451) actual value is: $othval ${end}"
1810+
read -p " ${blu}Set new value: ${end}" oth
18111811
oth=${oth:-$othval}
18121812
echo ""
18131813
elif [[ $(echo "${cache_valid}" | cut -c-1) == "[" && $(echo "${cache_valid}" | rev | cut -c-1) == "]" ]]; then

lib/site-ssl

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,33 @@ site_ssl_on() {
9999
fi
100100

101101

102-
echo "${gre}"
103-
echo "*************************************************************************************************"
104-
echo "** Please, be careful with the number of intents or certificates you try to get. **"
105-
echo "** Let’s Encrypt provides rate limits to ensure fair usage by as many people as possible. **"
106-
echo "** **"
107-
echo "** If you are getting errors or having issues when trying to get a new certificate **"
108-
echo "** read about the Let's Encrypt rate limit - https://letsencrypt.org/docs/rate-limits/ **"
109-
echo "*************************************************************************************************"
102+
echo "${blu}"
103+
echo "**********************************************************************************************"
104+
echo "** ${bol}Please, be careful with the number of intents or certificates you try to get.${end}${blu} **"
105+
echo "** ${bol}Let’s Encrypt provides rate limits to ensure fair usage by as many people as possible.${end}${blu} **"
106+
echo "** **"
107+
echo "** If you are getting errors or having issues when trying to get a new certificate **"
108+
echo "** read about the Let's Encrypt rate limits - https://letsencrypt.org/docs/rate-limits/ **"
109+
echo "**********************************************************************************************"
110110
echo "${end}"
111-
[[ $subdomain == "false" ]] && echo "${blu}Please, be sure that${end} $domain ${blu}and${end} www.$domain ${blu}are both currently pointing (DNS) to this server. ${end}"
112-
[[ $subdomain == "true" ]] && echo "${blu}Please, be sure that the${end} $domain ${blu}subdomain is currently pointing (DNS) to this server. ${end}"
113-
echo "${blu}Firewall Settings: Port 80 (TCP) and port 443 (TCP and UDP) must be open (inbound and outbound). ${end}"
111+
[[ $subdomain == "false" ]] && echo "${blu}${dim}* Please, be sure that${end} $domain ${blu}${dim}and${end} www.$domain ${blu}${dim}are both currently pointing (DNS) to this server. ${end}"
112+
[[ $subdomain == "true" ]] && echo "${blu}${dim}* Please, be sure that the${end} $domain ${blu}${dim}subdomain is currently pointing (DNS) to this server. ${end}"
113+
echo "${blu}${dim}** Firewall Settings: Port 80 (TCP) and port 443 (TCP and UDP) must be open (inbound and outbound). ${end}"
114114

115115
# We need an email to notify each renew intent (cron)
116116
while [[ -z $cermail ]]
117117
do
118118
echo "${blu}"
119119
read -p "Please, enter an email to register your new certificate: ${end}" cermail
120120
email_update $cermail
121-
[[ $(conf_read mail) != $cermail ]] && cermail=""
121+
122+
[[ -z $(conf_read mail) ]] && unset cermail
123+
[[ -z $x ]] && local x=1 || local x=$((x+1))
124+
125+
if [[ $x -ge 3 && -z $(conf_read mail) ]]; then
126+
echo "${red}[ERROR] Please, enter a valid email address!${end}"
127+
exit 1
128+
fi
122129
done
123130

124131
# Create new certificate
@@ -272,7 +279,7 @@ site_ssl_off() {
272279
else
273280
echo "${blu}Select 'Y' to revoke and delete all the certificate files."
274281
echo "Select 'N' if you only want to deactivate this certificate momentary and you will activate it later again."
275-
echo "${gre}"
282+
echo "${blu}"
276283
echo "Do you want to delete and revoke this certificate [y/N]? "
277284
while read -r -n 1 -s answer; do
278285
answer=${answer:-n}

lib/sites

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ wp_cache_plugins() {
3232
sudo rm /var/www/$domain/htdocs/nginx-helper-plugin.zip
3333
echo ""
3434
echo "${gre} Nginx Helper Plugin has been installed!"
35-
echo " Please, activate this plugin for a better experience with FastCgi Cache."
36-
echo "${blu} ** IMPORTANT - Plugin Settings **"
35+
echo "${dim} Please, activate this plugin for a better experience with FastCgi Cache.${end}"
36+
echo "${blu} ** IMPORTANT - Plugin Settings **${dim}"
3737
echo "- Go to “Menu > Settings > Nginx Helper” The “Caching Method” should be set to “Nginx FastCgi Cache”."
3838
echo "- Support for purge/url method is a premium feature only included in NGINX Plus (not-free) and we recommend not to trust in solutions or tools that use third-party NGINX modules to offer this feature."
3939
echo "- The Purge Method should be set to “Delete local server cache file”."
@@ -53,8 +53,8 @@ wp_cache_plugins() {
5353
sudo rm /var/www/$domain/htdocs/redis-cache-plugin.zip
5454
echo ""
5555
echo "${gre} Redis Object Cache Plugin has been installed!"
56-
echo " Please, activate this plugin for a better experience with WordPress Object Cache."
57-
echo "${blu} ** IMPORTANT - Plugin Settings **"
56+
echo "${dim} Please, activate this plugin for a better experience with WordPress Object Cache.${end}"
57+
echo "${blu} ** IMPORTANT - Plugin Settings **${dim}"
5858
echo "- Go to “Menu > Settings > Redis” and be sure that Object Cache is enabled. "
5959
echo "${end}"
6060
else
@@ -207,10 +207,6 @@ wpinstall() {
207207

208208
if [[ $ext_login == "true" ]]; then
209209
echo "${blu}${dim}External DB Credentials found! (${dburl}:${dbport})${end}"
210-
elif [[ -n $retry && $retry -ge 3 ]]; then
211-
setupmysql="N"
212-
local db_error_flag="true"
213-
echo "${red}[ERROR] Database creation failed after 3 retries! ${blu}"
214210
elif [[ ( $dbhost == "localhost" && $(check_mysql_connection localhost) != "true" ) || ( $dbhost != "localhost" && $(check_mysql_connection $dburl $dbport $dburoot $dbproot -master-admin) != "true" ) ]]; then
215211
# Reset variables
216212
local dburl=""
@@ -219,8 +215,11 @@ wpinstall() {
219215
local dbproot=""
220216

221217
# Prevent infinite loops, just 3 intents!
222-
[[ -z $retry ]] && local retry=0
223-
local retry=$(($retry+1))
218+
[[ -z $retry1 ]] && local retry1=1 || local retry1=$(($retry1+1))
219+
if [[ $retry1 -ge 3 ]]; then
220+
local db_error_flag="true"
221+
break;
222+
fi
224223

225224
# While loop
226225
done="0"
@@ -269,6 +268,14 @@ wpinstall() {
269268

270269
if [[ $dbreuse != [yY] ]]; then
271270
echo ""
271+
272+
# Prevent infinite loops, just 3 intents!
273+
[[ -z $retry2 ]] && local retry2=1 || local retry2=$(($retry2+1))
274+
if [[ $retry2 -ge 3 ]]; then
275+
local db_error_flag="true"
276+
break 2;
277+
fi
278+
272279
read -p "Please enter a new DB_NAME for your Database: " newdbname
273280
[[ -z "$newdbname" ]] && newdbname="$dbname"
274281
dbname="$newdbname"
@@ -318,6 +325,14 @@ wpinstall() {
318325

319326
if [[ $dbureuse != [yY] ]]; then
320327
echo ""
328+
329+
# Prevent infinite loops, just 3 intents!
330+
[[ -z $retry3 ]] && local retry3=1 || local retry3=$(($retry3+1))
331+
if [[ $retry3 -ge 3 ]]; then
332+
local db_error_flag="true"
333+
break 2;
334+
fi
335+
321336
read -p "Please enter a new DB_User for your Database: " newdbuser
322337
[[ -z "$newdbuser" ]] && newdbuser=$dbuser
323338
dbuser=$newdbuser
@@ -458,6 +473,16 @@ _EOF_
458473
done
459474
fi
460475

476+
# BREAK the installation in case of 3 or more error/retries...
477+
if [[ $db_error_flag == "true" ]]; then
478+
echo "${red}[ERROR] Database configuration failed after 3 retries! ${end}"
479+
if [[ -n $domain ]]; then
480+
[[ -z $subfolder ]] && site $domain -delete=force || site $domain -delete=force -subfolder=$subfolder
481+
fi
482+
echo "${red}[ERROR] Site creation aborted! ${end}"
483+
exit 1
484+
fi
485+
461486
# Display data just to confirm the DB creation.
462487
if [[ $type == [45] && $db_error_flag != "true" ]]; then
463488
echo "${blu}"
@@ -610,6 +635,7 @@ deletesite() {
610635
# In case of custom cache
611636
if [[ -f /etc/nginx/conf.d/webinoly.conf ]]; then
612637
sudo sed -i "/^fastcgi_cache_path \/run\/nginx-cache\/$(echo $domain | sed 's/[^0-9A-Za-z]/_/g').*/d" /etc/nginx/conf.d/webinoly.conf
638+
sudo sed -i "/^proxy_cache_path \/run\/nginx-cache\/$(echo $domain | sed 's/[^0-9A-Za-z]/_/g').*/d" /etc/nginx/conf.d/webinoly.conf
613639
[[ -f /etc/nginx/conf.d/webinoly.conf && ( ! -s /etc/nginx/conf.d/webinoly.conf || -z $(cat -v /etc/nginx/conf.d/webinoly.conf | grep -m 1 '[^[:space:]]')) ]] && sudo rm /etc/nginx/conf.d/webinoly.conf
614640
fi
615641

@@ -683,7 +709,7 @@ deletesite_subfolder() {
683709
sudo sed -i "/# WebinolyNginxServerStart/,/# WebinolyNginxServerEnd/{\|location $subfolder/ |d}" /etc/nginx/sites-available/$domain
684710

685711
sudo rm -rf /var/www/$domain/htdocs$subfolder
686-
echo "${gre}Subfolder successfully removed!${end}"
712+
echo "${gre}Subfolder ${blu}${domain}${subfolder}${gre} successfully removed!${end}"
687713
}
688714

689715

@@ -1588,8 +1614,8 @@ wp_cache() {
15881614
[[ -n $subfolder ]] && sudo sed -i "/ apps.d\/$domain$subname-php.conf;/c \ include apps.d/$domain$subname-wpfc.conf;" /etc/nginx/sites-available/$domain
15891615
if [[ $(is_parked $domain) == "false" && ( ! -d /var/www/$domain/htdocs$subfolder/wp-content/plugins/nginx-helper || ! -d /var/www/$domain/htdocs$subfolder/wp-content/plugins/redis-cache ) ]]; then
15901616
if [[ -z $wp_cache_plugins ]]; then
1591-
echo "${gre}"
1592-
echo "We recommend Nginx Helper Plugin and Redis Object Cache Plugin as an easy way to manage FastCGI and Redis Cache on your WordPress site."
1617+
echo "${blu}${dim}"
1618+
echo "We recommend Nginx Helper Plugin and Redis Object Cache Plugin as an easy way to manage FastCGI and Redis Cache on your WordPress site.${end}"
15931619
echo "${blu}Do you want to install it now [Y/n]? ${end}"
15941620
while read -r -n 1 -s answer; do
15951621
answer=${answer:-y}
@@ -1954,7 +1980,7 @@ wp_replace_content() {
19541980

19551981
wp_conf_retrieve $domain false true $subfolder
19561982
if [[ $(is_wp_installed $domain $subfolder) != "true" ]]; then
1957-
echo "${red}[ERROR] WordPress is empty and still not configured in ${domain}${subfolder} site!${end}"
1983+
echo "${red}[ERROR] WordPress is empty and still not configured in ${blu}${domain}${subfolder}${red} site!${end}"
19581984
exit 1
19591985
fi
19601986

0 commit comments

Comments
 (0)