We are starting CHRISTMAS Sale. Get 30% OFF on lifetime licenses with code: FYSKK72

v-change-domain-owner doesn't work

Questions regarding the Command Line Interface
CLI
Spheerys
Posts: 126
Joined: Tue Dec 29, 2015 12:36 pm

v-change-domain-owner doesn't work

Postby Spheerys » Fri Nov 17, 2017 11:53 am

Hi,

I want to change several domains to another owner.
I have created a new user and when I run :

Code: Select all

v-change-domain-owner domain.tld NEWUSER

... I have this error :

Code: Select all

grep: /usr/local/vesta//data/users/users/web.conf: No file or directory of this type
grep: /usr/local/vesta//data/users/users/dns.conf: No file or directory of this type
grep: /usr/local/vesta//data/users/users/mail.conf: No file or directory of this type
Error: user users doesn't exist


OS : Debian 8.9
VestaCP version : 0.9.8 (amd64)
VestaCP Release: 17


What's going wrong ?

Spheerys
Posts: 126
Joined: Tue Dec 29, 2015 12:36 pm

Re: v-change-domain-owner doesn't work

Postby Spheerys » Fri Nov 17, 2017 9:57 pm

I dig a little bit and indeed, the path "/usr/local/vesta//data/users/users/" is not existing (the double / is not a big thing)
The correct path should be "/usr/local/vesta//data/users/NEWUSER/" and inside, I have all the listed files:

Code: Select all

~  ll /usr/local/vesta/data/users/NEWUSER/       
total 20K
-rw-rw---- 1 root root    0 nov.  17 11:59 backup.conf
-rw-rw---- 1 root root    0 nov.  17 11:59 cron.conf
-rw-rw---- 1 root root    0 nov.  17 11:59 db.conf
drwxrwx--- 2 root root 4,0K nov.  17 11:59 dns
-rw-rw---- 1 root root    0 nov.  17 11:59 dns.conf
-rw-rw---- 1 root root   80 nov.  17 11:59 history.log
drwxrwx--- 2 root root 4,0K nov.  17 11:59 mail
-rw-rw---- 1 root root    0 nov.  17 11:59 mail.conf
drwxrwx--- 2 root root 4,0K nov.  17 11:59 ssl
-rw-rw---- 1 root root    0 nov.  17 11:59 stats.log
-rw-rw---- 1 root root 1,2K nov.  17 12:52 user.conf
-rw-rw---- 1 root root    0 nov.  17 11:59 web.conf


Why the script v-change-domain-owner don't load the correct user variable ?

Here my v-change-domain-owner file (I never make modification inside) :

Code: Select all

#!/bin/bash
# info: change domain owner
# options: DOMAIN USER
#
# The function of changing domain ownership.


#----------------------------------------------------------#
#                    Variable&Function                     #
#----------------------------------------------------------#

# Argument definition
domain=$1
user=$2

# Includes
source $VESTA/func/ip.sh
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf


#----------------------------------------------------------#
#                    Verifications                         #
#----------------------------------------------------------#

