How to integrate buddyns with directadmin (requires SSH access)

babipanghang

New member
Joined
Jul 20, 2014
Messages
4
Having bought a VPS that came with only one IP available, i was looking for a way to be able to have a secondary DNS server controlled from within directadmin. There are off course the necessary secondary DNS services available, but each one that i found required manual entry of the zones to mirror.

Decided to give buddyns a try, and was happy to discover that they offer an API that i could use. Time to do some scripting.

First of all, you need to log in to buddyboard, and get to the account tab. Scroll all the way down, there should be a button there to request an API key. Click it, your key should appear there. Keep it secret like a password. You might want to copy it to your clipboard now.

Next step, log into your server with ssh and fire up your favourite text editor, and enter the following lines:
Code:
#!/bin/bash

curl -sH 'Authorization: Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' -XPOST -F "name=$domain" -F 'master=123.123.123.123' https://www.buddyns.com/api/v2/zone/ >> /var/log/dnsupdate.log
Be sure to replace xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx with your API key and 123.123.123.123 with your server's IP.
Now save that file as /usr/local/directadmin/scripts/custom/domain_create_post.sh
This script will automatically be called by directadmin each time a domain is added. When called, it adds the new domain to buddyns.

Next, create a new file and enter the following:
Code:
#!/bin/bash

curl -sH 'Authorization: Token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' -XDELETE  https://www.buddyns.com/api/v2/zone/$domain >> /var/log/dnsupdate.log
Again, replacing xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx with your API key.
Save that file as /usr/local/directadmin/scripts/custom/domain_destroy_post.sh
This script does the opposite of the first one, removing the domain from buddyns when it is removed from directadmin.

Last but not least, close your text editor and execute the following lines:
Code:
chmod 755 /usr/local/directadmin/scripts/custom/domain_create_post.sh
chmod 755 /usr/local/directadmin/scripts/custom/domain_destroy_post.sh
That should do the trick. You can find a log of the automatic buddyns updates at /var/log/dnsupdate.log.
 

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
14,255
Location
GMT +7.00
There are much more POST scripts which should be taken into consideration to keep DNS zones updated: create/destroy subdomain, create/destroy pointer and alias.
 

babipanghang

New member
Joined
Jul 20, 2014
Messages
4
There are much more POST scripts which should be taken into consideration to keep DNS zones updated: create/destroy subdomain, create/destroy pointer and alias.
BuddyNS should automatically synchronize every once in a while. Granted, it would be faster if sync now was triggered with every update. Might look into that.
Didn't actually try, but shouldn't creating a subdomain also trigger domain_create_post.sh? A subdomain, after all, is still a domain.

Anyway, thanks for your insights.
 

zEitEr

Super Moderator
Joined
Apr 11, 2005
Messages
14,255
Location
GMT +7.00
creating a subdomain also trigger domain_create_post.sh? A subdomain, after all, is still a domain.
Right, subdomains are presented in a DNS zone of its parent domain, so no need to execute separate scripts. But still aliases and pointers have different zones, and these scripts are to be executed:

domain_pointer_destroy_pre.sh
domain_pointer_destroy_post.sh
 
Top