evil-shrike / ddns-updater

Library for updating dynamic DNS
3 stars 0 forks source link

ddns-updater

Library for updating dynamic DNS.

NPM

The library supports the following Dynamic DNS services:

For external IP resolving it uses service:

Introduction blog post with details on how the package can be used in QNAP NAS.

Usage

var UpdaterClient = require("ddns-updater");
var config = require('./config.json');
var updater = new UpdaterClient(config);
updater.start();

where config.json:

{
    "domains" : [{
        "service"   : "namecheap",
        "name"      : "chebyrashka.guru",
        "hosts"     : ["@"],
        "settings"  : {
            "password": "1a111v11111111a1aaa11a11111111a1"
        }
    }],
    "interval"      : { "hours": 1 },
    "updateAlways"  : false
}

It makes sense to run the package via pm2 or the similar.

More advanced usage

var UpdaterClient = require("ddns-updater");
var config = { /* skipped*/ };
var updater = new UpdaterClient(config);

updater.on('ip:resolve:success', function (service, ip) {
    console.log('External IP resolved via ' + service + ' : ' + ip);
});

updater.on('ip:resolve:error', function (service, err) {
    .log('Failed to resolve external IP: ');
    console.log(err);
});

updater.on('ip:change', function (newIP, oldIP) {
    console.log("IP changed from " + oldIP + " to " + newIP);
});

updater.on('update:success', function (domain) {
    console.log("updated: " + JSON.stringify(domain));
});

updater.on('update:error', function (err, domain) {
    console.log('Failed to update IP via ' + domain.service + ':');
    console.log(err);
});

updater.start();

API

Config

domains

Type: Array
An array of objects describing a domain.
Every object in the array:

Example:

    "domains" : [{
        "service"  : "namecheap",
        "name"     : "chebyrashka.guru",
        "hosts"    : ["@", "www"],
        "settings" : {
            "password": "1a111v11111111a1aaa11a11111111a1"
        },
        "enable"   :  false
    }, {
        "service"  : "noip",
        "name"     : "my-awesome-cloud.ddns.net",
        "settings" : {
            "username": "me@google.com",
            "password": "my no-ip password"
        }
    }],

interval

Type: Object
How often to check external IP (and update if it's changed).
Value: An object in terms of interval.
Default: 1 hour
Example:

"internal": {"days": 1}

updateAlways

Type: Boolean
Default: false
true to update IP every time (once in interval), otherwise update only if IP changed.

resolver

Type: String
Default: "ipify"
Name of public IP resolve service. Currently supported:

updaters

Type: Object
An object with mapping of service name to updater class.

See Updaters below.

Events

"ip:resolve:success"

External IP was resolved. Arguments:

"ip:resolve:error"

An error occurred during IP resolving.
Arguments:

"ip:change"

External IP change was detected.
Arguments:

"update:success"

IP update successully completed.
Arguments:

"update:error"

An error occured during updating IP.
Arguments:

Updaters

Every service from config (domains[].service) is an Updater module. The tool expects every updater to implement the following API:

Resolvers

Resolver is a module loaded from resolvers folder. Module should implement the following API:

Name of resolver to use is specified in resolver config option.

Acknowledgments

The package was inspired by:

License

MIT