check_args '2' "$#" 'DOMAIN USER'
is_format_valid 'domain' 'user'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
owner=$($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


#----------------------------------------------------------#
#                       Action                             #
#----------------------------------------------------------#

# WEB domain
web_data=$(grep "DOMAIN='$domain'" $VESTA/data/users/$owner/web.conf)
if [ ! -z "$web_data" ]; then
    $BIN/v-suspend-web-domain $owner $domain >> /dev/null 2>&1
    eval $web_data

    # Change IP
    if [ ! -z "$ip" ]; then
        web_data=$(echo "$web_data" | sed "s/IP='$IP'/IP='$ip'/")
    fi

    # Check SSL
    if [ "$SSL" = 'yes' ]; then
        ssl_crt=$VESTA/data/users/$owner/ssl/$domain.crt
        ssl_key=$VESTA/data/users/$owner/ssl/$domain.key
        ssl_ca=$VESTA/data/users/$owner/ssl/$domain.ca
        ssl_pem=$VESTA/data/users/$owner/ssl/$domain.pem
        mv $ssl_crt $VESTA/data/users/$user/ssl/
        mv $ssl_key $VESTA/data/users/$user/ssl/
        mv $ssl_ca $VESTA/data/users/$user/ssl/ >> /dev/null 2>&1
        mv $ssl_pem $VESTA/data/users/$user/ssl/ >> /dev/null 2>&1
        rm -f $HOMEDIR/$owner/conf/web/ssl.$domain.*
    fi

    # Check ftp user account
    if [ ! -z "$FTP_USER" ]; then
        /usr/sbin/userdel -f  $FTP_USER >> /dev/null 2>&1
        old_str="FTP_USER='$FTP_USER'"
        new_str=$(echo "$old_str" | sed "s/${owner}_/${user}_/")
        web_data=$(echo "$web_data" | sed "s/$old_str/$new_str/")
    fi

    # Move config
    sed -i "/DOMAIN='$domain'/d" $VESTA/data/users/$owner/web.conf
    echo "$web_data" >> $VESTA/data/users/$user/web.conf

    # Move data
    mv $HOMEDIR/$owner/web/$domain $HOMEDIR/$user/web/

    # Change ownership
    find $HOMEDIR/$user/web/$domain -user $owner \
        -exec chown -h $user:$user {} \;

    # Rebuild config
    $BIN/v-unsuspend-web-domain $user $domain no >> /dev/null 2>&1
    $BIN/v-rebuild-web-domains $owner no
    $BIN/v-rebuild-web-domains $user
fi

# DNS domain
dns_data=$(grep "DOMAIN='$domain'" $VESTA/data/users/$owner/dns.conf)
if [ ! -z "$dns_data" ]; then
    eval $dns_data

    # Change IP
    if [ ! -z "$ip" ]; then
        dns_data=$(echo "$dns_data" | sed "s/IP='$IP'/IP='$ip'/")
        sed -i "s/$IP/$ip/g" $VESTA/data/users/$owner/dns/$domain.conf
    fi

    # Move config
    sed -i "/DOMAIN='$domain'/d" $VESTA/data/users/$owner/dns.conf
    echo "$dns_data" >> $VESTA/data/users/$user/dns.conf

    # Move dns records
    mv $VESTA/data/users/$owner/dns/$domain.conf \
        $VESTA/data/users/$user/dns/

    # Rebuild config
    $BIN/v-unsuspend-dns-domain $user $domain no >> /dev/null 2>&1
    $BIN/v-rebuild-dns-domains $owner no
    $BIN/v-rebuild-dns-domains $user

    # Resync dns cluster
    if [ ! -z "$DNS_CLUSTER" ]; then
        v-sync-dns-cluster
    fi
fi

# MAIL domain
mail_data=$(grep "DOMAIN='$domain'" $VESTA/data/users/$owner/mail.conf)
if [ ! -z "$mail_data" ]; then

    # Move config
    sed -i "/DOMAIN='$domain'/d" $VESTA/data/users/$owner/mail.conf
    echo "$mail_data" >> $VESTA/data/users/$user/mail.conf
    mv -f $VESTA/data/users/$owner/mail/$domain.conf \
        $VESTA/data/users/$user/mail/

    # Move DKIM
    if [ -e "$VESTA/data/users/$owner/mail/$domain.pem" ]; then
        mv -f $VESTA/data/users/$owner/mail/$domain.pem \
            $VESTA/data/users/$user/mail/
        mv -f $VESTA/data/users/$owner/mail/$domain.pub \
            $VESTA/data/users/$user/mail/
    fi

    # Move data
    mv $HOMEDIR/$owner/mail/$domain $HOMEDIR/$user/mail/

    # Change ownership
    find $HOMEDIR/$user/mail/$domain -user $owner \
        -exec chown -h $user {} \;

    # Rebuild config
    $BIN/v-unsuspend-mail-domain $user $domain no >> /dev/null 2>&1
    $BIN/v-rebuild-mail-domains $owner no
    $BIN/v-rebuild-mail-domains $user
fi

# Update counters
$BIN/v-update-user-counters $owner
$BIN/v-update-user-counters $user


#----------------------------------------------------------#
#                       Vesta                              #
#----------------------------------------------------------#

# Logging
log_event "$OK" "$ARGUMENTS"

exit


Is this script is working well on your place ?

Spheerys
Posts: 126
Joined: Tue Dec 29, 2015 12:36 pm

Re: v-change-domain-owner doesn't work

Postby Spheerys » Fri Nov 17, 2017 10:00 pm

Ahah... the called v-search-domain-owner script is returning "users" for any domain on the server !!!!
Here my v-search-domain-owner script :

Code: Select all

#!/bin/bash
# info: search domain owner
# options: DOMAIN [TYPE]
#
# The function that allows to find user objects.


#----------------------------------------------------------#
#                    Variable&Function                     #
#----------------------------------------------------------#

# Argument definition
domain=$(idn -t --quiet -u "$1" )
type=${2-any}

# Includes
source $VESTA/func/main.sh


#----------------------------------------------------------#
#                    Verifications                         #
#----------------------------------------------------------#

check_args '1' "$#" 'DOMAIN [TYPE]'


#----------------------------------------------------------#
#                       Action                             #
#----------------------------------------------------------#

# Define conf
case $type in
    web)    conf="$VESTA/data/users/*/web.conf" ;;
    dns)    conf="$VESTA/data/users/*/dns.conf" ;;
    mail)   conf="$VESTA/data/users/*/mail.conf" ;;
    *)      conf="$VESTA/data/users/*/*.conf"
esac


owner=$(grep -H "DOMAIN='$domain'" $conf | head -n 1 | cut -f7 -d '/')
if [ -z "$owner" ]; then
    exit $E_NOTEXIST
fi

echo $owner


#----------------------------------------------------------#
#                       Vesta                              #
#----------------------------------------------------------#

# Logging
#log_event "$OK" "$ARGUMENTS"

exit


Return to “CLI”



Who is online

Users browsing this forum: No registered users and 3 guests