Could we help you? Please click the banners. We are young and desperately need the money
This HowTo explains how the BuddyNS secondary DNS services can be easily implemented with Virtualmin domain management
1. Install the UNIX tool JQ. On Debian/Ubuntu you can do this easily like this:
aptitude install jq
2. If not yet installed - install the CURL command line tool like this (i.e. Debian / Ubuntu):
aptitude install curl
3. Create a script called virtualmin_post_changes_commands with the following content:
#! /bin/sh MASTER_NS=YOUR.IP.ADDRESS.HERE TOKEN="Enter Your BuddyNS Token Here. Go to BuddyNS account settings to generate one" ### Please check your settings in SYSTEM SETTINGS => SERVER TEMPLATES => [YOUR TEMPLATE] => BIND DNS domain => Add sub-domain DNS records to parent domain? => NO ### Reason: After a lot of testing we found out that Virtualmin does not handle it well adding sub-server domain settings to parent domain automatically ### Alternative solution: do NOT enable the DNS functionality on subdomains and enter subdomain values yourself on primary domain upon creating sub-server creation. if [ $VIRTUALSERVER_ACTION = "CREATE_DOMAIN" ] && [ $VIRTUALSERVER_DNS = "1" ]; then echo "<strong>Updating buddyNS (secondary nameserver) settings ...</strong><br/>" echo "Creating domain on buddyNS and issuing synchronisation ...<br/>" ### Delete zone first (in case it already exists for some reason) ### echo "... Checking if zone <strong>$VIRTUALSERVER_DOM</strong> already exists on buddyNS. If so, remove it in order to recreate and sync the zone information properly...<br/>" curl -ss -H "Authorization: Token ${TOKEN}" -XDELETE https://www.buddyns.com/api/v2/zone/$VIRTUALSERVER_DOM |jq ".[]" ### (Re)create zone on buddyNS ### echo "<br/>... Creating new zone <strong>$VIRTUALSERVER_DOM</strong> immediately ...<br/>" curl -ss -H "Authorization: Token ${TOKEN}" -XPOST -F "name=$VIRTUALSERVER_DOM" -F "master=$MASTER_NS" https://www.buddyns.com/api/v2/zone/ |jq ".[]" ### To be sure that all data is being synced: force zone sync immediately ### echo "<br/>... Forcing buddyNS to sync the zone <strong>$VIRTUALSERVER_DOM</strong> with our MASTER nameserver $MASTER_NS ...<br/>" curl -ss -H "Authorization: Token ${TOKEN}" -XGET https://www.buddyns.com/api/v2/sync/$VIRTUALSERVER_DOM |jq ".[]" echo "<br/>... done<br/><br/>" fi if [ $VIRTUALSERVER_ACTION = "MODIFY_DOMAIN" ] && [ $VIRTUALSERVER_DNS = "1" ]; then echo "<strong>Updating buddyNS (secondary nameserver) settings ...</strong><br/>" echo "Modifying domain parameters on buddyNS ...<br/>" ### We have to do basically the same as when we create a new domain. Since we remove the old domain in the pre changes commands and now we recreate the domain on buddyNS again ### echo "... Checking if zone <strong>$VIRTUALSERVER_DOM</strong> already exists on buddyNS. If so, remove it in order to recreate and sync the zone information properly...<br/>" curl -ss -H "Authorization: Token ${TOKEN}" -XDELETE https://www.buddyns.com/api/v2/zone/$VIRTUALSERVER_DOM |jq ".[]" ### (Re)create zone on buddyNS ONLY if DNS option is enabled (it could be that the DNS options has just been disabled - in that case the zone shall remain deleted on buddyNS ### echo "<br/>... Creating new zone <strong>$VIRTUALSERVER_DOM</strong> immediately ...<br/>" curl -ss -H "Authorization: Token ${TOKEN}" -XPOST -F "name=$VIRTUALSERVER_DOM" -F "master=$MASTER_NS" https://www.buddyns.com/api/v2/zone/ |jq ".[]" ### To be sure that all data is being synced: force zone sync immediately ### echo "<br/>... Forcing buddyNS to sync the zone <strong>$VIRTUALSERVER_DOM</strong> with our MASTER nameserver $MASTER_NS ...<br/>" curl -ss -H "Authorization: Token ${TOKEN}" -XGET https://www.buddyns.com/api/v2/sync/$VIRTUALSERVER_DOM |jq ".[]" echo "<br/>... done<br/><br/>" fi ## In any case try to also remove it from buddyNS to be sure that there is no residual unnecessary data if [ $VIRTUALSERVER_ACTION = "DELETE_DOMAIN" ]; then echo "<strong>Updating buddyNS (secondary nameserver) settings ...</strong><br/>" echo "Deleting the zone <strong>$VIRTUALSERVER_DOM</strong> from buddyNS ...<br/>" curl -ss -H "Authorization: Token ${TOKEN}" -XDELETE https://www.buddyns.com/api/v2/zone/$VIRTUALSERVER_DOM |jq ".[]" echo "<br/>Deleting Letsencrypt certificate(s)..." /home/srvdata/remove_ssl_cert $VIRTUALSERVER_DOM echo "<br/>... done<br/><br/>" fi
4. Create a script called virtualmin_pre_changes_commands with the following content:
#! /bin/sh MASTER_NS=IP.OF.YOUR-MASTER.DNS TOKEN="Enter Your BuddyNS Token Here. Go to BuddyNS account settings to generate one" if [ "$VIRTUALSERVER_ACTION" = "MODIFY_DOMAIN" ]; then echo "<strong>Updating buddyNS (secondary nameserver) settings ...</strong><br/>" ### To be on the safe side we generally remove the zone from buddyNS. Because at this stage we do not know exactly what the user selected. The domain will be recreated and resynced within the POST script if required ### echo "... Delete existing zone <strong>$VIRTUALSERVER_DOM</strong> on buddyNS ...<br/>" curl -ss -H "Authorization: Token ${TOKEN}" -XDELETE https://www.buddyns.com/api/v2/zone/$VIRTUALSERVER_DOM |jq ".[]" echo "<br/>... done<br/><br/>" fi
5. Add the 2 scripts to the Virtualmin domain configuration:
Test the configuration by adding a new domain and check the messages on the screen. Logon to www.buddyns.com to see if the new domain has been created and synced properly.
Let us know in the comments if something is not working out.
Make sure that you set this option:
Please check your settings in SYSTEM SETTINGS => SERVER TEMPLATES => [YOUR TEMPLATE] => BIND DNS domain => Add sub-domain DNS records to parent domain? => NO
This might look like this: