Skip to content

A UNIX daemon for managing custom dnsmasq name records

Notifications You must be signed in to change notification settings

open0x20/api-dnsmasq-dynconf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

api-dnsmasq-dynconf

A service to manage dnsmasq entries/records via HTTP API.

Endpoints

Method Path Description
GET /list Returns a JSON formatted list of entries from /etc/dnsmasq.d/custom.conf
PUT /add Adds an entry to /etc/dnsmasq.d/custom.conf
POST /delete Removes an entry from /etc/dnsmasq.d/custom.conf

Every request (except /list, which is public) requires the following payload:

{
    "name": "",
    "ip": "",
    "secret": ""
}

It is also required to set the header Content-Type: application/json for all requests with a json payload. Otherwise a 400 Bad Request will be returned.

Examples

GET /list


HTTP/1.1 200 OK
{
    "addresses": [
        {
            "name": "test1.example.com",
            "ip": "127.0.0.1"
        },
        {
            "name": "test2.example.com",
            "ip": "127.0.0.2"
        },
    ]
}
PUT /add
Content-Type: application/json

{
    "name": "test3.example.com",
    "ip": "127.0.0.3",
    "secret": "ABCDEF"
}

HTTP/1.1 200 OK
POST /delete
Content-Type: application/json

{
    "name": "test3.example.com",
    "ip": "127.0.0.3",
    "secret": "ABCDEF"
}

HTTP/1.1 200 OK

Some negative examples aswell...

PUT /add
Content-Type: application/json

{
    "name": "test3.example.com",
    "ip": "127.0.0.3",
    "secret": "WRONG_SECRET"
}

HTTP/1.1 401 Unauthorized
PUT /add
Content-Type: application/json

{
    "name": "test3.example.com"
}

HTTP/1.1 400 Bad Request

Setup

The following files are required prior to startup. They will be created empty if missing:

/etc/dnsmdcd.token          # contains your secret token
/etc/dnsmasq.d/custom.conf  # create as empty file

Owner of the files should be root as the program is expecting root privileges. The service will listen on 127.0.0.1:47078. Use a reverse proxy for HTTPS.

Binaries

Precompiled binaries can be found here.

SHA256 hashes:

sha256sum -b FILE
latest/arm/dnsmdcd   - 63058372d5603b3ff5e73633d54740a030560718029c68490fef75a849394a9c
latest/armv7/dnsmdcd - 7b03e635e2ba5f93a04f1bfb6cc0778db6885eab3cddbf8f3ce01d27ed3d2296

Building

Either compile on the target itself or install a cross compiler.

Read more on cross compiling rust here.

Install the target architecture:

# RaspberryPi 2 or lower
rustup target add arm-unknown-linux-gnueabihf

# RaspberryPi 3 or higher
rustup target add armv7-unknown-linux-gnueabihf

Compile on RaspberryPi

After the architecture has been installed with rustup, simply run the following:

# For RaspberryPi 2 or lower
cargo build --release --target arm-unknown-linux-gnueabihf

# For RaspberryPi 3 or higher
cargo build --release --target armv7-unknown-linux-gnueabihf

Cross-Compiling

Install the cross-compiler (debian):

# Not tested if existent
apt install arm-linux-gnueabihf-gcc
apt install armv7-linux-gnueabihf-gcc

Install the cross-linker (debian):

TODO

Installation

Copy the dnsmdcd.service file into /etc/systemd/system/ and the binary dnsmdcd into /usr/sbin/. Then you can simply run the following commands to start/stop the service:

systemctl start dnsmdcd.service
systemctl stop dnsmdcd.service

About

A UNIX daemon for managing custom dnsmasq name records

Resources

Stars

Watchers

Forks

Releases

No releases published