• Introducing WebPros Cloud - a fully managed infrastructure platform purpose-built to simplify the deployment of WebPros products !  WebPros Cloud enables you to easily deliver WebPros solutions — without the complexity of managing the infrastructure.
    Join the pilot program today!
  • Support for BIND DNS has been removed from Plesk for Windows due to security and maintenance risks.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS.

/usr/local/psa/bin/dns --info <domain> gives output if DNS control is off

Frater

Regular Pleskian
We have several Plesk servers and many domains.
One Plesk server normally handles domains with DNS-control (though not all) and the others have foreign DNS-control.

Today I changed the MX-record of a domain on the Plesk-server and found out a bit later that this server didn't have DNS-control. Normally I would have turned DNS-control off on this server, but apparently I forgot this when I initially configured this domain.

Now I want to write a little script in bash that checks if DNS-control is turned off if the DNS is foreign.

This would have been easy if the CLI-utility /usr/local/psa/bin/dns --info <domain> would give me the info if DNS-control is turned off. I'm able to turn it off or on with this utility, but I can't see its current status.

When DNS-control is turned off for a specific domain it will still give the records it would have if it had control.
The utility shouldn't do this.


Could this be changed?

Anyone knows how I can query the 'psa' database for this setting?
 
Last edited:
mysql> select status from dns_zone where name='domainnn.fr';
+--------+
| status |
+--------+
| 0 |
+--------+
1 row in set (0.00 sec)

~# /usr/local/psa/bin/dns --off domainnn.fr
SUCCESS: Switching DNS state for Domain 'domainnn.fr' complete.

mysql> select status from dns_zone where name='domainnn.fr';
+--------+
| status |
+--------+
| 1 |
+--------+
1 row in set (0.00 sec)
 
Thanks Igor for this fast reply.
I immediately started to write the script...

As you can see I'm better with bash than with mysql
I just copied the mysql statement from an example.
I know that the one that should merely get the domains is wrong.
Maybe you can give the proper one.

The script is working though!!!


cat pleskdns
Code:
#!/bin/bash

HT=`echo -en '\t'`

TMP1=`mktemp`
TMP2=`mktemp`
TMP3=`mktemp`
TMP4=`mktemp`

# get IP's of this server
ifconfig | egrep -o 'inet addr:[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | awk -F: '{print $2}' >/tmp/IPS

# get all hosted domains
mysql -uadmin -p`cat /etc/psa/.psa.shadow` psa -e "SELECT domains.name FROM domains, Limits WHERE domains.limits_id = Limits.id ORDER BY domains.name ASC; " | egrep '[a-z0-9.-]+\.[a-z]+$' | sort | uniq >${TMP1}

if [ ! -z "$1" ] ; then
  if grep -qi "$1" ${TMP1} ; then
    grep -i "$1" ${TMP1} >${TMP2}
    cat ${TMP2} >${TMP1}
  else
    echo "Domain $1 not found on this server!" >&2
    exit 1
  fi
fi

while read DOMAIN ; do

   DNS_OFF=$(mysql -uadmin -p`cat /etc/psa/.psa.shadow` psa -e "select status from dns_zone where name='${DOMAIN}';" 2>/dev/null | tr -cd '0-9')

   host -t NS ${DOMAIN} | grep -o 'name server .*' | awk '{print $3}' >${TMP2}

   while read NS ; do
     host -t A ${NS} | grep -o 'has address .*' | awk '{print $3}' >>${TMP3}
   done <${TMP2}

   THIS_SERVER_IS_DNS=0
   while read IP ; do
     grep -q "^${IP}$" ${TMP3} && THIS_SERVER_IS_DNS=1
   done < /tmp/IPS

   if [ "${DNS_OFF}" = "0" ] ; then
     if [ "${THIS_SERVER_IS_DNS}" = "0" ] ; then
       echo -e "DNS is turned on for ${DOMAIN}, but should be turned OFF\n\tThese servers are doing it:"
       cat ${TMP2} | sed "s/.*/${HT}${HT}${HT}${HT}${HT}&/g"
       echo -e '\n'
     fi
   fi
done<${TMP1}

rm ${TMP1}
rm ${TMP2}
rm ${TMP3}
rm ${TMP4}
 
Back
Top