From fb0505881eb7cda9c2d6e33ae9ddc460c0d623d9 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 12 Feb 2015 17:24:30 +0000 Subject: [PATCH] add ddns-client --- ddns-client.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 12 +++++----- 2 files changed, 65 insertions(+), 6 deletions(-) create mode 100755 ddns-client.js diff --git a/ddns-client.js b/ddns-client.js new file mode 100755 index 0000000..07bc306 --- /dev/null +++ b/ddns-client.js @@ -0,0 +1,59 @@ +#!/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({ + service: [ 's', 'The service to use for updates i.e. redirect-www.org', 'string', 'redirect-www.org' ] +, hostname: [ 'h', 'The hostname you wish to update i.e. example.com', 'string' ] +, type: [ 't', 'The record type i.e. A, MX, CNAME, etc', 'string', 'A' ] +, 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' ] +}); + +cli.main(function (args, options) { + //console.log(options); + options.hostname = options.hostname || args[0] + options.answer = options.answer || args[1] + + if (options.insecure) { + console.error('--insecure is not supported. You must use secure connections.'); + return; + } + + 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({ + updater: options.service + , port: options.port + , cacert: options.cacert + , ddns: [ + { "name": options.hostname + , "value": options.answer + , "type": options.type + } + ] + }).then(function (data) { + if ('string') { + data = JSON.parse(data); + } + + console.log(JSON.stringify(data, null, ' ')); + console.log('Test with'); + console.log('dig ' + options.hostname + ' ' + options.type); + }) +}); diff --git a/package.json b/package.json index 072b7eb..0f2cd8a 100644 --- a/package.json +++ b/package.json @@ -37,14 +37,14 @@ }, "homepage": "https://github.com/Daplie/walnut", "dependencies": { - "bluebird": "^2.9.6", - "connect": "^3.3.4", - "foreachasync": "^5.0.5", - "ssl-root-cas": "^1.1.7", - "vhost": "^3.0.0", "bluebird": "^2.9.3", "check-ip-address": "^1.0.0", + "cli": "^0.6.5", + "connect": "^3.3.4", "express": "^4.11.2", - "request": "^2.51.0" + "foreachasync": "^5.0.5", + "request": "^2.51.0", + "ssl-root-cas": "^1.1.7", + "vhost": "^3.0.0" } }