cPanel - Domain already exists error while adding a subdomain or addon domain

Domain already exists error while adding a subdomain or addon domain



A very common error  when adding an addon or parked domain via cpanel. Unfortunately, the error they see is usually very generic and doesn’t provide any information such as “can not create domain”. This is usually due to the domain name existing *somewhere* and checking these locations/steps out should help you find the domain that is lurking somewhere and causing the issues.

Reason 1: There is an existing zone file on the server.

1) You can use the following command to check whether zone exists or not,


# dig @server_ip domain.com

If there is a zone file exists, this will show the A record of the domain.com.

2) If there is a zone file that exists, log into the server that the zone file is pointing to and make sure the domain doesn’t exist:

# /scripts/whoowns domain.com

If it does, you would need to remove this prior to adding their new addon domain. If it does not, continue on

3) Remove the zone file from master by running the following command:

# ./killdns domain.com

 This will then get rid of the pesky zone file that is getting in the way of their addon creation

Reason 2: There are old traces of the domain on the server

1) Log into the server where the customer is seeing problems adding the domain and confirm that the domain does not exist on the server.

# /scripts/whoowns domain.com

2) Check Cpanel files for traces of the problem domain name

# grep domain.com /var/cpanel/users/*

# grep -R domain.com /var/cpanel/userdata/*

3) Edit any files that are found and remove the traces of the domain name the customer is trying to add. You also may need to remove the entire file for the domain in the /var/cpanel/userdata/USERNAME/ directory.

 4) Rebuild the user domains database

# /scripts/updateuserdomains

5) Rebuild the Apache configuration and make sure apache is running with all traces of the bad domain removed.

# /scripts/rebuildhttpdconf ; service httpd restart

This should have all traces that were left behind from when this domain name was removed in the past and then will no longer cause a conflict when the customer tries to add the domain again.

cPanel - Bash script To Change password of all mail accounts

 Bash script To Change password of all mail accounts

The bash script given below will change the password of all the mail accounts in a cpanel server. The new password with mail account user name will be saved in to '/root/mailaccounts.txt'.




#!/bin/bash -   

#title          :changeallmailpass.sh

#description    :To Change password of all mail accounts in a cPanel Server

#author         :Arun Ghosh

#date           :20130812

#version        :1.0   

#usage          :./changeallmailpass.sh

#notes          :      

#bash_version   :4.2.25(1)-release

#============================================================================

genpasswd() {

        tr -dc A-Za-z0-9_ < /dev/urandom | head -c 12 | xargs

}

cat /dev/null > /root/mailaccounts.txt

CP_ACCOUNTS=`ls -1A /var/cpanel/users/`

for CP_USER in `echo -n $CP_ACCOUNTS`

do

    USER_DOMAIN=`grep -i ^dns /var/cpanel/users/$CP_USER |cut -d= -f2`

    for DOMAIN in `echo -n "$USER_DOMAIN"`

    do

        SHADOW_FILE="/home/$CP_USER/etc/$DOMAIN/shadow"

        if [ -f $SHADOW_FILE ] && [ -s $SHADOW_FILE ]

        then

            cat /dev/null > "/home/$CP_USER/etc/$DOMAIN/shadow.tmp"

            for shadow in `cat $SHADOW_FILE`

            do

                NEW_PASS=$(genpasswd)

                MD5_PASS=$(openssl passwd -1 $NEW_PASS)

                user=$(echo $shadow | cut -d":" -f1)

                rest=$(echo $shadow | cut -d":" -f3-)

                echo -e "$NEW_PASS\t$user@$DOMAIN" >> "/root/mailaccounts.txt"

                echo "$user:$MD5_PASS:$rest" >> "/home/$CP_USER/etc/$DOMAIN/shadow.tmp"

               

            done

            mv "/home/$CP_USER/etc/$DOMAIN/shadow" "/home/$CP_USER/etc/$DOMAIN/shadow.$(date +%s)"

            mv "/home/$CP_USER/etc/$DOMAIN/shadow.tmp" "/home/$CP_USER/etc/$DOMAIN/shadow"

            chmod 640 "/home/$CP_USER/etc/$DOMAIN/shadow"

            chown $CP_USER:$CP_USER "/home/$CP_USER/etc/$DOMAIN/shadow"        

        fi

    done

