minor updates to holepunch
This commit is contained in:
parent
fe02a72e02
commit
ed4e23e924
|
@ -14,6 +14,7 @@ cli.parse({
|
|||
, 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' ]
|
||||
, token: [ false, 'Token', 'string' ]
|
||||
});
|
||||
|
||||
cli.main(function (args, options) {
|
||||
|
@ -46,6 +47,7 @@ cli.main(function (args, options) {
|
|||
, "value": options.answer
|
||||
, "type": options.type
|
||||
, "priority": options.priority
|
||||
, "token": options.token
|
||||
}
|
||||
]
|
||||
}).then(function (data) {
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
'use strict';
|
||||
|
||||
var PromiseA = require('bluebird').Promise
|
||||
, updateIp = require('./helpers/update-ip.js').update
|
||||
, request = PromiseA.promisifyAll(require('request'))
|
||||
, requestAsync = PromiseA.promisify(require('request'))
|
||||
, upnpForward = require('./helpers/upnp-forward').upnpForward
|
||||
, pmpForward = require('./helpers/pmp-forward').pmpForward
|
||||
, loopbackHttps = require('./loopback-https')
|
||||
//, checkip = require('check-ip-address')
|
||||
;
|
||||
var PromiseA = require('bluebird').Promise;
|
||||
var updateIp = require('./helpers/update-ip.js').update;
|
||||
var request = PromiseA.promisifyAll(require('request'));
|
||||
var requestAsync = PromiseA.promisify(require('request'));
|
||||
var upnpForward = require('./helpers/upnp-forward').upnpForward;
|
||||
var pmpForward = require('./helpers/pmp-forward').pmpForward;
|
||||
var loopbackHttps = require('./loopback-https');
|
||||
//var checkip = require('check-ip-address');
|
||||
|
||||
function openPort(ip, port) {
|
||||
if (!/tcp|https|http/.test(port.protocol || 'tcp')) {
|
||||
|
@ -52,7 +51,7 @@ function beacon(hostnames, ports) {
|
|||
|
||||
console.log("Updated DynDNS");
|
||||
console.log(data);
|
||||
|
||||
|
||||
ports.forEach(function (port) {
|
||||
promises.push(openPort(JSON.parse(data)[0].answers[0] || hostname, port));
|
||||
});
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
'use strict';
|
||||
|
||||
var PromiseA = require('bluebird').Promise
|
||||
, natpmp = require('nat-pmp')
|
||||
, exec = require('child_process').exec
|
||||
;
|
||||
var PromiseA = require('bluebird').Promise;
|
||||
var natpmp = require('nat-pmp');
|
||||
var exec = require('child_process').exec;
|
||||
|
||||
exports.pmpForward = function (port) {
|
||||
return new PromiseA(function (resolve, reject) {
|
||||
exec('ip route show default', function (err, stdout, stderr) {
|
||||
var gw
|
||||
;
|
||||
var gw;
|
||||
|
||||
if (err || stderr) { reject(err || stderr); return; }
|
||||
|
||||
|
||||
// default via 192.168.1.1 dev eth0
|
||||
gw = stdout.replace(/^default via (\d+\.\d+\.\d+\.\d+) dev[\s\S]+/m, '$1');
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
var PromiseA = require('bluebird').Promise
|
||||
, https = require('https')
|
||||
, fs = require('fs')
|
||||
, path = require('path')
|
||||
;
|
||||
var PromiseA = require('bluebird').Promise;
|
||||
var https = require('https');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
module.exports.update = function (opts) {
|
||||
return new PromiseA(function (resolve, reject) {
|
||||
var options
|
||||
, hostname = opts.updater || 'redirect-www.org'
|
||||
, port = opts.port || 65443
|
||||
;
|
||||
var options;
|
||||
var hostname = opts.updater || 'redirect-www.org';
|
||||
var port = opts.port || 65443;
|
||||
|
||||
options = {
|
||||
host: hostname
|
||||
|
@ -25,6 +23,11 @@ module.exports.update = function (opts) {
|
|||
, auth: opts.auth || 'admin:secret'
|
||||
, 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);
|
||||
|
||||
https.request(options, function(res) {
|
||||
|
|
|
@ -19,7 +19,7 @@ exports.upnpForward = function (port) {
|
|||
console.log('mappings');
|
||||
console.log(mappings);
|
||||
});
|
||||
|
||||
|
||||
return promitter;
|
||||
})*/;
|
||||
});
|
||||
|
@ -49,8 +49,24 @@ client.externalIp(function(err, ip) {
|
|||
});
|
||||
*/
|
||||
|
||||
if (require.main === module) {
|
||||
exports.upnpForward({ public: 65080, private: 65080, ttl: 0 }).then(function () {
|
||||
function usage() {
|
||||
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');
|
||||
}).catch(function (err) {
|
||||
console.error('ERROR');
|
||||
|
@ -58,3 +74,8 @@ if (require.main === module) {
|
|||
throw err;
|
||||
});
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
run();
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue