Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
Fixes after testing.
  • Loading branch information
QROkes committed Sep 30, 2020
1 parent d4b4083 commit 9d5bcc5
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 65 deletions.
81 changes: 48 additions & 33 deletions lib/bkp
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ bkp_local_db() {
fi

if [[ -n $wp ]]; then
wp_dbdata $wp # Here to not ask twice for external-db data
if [[ $(is_wp $wp $subfolder) != "true" ]]; then
echo "${red}[ERROR] Please, enter a valid WP site!${end}"
exit 1
elif [[ $(is_wp_installed $wp) != "true" ]]; then
echo "${red}[ERROR] Your WP site database is still empty!${end}"
exit 1
else
wp_dbdata $wp
local dbname=$wp_dbname
local dburl=$wp_dburl
local dbport=$wp_dbport
local uroot=$wp_uroot
local proot$wp_proot
local proot=$wp_proot
fi
else
if [[ -z $external_db ]]; then
Expand All @@ -75,7 +75,7 @@ bkp_local_db() {
exit 1
fi

local checkdbname=$(sudo mysqlshow -h "$dburl" -P "$dbport" -u"$dburoot" -p"$dbproot" | grep -ow $dbname)
local checkdbname=$(sudo mysqlshow -h "$dburl" -P "$dbport" -u"$uroot" -p"$proot" | grep -ow $dbname)
fi

if [[ $checkdbname != $dbname ]]; then
Expand Down Expand Up @@ -103,7 +103,7 @@ bkp_local_db() {
fi

[[ -z $filename ]] && local filename="webinoly-backup-db_${fn}_$(date +%F)-$(date +%T).sql"
if [[ $wp_dbhost == "localhost" && -z $dbhost ]]; then
if [[ $wp_dbhost == "localhost" || -z $external_db ]]; then
sudo mysqldump --user=admin --password=$ADMIN_PASS --single-transaction --lock-tables --quick --databases $dbname > $destination/$filename
else
sudo mysqldump -h "$dburl" -P "$dbport" -u"$uroot" -p"$proot" --single-transaction --lock-tables --quick --databases $dbname > $destination/$filename
Expand Down Expand Up @@ -225,7 +225,7 @@ bkp_s3_profile() {

wp_dbdata $add_db_pre false
if [[ $wp_dbhost != "localhost" && -z $(conf_read external-dbu) && -z $(conf_read external-dbp) ]]; then
echo "${red}[ERROR] Database host is not localhost!${end}"
echo "${red}[ERROR] Database host is not localhost!${dim} (External databases are supported with -external-db-save)${end}"
exit 1
fi

Expand Down Expand Up @@ -415,7 +415,11 @@ check_exported_conf() {
[[ -n $(conf_read_exported mail) ]] && sudo webinoly -email=$(conf_read_exported mail)
[[ -n $(conf_read_exported header-hsts) ]] && sudo webinoly -header-hsts=$(conf_read_exported header-hsts)
[[ -n $(conf_read_exported header-referrer) ]] && sudo webinoly -header-referrer=$(conf_read_exported header-referrer)
[[ -s /opt/webinoly/templates/source/csp_webinoly.data ]] && sudo webinoly -header-csp=reload

if tar -tvf $file --absolute-names | grep -oq "/opt/webinoly/templates/source/csp_webinoly.data"; then
tar -C / -xf $file /opt/webinoly/templates/source/csp_webinoly.data --absolute-names
sudo webinoly -header-csp=reload
fi

[[ -n $(conf_read_exported log-lines) ]] && conf_write log-lines $(conf_read_exported log-lines)
[[ -n $(conf_read_exported awsiamrole) ]] && conf_write awsiamrole $(conf_read_exported awsiamrole)
Expand All @@ -425,22 +429,6 @@ check_exported_conf() {
[[ -n $(conf_read_exported external-dbx) ]] && conf_write external-dbx $(conf_read_exported external-dbx)
[[ -n $(conf_read_exported external-dbu) ]] && conf_write external-dbu $(conf_read_exported external-dbu)
[[ -n $(conf_read_exported external-dbp) ]] && conf_write external-dbp $(conf_read_exported external-dbp)

if [[ $(conf_read_exported smtp) == "true" && -s /var/www/webinoly_backup_smtp ]]; then
local smtpdata=$(sudo sed -n 1p /var/www/webinoly_backup_smtp)
local main=$(echo $smtpdata | cut -d' ' -f 1 -s)
local host=$(echo $smtpdata | cut -d' ' -f 2 -s | cut -d':' -f 1 -s)
local user=$(echo $smtpdata | cut -d' ' -f 3 -s | cut -d':' -f 1 -s)
local pass=$(echo $smtpdata | cut -d' ' -f 3 -s | cut -d':' -f 2 -s)

sudo rm -rf /var/www/webinoly_backup_smtp

if [[ -n $host && -n $user && -n $pass && -n $main ]]; then
sudo webinoly -smtp=[$host,$user,$pass,$main]
else
echo "${red}[ERROR] SMTP Configuration recovery failed! ${end}"
fi
fi
}


Expand Down Expand Up @@ -547,19 +535,30 @@ import_site() {

# Remove old configurations
remove_nginx_default_server $domain
source /opt/webinoly/lib/site-ssl
[[ $(is_ssl $domain) == "true" ]] && revoke="off" && site_ssl_off > /dev/null 2>&1


if [[ $(conf_read php) != "true" && ( $(is_wp $domain) == "true" || $(is_php $domain) == "true" ) ]]; then
echo "${red}[WARNING] Your site may not work because PHP is not installed!${end}"
fi

if [[ -s /var/www/$domain/webinoly_backup_db && $(conf_read mysql) == "true" && -z $skip_db ]]; then
if [[ -s /var/www/$domain/webinoly_backup_db && $(conf_read mysql) == "true" && $(check_mysql_connection localhost) == "true" && -z $skip_db ]]; then
sudo webinoly -db-import -file=/var/www/$domain/webinoly_backup_db
sudo rm -rf /var/www/$domain/webinoly_backup_db
elif [[ -f /var/www/$domain/webinoly_backup_db && $(conf_read mysql) != "true" && -z $skip_db ]]; then

if [[ $overwrite != "on" ]]; then
wp_dbdata $domain
sudo mysql --connect-timeout=10 --user=admin -p$ADMIN_PASS <<_EOF_
CREATE USER '${wp_dbuser}'@'%' IDENTIFIED BY '${wp_dbpass}';
GRANT ALL PRIVILEGES ON ${wp_dbname}.* TO ${wp_dbuser}@${wp_dbhost} IDENTIFIED BY '${wp_dbpass}';
FLUSH PRIVILEGES;
_EOF_

fi

elif [[ -f /var/www/$domain/webinoly_backup_db && ( $(conf_read mysql) != "true" || $(check_mysql_connection localhost) != "true" ) && -z $skip_db ]]; then
echo "${red}[ERROR] Database backup found but can not be restored because MySQL is not installed!${end}"
exit 1
fi

echo "${gre}Webinoly Site Backup${blu} $domain ${gre}imported successfully!${end}"
Expand Down Expand Up @@ -610,21 +609,37 @@ import_server() {
sudo rm -rf /var/www/webinoly_backup_dball
elif [[ -s /var/www/webinoly_backup_dball && $(conf_read mysql) != "true" && -z $skip_db ]]; then
echo "${red}[ERROR] Database backup found but can not be restored because MySQL is not installed!${end}"
exit 1
fi

echo "${gre}Webinoly Full Server Backup imported successfully!${end}"
fi


# Default-Site and Tools Site Settings!
[[ -f /etc/nginx/sites-available/$(conf_read_exported tools-site) ]] && sudo webinoly -tools-site=$(conf_read_exported default-site)

if [[ -f /etc/nginx/sites-available/$(conf_read_exported default-site) ]]; then
remove_nginx_default_server $(conf_read_exported default-site)
sudo webinoly -default-site=$(conf_read_exported default-site)
# SMTP Configuration - should be here after sites are extracted and only if sites are imported.
if [[ $import == "full" && $(conf_read_exported smtp) == "true" && -s /var/www/webinoly_backup_smtp ]]; then
local smtpdata=$(sudo sed -n 1p /var/www/webinoly_backup_smtp)
local main=$(echo $smtpdata | cut -d' ' -f 1 -s)
local host=$(echo $smtpdata | cut -d' ' -f 2 -s | cut -d':' -f 1 -s)
local user=$(echo $smtpdata | cut -d' ' -f 3 -s | cut -d':' -f 1 -s)
local pass=$(echo $smtpdata | cut -d' ' -f 3 -s | cut -d':' -f 2 -s)
sudo rm -rf /var/www/webinoly_backup_smtp

if [[ -n $host && -n $user && -n $pass && -n $main ]]; then
sudo webinoly -smtp=[$host,$user,$pass,$main]
else
echo "${red}[ERROR] SMTP Configuration recovery failed! ${end}"
fi
fi

# Default-Site and Tools Site Settings! - should be here after sites are extracted and only if sites are imported.
if [[ $import =~ ^(stack|full)$ ]]; then
if [[ -f /etc/nginx/sites-available/$(conf_read_exported default-site) ]]; then
remove_nginx_default_server $(conf_read_exported default-site)
sudo webinoly -default-site=$(conf_read_exported default-site)
fi

[[ -f /etc/nginx/sites-available/$(conf_read_exported tools-site) ]] && sudo webinoly -tools-site=$(conf_read_exported default-site)
fi

sudo mv /opt/webinoly/webinoly.conf.exported /opt/webinoly/webinoly.conf.imported_$(date +%F)-$(date +%T)
}

Expand Down
27 changes: 26 additions & 1 deletion lib/general
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ wp_dbdata() {
wp_dbname=$( grep -F "DB_NAME" $wpconfpath | cut -f 4 -d "'" -s)
wp_dbuser=$( grep -F "DB_USER" $wpconfpath | cut -f 4 -d "'" -s)
wp_dbhost=$( grep -F "DB_HOST" $wpconfpath | cut -f 4 -d "'" -s)
wp_dbpass=$( grep -F "DB_PASSWORD" $wpconfpath | cut -f 4 -d "'" -s)
wp_dburl=$(echo "$wp_dbhost" | cut -f 1 -d ':')
wp_dbport=$(echo "$wp_dbhost" | cut -f 2 -d ':' -s)
wp_dbpref=$( grep -F "table_prefix" $wpconfpath | cut -f 2 -d "'" -s)
Expand Down Expand Up @@ -719,11 +720,35 @@ email_update() {
conf_write mail $mail
[[ ! -f /root/.forward ]] && sudo touch /root/.forward || sudo truncate -s 0 /root/.forward
sudo echo "$mail" >> /root/.forward
[[ -d /etc/letsencrypt/renewal ]] && sudo certbot update_account --email $mail
[[ -d /etc/letsencrypt/renewal ]] && sudo certbot update_account --email $mail --no-eff-email
echo "${gre}Email address has been successfuly validated and saved!"
else
echo "${red}Please enter a valid email address!"
fi
echo "${end}"
}


edit_wp_db_url() {
#Example: edit_wp_db_url example.com "http://${domain}${subfolder}"
wp_dbdata $1
if [[ -n $1 && -n $2 && $(is_wp $1 $subfolder) == "true" && $(is_wp_installed $1) == "true" ]]; then
if [[ $wp_dbhost == "localhost" && $(check_mysql_connection localhost) == "true" ]]; then
sudo mysql --connect-timeout=10 --user=admin -p$ADMIN_PASS <<_EOF_
USE $wp_dbname;
UPDATE ${wp_dbpref}options SET option_value='$2' WHERE option_name='home';
UPDATE ${wp_dbpref}options SET option_value='$2' WHERE option_name='siteurl';
FLUSH PRIVILEGES;
_EOF_

elif [[ $(check_mysql_connection $wp_dburl $wp_dbport $wp_uroot $wp_proot) == "true" ]]; then
sudo mysql --connect-timeout=10 -h "$wp_dburl" -P "$wp_dbport" -u"$wp_uroot" -p"$wp_proot" <<_EOF_
USE $wp_dbname;
UPDATE ${wp_dbpref}options SET option_value='$2' WHERE option_name='home';
UPDATE ${wp_dbpref}options SET option_value='$2' WHERE option_name='siteurl';
FLUSH PRIVILEGES;
_EOF_
fi
fi
}

1 change: 0 additions & 1 deletion lib/site-ssl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# This is a library for Site Manager Plugin
# Functions for SSL On/Off

source /opt/webinoly/lib/general

ssl_nginx() {
sudo sed -i '/listen 80/c \ listen 443 ssl http2;' /etc/nginx/sites-available/$domain
Expand Down
28 changes: 3 additions & 25 deletions lib/sites
Original file line number Diff line number Diff line change
Expand Up @@ -603,30 +603,6 @@ createsite() {
}


edit_wp_db_url() {
#Example: edit_wp_db_url example.com "http://${domain}${subfolder}"
wp_dbdata $1
if [[ -n $1 && -n $2 && $(is_wp $1 $subfolder) == "true" && $(is_wp_installed $1) == "true" ]]; then
if [[ $wp_dbhost == "localhost" && $(check_mysql_connection localhost) == "true" ]]; then
sudo mysql --connect-timeout=10 --user=admin -p$ADMIN_PASS <<_EOF_
USE $wp_dbname;
UPDATE ${wp_dbpref}options SET option_value='$2' WHERE option_name='home';
UPDATE ${wp_dbpref}options SET option_value='$2' WHERE option_name='siteurl';
FLUSH PRIVILEGES;
_EOF_

elif [[ $(check_mysql_connection $wp_dburl $wp_dbport $wp_uroot $wp_proot) == "true" ]]; then
sudo mysql --connect-timeout=10 -h "$wp_dburl" -P "$wp_dbport" -u"$wp_uroot" -p"$wp_proot" <<_EOF_
USE $wp_dbname;
UPDATE ${wp_dbpref}options SET option_value='$2' WHERE option_name='home';
UPDATE ${wp_dbpref}options SET option_value='$2' WHERE option_name='siteurl';
FLUSH PRIVILEGES;
_EOF_
fi
fi
}


force_redirect() {
if ! [[ $force_redirect =~ ^(www|root|off)$ ]]; then
echo "${red}[ERROR] Please, enter a valid argument!${end}"
Expand Down Expand Up @@ -1267,8 +1243,10 @@ clone_wp_site() {
local wpsub="/$(echo $appfile | cut -f 2- -d "_" -s | cut -f -1 -d "-" -s | sed "s/_/\//g")"
if [[ -n $wpsub && -f /var/www/$domain/htdocs$wpsub/wp-config.php ]]; then
echo "${gre}${dim}WordPress installed in a subfolder${blu} '${wpsub}' ${gre}was found, we will clone it too...${end}"
# Silenced because some times files are still not all copied and this commands reload nginx causing unexpected errors.
# At the end when all the files are copied everything is fine and nothing to worry!
sudo site $domain -subfolder=$wpsub -delete=keep-db > /dev/null 2>&1
sudo site $domain -clone-from=$clone_from -subfolder=$wpsub
sudo site $domain -clone-from=$clone_from -subfolder=$wpsub > /dev/null 2>&1
fi
fi
fi
Expand Down
12 changes: 7 additions & 5 deletions plugins/site
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# shopt is necessary for this kind !(html|22222) of patterns
shopt -s extglob

source /opt/webinoly/lib/general
source /opt/webinoly/lib/sites
check_for_parameters $@
api-events_update sis
Expand All @@ -33,8 +34,9 @@ if [[ -n $wp || -n $mysql ]]; then
exth=$(conf_read external-dbh)
fi

[[ $wp == "true" ]] && wp=[true,true,$exth,$dona,$dona,random,wp_,$(conf_read external-dbu),$(conf_read external-dbp)]
[[ $mysql == "true" ]] && mysql=[$exth,$dona,$dona,random,$(conf_read external-dbu),$(conf_read external-dbp)]
extp=$( echo $(conf_read external-dbp) | openssl enc -d -a -salt )
[[ $wp == "true" ]] && wp=[true,true,$exth,$dona,$dona,random,wp_,$(conf_read external-dbu),$extp]
[[ $mysql == "true" ]] && mysql=[$exth,$dona,$dona,random,$(conf_read external-dbu),$extp]
echo "${blu}External DB credentials found!${end}"
fi

Expand Down Expand Up @@ -108,9 +110,6 @@ elif [[ -n $subfolder && ( -n $cache || -n $yoast_sitemap || -n $multisite_conve
elif [[ -n $subfolder && -n $clone_from && ! -d /var/www/$clone_from/htdocs$subfolder ]]; then
echo "${red}[ERROR] Subfolder not found!${end}"
exit 1
elif [[ -n $subfolder && -z $clone_from && -n $env && ! -d /var/www/$domain/htdocs$subfolder ]]; then
echo "${red}[ERROR] Subfolder not found!${end}"
exit 1
else
subname=$(echo $subfolder | sed "s/\//_/g")
fi
Expand Down Expand Up @@ -258,6 +257,9 @@ elif [[ -n $proxy && -n $domain ]]; then
if [[ -n $subfolder && -f /etc/nginx/sites-available/$domain && $(is_proxy $domain) != "true" ]]; then
echo "${red}[ERROR] Reverse Proxy subfolders only can be installed when main site is reverse proxy! (We will fix this issue soon)${end}"
exit 1
elif [[ -z $subfolder && $(is_empty_root_site $domain) == "true" && -z $(grep -F "proxy.conf;" /etc/nginx/sites-available/$domain) ]]; then
echo "${red}[ERROR] Reverse-Proxy site incompatible with your current subfolders! (We will fix this issue soon)${end}"
exit 1
fi

reverse_proxy
Expand Down

0 comments on commit 9d5bcc5

Please sign in to comment.