Skip to content
Petr Bena edited this page May 13, 2019 · 14 revisions

API documentation can be found simply by opening /api.php in your browser

In order to enable api, you need to edit your config file and put $g_api_enabled = true;

Some API allow GET method, but most of them need be sent via POST, here are some examples using curl

Cookies must be operational for user sessions to work. --insecure option is useful in case you are using self-signed or untrusted certificate.

Login

curl -X POST --insecure 'https://your-server/dns/api.php' -d 'action=login_token&token=test'  -c cookies -b cookies
{
    "result": "success"
}

Tokens

DNS tool supports login concept of tokens. These are shared secrets that are known by user and server, working in similar way to TSIG keys. User provides the secret to authenticate themselves. These secrets are stored in $g_api_tokens and can be used in $g_auth_roles_map instead of username in order to map roles to them.

Check if you are logged in

curl -X POST --insecure 'https://your-server/dns/api.php' -d 'action=is_logged' -c cookies -b cookies
{
    "is_logged": true,
    "user": "test",
    "role": "root"
}

List available zones

curl -X POST --insecure 'https://your-server/dns/api.php' -d 'action=list_zones' -c cookies -b cookies

Manipulating DNS records

Display records

curl -X POST --insecure 'https://your-server/dns/api.php' -d 'action=list_records&zone=domain.org' -c cookies -b cookies

Create a new record

curl -X POST --insecure 'https://your-server/dns/api.php' -d 'action=create_record&zone=domain.org&record=test&ttl=1&type=A&value=1.2.3.4' -c cookies -b cookies

Delete a record

When deleting a record, you need to provide all the details (value, TTL, etc.) - because it's possible to have multiple records with same name. Running delete with nsupdate without specifying all details would delete unspecified / random (probably first) record only from DNS server.

For that reason you have to explicitly specify all details.

curl -X POST --insecure 'https://your-server/dns/api.php' -d 'action=delete_record&zone=domain.org&record=test&ttl=1&type=A&value=1.2.3.4' -c cookies -b cookies

Clone this wiki locally