From d40e86cc56bf5d352f00da459ffb89f0d5147e28 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 13 Jun 2018 11:18:54 -0600 Subject: [PATCH] update question asking, fix some config stuff --- bin/telebit.js | 33 +++++++++++++++++++++++++++++++-- bin/telebitd.js | 8 +++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/bin/telebit.js b/bin/telebit.js index ee925a7..12208b8 100644 --- a/bin/telebit.js +++ b/bin/telebit.js @@ -117,6 +117,7 @@ function askForConfig(answers, mainCb) { console.info(""); // TODO attempt to read email from npmrc or the like? rl.question('email: ', function (email) { + email = /@/.test(email) && email.trim(); if (!email) { askEmail(cb); return; } answers.email = email.trim(); answers.agree_tos = true; @@ -170,7 +171,30 @@ function askForConfig(answers, mainCb) { } ]; var standardSet = [ - function askNewsletter(cb) { + function askUpdates(cb) { + var options = [ 'newsletter', 'important', 'required' ]; + if (-1 !== options.indexOf(answers.updates)) { cb(); return; } + console.info(""); + console.info(""); + console.info("What updates would you like to receive? (" + options.join(',') + ")"); + console.info(""); + rl.question('email preference (default: important): ', function (updates) { + updates = (updates || '').trim().toLowerCase(); + if (!updates) { updates = 'important'; } + if (-1 === options.indexOf(updates)) { askUpdates(cb); return; } + + if ('newsletter' === updates) { + answers.newsletter = true; + answers.communityMember = true; + } else if ('important' === updates) { + answers.communityMember = true; + } + + setTimeout(cb, 250); + }); + } + /* + , function askNewsletter(cb) { if (answers.newsletter) { cb(); return; } console.info(""); console.info(""); @@ -196,6 +220,7 @@ function askForConfig(answers, mainCb) { setTimeout(cb, 250); }); } + */ , function askTelemetry(cb) { if (answers.telemetry) { cb(); return; } console.info(""); @@ -280,7 +305,11 @@ function askForConfig(answers, mainCb) { function next() { var q = nextSet.shift(); - if (!q) { if (useTty) { stdin.close(); } rl.close(); mainCb(null, answers); return; } + if (!q) { + if (useTty) { stdin.end(); stdin.close(); } + rl.close(); mainCb(null, answers); + return; + } q(next); } diff --git a/bin/telebitd.js b/bin/telebitd.js index 4e31983..34260b9 100755 --- a/bin/telebitd.js +++ b/bin/telebitd.js @@ -75,8 +75,10 @@ var controlServer; var tun; function serveControls() { - if (!state.config.disable && state.config.relay && (state.config.token || state.config.agreeTos)) { - tun = rawTunnel(); + if (!state.config.disable) { + if (state.config.relay && (state.config.token || state.config.agreeTos)) { + tun = rawTunnel(); + } } controlServer = http.createServer(function (req, res) { var opts = url.parse(req.url, true); @@ -116,7 +118,7 @@ function serveControls() { }); } - if (/\binit\b/.test(opts.path)) { + if (/\b(init|config)\b/.test(opts.path)) { var conf = {}; var fresh; if (!opts.body) {