walnut.js/ddns-client.js

78 lines
2.5 KiB
JavaScript
Raw Normal View History

2015-02-12 17:24:30 +00:00
#!/usr/bin/env node
'use strict';
// dig -p 53 @redirect-www.org pi.nadal.daplie.com A
var updateIp = require('./holepunch/helpers/update-ip.js').update;
var cli = require('cli');
cli.parse({
2015-11-20 22:24:18 +00:00
service: [ 's', 'The service to use for updates i.e. ns1.example.org', 'string' ]
2015-02-12 17:24:30 +00:00
, hostname: [ 'h', 'The hostname you wish to update i.e. example.com', 'string' ]
2015-11-23 09:31:17 +00:00
, pathname: [ false, 'The api route to which to POST i.e. /api/ddns', 'string', '/api/com.daplie.dns/ddns' ]
2015-11-20 22:24:18 +00:00
, type: [ 't', 'The record type i.e. A, AAAA, MX, CNAME, ANAME, FWD, etc', 'string', 'A' ]
2015-02-12 17:24:30 +00:00
, priority: [ 'p', 'The priority (for MX and other records)', 'string' ]
, port: [ false, 'The port (default https/443)', 'number', 443 ]
, insecure: [ false, '(deprecated) allow insecure non-https connections', 'boolean' ]
, cacert: [ false, '(not implemented) specify a CA for "self-signed" https certificates', 'string' ]
, answer: [ 'a', 'The answer', 'string' ]
2015-09-25 08:07:08 +00:00
, token: [ false, 'Token (TODO or filepath to token)', 'string' ]
2015-02-12 17:24:30 +00:00
});
cli.main(function (args, options) {
//console.log(options);
2015-11-20 22:24:18 +00:00
options.hostname = options.hostname || args[0];
options.answer = options.answer || args[1];
2015-02-12 17:24:30 +00:00
if (options.insecure) {
2015-09-25 08:07:08 +00:00
//console.error('--insecure is not supported. You must use secure connections.');
//return;
options.cacert = false;
2015-02-12 17:24:30 +00:00
}
if (!options.hostname) {
console.error('Usage: ddns-client HOSTNAME ANSWER -t A -s updater.mydns.com');
console.error('Example: ddns-client example.com');
console.error('Note: if you omit ANSWER, it is assumed that the dyndns service will use the request ip');
return;
}
//console.log('args');
//console.log(args);
//console.log(options);
return updateIp({
2015-11-20 22:24:18 +00:00
hostname: options.service
, updater: options.service
2015-02-12 17:24:30 +00:00
, port: options.port
, cacert: options.cacert
2015-11-20 22:24:18 +00:00
, pathname: options.pathname
2015-09-25 08:07:08 +00:00
, token: options.token
2015-02-12 17:24:30 +00:00
, ddns: [
{ "name": options.hostname
, "value": options.answer
, "type": options.type
2015-02-14 09:14:05 +00:00
, "priority": options.priority
2015-11-23 09:31:17 +00:00
, "token": options.token // device should go here?
//, "ttl": options.ttl
//, "device": ''
2015-02-12 17:24:30 +00:00
}
]
}).then(function (data) {
if ('string') {
2015-09-25 08:07:08 +00:00
try {
data = JSON.parse(data);
} catch(e) {
console.error(data);
}
2015-02-12 17:24:30 +00:00
}
console.log(JSON.stringify(data, null, ' '));
console.log('Test with');
console.log('dig ' + options.hostname + ' ' + options.type);
2015-11-23 09:31:17 +00:00
}, function (err) {
console.error('[DDNS CLIENT]');
console.error(err.stack);
console.error(err.data);
2015-10-05 19:51:58 +00:00
});
2015-02-12 17:24:30 +00:00
});