Skip to content

Kartoffelbauer/gandi-record-updater

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

gandi-record-updater

A efficient zone file updater algorithm for the Gandi LiveDNS API. The program is able to update the zone files of multiple domains (and there subdomains) by passing all required informationen over the command line.

The program has been tested on Debian 10 so far, but should also run on older versions.

Once execution started, the program checks at regular intervals whether the IP address of the system has changed. If this is the case, it will automatically update the corresponding subdomains of the given domains using the corresponding API keys. The program then goes back to sleep for a configurable amount of time to unload the CPU. Thanks to highly efficient programming language C++, the program is perfect for low-performance servers such as the raspberry pi.

Goal

You don't have a static ip address, but you want your homeserver to be permanently accessible.

Requirements

Debian Packages

All you need is the tool CURL, which should already be installed on the most distributions. If not you can get it by typing sudo apt-get install curl.

API key

In order to access the zone files, the program needs to know the API key. To get such an key visit https://account.gandi.net/en/ and apply for a production key.

Installation

Download the recUpdater.cpp file from here as zip/tar.gz and extract it.

[Optional] Compiling

If you don't want to or can't use the precompiled version (e.g. diffrent architecture), you can compile the recUpdater.cpp file yourself by using the following command:

g++ recUpdater.cpp -o recUpdater.out -lstdc++fs -std=c++17 -pthread

Cleaning up

Its not required but I recommended to put the compiled file (`recUpdater.out`) in a subdirectory, such as `/opt/recUpdater/` so that everything is nice and clean.


Create corresponding directory:
sudo mkdir /opt/recUpdater

Move executable to newly created folder:
sudo mv recUpdater.out /opt/recUpdater/

Execution

With the API key ready we can now look at the syntax of the command.

Syntax: <command> -k <APIKey> -d <domain> <subdomain1> <subdomain2> subdomain...>

Parameters:

-k for specifying the API key
-d for specifying the Domain followed by all subdomains

Examples:

The following will create / update three records called www, mail and cloud for example.com:
./recUpdater.out -k L1K2X3?45D6$89G0P -d example.com www mail cloud

This will create / update two records called www and mail for example1.com and one record called cloud for example2.de:
./recUpdater.out -k L1K2X3?45D6$89G0P -d example1.com www mail -d example2.de cloud

This example will create / update one record called www for example1.com with the first API key and one record called mail for example2.de with the second API key:
./recUpdater.out -k L1K2X3?45D6$89G0P -d example1.com www -k 4LGH%$RTL5HL3D2B9CO -d example2.de mail

Start at boot

In order to automatically run the program after every system start, you have to create a service file. To do so type sudo nano /etc/systemd/system/recUpdater.service and paste the following:

[Unit]
Description=Record updater for gandi.net
After=network.target

[Service]
Type=simple
Restart=on-failure
RestartSec=120
ExecStart=/path/to/executable/recUpdater.out -k 3544558468576543 -d example.com www cloud mail

[Install]
WantedBy=multi-user.target

Replace the statement after ExecStart= with the path to the executable file, followed by all further details, as already mentioned above. Save and exit. To activate the service type sudo service enable recUpdater.service.

Configuration

Before you can configure anything, you must have successfully started the program at least once so that the configuration file has been created. To do so see Execution section. You can find the configuration file at /etc/recUpdater/recUpdater.conf. All settings in this file are self-explanatory.