-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
48 lines (44 loc) · 1.79 KB
/
index.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
var Analyzer = require('./lib/analyzer');
var analyzer = new Analyzer();
var formatter = require('./lib/formatter');
module.exports = function sslCheckDroid() {
return {
sslCheck: function sslCheck(req, res) {
var droid = this;
analyzer.checkSite(req.params.url, req.params.startNew)
.then(function checkSiteCompleted(data) {
if (data.status !== 'READY') {
// Continue polling status
delete req.params.startNew;
return setTimeout(function timeoutCheckSite() {
res.text('_Continuing SSL analysis for ' + req.params.url + ' - Status:_ `' + data.status + '`').send();
droid.sslCheck(req, res);
}, 60000);
}
// Analysis complete - Retrieve endpoints information
return analyzer.getDetailedReport(req.params.url, data)
.then(function detailedReportCompleted(report) {
var attachment = formatter.sslcheck(report);
if (req.params.channel && attachment.color === 'danger') {
res.attachment(attachment, req.params.channel);
}
return res.attachment(attachment).send();
})
.catch(function detailedReportError(err) {
return res.text('An error has occurred while trying to exeucte a SSL check.\n```' + err + '```').send();
});
})
.catch(function checkSiteError(err) {
return res.text('An error has occurred while trying to exeucte a SSL check.\n```' + err + '```').send();
});
},
newSslCheck: function newSslCheck(req, res) {
req.params.startNew = true;
this.sslCheck(req, res);
},
sslAlert: function sslAlert(req, res) {
req.params.startNew = true;
this.sslCheck(req, res);
}
};
};