2015-02-19 22:08:33 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-02-20 22:34:39 +00:00
|
|
|
console.log('\n\n\nWelcome to WALNUT!');
|
|
|
|
|
2015-02-19 06:06:56 +00:00
|
|
|
//var config = require('./device.json');
|
|
|
|
var securePort = process.argv[2] || 443;
|
|
|
|
var insecurePort = process.argv[3] || 80;
|
|
|
|
var redirects = require('./redirects.json');
|
|
|
|
var path = require('path');
|
2015-02-12 09:40:37 +00:00
|
|
|
|
2015-02-19 06:06:56 +00:00
|
|
|
// force SSL upgrade server
|
|
|
|
var certsPath = path.join(__dirname, 'certs');
|
|
|
|
// require('ssl-root-cas').inject();
|
|
|
|
var vhostsdir = path.join(__dirname, 'vhosts');
|
2015-02-12 09:40:37 +00:00
|
|
|
|
2015-02-19 22:08:33 +00:00
|
|
|
function phoneHome() {
|
|
|
|
var holepunch = require('./holepunch/beacon');
|
|
|
|
var ports;
|
2015-02-19 06:06:56 +00:00
|
|
|
|
|
|
|
ports = [
|
2015-02-19 22:08:33 +00:00
|
|
|
{ private: 65022
|
|
|
|
, public: 65022
|
2015-02-19 06:06:56 +00:00
|
|
|
, protocol: 'tcp'
|
|
|
|
, ttl: 0
|
|
|
|
, test: { service: 'ssh' }
|
|
|
|
, testable: false
|
|
|
|
}
|
2015-02-19 22:08:33 +00:00
|
|
|
, { private: 650443
|
|
|
|
, public: 650443
|
2015-02-19 06:06:56 +00:00
|
|
|
, protocol: 'tcp'
|
|
|
|
, ttl: 0
|
|
|
|
, test: { service: 'https' }
|
|
|
|
}
|
2015-02-19 22:08:33 +00:00
|
|
|
, { private: 65080
|
|
|
|
, public: 65080
|
2015-02-19 06:06:56 +00:00
|
|
|
, protocol: 'tcp'
|
|
|
|
, ttl: 0
|
|
|
|
, test: { service: 'http' }
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
// TODO return a middleware
|
|
|
|
holepunch.run(require('./redirects.json').reduce(function (all, redirect) {
|
|
|
|
if (!all[redirect.from.hostname]) {
|
|
|
|
all[redirect.from.hostname] = true;
|
|
|
|
all.push(redirect.from.hostname)
|
|
|
|
}
|
|
|
|
if (!all[redirect.to.hostname]) {
|
|
|
|
all[redirect.to.hostname] = true;
|
|
|
|
all.push(redirect.to.hostname)
|
|
|
|
}
|
|
|
|
|
|
|
|
return all;
|
|
|
|
}, []), ports).catch(function () {
|
|
|
|
console.error("Couldn't phone home. Oh well");
|
|
|
|
});
|
2015-02-19 22:08:33 +00:00
|
|
|
}
|
|
|
|
require('./lib/insecure-server').create(securePort, insecurePort, redirects);
|
2015-02-20 21:21:37 +00:00
|
|
|
require('./lib/vhost-sni-server.js').create(securePort, certsPath, vhostsdir)
|
|
|
|
//.then(phoneHome)
|
|
|
|
;
|