DA API Feauture request: deleting DNS records

100nx

New member
Joined
May 8, 2008
Messages
3
Hello,

as the title states I would really like to see API support for deleting DNS records. In the API section of this forum there's a topic with some posts from people who are also looking for this option.

Currently it is possible to create DNS records using the API:
CMD_API_DNS_CONTROL?domain=domain.com&action=add&type=A|NS|MX|CNAME|PTR&name=namevalue&value=recordvalue

Also its possible to get a list of all the record types, names, and values in the zone, by parsing the result of
CMD_API_DNS_CONTROL?domain=domain.com&urlencoded=yes

For selecting (and possibly also deleting, which is not documented, at least I could not find it) one can use:
CMD_API_DNS_CONTROL?domain=domain.com&action=select&selecttype=encoded
where "selecttype" is one of arecs0, nsrecs0, mxrecs0, cnamerecs0, ptrrecs0 (0 and be any number, generally starting from zero, going up), and also where "encoded" is the url encoded version of: name=www&value=1.2.3.4

But when using the API, how can one retrieve the "selecttype" value, which is not included in the raw dump of the zone?

To summarize: is there a way to delete DNS records using the API, and if not would you be willing to add it? Wouldn't it for instance be possible for the api to delete records by recordtype and record name only, as in:
CMD_API_DNS_CONTROL?domain=domain.com&action=delete&type=A|NS|MX|CNAME|PTR&name=namevalue
Or if it would be easier for you to link the API function to the "normal" CMD_DNS_CONTROL delete function, by leaving the "selecttype" in there is it then true that for instance the third A-record in the raw zone dump would be arecs2 ?

Your reply/efforts would be greatly appreciated by me and many others.

Thanks in advance,

Jeroen
 
Last edited:
Hello,

It's all in here, although maybe a bit ambiguous.
http://www.directadmin.com/features.php?id=504

Everything you can do in a browser, you can do via the API.. they use the exact same processing code.. the CMD_API bits just changes how the returned data looks.

So.. if you ever want to find out exactly what to pass DA, go into DA in a browser, go to the place you want to run the command (eg, delete the record) but right before clicking the delete button, go into ssh, type:
Code:
cd /usr/local/directadmin
killall -9 directadmin
./directadmin b800
to enter the debug mode.
Hit the Delete button. Press ctrl-c in debug mode and type "./directadmin d" to start it up in the normal daemon mode again.
In your ssh screen you should be looking at exactly what your browser dumped to DA. You'll want to get your script to do that exact same thing.. except with CMD_API_DNS_CONTROL instead of CMD_DNS_CONTROL.

In any case, back to your question, this is the "delete" bit:
Code:
CMD_API_DNS_CONTROL?domain=[b]domain.com[/b]&action=select&[b]selecttype[/b]=[b]encoded[/b]
where "selecttype" is one of arecs0, nsrecs0, mxrecs0, cnamerecs0, ptrrecs0 (0 can be any number, generally starting from zero, going up).
so all of the selecttype options are right there.

An example, you want to delete the "ftp" A record that points to 192.168.0.2 in the domain: domain.com:
Code:
CMD_API_DNS_CONTROL?domain=domain.com&action=select&arecs0=[i]name=ftp&value=&#49&#57&#50.&#49&#54&#56.&#48.&#50[/i]
Now the italic bit there (everything after arecs0= ) needs to be url encoded so things like the & and = characters are not plain as you see them here, or it won't work.

For an complete example, do the above debugging method with DA to see exactly what your browser is passing DA to see what you need to do to encode things with your script.

Hope that helps! ;)

John
 
Very helpful, John.

Care to write it as a How-To? Or should I just move/rename the post above?

Jeff
 
Hey John,

First of all, thanks a lot for your response, it was very helpfull!

Though after testing and playing around a bit, I concluded the following:
The "encoded" value for selecttype should not be (url)encoded at all, at least when I do url-encode it, nothing happens, record is not deleted, when I do NOT encode it, then the correct record is deleted. Is this due to any recent changes, or does something go wrong here?

Greetings,

Jeroen
 
Go into the Admin Level -> DNS Admin with your browser.
Go through the form values to see what is there.

Also, you can load up DA into debug mode to see what your browser is passing, eg:

cd /usr/local/directadmin
killall -9 directadmin
./directadmin b800

Then trigger it from your browser, and your script to see what the difference is.

John
 
Back
Top