minor updates to holepunch

This commit is contained in:
AJ ONeal 2015-08-14 17:00:28 +00:00
parent fe02a72e02
commit ed4e23e924
5 changed files with 78 additions and 29 deletions

View File

@ -14,6 +14,7 @@ cli.parse({
, insecure: [ false, '(deprecated) allow insecure non-https connections', 'boolean' ] , insecure: [ false, '(deprecated) allow insecure non-https connections', 'boolean' ]
, cacert: [ false, '(not implemented) specify a CA for "self-signed" https certificates', 'string' ] , cacert: [ false, '(not implemented) specify a CA for "self-signed" https certificates', 'string' ]
, answer: [ 'a', 'The answer', 'string' ] , answer: [ 'a', 'The answer', 'string' ]
, token: [ false, 'Token', 'string' ]
}); });
cli.main(function (args, options) { cli.main(function (args, options) {
@ -46,6 +47,7 @@ cli.main(function (args, options) {
, "value": options.answer , "value": options.answer
, "type": options.type , "type": options.type
, "priority": options.priority , "priority": options.priority
, "token": options.token
} }
] ]
}).then(function (data) { }).then(function (data) {

View File

@ -1,14 +1,13 @@
'use strict'; 'use strict';
var PromiseA = require('bluebird').Promise var PromiseA = require('bluebird').Promise;
, updateIp = require('./helpers/update-ip.js').update var updateIp = require('./helpers/update-ip.js').update;
, request = PromiseA.promisifyAll(require('request')) var request = PromiseA.promisifyAll(require('request'));
, requestAsync = PromiseA.promisify(require('request')) var requestAsync = PromiseA.promisify(require('request'));
, upnpForward = require('./helpers/upnp-forward').upnpForward var upnpForward = require('./helpers/upnp-forward').upnpForward;
, pmpForward = require('./helpers/pmp-forward').pmpForward var pmpForward = require('./helpers/pmp-forward').pmpForward;
, loopbackHttps = require('./loopback-https') var loopbackHttps = require('./loopback-https');
//, checkip = require('check-ip-address') //var checkip = require('check-ip-address');
;
function openPort(ip, port) { function openPort(ip, port) {
if (!/tcp|https|http/.test(port.protocol || 'tcp')) { if (!/tcp|https|http/.test(port.protocol || 'tcp')) {
@ -52,7 +51,7 @@ function beacon(hostnames, ports) {
console.log("Updated DynDNS"); console.log("Updated DynDNS");
console.log(data); console.log(data);
ports.forEach(function (port) { ports.forEach(function (port) {
promises.push(openPort(JSON.parse(data)[0].answers[0] || hostname, port)); promises.push(openPort(JSON.parse(data)[0].answers[0] || hostname, port));
}); });

View File

@ -1,18 +1,16 @@
'use strict'; 'use strict';
var PromiseA = require('bluebird').Promise var PromiseA = require('bluebird').Promise;
, natpmp = require('nat-pmp') var natpmp = require('nat-pmp');
, exec = require('child_process').exec var exec = require('child_process').exec;
;
exports.pmpForward = function (port) { exports.pmpForward = function (port) {
return new PromiseA(function (resolve, reject) { return new PromiseA(function (resolve, reject) {
exec('ip route show default', function (err, stdout, stderr) { exec('ip route show default', function (err, stdout, stderr) {
var gw var gw;
;
if (err || stderr) { reject(err || stderr); return; } if (err || stderr) { reject(err || stderr); return; }
// default via 192.168.1.1 dev eth0 // default via 192.168.1.1 dev eth0
gw = stdout.replace(/^default via (\d+\.\d+\.\d+\.\d+) dev[\s\S]+/m, '$1'); gw = stdout.replace(/^default via (\d+\.\d+\.\d+\.\d+) dev[\s\S]+/m, '$1');
console.log('Possible PMP gateway is', gw); console.log('Possible PMP gateway is', gw);
@ -55,3 +53,29 @@ exports.pmpForward = function (port) {
}); });
}); });
}; };
function usage() {
console.warn("");
console.warn("node helpers/pmp-forward [public port] [private port] [ttl]");
console.warn("");
}
function run() {
var pubPort = parseInt(process.argv[2], 10) || 0;
var privPort = parseInt(process.argv[3], 10) || pubPort;
var ttl = parseInt(process.argv[4], 10) || 0;
var options = { public: pubPort, private: privPort, ttl: ttl };
if (!pubPort) {
usage();
return;
}
exports.pmpForward(options).then(function () {
console.log('done');
});
}
if (require.main === module) {
run();
}

View File

@ -1,18 +1,16 @@
#!/usr/bin/env node #!/usr/bin/env node
'use strict'; 'use strict';
var PromiseA = require('bluebird').Promise var PromiseA = require('bluebird').Promise;
, https = require('https') var https = require('https');
, fs = require('fs') var fs = require('fs');
, path = require('path') var path = require('path');
;
module.exports.update = function (opts) { module.exports.update = function (opts) {
return new PromiseA(function (resolve, reject) { return new PromiseA(function (resolve, reject) {
var options var options;
, hostname = opts.updater || 'redirect-www.org' var hostname = opts.updater || 'redirect-www.org';
, port = opts.port || 65443 var port = opts.port || 65443;
;
options = { options = {
host: hostname host: hostname
@ -25,6 +23,11 @@ module.exports.update = function (opts) {
, auth: opts.auth || 'admin:secret' , auth: opts.auth || 'admin:secret'
, ca: [ fs.readFileSync(path.join(__dirname, '..', 'certs', 'ca', 'my-root-ca.crt.pem')) ] , ca: [ fs.readFileSync(path.join(__dirname, '..', 'certs', 'ca', 'my-root-ca.crt.pem')) ]
}; };
if (opts.jwt) {
options.headers['Authorization'] = 'Bearer ' + opts.jwt;
}
options.agent = new https.Agent(options); options.agent = new https.Agent(options);
https.request(options, function(res) { https.request(options, function(res) {

View File

@ -19,7 +19,7 @@ exports.upnpForward = function (port) {
console.log('mappings'); console.log('mappings');
console.log(mappings); console.log(mappings);
}); });
return promitter; return promitter;
})*/; })*/;
}); });
@ -49,8 +49,24 @@ client.externalIp(function(err, ip) {
}); });
*/ */
if (require.main === module) { function usage() {
exports.upnpForward({ public: 65080, private: 65080, ttl: 0 }).then(function () { console.warn("");
console.warn("node helpers/upnp-forward [public port] [private port] [ttl]");
console.warn("");
}
function run() {
var pubPort = parseInt(process.argv[2], 10) || 0;
var privPort = parseInt(process.argv[3], 10) || pubPort;
var ttl = parseInt(process.argv[4], 10) || 0;
var options = { public: pubPort, private: privPort, ttl: ttl };
if (!pubPort) {
usage();
return;
}
exports.upnpForward(options).then(function () {
console.log('done'); console.log('done');
}).catch(function (err) { }).catch(function (err) {
console.error('ERROR'); console.error('ERROR');
@ -58,3 +74,8 @@ if (require.main === module) {
throw err; throw err;
}); });
} }
if (require.main === module) {
run();
return;
}