myvesta/bin/v-move-domain-and-database-to-account
myvesta d3fb4e13d5 v-move-domain-and-database-to-account: Update wordfence-waf.php
Update v-move-domain-and-database-to-account

Update v-delete-web-domain: deleting /hdd/home/$user/web/$domain

Update v-delete-user: deleting /hdd/home/$user

Update v-delete-mail-domain: removing /hdd/home/$user/mail/$domain_idn

Update v-change-domain-owner: moving /hdd/home/$owner/web/$domain

Update v-change-domain-owner: moving /hdd/home/$owner/mail/$domain

Update v-move-folder-and-make-symlink: debug and additional checking
2025-05-26 09:39:29 +02:00

147 lines
4.5 KiB
Bash

#!/bin/bash
# info: change domain and database owner
# options: DOMAIN USER
#
# The function of changing domain and database ownership.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
whoami=$(whoami)
if [ "$whoami" != "root" ]; then
echo "You must be root to execute this script"
exit 1
fi
# Argument definition
domain=$1
user=$2
# Importing system environment
source /etc/profile
# Includes
source /usr/local/vesta/func/main.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'DOMAIN USER'
is_format_valid 'domain' 'user'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
owner=$(/usr/local/vesta/bin/v-search-domain-owner $domain)
if [ -z "$owner" ]; then
check_result $E_NOTEXIST "domain $domain doesn't exist"
fi
if [ "$owner" = "$user" ]; then
exit
fi
USER_DATA=$VESTA/data/users/$owner
is_object_unsuspended 'user' 'USER' "$owner"
USER_DATA=$VESTA/data/users/$user
USER_TO=$user
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
RET=$OK
echo "================================="
r=$(/usr/local/vesta/bin/v-get-database-credentials-of-domain $domain)
echo $r
eval $r
echo "================================="
if [ ! -z "$DATABASE_NAME" ]; then
echo "=== v-change-database-owner $DATABASE_NAME $USER_TO"
/usr/local/vesta/bin/v-change-database-owner $DATABASE_NAME $USER_TO
if [ $? -ne 0 ]; then
echo "=== v-change-database-owner failed"
RET=$E_NOTEXIST
fi
if [ ! -z "$DATABASE_USERNAME" ] && [ ! -z "$CONFIG_FILE_FULL_PATH" ]; then
replace_php_config_value "${DATABASE_NAME}" "${USER_TO}_${DATABASE_NAME_WITHOUT_USER_PREFIX}" "$CONFIG_FILE_FULL_PATH" "yes"
replace_php_config_value "${DATABASE_USERNAME}" "${USER_TO}_${DATABASE_USERNAME_WITHOUT_USER_PREFIX}" "$CONFIG_FILE_FULL_PATH" "yes"
else
if [ -z "$DATABASE_USERNAME" ]; then
echo "=== DATABASE_USERNAME is empty, so we will not change config file"
fi
if [ -z "$CONFIG_FILE_FULL_PATH" ]; then
echo "=== CONFIG_FILE_FULL_PATH is empty, so we will not change config file"
fi
fi
else
echo "=== DATABASE_NAME is empty, so we will not move database"
fi
echo "=== v-change-domain-owner $domain $USER_TO"
/usr/local/vesta/bin/v-change-domain-owner $domain $USER_TO
if [ $? -ne 0 ]; then
echo "=== v-change-domain-owner failed"
RET=$E_NOTEXIST
fi
#----------------------------------------------------------#
# Update Wordfence WAF Path #
#----------------------------------------------------------#
filepath="/home/USER_TO/web/$domain/public_html/.user.ini"
filename=$(basename $filepath)
# Check if file exists
if [ -f "$filepath" ]; then
echo "Updating $filename with new user path..."
# Temporary file for modification
tmp_file=$(mktemp)
# Change path from old USER to new USER_TO
sed "s|/home/$owner/public_html|/home/$USER_TO/public_html|g" "$filepath" > "$tmp_file"
# Check if replacement was successful and update file
if [ $? -eq 0 ]; then
mv "$tmp_file" "$filepath"
echo "$filename updated successfully."
else
echo "Failed to update $filename file."
rm "$tmp_file" # Deletes temporary file
fi
fi
filepath="/home/USER_TO/web/$domain/public_html/wordfence-waf.php"
filename=$(basename $filepath)
# Check if file exists
if [ -f "$filepath" ]; then
echo "Updating $filename with new user path..."
# Temporary file for modification
tmp_file=$(mktemp)
# Change path from old USER to new USER_TO
sed "s|/home/$owner/public_html|/home/$USER_TO/public_html|g" "$filepath" > "$tmp_file"
# Check if replacement was successful and update file
if [ $? -eq 0 ]; then
mv "$tmp_file" "$filepath"
echo "$filename updated successfully."
else
echo "Failed to update $filename file."
rm "$tmp_file" # Deletes temporary file
fi
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
log_event "$RET" "$ARGUMENTS"
exit