-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcli.js
50 lines (45 loc) · 1.39 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env node
const tlsCheck = require('./index');
const versions = require('./methods');
async function main() {
const args = process.argv.slice(2);
console.log(`Checking TLS against ${args.length} website(s)...\n`);
for (let arg of args) {
if (!arg.startsWith('http')) {
arg = 'https://' + arg;
}
let { hostname, port } = new URL(arg);
for (let version of versions) {
const res = await getFormattedResult({ hostname, port, version });
console.log(res);
}
console.log(' ');
}
}
/**
* Get the formatted result with emoji and all.
* @param {string} hostname
* @param {number} port
* @param {string} version
*/
async function getFormattedResult({ hostname, port, version }) {
let emoji = '✅'
let message = 'Enabled.';
try {
await tlsCheck({ hostname, port, version });
} catch (e) {
if (e.code === 'ERR_TLS_INVALID_PROTOCOL_VERSION') {
emoji = '🔶';
message = 'Your client had a problem. Try updating OpenSSL.';
} else if (e.code === 'ECONNRESET') {
emoji = '❌';
message = 'Disabled.';
} else {
emoji = '🤦♀️';
message = e.toString();
}
}
const origin = port ? `${hostname}:${port}` : hostname;
return `${emoji} ${origin} ${version} ${message}`;
}
main();