Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ var fs = require("fs"),

var settings = JSON.parse(fs.readFileSync("./settings.json"));

var lookup = new Lookup(settings.currentIP);
var lookup = new Lookup(settings.CURRENT_IP);
var dns = new DNSimple(settings);

// the update event is fired when there is a mismatch of
// IP addresses
lookup.on('update', function(public_ip) {
writeln("IP address mismatch:");
writeln("\tCurrent IP: " + settings.currentIP);
writeln("\tCurrent IP: " + settings.CURRENT_IP);
writeln("\t Public IP: " + public_ip);
writeln("Updating record...");

Expand All @@ -29,7 +29,7 @@ dns.on('updated', function(data) {
writeln("Domain IP updated successfully.");

var parentRecord = JSON.parse(data);
settings.currentIP = parentRecord.record.content;
settings.CURRENT_IP = parentRecord.record.content;

writeln("Updating local settings...");

Expand Down
29 changes: 10 additions & 19 deletions lib/dnsimple.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,32 @@ var DNSimple = function(settings) {

DNSimple.prototype = new events.EventEmitter();

// Builds the token used for authenticating to the DNSimple API
DNSimple.prototype.token = function() {
return dnsimple.settings.username + ":" + dnsimple.settings.token
}

// updates the IP of the domain specified in the
// settings file
// updates the IP of the domain specified in the settings file
DNSimple.prototype.update = function(new_ip) {
var dnsimple = this;

var path = "/domains/" + dnsimple.settings.domain + "/records/" + dnsimple.settings.recordID;
var path = `/v2/${dnsimple.settings.ACCOUNT_ID}/zones/${dnsimple.settings.DNS_ZONE_ID}/records/${dnsimple.settings.DNS_RECORD_ID}`

var record = JSON.stringify({
record: {
content: new_ip,
ttl: 86400
}
});

dnsimple.put(path, record);
dnsimple.patch(path, record);
}

// put is a convience method for sending an HTTP PUT
// statement.
DNSimple.prototype.put = function(path, data) {
// patch is a convience method for sending an HTTP PATCH statement.
DNSimple.prototype.patch = function(path, data) {
dnsimple = this;

var options = {
host : "dnsimple.com",
host : "api.dnsimple.com",
path: path,
method : "PUT",
method : "PATCH",
headers : {
"Authorization": `Bearer ${dnsimple.settings.AUTH_TOKEN}`,
"Accept" : "application/json",
"Content-Type": "application/json",
"X-DNSimple-Token" : dnsimple.token(),
"Content-Length" : data.length
}
};
Expand All @@ -56,9 +47,9 @@ DNSimple.prototype.put = function(path, data) {
var status = res.statusCode;
res.on("data", function(d) {
if( status == 200 ) {
dnsimple.emit("updated", d);
dnsimple.emit("updated");
} else {
dnsimple.emit("error", d);
dnsimple.emit("error");
}
});
});
Expand Down
12 changes: 6 additions & 6 deletions settings.json.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"currentIP": "0.0.0.0",
"username": "[email protected]",
"token": "your api token",
"domain": "example.com",
"recordID": "123456"
}
"CURRENT_IP": "1.1.1.1",
"ACCOUNT_ID": 123456,
"DNS_ZONE_ID": "domain.com",
"DNS_RECORD_ID": 123456,
"AUTH_TOKEN": "ABCXYZ"
}