add client-side otp

This commit is contained in:
AJ ONeal 2018-06-13 14:48:29 -06:00
parent bff71aa813
commit d9bca46510
1 changed files with 21 additions and 22 deletions

View File

@ -124,6 +124,9 @@ function serveControls() {
}); });
} }
//
// without proper config
//
if (/\b(init|config)\b/.test(opts.pathname)) { if (/\b(init|config)\b/.test(opts.pathname)) {
var conf = {}; var conf = {};
var fresh; var fresh;
@ -214,19 +217,28 @@ function serveControls() {
return; return;
} }
// TODO check for message from remote about email listSuccess();
if (/\btelebit\.cloud\b/i.test(state.config.relay) && state.config.email && !state.token) {
res.statusCode = 200;
res.end('{"success":true,"code":"AWAIT_AUTH","message":"Check your email. You must verify your email address to activate this device."}');
} else {
res.statusCode = 200;
res.end('{"success":true}');
}
}); });
return; return;
} }
if (/restart/.test(opts.pathname)) {
tun.end();
res.end('{"success":true}');
controlServer.close(function () {
// TODO closeAll other things
process.nextTick(function () {
// system daemon will restart the process
process.exit(22); // use non-success exit code
});
});
return;
}
//
// Check for proper config
//
if (!state.config.relay || !state.config.email || !state.config.agreeTos) { if (!state.config.relay || !state.config.email || !state.config.agreeTos) {
res.statusCode = 400; res.statusCode = 400;
res.end('{"error":{"code":"E_CONFIG","message":"Invalid config file. Please run \'telebit init\'"}}'); res.end('{"error":{"code":"E_CONFIG","message":"Invalid config file. Please run \'telebit init\'"}}');
@ -368,19 +380,6 @@ function serveControls() {
return; return;
} }
if (/restart/.test(opts.pathname)) {
tun.end();
res.end('{"success":true}');
controlServer.close(function () {
// TODO closeAll other things
process.nextTick(function () {
// system daemon will restart the process
process.exit(22); // use non-success exit code
});
});
return;
}
if (/list/.test(opts.pathname)) { if (/list/.test(opts.pathname)) {
listSuccess(); listSuccess();
return; return;
@ -478,7 +477,7 @@ function connectTunnel() {
return i; return i;
} }
function getOtp() { function getOtp() {
return leftpad(Math.random() * 9999, 4, '0'); return leftpad(Math.round(Math.random() * 9999), 4, '0');
} }
process.on('SIGINT', sigHandler); process.on('SIGINT', sigHandler);
state.net = state.net || { state.net = state.net || {