-
Notifications
You must be signed in to change notification settings - Fork 104
/
app.js
executable file
·137 lines (122 loc) · 3.55 KB
/
app.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env node
let Promise = require('bluebird'),
verify = Promise.promisify(require('./index.js').verify),
argv = process.argv.slice(2),
getAddressFromTextFile = require('./methods/readfromfile.js').getAddressFromTextFile,
loggerOptions = require('./logger.js').loggerOptions,
logger = require('./logger.js').logger
if (argv.length === 0) {
throw new Error('You must provide one or more email addresses.')
}
let addresses = [],
domain = null,
err_msg = null,
options = {
port : 25,
sender : 'name@example.org',
fqdn : 'mail.example.org',
concurrency: 1,
debug: false
}
//todo: code refactoring
for (var i = 0 ; i < argv.length ; i++) {
if (argv[i] === '-d') {
if (argv[++i]) {
domain = '@' + argv[i]
}
else {
err_msg = 'Malformed Domain Command'
break
}
}
else if (domain && argv[i] === '-n') {
if (argv[i + 1] && argv[i + 2]) {
var first = argv[++i],
firstletter = first.charAt(0),
last = argv[++i],
lastletter = last.charAt(0)
addresses.push(first + domain)
addresses.push(last + domain)
addresses.push(first + last + domain)
addresses.push(first + '.' + last + domain)
addresses.push(last + first + domain)
addresses.push(last + '.' + first + domain)
addresses.push(firstletter + last + domain)
addresses.push(firstletter + '.' + last + domain)
addresses.push(firstletter + lastletter + domain)
addresses.push(firstletter + domain)
addresses.push(last + firstletter + domain)
addresses.push(last + '.' + firstletter + domain)
addresses.push(first + lastletter + domain)
addresses.push(first + '.' + lastletter + domain)
}
else {
err_msg = 'Malformed Domain Command'
break
}
}
else if (domain && argv[i] === '-s') {
require('./standard.json').addresses.forEach(function (val, index, array) {
addresses.push(val + domain)
})
}
else if (argv[i] === '-sd' && argv[i+1]) {
options.sender = argv[++i]
}
else if (argv[i] === '-p' && argv[i+1] && argv[i+1] % 1 === 0) {
options.port = argv[++i]
}
else if (argv[i] === '-t' && argv[i+1] && argv[i+1] % 1 === 0) {
options.timeout = parseInt(argv[++i])
}
else if (argv[i] === '-f' && argv[i+1]) {
options.fqdn = argv[++i]
}
else if (argv[i] === '-dns' && argv[i+1]) {
options.dns = argv[++i]
}
else if (argv[i] === '-c' && argv[i+1]) {
options.concurrency = parseInt(argv[++i])
}
else if (argv[i] === '--debug' && argv[i+1]) {
options.debug = true
}
else if (domain) {
addresses.push(argv[i] + domain)
}
else if (argv[i] === '-file' || argv[i] === '--file'){
// check argv filename supplied?
if (!argv[i+1]) {
throw new Error('You must supply the path to the file.')
} else {
getAddressFromTextFile(argv[i+1])
.forEach(function (val, index, array) {
addresses.push(val)
})
break // immediately exit to prevent adding the filename itself to the addresses vars
}
}
else {
addresses.push(argv[i])
}
}
if (err_msg) {
console.log(err_msg)
}
else {
if(options.debug) {
loggerOptions.enable()
logger.info('DEBUG')
logger.info('OPTIONS: ' + JSON.stringify(options))
}
Promise.map(addresses, function(val) {
let individualOptions = Object.assign({email:val},options)
return verify(individualOptions)
.then((info) => {
console.log(info);
})
.catch((err) => {
console.log(err);
})
}, {concurrency: options.concurrency})
}