wp host
WP host now has support for Unix sockets and localhost with custom port.
This commit is contained in:
parent
2c4cda5392
commit
25b3dfc4c0
5 changed files with 187 additions and 116 deletions
76
lib/bkp
76
lib/bkp
|
@ -87,19 +87,19 @@ bkp_local_db() {
|
|||
exit 1
|
||||
else
|
||||
wp_conf_retrieve $wp true true $subfolder
|
||||
[[ $wp_dbhost == "localhost" ]] && check_for_mysql
|
||||
[[ $wp_dbhost_host == "localhost" ]] && check_for_mysql
|
||||
[[ -n $subfolder ]] && local subname=$(echo $subfolder | sed "s/\//_/g")
|
||||
fi
|
||||
|
||||
if [[ $wp_dbhost != "localhost" && ( -z $extdb_user || -z $extdb_pass || -z $extdb_url || -z $extdb_port ) ]]; then
|
||||
if [[ $wp_dbhost_host != "localhost" && ( -z $extdb_user || -z $extdb_pass || -z $extdb_url || -z $extdb_port ) ]]; then
|
||||
echo "${red}[ERROR] Invalid data for External Database!${end}"
|
||||
exit 1
|
||||
|
||||
# Duplicate check: we need this only to prevent error in the next is_wp_installed
|
||||
elif [[ $wp_dbhost != "localhost" && $(check_mysql_connection $extdb_url $extdb_port $extdb_user $extdb_pass) != "true" ]]; then
|
||||
elif [[ $wp_dbhost_host != "localhost" && $(check_mysql_connection $extdb_url $extdb_port $extdb_user $extdb_pass) != "true" ]]; then
|
||||
echo "${red}[ERROR] External DB Connection failed!${end}"
|
||||
exit 1
|
||||
elif [[ $wp_dbhost == "localhost" && $(check_mysql_connection localhost) != "true" ]]; then
|
||||
elif [[ $wp_dbhost_host == "localhost" && $(check_mysql_connection localhost $mysql_param) != "true" ]]; then
|
||||
echo "${red}[ERROR] Localhost DB Connection failed!${end}"
|
||||
exit 1
|
||||
|
||||
|
@ -176,7 +176,7 @@ bkp_local_db() {
|
|||
[[ -z $filename ]] && local filename="webinoly-backup-db_${fn}_$(date +%F)-$(date +%T).sql"
|
||||
|
||||
|
||||
if [[ ( $wp_dbhost == "localhost" || -z $external_db ) && $(check_mysql_connection localhost) == "true" ]]; then
|
||||
if [[ ( $wp_dbhost_host == "localhost" || -z $external_db ) && $(check_mysql_connection localhost $mysql_param) == "true" ]]; then
|
||||
sudo mysqldump --user=admin --single-transaction --lock-tables --quick $db_name_list > $destination/$filename
|
||||
elif [[ $(check_mysql_connection $extdb_url $extdb_port $extdb_user $extdb_pass) == "true" ]]; then
|
||||
sudo mysqldump -h "$extdb_url" -P "$extdb_port" -u"$extdb_user" -p"$extdb_pass" --single-transaction --lock-tables --quick $db_name_list > $destination/$filename
|
||||
|
@ -739,35 +739,41 @@ export_site() {
|
|||
|
||||
# Include database backup for this site!
|
||||
if [[ -z $skip_db ]]; then
|
||||
if [[ $(conf_read mysql) == "true" && $(is_wp $siteto $subfolder) == "true" && $( wp_config_read $siteto DB_HOST $subfolder ) == "localhost" && $(is_wp_installed $siteto $subfolder) == "true" ]]; then
|
||||
# We use dbnames instead of domains because is easier to include subfolders
|
||||
if [[ -z $export_db_list ]]; then
|
||||
local export_db_list="$( wp_config_read $siteto DB_NAME $subfolder )"
|
||||
else
|
||||
local export_db_list="$export_db_list,$( wp_config_read $siteto DB_NAME $subfolder )"
|
||||
if [[ $(is_wp $siteto $subfolder) == "true" ]]; then
|
||||
wp_conf_retrieve $siteto false false $subfolder
|
||||
if [[ $(conf_read mysql) == "true" && $wp_dbhost_host == "localhost" && $(is_wp_installed $siteto $subfolder) == "true" && -n $wp_dbname ]]; then
|
||||
# We use dbnames instead of domains because is easier to include subfolders
|
||||
if [[ -z $export_db_list ]]; then
|
||||
local export_db_list="$wp_dbname"
|
||||
else
|
||||
local export_db_list="$export_db_list,$wp_dbname"
|
||||
fi
|
||||
echo "${blu}${dim}Database included: ${siteto}${subfolder} ${end}"
|
||||
elif [[ $wp_dbhost_host == "localhost" ]]; then
|
||||
echo "${red}${dim}Database not found or empty: ${siteto}${subfolder} ${end}"
|
||||
elif [[ -n $wp_dbhost_host && $wp_dbhost_host != "localhost" ]]; then
|
||||
echo "${red}${dim}External database not included: ${siteto}${subfolder} ${end}"
|
||||
fi
|
||||
echo "${blu}${dim}Database included: ${siteto}${subfolder} ${end}"
|
||||
elif [[ $(is_wp $siteto $subfolder) == "true" && $( wp_config_read $siteto DB_HOST $subfolder ) == "localhost" ]]; then
|
||||
echo "${red}${dim}Database not found or empty: ${siteto}${subfolder} ${end}"
|
||||
elif [[ $(is_wp $siteto $subfolder) == "true" && $( wp_config_read $siteto DB_HOST $subfolder ) != "localhost" ]]; then
|
||||
echo "${red}${dim}External database not included: ${siteto}${subfolder} ${end}"
|
||||
fi
|
||||
|
||||
# Check if site contains WP in subfolders
|
||||
for sit in "/etc/nginx/apps.d/${siteto}_"*-wpcommon.conf
|
||||
do
|
||||
local suby="/$(echo $sit | cut -f 2- -d "_" -s | cut -f -1 -d "-" -s | sed "s/_/\//g")"
|
||||
if [[ -n $suby && $(conf_read mysql) == "true" && -f /var/www/$siteto/htdocs$suby/wp-config.php && $( wp_config_read $siteto DB_HOST $suby ) == "localhost" && $(is_wp_installed $siteto $suby) == "true" ]]; then
|
||||
if [[ -z $export_db_list ]]; then
|
||||
local export_db_list="$( wp_config_read $siteto DB_NAME $suby )"
|
||||
else
|
||||
local export_db_list="$export_db_list,$( wp_config_read $siteto DB_NAME $suby )"
|
||||
if [[ $(is_wp $siteto $suby) == "true" ]]; then
|
||||
wp_conf_retrieve $siteto false false $suby
|
||||
if [[ -n $suby && $(conf_read mysql) == "true" && $wp_dbhost_host == "localhost" && $(is_wp_installed $siteto $suby) == "true" && -n $wp_dbname ]]; then
|
||||
if [[ -z $export_db_list ]]; then
|
||||
local export_db_list="$wp_dbname"
|
||||
else
|
||||
local export_db_list="$export_db_list,$wp_dbname"
|
||||
fi
|
||||
echo "${blu}${dim}Database included: ${siteto}${suby} ${end}"
|
||||
elif [[ -n $suby && $wp_dbhost_host == "localhost" ]]; then
|
||||
echo "${red}${dim}Database not found or empty: ${siteto}${suby} ${end}"
|
||||
elif [[ -n $suby && -n $wp_dbhost_host && $wp_dbhost_host != "localhost" ]]; then
|
||||
echo "${red}${dim}External database not included: ${siteto}${suby} ${end}"
|
||||
fi
|
||||
echo "${blu}${dim}Database included: ${siteto}${suby} ${end}"
|
||||
elif [[ -n $suby && -f /var/www/$siteto/htdocs$suby/wp-config.php && $( wp_config_read $siteto DB_HOST $suby ) == "localhost" ]]; then
|
||||
echo "${red}${dim}Database not found or empty: ${siteto}${suby} ${end}"
|
||||
elif [[ -n $suby && -f /var/www/$siteto/htdocs$suby/wp-config.php && $( wp_config_read $siteto DB_HOST $suby ) != "localhost" ]]; then
|
||||
echo "${red}${dim}External database not included: ${siteto}${suby} ${end}"
|
||||
fi
|
||||
local suby=""
|
||||
done
|
||||
|
@ -882,18 +888,17 @@ import_site() {
|
|||
# Database recovery - create users because they are not imported
|
||||
if [[ -n $db_create_users && $overwrite != "on" && $(is_wp $domain) == "true" ]]; then
|
||||
wp_conf_retrieve $domain true false
|
||||
|
||||
if [[ $wp_dbhost == "localhost" && -n $wp_dbname && -n $wp_dbuser && -n $wp_dbpass && -n $(sudo mysqlshow --user=admin | grep -ow $wp_dbname) ]]; then
|
||||
if [[ $wp_dbhost_host == "localhost" && -n $wp_dbname && -n $wp_dbuser && -n $wp_dbpass && -n $(sudo mysqlshow --user=admin "${mysql_params[@]}" | grep -ow $wp_dbname) ]]; then
|
||||
echo "${blu}${dim}Restoring database for${end}${dim} $domain ${blu}${dim}site!${end}"
|
||||
|
||||
# Check if user exists
|
||||
if [[ -z $(sudo mysql --connect-timeout=10 --user=admin -e "SELECT User FROM mysql.user;" | grep -ow $wp_dbuser) ]]; then
|
||||
sudo mysql --connect-timeout=10 --user=admin <<_EOF_
|
||||
if [[ -z $(sudo mysql --connect-timeout=10 --user=admin -e "SELECT User FROM mysql.user;" "${mysql_params[@]}" | grep -ow $wp_dbuser) ]]; then
|
||||
sudo mysql --connect-timeout=10 --user=admin "${mysql_params[@]}" <<_EOF_
|
||||
CREATE USER '${wp_dbuser}'@'localhost' IDENTIFIED BY '${wp_dbpass}';
|
||||
GRANT $(db_user_role) on ${wp_dbname}.* to '${wp_dbuser}'@'localhost';
|
||||
FLUSH PRIVILEGES;
|
||||
_EOF_
|
||||
elif [[ $(check_mysql_connection localhost $wp_dbuser $wp_dbpass $wp_dbname) != "true" ]]; then
|
||||
elif [[ $(check_mysql_connection localhost $wp_dbuser $wp_dbpass $wp_dbname $mysql_param) != "true" ]]; then
|
||||
echo "${red}${dim}[ERROR] Database cannot be restored, seems like a user with the same name already exists.${end}"
|
||||
else
|
||||
echo "${blu}${dim}DB user already exists and a successful connection can be established, so we will use it.${end}"
|
||||
|
@ -908,18 +913,17 @@ _EOF_
|
|||
local suby="/$(echo $sit | cut -f 2- -d "_" -s | cut -f -1 -d "-" -s | sed "s/_/\//g")"
|
||||
if [[ -n $suby && -f /var/www/$domain/htdocs$suby/wp-config.php ]]; then
|
||||
wp_conf_retrieve $domain true false $suby
|
||||
|
||||
if [[ $wp_dbhost == "localhost" && -n $wp_dbname && -n $wp_dbuser && -n $wp_dbpass && -n $(sudo mysqlshow --user=admin | grep -ow $wp_dbname) ]]; then
|
||||
if [[ $wp_dbhost_host == "localhost" && -n $wp_dbname && -n $wp_dbuser && -n $wp_dbpass && -n $(sudo mysqlshow --user=admin "${mysql_params[@]}" | grep -ow $wp_dbname) ]]; then
|
||||
echo "${blu}${dim}Restoring database for${end}${dim} ${domain}${suby} ${blu}${dim}site!${end}"
|
||||
|
||||
# Check if user exists
|
||||
if [[ -z $(sudo mysql --connect-timeout=10 --user=admin -e "SELECT User FROM mysql.user;" | grep -ow $wp_dbuser) ]]; then
|
||||
sudo mysql --connect-timeout=10 --user=admin <<_EOF_
|
||||
if [[ -z $(sudo mysql --connect-timeout=10 --user=admin -e "SELECT User FROM mysql.user;" "${mysql_params[@]}" | grep -ow $wp_dbuser) ]]; then
|
||||
sudo mysql --connect-timeout=10 --user=admin "${mysql_params[@]}" <<_EOF_
|
||||
CREATE USER '${wp_dbuser}'@'localhost' IDENTIFIED BY '${wp_dbpass}';
|
||||
GRANT $(db_user_role) on ${wp_dbname}.* to '${wp_dbuser}'@'localhost';
|
||||
FLUSH PRIVILEGES;
|
||||
_EOF_
|
||||
elif [[ $(check_mysql_connection localhost $wp_dbuser $wp_dbpass $wp_dbname) != "true" ]]; then
|
||||
elif [[ $(check_mysql_connection localhost $wp_dbuser $wp_dbpass $wp_dbname $mysql_param) != "true" ]]; then
|
||||
echo "${red}${dim}[ERROR] Database cannot be restored, seems like a user with the same name already exists.${end}"
|
||||
else
|
||||
echo "${blu}${dim}DB user already exists and a successful connection can be established, so we will use it.${end}"
|
||||
|
|
170
lib/general
170
lib/general
|
@ -324,45 +324,72 @@ check_for_mysql_client() {
|
|||
|
||||
|
||||
check_mysql_connection() {
|
||||
# Examples for admin connection:
|
||||
# Localhost: $(check_mysql_connection localhost)
|
||||
# Unix socket: $(check_mysql_connection localhost /var/run/mysqld/mysqld.sock)
|
||||
# Custom port: $(check_mysql_connection localhost 3307)
|
||||
# External DB: $(check_mysql_connection $dburl $dbport $dburoot $dbproot)
|
||||
|
||||
# Examples for especific User connection:
|
||||
# Localhost: $(check_mysql_connection localhost $wp_dbuser $wp_dbpass)
|
||||
# Unix socket: $(check_mysql_connection localhost $wp_dbuser $wp_dbpass /var/run/mysqld/mysqld.sock)
|
||||
# Custom port: $(check_mysql_connection localhost $wp_dbuser $wp_dbpass 3307)
|
||||
# External DB: $(check_mysql_connection $extdb_url $extdb_port $wp_dbuser $wp_dbpass)
|
||||
|
||||
# Examples for especific DBname/User connection:
|
||||
# Note: Error message is not displayed!
|
||||
# Localhost: $(check_mysql_connection localhost $wp_dbuser $wp_dbpass $wp_dbname)
|
||||
# Unix socket: $(check_mysql_connection localhost $wp_dbuser $wp_dbpass $wp_dbname /var/run/mysqld/mysqld.sock)
|
||||
# Custom port: $(check_mysql_connection localhost $wp_dbuser $wp_dbpass $wp_dbname 3307)
|
||||
# External DB: $(check_mysql_connection $extdb_url $extdb_port $wp_dbuser $wp_dbpass $wp_dbname)
|
||||
|
||||
local query="quit"
|
||||
|
||||
if [[ -n $1 && ${1,,} != "localhost" && -n $2 && -n $3 && -n $4 ]]; then
|
||||
local error_display="true"
|
||||
|
||||
if [[ -n $1 && ${1,,} != "localhost" && $(is_url $1) =~ ^(http|https|true|http\+ip|https\+ip|ip)$ && -n $2 && -n $3 && -n $4 ]]; then
|
||||
check_for_mysql_client
|
||||
[[ -n $5 ]] && local query="use $5"
|
||||
sudo mysql --connect-timeout=10 -h "$1" -P "$2" -u"$3" -p"$4" -e "$query"
|
||||
if [[ $? != "0" ]]; then
|
||||
echo "${red}============================================" >&2
|
||||
echo " [Error] Database conection failed." >&2
|
||||
echo "============================================${end}" >&2
|
||||
echo "" >&2
|
||||
echo "false"
|
||||
else
|
||||
echo "true"
|
||||
if [[ -n $5 ]]; then
|
||||
local query="use $5"
|
||||
local error_display="false"
|
||||
fi
|
||||
sudo mysql --connect-timeout=10 -h "$1" -P "$2" -u"$3" -p"$4" -e "$query" 2>/dev/null
|
||||
[[ $? != "0" ]] && local out="false"
|
||||
elif [[ ${1,,} == "localhost" && $(conf_read mysql) == "true" ]]; then
|
||||
# In case of custom DB user
|
||||
if [[ -n $2 && -n $3 ]]; then
|
||||
[[ -n $4 ]] && local query="use $4"
|
||||
sudo mysql --connect-timeout=10 --user=$2 -p$3 -e "$query" 2>/dev/null
|
||||
[[ $? != "0" ]] && echo "false" || echo "true"
|
||||
else
|
||||
sudo mysql --connect-timeout=10 --user=admin -e "$query"
|
||||
if [[ $? != "0" ]]; then
|
||||
echo "${red}============================================" >&2
|
||||
echo " [Error] Database conection failed." >&2
|
||||
echo "============================================${end}" >&2
|
||||
echo "" >&2
|
||||
echo "false"
|
||||
else
|
||||
echo "true"
|
||||
if [[ -S $4 ]]; then
|
||||
local mysql_params="-S${4}"
|
||||
elif [[ $4 =~ ^[0-9]+$ && $4 -ge 0 && $4 -le 65535 ]]; then
|
||||
local mysql_params=(-P${4} --protocol=TCP)
|
||||
elif [[ -n $4 ]]; then
|
||||
local query="use $4"
|
||||
[[ -S $5 ]] && local mysql_params="-S${5}"
|
||||
[[ $5 =~ ^[0-9]+$ && $5 -ge 0 && $5 -le 65535 ]] && local mysql_params=(-P${5} --protocol=TCP)
|
||||
fi
|
||||
# We need the protocol socket fixed to prevent warnings when custom port is used.
|
||||
sudo mysql --connect-timeout=10 --user=$2 -p$3 -e "$query" "${mysql_params[@]}" 2>/dev/null
|
||||
[[ $? != "0" ]] && local out="false"
|
||||
local error_display="false"
|
||||
else
|
||||
# In case of Unix socket or localhost with custom port
|
||||
[[ -S $2 ]] && local mysql_params="-S${2}"
|
||||
[[ $2 =~ ^[0-9]+$ && $2 -ge 0 && $2 -le 65535 ]] && local mysql_params=(-P${2} --protocol=TCP)
|
||||
sudo mysql --connect-timeout=10 --user=admin -e "$query" "${mysql_params[@]}" 2>/dev/null
|
||||
[[ $? != "0" ]] && local out="false"
|
||||
fi
|
||||
else
|
||||
local out="false"
|
||||
fi
|
||||
|
||||
if [[ $out == "false" && $error_display != "false" ]]; then
|
||||
echo "${red}============================================" >&2
|
||||
echo " [Error] Database conection failed." >&2
|
||||
echo "============================================${end}" >&2
|
||||
echo "" >&2
|
||||
echo "false"
|
||||
elif [[ $out == "false" ]]; then
|
||||
echo "false"
|
||||
else
|
||||
echo "true"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -487,6 +514,22 @@ wp_conf_retrieve() {
|
|||
# $3 set to false if you want to disable WP Domain Mapping check (wp_pref will be for the main site when disabled, wp_ instead of wp_3_).
|
||||
# $4 is subfolder
|
||||
|
||||
# Prevent unwanted values when called multiple times
|
||||
unset wp_config
|
||||
unset wp_dbname
|
||||
unset wp_dbuser
|
||||
unset wp_dbhost
|
||||
unset wp_dbpass
|
||||
unset wp_dbpref
|
||||
unset wp_dbhost_host
|
||||
unset wp_dbhost_port
|
||||
unset wp_dbhost_socket
|
||||
unset wp_dbpref_main
|
||||
unset wp_blogid
|
||||
unset mysql_params
|
||||
unset mysql_param
|
||||
|
||||
|
||||
wp_config=$(wp_config_path $1 $4)
|
||||
# Just in case: We should always check is_wp before calling this function
|
||||
# The best error message is the one that never shows up! :)
|
||||
|
@ -500,19 +543,40 @@ wp_conf_retrieve() {
|
|||
wp_dbhost=$( wp_config_read $1 DB_HOST $4 )
|
||||
wp_dbpass=$( wp_config_read $1 DB_PASSWORD $4 )
|
||||
wp_dbpref=$( grep -F "table_prefix" $wp_config | cut -f 2 -d "'" -s)
|
||||
wp_extdb_url=$(echo "$wp_dbhost" | cut -f 1 -d ':')
|
||||
wp_extdb_port=$(echo "$wp_dbhost" | cut -f 2 -d ':' -s)
|
||||
|
||||
# wp_dbhost - Always contains the complete string
|
||||
# wp_dbhost_host - Only the host part
|
||||
# wp_dbhost_port - Only the port part (default: 3306)
|
||||
# wp_dbhost_socket - Only the socket path if exist (default: empty)
|
||||
|
||||
# Example: localhost:3307 (host: localhost, port:3307)
|
||||
# Example: localhost:/var/run/mysqld/mysqld.sock (host: localhost, socket:/var/run/mysqld/mysqld.sock)
|
||||
# Example: mysql.example.com:3306 (host: mysql.example.com, port:3307)
|
||||
|
||||
wp_dbhost_host=$(echo "$wp_dbhost" | cut -f 1 -d ':')
|
||||
local host_pars=$(echo "$wp_dbhost" | cut -f 2 -d ':' -s)
|
||||
if [[ $host_pars =~ ^[0-9]+$ && $host_pars -ge 0 && $host_pars -le 65535 ]]; then
|
||||
wp_dbhost_port=$host_pars
|
||||
mysql_params=(-P${wp_dbhost_port} --protocol=TCP) # Array because it fails to split the args in MySQL http://mywiki.wooledge.org/BashFAQ/050
|
||||
mysql_param="$wp_dbhost_port"
|
||||
elif [[ -S $host_pars ]]; then
|
||||
wp_dbhost_socket=$host_pars
|
||||
mysql_params="-S${wp_dbhost_socket}"
|
||||
mysql_param="$wp_dbhost_socket"
|
||||
else
|
||||
wp_dbhost_host=$wp_dbhost
|
||||
fi
|
||||
|
||||
wp_dbpref_main=${wp_dbpref} # In case of domain mapping this variable always remains with the main site info
|
||||
|
||||
[[ ${wp_dbhost,,} == "localhost" ]] && wp_dbhost=${wp_dbhost,,}
|
||||
[[ -z $wp_extdb_port ]] && wp_extdb_port="3306"
|
||||
#[[ -z $wp_dbhost_port ]] && wp_dbhost_port="3306"
|
||||
|
||||
|
||||
if [[ $2 != "false" ]]; then
|
||||
if [[ -z $external_db && -n $wp_dbhost && $wp_dbhost != "localhost" && $wp_dbhost == "$(conf_read external-dbh):$(conf_read external-dbx)" ]]; then
|
||||
if [[ $2 != "false" && $wp_dbhost_host != "localhost" && -z $wp_dbhost_socket && $(is_url $wp_dbhost) =~ ^(http|https|true|http\+ip|https\+ip|ip)$ ]]; then
|
||||
if [[ -z $external_db && -n $(conf_read external-dbh) && -n $(conf_read external-dbx) && $wp_dbhost == "$(conf_read external-dbh):$(conf_read external-dbx)" ]]; then
|
||||
check_external_db_saved
|
||||
elif [[ -z $external_db && -n $wp_dbhost && $wp_dbhost != "localhost" && -n $(conf_read external-dbh) && $wp_dbhost != "$(conf_read external-dbh):$(conf_read external-dbx)" ]]; then
|
||||
elif [[ -z $external_db && -n $(conf_read external-dbh) ]]; then
|
||||
echo "${dim}[INFO] External Database saved credentials found, but we cannot use it because not the same host!${end}" >&2
|
||||
fi
|
||||
|
||||
|
@ -527,14 +591,14 @@ wp_conf_retrieve() {
|
|||
unset extdb_port
|
||||
fi
|
||||
fi
|
||||
if [[ -z $external_db && -n $wp_dbhost && $wp_dbhost != "localhost" ]]; then
|
||||
if [[ -z $external_db ]]; then
|
||||
echo "" >&2
|
||||
echo "${gre}External DB${blu} '${wp_dbhost}' ${gre}found in:${blu}${dim} ${1}${4} ${end}" >&2
|
||||
read -p "${blu}External DB username: ${end}" extdb_user
|
||||
read -p "${blu}External DB password: ${end}" extdb_pass
|
||||
extdb_host=$wp_dbhost
|
||||
extdb_url=$wp_extdb_url
|
||||
extdb_port=$wp_extdb_port
|
||||
extdb_url=$wp_dbhost_host
|
||||
extdb_port=$wp_dbhost_port
|
||||
external_db="[${extdb_user},${extdb_pass},${extdb_host}]"
|
||||
fi
|
||||
fi
|
||||
|
@ -552,9 +616,8 @@ wp_conf_retrieve() {
|
|||
|
||||
if [[ $(is_wp_multisite $maindom $4) =~ ^(subdomain|subdirectory)$ ]]; then
|
||||
local dbq="USE $wp_dbname; SELECT blog_id FROM ${wp_dbpref}blogs WHERE domain='$1' OR domain='www.$1';"
|
||||
|
||||
if [[ $wp_dbhost == "localhost" && $(check_mysql_connection localhost) == "true" ]]; then
|
||||
local bid=$(sudo mysql --connect-timeout=10 --user=admin -e "$dbq")
|
||||
if [[ $wp_dbhost == "localhost" && $(check_mysql_connection localhost $mysql_param) == "true" ]]; then
|
||||
local bid=$(sudo mysql --connect-timeout=10 --user=admin -e "$dbq" "${mysql_params[@]}")
|
||||
elif [[ $(check_mysql_connection $extdb_url $extdb_port $extdb_user $extdb_pass) == "true" ]]; then
|
||||
local bid=$(sudo mysql --connect-timeout=10 -h "$extdb_url" -P "$extdb_port" -u"$extdb_user" -p"$extdb_pass" -e "$dbq")
|
||||
fi
|
||||
|
@ -935,13 +998,13 @@ is_cache() {
|
|||
is_wp_multisite() {
|
||||
if [[ $(is_wp $1 $2) == "true" ]]; then
|
||||
wp_conf_retrieve $1 true false $2 # 3th parameter should always be 'false' to prevent an infinite loop!
|
||||
if [[ -n $wp_dbhost && -n $wp_dbname && -n $wp_dbpref ]]; then
|
||||
if [[ -n $wp_dbhost_host && -n $wp_dbname && -n $wp_dbpref ]]; then
|
||||
local dbsetup="SELECT * FROM information_schema.tables WHERE table_schema = '$wp_dbname' AND table_name = '${wp_dbpref}sitemeta' LIMIT 1;"
|
||||
local dbsetuc="USE $wp_dbname; SELECT meta_value FROM ${wp_dbpref}sitemeta where meta_key='subdomain_install';"
|
||||
|
||||
if [[ $wp_dbhost == "localhost" && $(check_mysql_connection localhost) == "true" ]]; then
|
||||
wpmu=$(sudo mysql --connect-timeout=10 --user=admin -e "$dbsetup")
|
||||
[[ -n $wpmu ]] && mutype=$(sudo mysql --connect-timeout=10 --user=admin -e "$dbsetuc")
|
||||
if [[ $wp_dbhost_host == "localhost" && $(check_mysql_connection localhost $mysql_param) == "true" ]]; then
|
||||
wpmu=$(sudo mysql --connect-timeout=10 --user=admin -e "$dbsetup" "${mysql_params[@]}")
|
||||
[[ -n $wpmu ]] && mutype=$(sudo mysql --connect-timeout=10 --user=admin -e "$dbsetuc" "${mysql_params[@]}")
|
||||
elif [[ $(check_mysql_connection $extdb_url $extdb_port $extdb_user $extdb_pass) == "true" ]]; then
|
||||
wpmu=$(sudo mysql --connect-timeout=10 -h "$extdb_url" -P "$extdb_port" -u"$extdb_user" -p"$extdb_pass" -e "$dbsetup")
|
||||
[[ -n $wpmu ]] && mutype=$(sudo mysql --connect-timeout=10 -h "$extdb_url" -P "$extdb_port" -u"$extdb_user" -p"$extdb_pass" -e "$dbsetuc")
|
||||
|
@ -975,11 +1038,11 @@ is_wp_installed() {
|
|||
# but that makes no-sense because even if it's not mapped, it will return the main site data
|
||||
# Until now, we don't need a "is_domain_mapped" function, maybe we can change "is_wp_installed" to only be true for main domain sites, not parked (if it's not mapped). This can change in the future!!!
|
||||
|
||||
if [[ -n $wp_dbhost && -n $wp_dbname && -n $wp_dbpref ]]; then
|
||||
if [[ -n $wp_dbhost_host && -n $wp_dbname && -n $wp_dbpref ]]; then
|
||||
local dbsetup="SELECT * FROM information_schema.tables WHERE table_schema = '$wp_dbname' AND table_name = '${wp_dbpref}options' LIMIT 1;"
|
||||
|
||||
if [[ $wp_dbhost == "localhost" && $(check_mysql_connection localhost) == "true" ]]; then
|
||||
[[ -n $(sudo mysql --connect-timeout=10 --user=admin -e "$dbsetup") ]] && echo "true" || echo "false"
|
||||
if [[ $wp_dbhost_host == "localhost" && $(check_mysql_connection localhost $mysql_param) == "true" ]]; then
|
||||
[[ -n $(sudo mysql --connect-timeout=10 --user=admin -e "$dbsetup" "${mysql_params[@]}") ]] && echo "true" || echo "false"
|
||||
elif [[ $(check_mysql_connection $extdb_url $extdb_port $extdb_user $extdb_pass) == "true" ]]; then
|
||||
[[ -n $(sudo mysql --connect-timeout=10 -h "$extdb_url" -P "$extdb_port" -u"$extdb_user" -p"$extdb_pass" -e "$dbsetup") ]] && echo "true" || echo "false"
|
||||
else
|
||||
|
@ -1169,9 +1232,9 @@ edit_wp_db_url_multisite() {
|
|||
local wp_blogid=$3
|
||||
local dbsetup="SELECT * FROM information_schema.tables WHERE table_schema = '$wp_dbname' AND table_name = '${wp_dbpref}options' LIMIT 1;"
|
||||
|
||||
if [[ $wp_dbhost == "localhost" && -n $(sudo mysql --connect-timeout=10 --user=admin -e "$dbsetup") ]]; then
|
||||
if [[ $wp_dbhost_host == "localhost" && -n $(sudo mysql --connect-timeout=10 --user=admin -e "$dbsetup" "${mysql_params[@]}") ]]; then
|
||||
echo "${blu}${dim}WordPress blog ID (${wp_dbpref}) found and validated in a WP Multisite Network!${end}" >&2
|
||||
elif [[ $wp_dbhost != "localhost" && -n $(sudo mysql --connect-timeout=10 -h "$extdb_url" -P "$extdb_port" -u"$extdb_user" -p"$extdb_pass" -e "$dbsetup") ]]; then
|
||||
elif [[ $wp_dbhost_host != "localhost" && -n $(sudo mysql --connect-timeout=10 -h "$extdb_url" -P "$extdb_port" -u"$extdb_user" -p"$extdb_pass" -e "$dbsetup") ]]; then
|
||||
echo "${blu}${dim}WordPress blog ID (${wp_dbpref}) found and validated in a WP Multisite Network!${end}" >&2
|
||||
else
|
||||
echo "${red}${dim}[ERROR] WordPress blog ID (${wp_dbpref}) not found!${end}" >&2
|
||||
|
@ -1180,9 +1243,9 @@ edit_wp_db_url_multisite() {
|
|||
fi
|
||||
fi
|
||||
|
||||
if [[ -n $wp_dbhost && -n $wp_dbname && -n $wp_dbpref_main && -n $wp_blogid ]]; then
|
||||
if [[ $wp_dbhost == "localhost" && $(check_mysql_connection localhost) == "true" ]]; then
|
||||
sudo mysql --connect-timeout=10 --user=admin <<_EOF_
|
||||
if [[ -n $wp_dbhost_host && -n $wp_dbname && -n $wp_dbpref_main && -n $wp_blogid ]]; then
|
||||
if [[ $wp_dbhost_host == "localhost" && $(check_mysql_connection localhost $mysql_param) == "true" ]]; then
|
||||
sudo mysql --connect-timeout=10 --user=admin "${mysql_params[@]}" <<_EOF_
|
||||
USE $wp_dbname;
|
||||
UPDATE ${wp_dbpref_main}blogs SET domain='$2' WHERE blog_id='${wp_blogid}';
|
||||
UPDATE ${wp_dbpref_main}blogs SET path='/' WHERE blog_id='${wp_blogid}';
|
||||
|
@ -1214,9 +1277,10 @@ edit_wp_db_url() {
|
|||
|
||||
if [[ -n $1 && -n $2 && $(is_wp_installed $1 $3) == "true" ]]; then
|
||||
wp_conf_retrieve $1 true true $3
|
||||
if [[ -n $wp_dbhost && -n $wp_dbname && -n $wp_dbpref ]]; then
|
||||
if [[ $wp_dbhost == "localhost" && $(check_mysql_connection localhost) == "true" ]]; then
|
||||
sudo mysql --connect-timeout=10 --user=admin <<_EOF_
|
||||
|
||||
if [[ -n $wp_dbhost_host && -n $wp_dbname && -n $wp_dbpref ]]; then
|
||||
if [[ $wp_dbhost_host == "localhost" && $(check_mysql_connection localhost $mysql_param) == "true" ]]; then
|
||||
sudo mysql --connect-timeout=10 --user=admin "${mysql_params[@]}" <<_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';
|
||||
|
|
37
lib/sites
37
lib/sites
|
@ -490,17 +490,17 @@ db_delete() {
|
|||
wp_conf_retrieve $1 true false $2
|
||||
[[ -z $wp_config ]] && return
|
||||
|
||||
if [[ -z $wp_dbhost || -z $wp_dbname || -z $wp_dbuser ]]; then
|
||||
if [[ -z $wp_dbhost_host || -z $wp_dbname || -z $wp_dbuser ]]; then
|
||||
echo "${red}[ERROR] Database${blu} ${1}${2} ${red}cannot be deleted! ${dim}(WP configuration corrupted)${end}"
|
||||
return
|
||||
elif [[ ( $wp_dbhost == "localhost" && ( $(conf_read mysql) != "true" || $(check_mysql_connection localhost) != "true" )) || ( $wp_dbhost != "localhost" && $(check_mysql_connection $extdb_url $extdb_port $extdb_user $extdb_pass) != "true" ) ]]; then
|
||||
elif [[ ( $wp_dbhost_host == "localhost" && ( $(conf_read mysql) != "true" || $(check_mysql_connection localhost $mysql_param) != "true" )) || ( $wp_dbhost_host != "localhost" && $(check_mysql_connection $extdb_url $extdb_port $extdb_user $extdb_pass) != "true" ) ]]; then
|
||||
echo "${red}[ERROR] Database${blu} ${1}${2} ${red}cannot be deleted! ${dim}(DB Connection failed)${end}"
|
||||
return
|
||||
fi
|
||||
|
||||
dbsetup="DELETE FROM mysql.user WHERE User='$wp_dbuser';DROP DATABASE IF EXISTS $wp_dbname;DELETE FROM mysql.db WHERE Db='$wp_dbname' OR Db='$wp_dbname\\_%';FLUSH PRIVILEGES;"
|
||||
if [[ $wp_dbhost == "localhost" ]]; then
|
||||
sudo mysql --connect-timeout=10 --user=admin -e "$dbsetup"
|
||||
if [[ $wp_dbhost_host == "localhost" ]]; then
|
||||
sudo mysql --connect-timeout=10 --user=admin -e "$dbsetup" "${mysql_params[@]}"
|
||||
echo "${gre}${dim}Database of your site ${blu}${1}${2}${gre} has been successfully deleted! ${end}"
|
||||
else
|
||||
if [[ $extdb_user == "root" && -z $extdb_pass ]]; then
|
||||
|
@ -1654,7 +1654,7 @@ cloning_site() {
|
|||
local custom_wp_dbpref=$( grep -F "table_prefix" $(wp_config_path $domain $subfolder) | cut -f 2 -d "'" -s)
|
||||
fi
|
||||
|
||||
if [[ $( wp_config_read $domain DB_HOST $subfolder ) == "localhost" ]]; then
|
||||
if [[ $(echo "$(wp_config_read $domain DB_HOST $subfolder)" | cut -f 1 -d ':' ) == "localhost" ]]; then
|
||||
[[ -z $subfolder ]] && sudo site $domain -delete=force > /dev/null 2>&1 || sudo site $domain -subfolder=$subfolder -delete=force > /dev/null 2>&1
|
||||
else
|
||||
if [[ -n $extdb_user && -n $extdb_pass && -n $extdb_host ]]; then
|
||||
|
@ -1782,9 +1782,9 @@ cloning_site() {
|
|||
wp_config_write $domain DB_PASSWORD \'$AUTOGENPASS_WPDB\' $subfolder
|
||||
wp_config_write $domain WP_CACHE_KEY_SALT \'wp_$domain$(echo $subfolder | sed "s/\//_/g")\' $subfolder
|
||||
|
||||
if [[ $wp_dbhost == "localhost" ]]; then
|
||||
if [[ $wp_dbhost_host == "localhost" ]]; then
|
||||
site -mysql=[localhost,$dom,$usr,$AUTOGENPASS_WPDB] > /dev/null 2>&1
|
||||
mysqldump -u admin $wp_dbname | mysql -u admin $dom
|
||||
mysqldump -u admin "${mysql_params[@]}" $wp_dbname | mysql -u admin "${mysql_params[@]}" $dom
|
||||
|
||||
# No need of force-redirect check because this is a new and different site.
|
||||
edit_wp_db_url $domain "http://${domain}${subfolder}" $subfolder
|
||||
|
@ -1842,15 +1842,15 @@ wp_replace_content() {
|
|||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -n $wp_dbhost && -n $wp_dbname && -n $wp_dbpref ]]; then
|
||||
if [[ ( $wp_dbhost == "localhost" && $(check_mysql_connection localhost) != "true" ) || ( $wp_dbhost != "localhost" && $(check_mysql_connection $extdb_url $extdb_port $extdb_user $extdb_pass) != "true" ) ]]; then
|
||||
if [[ -n $wp_dbhost_host && -n $wp_dbname && -n $wp_dbpref ]]; then
|
||||
if [[ ( $wp_dbhost_host == "localhost" && $(check_mysql_connection localhost $mysql_param) != "true" ) || ( $wp_dbhost_host != "localhost" && $(check_mysql_connection $extdb_url $extdb_port $extdb_user $extdb_pass) != "true" ) ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
query="USE $wp_dbname; UPDATE ${wp_dbpref}posts SET post_content = REPLACE (post_content,'$search','$replace'); FLUSH PRIVILEGES;"
|
||||
|
||||
if [[ $wp_dbhost == "localhost" ]]; then
|
||||
sudo mysql --connect-timeout=10 --user=admin -e "$query"
|
||||
if [[ $wp_dbhost_host == "localhost" ]]; then
|
||||
sudo mysql --connect-timeout=10 --user=admin -e "$query" "${mysql_params[@]}"
|
||||
else
|
||||
sudo mysql --connect-timeout=10 -h "$extdb_url" -P "$extdb_port" -u"$extdb_user" -p"$extdb_pass" -e "$query"
|
||||
fi
|
||||
|
@ -1975,7 +1975,7 @@ site_info_subfolder() {
|
|||
|
||||
if [[ $typesite == "wp" ]]; then
|
||||
local wph=$(wp_config_read $domain DB_HOST $subfolder)
|
||||
if [[ ${wph,,} == "localhost" || -n $external_db || $wph == "$(conf_read external-dbh):$(conf_read external-dbx)" ]]; then
|
||||
if [[ ${wph,,} == "localhost" || $(echo "${wph,,}" | cut -f 1 -d ':') == "localhost" || -n $external_db || $wph == "$(conf_read external-dbh):$(conf_read external-dbx)" ]]; then
|
||||
local wpmu=$(is_wp_multisite $domain $subfolder)
|
||||
wp_conf_retrieve $domain true true $subfolder
|
||||
else
|
||||
|
@ -2052,7 +2052,7 @@ site_info() {
|
|||
|
||||
if [[ $typesite == "WordPress" || ( $typesite == "Parked" && $(is_wp $domain) == "true" ) ]]; then
|
||||
local wph=$(wp_config_read $domain DB_HOST)
|
||||
if [[ ${wph,,} == "localhost" || -n $external_db || $wph == "$(conf_read external-dbh):$(conf_read external-dbx)" ]]; then
|
||||
if [[ ${wph,,} == "localhost" || $(echo "${wph,,}" | cut -f 1 -d ':') == "localhost" || -n $external_db || $wph == "$(conf_read external-dbh):$(conf_read external-dbx)" ]]; then
|
||||
local wpmu=$(is_wp_multisite $domain)
|
||||
wp_conf_retrieve $domain true true
|
||||
else
|
||||
|
@ -2120,14 +2120,13 @@ wp_env_type() {
|
|||
fi
|
||||
|
||||
# WordPress Reading Settings: Discourage Search Engines
|
||||
wp_conf_retrieve $domain true true $subfolder
|
||||
|
||||
if [[ -n $wp_dbhost && $wp_dbhost != "localhost" && ( -z $extdb_url || -z $extdb_port || -z $extdb_user || -z $extdb_pass ) ]]; then
|
||||
wp_conf_retrieve $domain true true $subfolder
|
||||
if [[ -n $wp_dbhost_host && $wp_dbhost_host != "localhost" && ( -z $extdb_url || -z $extdb_port || -z $extdb_user || -z $extdb_pass ) ]]; then
|
||||
echo "${red}${dim}[ERROR] Discourage Search Engines WP option not updated! (External DB data not available)${end}"
|
||||
elif [[ -n $wp_dbhost && -n $wp_dbname && -n $wp_dbpref ]]; then
|
||||
elif [[ -n $wp_dbhost_host && -n $wp_dbname && -n $wp_dbpref ]]; then
|
||||
if [[ $(is_wp_installed $domain $subfolder) == "true" ]]; then
|
||||
if [[ $wp_dbhost == "localhost" && $(check_mysql_connection localhost) == "true" ]]; then
|
||||
sudo mysql --connect-timeout=10 --user=admin <<_EOF_
|
||||
if [[ $wp_dbhost_host == "localhost" && $(check_mysql_connection localhost $mysql_param) == "true" ]]; then
|
||||
sudo mysql --connect-timeout=10 --user=admin "${mysql_params[@]}" <<_EOF_
|
||||
USE $wp_dbname;
|
||||
UPDATE ${wp_dbpref}options SET option_value='$index' WHERE option_name='blog_public';
|
||||
FLUSH PRIVILEGES;
|
||||
|
|
14
lib/verify
14
lib/verify
|
@ -1071,12 +1071,16 @@ if [[ -z $critical_mode ]]; then
|
|||
echo "${blu}${dim}- [INFO] HTTP Authentication Credentials not found for $ver_domi${end}${red}"
|
||||
fi
|
||||
|
||||
wp_conf_retrieve $ver_domi false > /dev/null
|
||||
if [[ $wp_dbhost == "localhost" && -n $wp_dbuser && -n $wp_dbpass && -n $wp_dbname && $(check_mysql_connection localhost $wp_dbuser $wp_dbpass $wp_dbname) != "true" ]]; then
|
||||
echo "${dim}- [WARNING] Database connection failed for your WP site $ver_domi (localhost) ${end}${red}"
|
||||
wp_conf_retrieve $ver_domi false false
|
||||
if [[ $wp_dbhost_host == "localhost" && ( -z $wp_dbuser || -z $wp_dbpass || -z $wp_dbname || $(check_mysql_connection localhost $wp_dbuser $wp_dbpass $wp_dbname $mysql_param) != "true" ) ]]; then
|
||||
echo "${red}${dim}- [WARNING] Database connection failed for your WP site $ver_domi (${wp_dbhost}) ${end}${red}"
|
||||
local ver_nine_war="1"
|
||||
elif [[ -n $wp_dbhost && $wp_dbhost != "localhost" && -n $extdb_url && -n $extdb_port && -n $wp_dbuser && -n $wp_dbpass && -n $wp_dbname && $(check_mysql_connection $extdb_url $extdb_port $wp_dbuser $wp_dbpass $wp_dbname 2>/dev/null) != "true" ]]; then
|
||||
echo "${dim}- [WARNING] Database connection failed for your WP site $ver_domi (${wp_dbhost}) ${end}${red}"
|
||||
|
||||
elif [[ $wp_dbhost_host == "localhost" && -n $wp_dbhost_port ]]; then
|
||||
echo "${blu}${dim}- [INFO] Localhost with custom port could have a negative impact in performance (Site: $ver_domi | Host: ${wp_dbhost}).${end}${red}"
|
||||
|
||||
elif [[ $wp_dbhost_host != "localhost" && ( -z $wp_dbhost_host || -z $wp_dbhost_port || -z $wp_dbuser || -z $wp_dbpass || -z $wp_dbname || $(check_mysql_connection $wp_dbhost_host $wp_dbhost_port $wp_dbuser $wp_dbpass $wp_dbname) != "true" ) ]]; then
|
||||
echo "${red}${dim}- [WARNING] Database connection failed for your WP site $ver_domi (${wp_dbhost}) ${end}${red}"
|
||||
local ver_nine_war="1"
|
||||
fi
|
||||
fi
|
||||
|
|
6
usr/site
6
usr/site
|
@ -372,13 +372,13 @@ elif [[ -n $clone_from ]]; then
|
|||
|
||||
if [[ $(is_wp $clone_from $subfolder) == "true" ]]; then
|
||||
#We need to call this function in the parent shell to preserve variables and avoid asking two times for the same values in case of external db.
|
||||
wp_conf_retrieve $clone_from true false $subfolder
|
||||
wp_conf_retrieve $clone_from true false $subfolder
|
||||
iswpclone="true"
|
||||
|
||||
if [[ -z $wp_dbhost || -z $wp_dbname || -z $wp_dbpref ]]; then
|
||||
if [[ -z $wp_dbhost ||-z $wp_dbhost_host || -z $wp_dbname || -z $wp_dbpref ]]; then
|
||||
echo "${red}[ERROR] Can not retrieve WP data ${dim}(WP Configuration corrupted)!${end}"
|
||||
exit 1
|
||||
elif [[ ( $wp_dbhost == "localhost" && $(check_mysql_connection localhost) != "true" ) || ( $wp_dbhost != "localhost" && $(check_mysql_connection $extdb_url $extdb_port $extdb_user $extdb_pass) != "true" ) ]]; then
|
||||
elif [[ ( $wp_dbhost_host == "localhost" && $(check_mysql_connection localhost $mysql_param) != "true" ) || ( $wp_dbhost_host != "localhost" && $(check_mysql_connection $extdb_url $extdb_port $extdb_user $extdb_pass) != "true" ) ]]; then
|
||||
exit 1
|
||||
elif [[ $(is_wp_multisite $clone_from $subfolder) != "false" ]]; then
|
||||
echo "${red}[ERROR] WordPress Multisite can not be cloned!${end}"
|
||||
|
|
Loading…
Reference in a new issue