done



cPanel - Bash script To change password of a single mail account in cPanel via terminal


Bash script To change password of a mail account in cPanel via command line

The bash script given below will help you to change the password of a single mail account in a cpanel server via command line.

Let the script name is 'changemailpass.sh'. You can change the password of a mail account by using the following format.

# ./changemailpass.sh <mail_account> <newpassword>



#!/bin/bash -  
#title          :changemailpass.sh
#description    :To change password of a single mail account in cPanel via terminal
#author         :Arun Ghosh
#date           :20130811
#version        :1.0   
#usage          :./changemailpass.sh
#notes          :      
#bash_version   :4.2.25(1)-release
#============================================================================

MAIL_USER=$1
NEW_PASS=$2

MAIL_FLAG=false
DOMAIN=$(echo $MAIL_USER | cut -d"@" -f2)
MAIL=$(echo $MAIL_USER | cut -d"@" -f1)

EXIST=`grep ^$DOMAIN /etc/userdomains`

if [ "$EXIST" ]
then

CP_USER=`grep ^$DOMAIN /etc/userdomains | cut -d":" -f2 | tr -d ' '`
SHADOW_FILE="/home/$CP_USER/etc/$DOMAIN/shadow"

cat /dev/null > "/home/$CP_USER/etc/$DOMAIN/shadow.tmp"
for shadow in `cat /home/$CP_USER/etc/$DOMAIN/shadow`
do

pass=$(openssl passwd -1 $NEW_PASS)
user=$(echo $shadow | cut -d":" -f1)
rest=$(echo $shadow | cut -d":" -f3-)

if [ "$user" == "$MAIL" ]
then
MAIL_FLAG=true
echo "$user":$pass:$rest >> /home/$CP_USER/etc/$DOMAIN/shadow.tmp
else
echo $shadow >>/home/$CP_USER/etc/$DOMAIN/shadow.tmp
fi

done

if [ $MAIL_FLAG = false ]
then
echo "$1 not exists..!!";
elif [ $MAIL_FLAG = true ]
then

echo "$1 password changed to: $2"
fi
mv "/home/$CP_USER/etc/$DOMAIN/shadow" "/home/$CP_USER/etc/$DOMAIN/shadow.$(date +%s)"
mv "/home/$CP_USER/etc/$DOMAIN/shadow.tmp" "/home/$CP_USER/etc/$DOMAIN/shadow"
chmod 640 "/home/$CP_USER/etc/$DOMAIN/shadow"
chown $CP_USER:$CP_USER "/home/$CP_USER/etc/$DOMAIN/shadow"
else
echo "Domain not in the server"
fi




cPanel - Bash script to List All Mail Accounts


 Bash script to List All Mail Accounts in cPanel Server


The bash script given below will list all the mail accounts in a cpanel server and the list is saved in '/root/mailaccounts.txt'. Depending upon the total accounts, it will take time to finish script.



#!/bin/bash -  
#title          :listallmailaccounts.sh
#description    :To List All Mail Accounts in cPanel via Terminal
#author         :Arun Ghosh
#date           :20130811
#version        :1.0   
#usage          :./listallmailaccounts.sh
#notes          :      
#bash_version   :4.2.25(1)-release
#============================================================================

cat /dev/null > /root/mailaccounts.txt

CP_ACCOUNTS=`ls -1A /var/cpanel/users/`

for user in `echo -n $CP_ACCOUNTS`
do/root/mailaccounts.txt
    domain=`grep -i ^dns /var/cpanel/users/$user |cut -d= -f2`
    for dom in `echo -n "$domain"`
    do
        PASSWD_FILE="/home/$user/etc/$dom/passwd"
        if [ -f $PASSWD_FILE ] && [ -s $PASSWD_FILE ]
        then
            for mail in `cat $PASSWD_FILE| cut -d":" -f1`
            do
                echo "$mail@$dom" >> mailaccounts.txt
            done
        fi
    done
done