mirror of
https://github.com/myvesta/vesta.git
synced 2024-11-03 04:00:20 -08:00
128 lines
3.9 KiB
Bash
128 lines
3.9 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 #
|
|
#----------------------------------------------------------#
|
|
|
|
# Path to .user.ini file
|
|
user_ini="$USER_DATA/web/$domain/public_html/.user.ini"
|
|
|
|
# Check if .user.ini exists
|
|
if [ -f "$user_ini" ]; then
|
|
echo "Updating .user.ini 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" "$user_ini" > "$tmp_file"
|
|
|
|
# Check if replacement was successful and update .user.ini
|
|
if [ $? -eq 0 ]; then
|
|
mv "$tmp_file" "$user_ini"
|
|
echo ".user.ini updated successfully."
|
|
else
|
|
echo "Failed to update .user.ini file."
|
|
rm "$tmp_file" # Deletes temporary file
|
|
fi
|
|
else
|
|
echo ".user.ini does not exist, no changes made."
|
|
fi
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
# Vesta #
|
|
#----------------------------------------------------------#
|
|
|
|
log_event "$RET" "$ARGUMENTS"
|
|
|
|
exit
|