Module for adding domains from Directadmin to DNSmanager

The question arose about creating a DNS cluster based on DNSmanager. Some servers are running directadmin.
A small digression on the logic of dnsmanager:
- when creating a reseller with its NS servers, a database with the same name is created;
- all reseller users write domains to the reseller database (name only has their username and password), as a result, each user has their own domains. This is necessary so that someone does not add the domain (which already exists) on another server (the domain is added on the server, and the cluster does not leave the DNS because such a domain already exists, but if all the servers use the same username and password , then when you delete - the domain will be deleted).

Based on this, a rule arises - each server must have its own username and password.

To import domains during their creation, renaming, removal from the direct admin to dns, the manager needs:
1. On the server with the direct admin, we look at the named.conf config.
In options {
add:
allow-transfer { IP1; IP2; IP3; IP4; };
notify yes;
also-notify { IP1; IP2; IP3; IP4; };
allow-recursion { localnets; };

IP1; IP2; IP3; IP4; - a list of IP from which you can pick up the zone.
I recommend adding both the main IP DNSmanager and the IP on which the DNS will spin.
2. On the server with the direct admin, look at:
cd /usr/local/directadmin/data/templates/custom

The zone.conf file, there is something like:
zone "|DOMAIN|" { type master; allow-transfer { IP1; }; notify yes; file "|PATH|/|DOMAIN|.db"; };

And if necessary, add our new IP there:
zone "|DOMAIN|" { type master; allow-transfer { IP1; IP2; IP3; IP4; }; notify yes; file "|PATH|/|DOMAIN|.db"; };

IP1; IP2; IP3; IP4; - a list of IP from which you can pick up the zone.
I recommend adding both the main IP DNSmanager and the IP on which DNS will be spinning (IP reseller).

3. On the server with the direct admin, we distort named:
Freebsd:
/etc/rc.d/named/restart

Linux:
/etc/init.d/named restart

4. On the server with the direct admin write 2 scripts.
First:
cd /usr/local/etc
mkdir dadnstodnsmanager
cd dadnstodnsmanager
touch add-domain.sh
mcedit add-domain.sh

We insert there
#!/bin/sh
DNSMGRIP="IP_DNSmanager"
USERDNS="Имя_Пользователя"
PASSUSERDNS="Пароль_Пользователя"
MASTERIP="IP_Мастера_(Главный_IP_Сервера)"
/usr/local/bin/curl --insecure https://${DNSMGRIP}:1500/dnsmgr\?authinfo=${USERDNS}:${PASSUSERDNS}\&out=xml\&func=domain.edit\&dtype=slave\&master=${MASTERIP}\&name=$1\&sok=ok >/dev/null 2>&1

Or just immediately insert the values:
#!/bin/sh
/usr/local/bin/curl --insecure https://IP:1500/dnsmgr\?authinfo=Пользователь:Пароль\&out=xml\&func=domain.edit\&dtype=slave\&master=Мастер_IP\&name=$1\&sok=ok

Further:
chmod +x /usr/local/etc/dadnstodnsmanager/add-domain.sh

Second script:
cd /usr/local/etc
mkdir dadnstodnsmanager
cd dadnstodnsmanager
touch delete-domain.sh
mcedit delete-domain.sh

We insert there:
#!/bin/sh
DNSMGRIP="IP_DNSmanager"
USERDNS="Имя_Пользователя"
PASSUSERDNS="Пароль_Пользователя"
MASTERIP="IP_Мастера_(Главный_IP_Сервера)"
/usr/local/bin/curl --insecure https://${DNSMGRIP}:1500/dnsmgr\?authinfo=${USERDNS}:${PASSUSERDNS}\&elid=$1\&func=domain.delete >/dev/null 2>&1

Or just immediately insert the values:
#!/bin/sh
/usr/local/bin/curl --insecure https://IP:1500/dnsmgr\?authinfo=Пользователь:Пароль\&elid=$1\&func=domain.delete >/dev/null 2>&1

Further:
chmod +x /usr/local/etc/dadnstodnsmanager/delete-domain.sh


5. Both scripts are ready, we check that they were not mistaken:
cd /usr/local/etc/dadnstodnsmanager/
./add-domain.sh testmeserver1.com

We look that the domain appeared in DNSmanager. It is best to do this with the domain that is on the server and it has DNS records.
If the domain appeared in DNSmanager and the records were transferred, then everything is fine.
If the domain has appeared but there are no records, run on DNSmanager
dig @IP_MASTER_Сервера testmeserver1.com axfr


If we get:
; <<>> DiG V.V.V <<>> @IP_MASTER_Сервера testmeserver1.com axfr
 ; (1 server found)
 ;; global options: +cmd
 ; Transfer failed.

Either the zone transfer is configured incorrectly (see section 1-2), or named is not restarted after the changes.
We look at the logs and fix until the server gives
#dig @IP_MASTER_Сервера testmeserver1.com axfr
 ; <<>> DiG V.V.V <<>> @IP_MASTER_Сервера testmeserver1.com axfr
 ; (1 server found)
 ;; global options: +cmd
 testmeserver1.com.      14400   IN      SOA     ns1.mydnsserver.com. hostmaster.testmeserver1.com. 2013111400 14400 3600 1209600 86400
 testmeserver1.com.      14400   IN      MX      10 mail.testmeserver1.com.
 testmeserver1.com.      14400   IN      TXT     "v=spf1 a mx ip4:IP_MASTER_Сервера ~all"
 testmeserver1.com.      14400   IN      A       IP_Домена
 testmeserver1.com.      14400   IN      NS      ns1.mydnsserver.com.
 testmeserver1.com.      14400   IN      NS      ns2.mydnsserver.com.
 testmeserver1.com.      14400   IN      NS      ns3.mydnsserver.com.
 ftp.testmeserver1.com.  14400   IN      A       IP_Домена
 localhost.testmeserver1.com. 14400 IN   AAAA    ::1
 localhost.testmeserver1.com. 14400 IN   A       127.0.0.1
 mail.testmeserver1.com. 14400   IN      A       IP_Домена
 pop.testmeserver1.com.  14400   IN      A       IP_Домена
 smtp.testmeserver1.com. 14400   IN      A       IP_Домена
 www.testmeserver1.com.  14400   IN      A       IP_Домена
 testmeserver1.com.      14400   IN      SOA     ns1.mydnsserver.com. hostmaster.testmeserver1.com. 2013111400 14400 3600 1209600 86400
 ;; Query time: 1 msec
 ;; SERVER: IP_MASTER_Сервера#53(IP_MASTER_Сервера)
 ;; WHEN: Fri Nov XX XX:XX:XX XXXX
 ;; XFR size: 15 records (messages 1, bytes 424)

If everything is fine, check the second script:
cd /usr/local/etc/dadnstodnsmanager/
./delete-domain.sh testmeserver1.com

Check that the domain has been removed from DNSmanager.

6. In the admin area there is a set of additional scripts executed before or after certain events.
They lie in:
/ usr / local / directadmin / scripts directory / custom

We are interested in:
domain_change_post.sh
domain_create_post.sh
domain_destroy_post.sh
domain_pointer_create_post.sh
domain_pointer_destroy_post.sh
subdomain_create_post.sh
subdomain_destroy_post.sh
user_create_post.sh

If they do not, then you need to create.

Let's take turns:

domain_change_post.sh is executed after the domain is renamed.
Edit it - add:
/usr/local/etc/dadnstodnsmanager/delete-domain.sh.sh $domain
/usr/local/etc/dadnstodnsmanager/add-domain.sh $newdomain


After renaming, the old domain will be removed from the cluster, and the new one will be added.

domain_create_post.sh is executed after the domain is created.
Edit it - add:
/usr/local/etc/dadnstodnsmanager/add-domain.sh $domain


domain_destroy_post.sh is executed after the domain is deleted.
Edit it - add:
/usr/local/etc/dadnstodnsmanager/delete-domain.sh $domain


domain_pointer_create_post.sh is executed after creating the domain domain pointer.
Edit it - add:
/usr/local/etc/dadnstodnsmanager/add-domain.sh $from


domain_pointer_destroy_post.sh is executed after creating the domain domain pointer.
Edit it - add:
/usr/local/etc/dadnstodnsmanager/delete-domain.sh $from


subdomain_create_post.sh is executed after the subdomain is created.
Edit it - add:
/usr/sbin/rndc reload $domain


subdomain_destroy_post.sh is executed after the subdomain is deleted.
Edit it - add:
/usr/sbin/rndc reload $domain


user_create_post.sh is executed after the user is created.
Edit it - add:
/usr/local/etc/dadnstodnsmanager/add-domain.sh $from


7. We carry out a check.
7.1 Created a user with a domain.
7.2 Logged in as a user and created a subdomain.
7.3 Logged in as a user and created a domain pointer.
7.4 Logged in as a user and created another domain2.
7.5 Logged in as a user and renamed domain2.
7.6 Logged in as a user and deleted the subdomain.
7.7 Logged in as a user and deleted the domain pointer.
7.8 Logged in as user and deleted domain2.
7.9 Removed user.
After each item, we check what is passed to dnsmanager.

If all the tests are successful, you can put into operation.

If you plan to use only one dnsmanager (on the wizard), then you can simply configure database replication and raise pds on the other NS servers, then when the domain or its records change, the hosting server will send the changes to the master server, and from there the changes will be transferred to server slave.

Also popular now: