-
Notifications
You must be signed in to change notification settings - Fork 0
/
fast-scan.js
215 lines (197 loc) · 7.64 KB
/
fast-scan.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import helper from './helper.js'
import extraction from './extraction.js'
import async from 'async'
import sanitizeHtml from 'sanitize-html'
import {convert} from 'html-to-text'
import cheerio from 'cheerio'
import engine from './engine.js'
async function find_username_normal (req) {
helper.log_to_file_queue(req.body.uuid, '[init] Selected websites: ' + helper.websites_entries.filter((item) => item.selected === 'true').length + ' for username: ' + req.body.string)
const time = new Date()
let all_results = []
const [first_re_try, first_profiles] = await find_username_normal_wrapper(req, helper.websites_entries)
helper.verbose && console.log(`Total time ${new Date() - time}`)
const [second_re_try, second_profiles] = await find_username_normal_wrapper(req, first_re_try)
helper.verbose && console.log(`Total time ${new Date() - time}`)
const [third_re_try, third_profiles] = await find_username_normal_wrapper(req, second_re_try)
helper.verbose && console.log(`Total time ${new Date() - time}`)
if (third_re_try.length > 0) {
const failed_sites = await get_failed(req, third_re_try)
all_results = Array.prototype.concat(first_profiles, second_profiles, third_profiles, failed_sites)
} else {
all_results = Array.prototype.concat(first_profiles, second_profiles, third_profiles)
}
all_results = all_results.filter(item => item)
return all_results.sort((first, second) => {
return helper.compare_objects(first, second, 'rate')
})
}
async function get_failed (req, failed) {
const temp_result = []
try {
await failed.forEach(site => {
const temp_profile = {
link: '',
method: ''
}
temp_profile.method = 'failed'
temp_profile.username = req.body.string
temp_profile.link = site.url.replace('{username}', req.body.string)
temp_result.push(temp_profile)
})
} catch (err) {
helper.verbose && console.log(err)
}
return temp_result
}
async function find_username_normal_wrapper (req, sites) {
const results = []
const re_try = []
const functions = []
try {
const temp_sites = sites.filter(site => site.selected === 'true')
if (temp_sites.length > 0) {
await temp_sites.forEach(site => {
if (site.detections.length > 0 && !helper.global_lock.includes(req.body.uuid)) {
functions.push(find_username_site.bind(null, req.body.uuid, req.body.string, req.body.option, site))
}
})
const temp_results = await async.parallelLimit(functions, 15)
await temp_results.forEach(item => {
if (item !== undefined) {
if (item.return === 1) {
results.push(item.profile)
} else {
helper.log_to_file_queue(req.body.uuid, '[Waiting to retry] ' + helper.get_site_from_url(item.site.url))
re_try.push(item.site)
}
}
})
}
} catch (err) {
helper.verbose && console.log(err)
}
return [re_try, results]
}
async function find_username_site (uuid, username, options, site) {
return new Promise(async (resolve, reject) => {
if (!helper.global_lock.includes(uuid)) {
try {
if (!options.includes('json')) {
helper.log_to_file_queue(uuid, '[Checking] ' + helper.get_site_from_url(site.url))
}
const [ret, source] = await helper.get_url_wrapper_text(site.url.replace('{username}', username))
if (source !== 'error-get-url') {
let title = 'unavailable'
let language = 'unavailable'
const [
temp_profile,
temp_detected,
detections_count
] = await engine.detect('fast', uuid, username, options, site, source)
if (temp_profile.found >= helper.detection_level[helper.detection_level.current].found && detections_count >= helper.detection_level[helper.detection_level.current].count) {
temp_profile.good = 'true'
}
temp_profile.text = sanitizeHtml(convert(source, {
wordwrap: false,
hideLinkHrefIfSameAsText: true,
ignoreHref: true,
ignoreImage: true
}))
if (temp_profile.text === '') {
temp_profile.text = 'unavailable'
}
try {
const $ = cheerio.load(source)
title = sanitizeHtml($('title').text())
if (title.length === 0) {
title = 'unavailable'
}
} catch (err) {
helper.verbose && console.log(err)
}
try {
language = helper.get_language_by_parsing(source)
if (language === 'unavailable') {
language = helper.get_language_by_guessing(temp_profile.text)
}
} catch (err) {
helper.verbose && console.log(err)
}
temp_profile.text = temp_profile.text.replace(/(\r\n|\n|\r)/gm, '')
temp_profile.title = title.replace(/(\r\n|\n|\r)/gm, '')
temp_profile.language = language
if (helper.strings_titles.test(temp_profile.title) || helper.strings_pages.test(temp_profile.text)) {
temp_profile.title = 'filtered'
temp_profile.text = 'filtered'
}
if (temp_profile.good === 'true') {
const temp_value = ((temp_profile.found / detections_count) * 100).toFixed(2)
temp_profile.rate = '%' + temp_value
if (temp_value >= 100.00) {
temp_profile.status = 'good'
} else if (temp_value >= 50.00 && temp_value < 100.00) {
temp_profile.status = 'maybe'
} else {
temp_profile.status = 'bad'
}
}
temp_profile.username = username
temp_profile.link = site.url.replace('{username}', username)
temp_profile.type = site.type
temp_profile.rank = site.global_rank
temp_profile.country = site.country
if (temp_profile.rank === 0) {
temp_profile.rank = 'unavailable'
}
if (temp_profile.status === 'good') {
if (options.includes('ExtractPatterns')) {
let temp_extracted_list = []
temp_extracted_list = await extraction.extract_patterns(site, source)
if (temp_extracted_list.length > 0) {
temp_profile.extracted = temp_extracted_list
}
}
if (options.includes('ExtractMetadata')) {
let temp_metadata_list = []
temp_metadata_list = await extraction.extract_metadata(site, source)
if (temp_metadata_list.length > 0) {
temp_profile.metadata = temp_metadata_list
}
}
}
['title', 'language', 'text', 'type', 'metadata', 'extracted', 'country'].forEach((item) => {
if (temp_profile[item] === '') {
temp_profile[item] = 'unavailable'
}
})
if (options.includes('FindUserProfilesFast') && !options.includes('GetUserProfilesFast')) {
temp_profile.method = 'find'
} else if (options.includes('GetUserProfilesFast') && !options.includes('FindUserProfilesFast')) {
temp_profile.method = 'get'
} else if (options.includes('GetUserProfilesFast') && options.includes('FindUserProfilesFast')) {
temp_profile.method = 'all'
}
resolve({
return: 1,
site: site,
profile: temp_profile
})
} else {
resolve({
return: 0,
site: site,
profile: []
})
}
} catch (err) {
resolve(undefined)
}
} else {
resolve(undefined)
}
})
}
export default {
find_username_normal
}