move intentional user messages and client data to CLI/UI
This commit is contained in:
parent
3a8f5fee4e
commit
553c385e34
|
@ -97,6 +97,7 @@ function connectTunnel() {
|
|||
if (!state.config.sortingHat) {
|
||||
state.config.sortingHat = path.resolve(__dirname, '..', 'lib/sorting-hat.js');
|
||||
}
|
||||
// TODO sortingHat.print();
|
||||
|
||||
// TODO Check undefined vs false for greenlock config
|
||||
var tun = remote.connect({
|
||||
|
@ -107,6 +108,37 @@ function connectTunnel() {
|
|||
, net: state.net
|
||||
, insecure: state.config.relay_ignore_invalid_certificates
|
||||
, token: state.token
|
||||
, handlers: {
|
||||
grant: function (grants) {
|
||||
console.info("");
|
||||
console.info("Connect to your device by any of the following means:");
|
||||
console.info("");
|
||||
grants.forEach(function (arr) {
|
||||
if ('ssh+https' === arr[0]) {
|
||||
console.info("SSH+HTTPS");
|
||||
} else if ('ssh' === arr[0]) {
|
||||
console.info("SSH");
|
||||
} else if ('tcp' === arr[0]) {
|
||||
console.info("TCP");
|
||||
} else if ('https' === arr[0]) {
|
||||
console.info("HTTPS");
|
||||
}
|
||||
console.log('\t' + arr[0] + '://' + arr[1] + (arr[2] ? (':' + arr[2]) : ''));
|
||||
if ('ssh+https' === arr[0]) {
|
||||
console.info("\tex: ssh -o ProxyCommand='openssl s_client -connect %h:%p -quiet' " + arr[1] + " -p 443\n");
|
||||
} else if ('ssh' === arr[0]) {
|
||||
console.info("\tex: ssh " + arr[1] + " -p " + arr[2] + "\n");
|
||||
} else if ('tcp' === arr[0]) {
|
||||
console.info("\tex: netcat " + arr[1] + " " + arr[2] + "\n");
|
||||
} else if ('https' === arr[0]) {
|
||||
console.info("\tex: curl https://" + arr[1] + "\n");
|
||||
}
|
||||
});
|
||||
}
|
||||
, access_token: function (jwt) {
|
||||
console.info("Received updated access_token:", jwt);
|
||||
}
|
||||
}
|
||||
, greenlockConfig: {
|
||||
version: state.greenlock.version || 'draft-11'
|
||||
, server: state.greenlock.server || 'https://acme-v02.api.letsencrypt.org/directory'
|
||||
|
|
|
@ -217,32 +217,9 @@ function _connect(state) {
|
|||
});
|
||||
}
|
||||
|
||||
function displayGrants(grants) {
|
||||
// TODO sortingHat.print();
|
||||
console.log("");
|
||||
console.log("Connect to your device by any of the following means:");
|
||||
console.log("");
|
||||
grants.forEach(function (arr) {
|
||||
if ('ssh+https' === arr[0]) {
|
||||
console.log("SSH+HTTPS");
|
||||
} else if ('ssh' === arr[0]) {
|
||||
console.log("SSH");
|
||||
} else if ('tcp' === arr[0]) {
|
||||
console.log("TCP");
|
||||
} else if ('https' === arr[0]) {
|
||||
console.log("HTTPS");
|
||||
}
|
||||
console.log('\t' + arr[0] + '://' + arr[1] + (arr[2] ? (':' + arr[2]) : ''));
|
||||
if ('ssh+https' === arr[0]) {
|
||||
console.log("\tex: ssh -o ProxyCommand='openssl s_client -connect %h:%p -quiet' " + arr[1] + " -p 443\n");
|
||||
} else if ('ssh' === arr[0]) {
|
||||
console.log("\tex: ssh " + arr[1] + " -p " + arr[2] + "\n");
|
||||
} else if ('tcp' === arr[0]) {
|
||||
console.log("\tex: netcat " + arr[1] + " " + arr[2] + "\n");
|
||||
} else if ('https' === arr[0]) {
|
||||
console.log("\tex: curl https://" + arr[1] + "\n");
|
||||
}
|
||||
});
|
||||
function noHandler(cmd) {
|
||||
console.warn("[telebit] state.handlers['" + cmd[1] + "'] not set");
|
||||
console.warn(cmd[2]);
|
||||
}
|
||||
|
||||
var connCallback;
|
||||
|
@ -287,7 +264,19 @@ function _connect(state) {
|
|||
err = null;
|
||||
} else if (cmd[1] === 'grant') {
|
||||
authenticated = true;
|
||||
displayGrants(cmd[2]);
|
||||
if (state.handlers[cmd[1]]) {
|
||||
state.handlers[cmd[1]](cmd[2]);
|
||||
} else {
|
||||
noHandler(cmd);
|
||||
}
|
||||
return;
|
||||
} else if (cmd[1] === 'access_token') {
|
||||
authenticated = true;
|
||||
if (state.handlers[cmd[1]]) {
|
||||
state.handlers[cmd[1]](cmd[2]);
|
||||
} else {
|
||||
noHandler(cmd);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
err = { message: 'unknown command "'+cmd[1]+'"', code: 'E_UNKNOWN_COMMAND' };
|
||||
|
|
Loading…
Reference in New Issue