forked from qeeqbox/social-analyzer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
1164 lines (1083 loc) · 37.7 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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// __G__ = "(G)bd249ce4"
// app.js (API, CLI & WEBAPP)
//
var google_api_key = "";
var google_api_cs = "";
var header_options = {
headers: {
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0',
}
};
console.log('[!] Detections are updated every often, make sure to get the most updated ones');
var semver = require('semver');
if (semver.satisfies(process.version, '>13 || <13')) {
console.log('[Good] NodeJS Version Check');
} else {
console.log('[Error] NodeJS Version Check');
process.exit(1);
}
var argv = require('yargs')
.alias('c', 'cli')
.alias('u', 'user')
.alias('w', 'website')
.alias('o', 'output')
.alias('l', 'list')
.alias('m','mode')
.usage('Usage: $0 -c -m "mode" -u "user" -w "website[s]" -o "output"')
.example('$0 -c -m "fast" -u "joe" -w "facebook"')
.example('$0 -c -m "fast" -u "natalie" -w "facebook wordpress"')
.describe('u', 'a user or stirng')
.describe('w', 'a website or websites sparated with space')
.describe('o', 'option output file')
.describe('l', 'list all available websites')
.describe('m', 'fast -> FindUserProfilesFast\nslow -> FindUserProfilesSlow\nspecial -> FindUserProfilesSpecial')
.help('h')
.alias('h', 'help')
.argv;
var tmp = require("tmp");
var express = require("express");
var fs = require("fs");
var tokenizer = require("wink-tokenizer");
var axios = require("axios")
var WordsNinjaPack = require("wordsninja");
var generatorics = require("generatorics");
var {
findWord
} = require("most-common-words-by-language");
var tesseract = require("node-tesseract-ocr");
var url = require("url");
var sanitizeHtml = require("sanitize-html");
var firefox = require("selenium-webdriver/firefox");
var {
Builder,
By
} = require("selenium-webdriver");
var util = require('util');
var https = require("follow-redirects").https;
var async = require("async");
var PrettyError = require('pretty-error');
var pe = new PrettyError();
require('express-async-errors');
//var jsdom = require('jsdom');
//var dom = new jsdom.JSDOM();
//var window = dom.window;
//var document = window.document;
//var $ = require('jquery')(window);
const {
htmlToText
} = require('html-to-text');
var _tokenizer = tokenizer();
var parsed_json = JSON.parse(fs.readFileSync("dict.json"));
var parsed_sites = JSON.parse(fs.readFileSync("sites.json"));
var app = express();
var WordsNinja = new WordsNinjaPack();
app.use(express.urlencoded({
extended: true
}));
app.use(express.json());
app.use(express.static("public"));
if (!fs.existsSync('logs')) {
fs.mkdirSync('logs');
}
var logs_queue = Promise.resolve();
function log_to_file_queue(uuid, msg) {
logs_queue = logs_queue.then(function() {
return new Promise(function(resolve) {
fs.appendFile("logs/" + uuid + "_log.txt", msg + "\n", function(err, data) {
console.log(msg)
resolve();
});
});
});
}
app.post("/get_logs", async function(req, res, next) {
var last_line = "nothinghere"
if (req.body.uuid != "") {
req.body.uuid = req.body.uuid.replace(/[^a-zA-Z0-9\-]+/g, '');
var data = fs.readFileSync("logs/" + req.body.uuid + "_log.txt").toString();
if (typeof data !== 'undefined' && data) {
last_line = data.split('\n').slice(-2)[0];
}
res.send(last_line)
}
})
function get_site_from_url(_url) {
temp = url.parse(_url.replace("{username}", "nothinghere")).hostname
return temp.replace("nothinghere.", "")
}
async function find_username_special(req) {
const time = new Date();
const functions = [];
parsed_sites.forEach((site) => {
if ("status" in site) {
if (site.status == "bad") {
return Promise.resolve();
}
}
if ("name" in site) {
if (site.name == "facebook") {
if (site.selected == "true") {
functions.push(find_username_site_special_facebook_1.bind(null, req.body.uuid, req.body.string, site));
}
}
}
});
const results = await async.parallelLimit(functions, 5);
console.log(`Total time ${new Date() - time}`);
return results.filter(item => item !== undefined)
}
async function find_username_site_special_facebook_1(uuid, username, site) {
return new Promise(async (resolve, reject) => {
log_to_file_queue(uuid, "[Checking] " + get_site_from_url(site.url))
let driver = new Builder()
.forBrowser("firefox")
.setFirefoxOptions(new firefox.Options().headless().windowSize({
width: 640,
height: 480
}))
.build();
try {
var timeouts = {
implicit: 0,
pageLoad: 10000,
script: 10000
};
var source = "";
var data = "";
var text_only = "unavailable";
var title = "unavailable";
var temp_profile = {
"found": 0,
"image": "",
"link": "",
"rate": "",
"title": "",
"text": "",
"type":""
};
var link = "https://mbasic.facebook.com/login/identify/?ctx=recoveqr";
await driver.manage().setTimeouts(timeouts);
await driver.get(link);;
await driver.findElement(By.id('identify_search_text_input')).sendKeys(username);
await driver.findElement(By.id('did_submit')).click();
source = await driver.getPageSource();
text_only = await driver.findElement(By.tagName("body")).getText();
await driver.quit()
if (source.includes("Try Entering Your Password")) {
temp_found = "true";
temp_profile.found += 1
}
if (temp_profile.found > 0) {
temp_profile.text = "unavailable";
temp_profile.title = "unavailable";
temp_profile.rate = "%" + ((temp_profile.found / 1) * 100).toFixed(2);
temp_profile.link = site.url.replace("{username}", username);
temp_profile.type = site.type
resolve(temp_profile);
} else {
resolve(undefined)
}
} catch (err) {
if (driver !== undefined) {
try {
await driver.quit()
} catch (err) {
console.log("Driver Session Issue")
}
}
resolve(undefined)
}
});
}
async function find_username_advanced(req) {
const time = new Date();
const functions = [];
parsed_sites.forEach((site) => {
if ("status" in site) {
if (site.status == "bad") {
return Promise.resolve();
}
}
if (site.selected == "true" && site.detections.length > 0) {
functions.push(find_username_site_new.bind(null, req.body.uuid, req.body.string, req.body.option, site));
}
});
const results = await async.parallelLimit(functions, 5);
console.log(`Total time ${new Date() - time}`);
return results.filter(item => item !== undefined)
}
async function find_username_site_new(uuid, username, options, site) {
return new Promise(async (resolve, reject) => {
log_to_file_queue(uuid, "[Checking] " + get_site_from_url(site.url))
let driver = new Builder()
.forBrowser("firefox")
.setFirefoxOptions(new firefox.Options().headless().windowSize({
width: 640,
height: 480
}))
.build();
try {
var timeouts = {
implicit: 0,
pageLoad: 5000,
script: 5000
};
var timeout = (site.timeout != 0) ? site.timeout * 1000 : 5000;
var implicit = (site.implicit != 0) ? site.implicit * 1000 : 0;
timeouts = {
implicit: implicit,
pageLoad: timeout,
script: timeout
};
console.log(timeouts)
var source = "";
var data = "";
var text_only = "unavailable";
var title = "unavailable";
var temp_profile = {
"found": 0,
"image": "",
"link": "",
"rate": "",
"title": "",
"text": "",
"type":""
};
var link = site.url.replace("{username}", username);
await driver.manage().setTimeouts(timeouts);
await driver.get(link);;
source = await driver.getPageSource();
data = await driver.takeScreenshot();
title = await driver.getTitle();
text_only = await driver.findElement(By.tagName("body")).getText();
await driver.quit()
if (options.includes("ShowUserProfilesSlow")) {
temp_profile["image"] = "data:image/png;base64,{image}".replace("{image}", data);
}
if (site.selected == "true" && site.detections.length > 0 && options.includes("FindUserProfilesSlow")) {
await Promise.all(site.detections.map(async detection => {
try {
if ("status" in detection) {
if (detection.status == "bad") {
return;
}
}
var temp_found = "false"
if (detection.type == "ocr" && data != "") {
tmpobj = tmp.fileSync();
fs.writeFileSync(tmpobj.name, Buffer.from(data, "base64"));
await tesseract.recognize(tmpobj.name, {
lang: "eng",
oem: 1,
psm: 3,
})
.then(text => {
text = text.replace(/[^A-Za-z0-9]/gi, "");
detection.string = detection.string.replace(/[^A-Za-z0-9]/gi, "");
if (text != "") {
if (text.toLowerCase().includes(detection.string.toLowerCase())) {
temp_found = "true";
}
if (detection.return == temp_found) {
//console.log(text);
//console.log(detection.string," > Found ocr");
temp_profile.found += 1;
}
}
})
.catch(error => {
console.log(error.message);
})
tmpobj.removeCallback();
} else if (detection.type == "normal" && source != "") {
if (source.toLowerCase().includes(detection.string.replace("{username}", username).toLowerCase())) {
temp_found = "true";
}
if (detection.return == temp_found) {
//console.log(detection.string," > normal");
temp_profile.found += 1
}
}
} catch (err) {
}
}));
}
if (temp_profile.found > 0 || temp_profile.image != "") {
temp_profile.text = sanitizeHtml(text_only);
temp_profile.title = sanitizeHtml(title);
temp_profile.rate = "%" + ((temp_profile.found / site.detections.length) * 100).toFixed(2);
temp_profile.link = site.url.replace("{username}", username);
temp_profile.type = site.type
resolve(temp_profile);
} else {
resolve(undefined)
}
} catch (err) {
if (driver !== undefined) {
try {
await driver.quit()
} catch (err) {
console.log("Driver Session Issue")
}
}
resolve(undefined)
}
});
}
async function find_username_normal(req) {
var functions = [];
var detections_result = [];
async function find_username_site(uuid, username, options, site, body) {
try {
log_to_file_queue(uuid, "[Checking] " + get_site_from_url(site.url))
var detections_count = 0;
var source = body;
var text_only = "unavailable";
var title = "unavailable";
var temp_profile = {
"found": 0,
"image": "",
"link": "",
"rate": "",
"title": "",
"text": "",
"type":""
};
await Promise.all(site.detections.map(async detection => {
var temp_found = "false";
if (detection.type == "normal" && options.includes("FindUserProfilesFast") && source != "" && detection.return == "true") {
detections_count += 1
if (source.toLowerCase().includes(detection.string.replace("{username}", username).toLowerCase())) {
temp_found = "true";
}
if (detection.return == temp_found) {
//console.log(detection.string, " > normal");
temp_profile.found += 1
}
}
}));
if (temp_profile.found > 0 && detections_count != 0) {
temp_profile.text = sanitizeHtml(htmlToText(body, {
wordwrap: false,
hideLinkHrefIfSameAsText: true,
ignoreHref: true,
ignoreImage: true
}));
if (temp_profile.text == "") {
temp_profile.text = "unavailable"
}
temp_profile.title = sanitizeHtml(title);
temp_profile.rate = "%" + ((temp_profile["found"] / detections_count) * 100).toFixed(2);
temp_profile.link = site.url.replace("{username}", username);
temp_profile.type = site.type
return Promise.resolve(temp_profile);
}
return Promise.resolve();
} catch (err) {
return Promise.reject();
}
}
async function find_username_sites(uuid, username, options, parsed_sites) {
await parsed_sites.forEach(site => {
if ("status" in site) {
if (site.status == "bad") {
return;
}
}
if (site.selected == "true" && site.detections.length > 0) {
functions.push(function(callback) {
var request = https.get(site.url.replace("{username}", username), header_options, function(res) {
var body = ""
res.on("data", function(chunk) {
body += chunk;
});
res.on("end", async function() {
var results = await find_username_site(uuid, username, options, site, body);
detections_result.push(results);
callback(null, "Done!");
});
});
request.on('error', function(e) {
callback(null, "Done!");
});
request.on('socket', function(socket) {
var timeout = (site.timeout != 0) ? site.timeout * 1000 : 5000;
socket.setTimeout(timeout, function() {
request.abort();
});
});
});
}
});
}
await find_username_sites(req.body.uuid, req.body.string, req.body.option, parsed_sites);
await async.parallelLimit(functions, 100);
return detections_result.filter(item => item !== undefined);
}
async function find_username_advanced_2(username, options) {
var detections_result = [];
async function find_username_site(username, options, driver, site) {
try {
if ("status" in site) {
if (site.status == "bad") {
return Promise.resolve();
}
}
if (site.selected == "true" && site.detections.length > 0 || site.selected == "true" && options.includes("ShowUserProfilesSlow")) {
var source = "";
var data = "";
var text_only = "unavailable";
var title = "unavailable";
var temp_profile = {
"found": 0,
"image": "",
"link": "",
rate: "",
title: "",
text: ""
};
var link = site.url.replace("{username}", username);
await driver.get(link);;
source = await driver.getPageSource();
data = await driver.takeScreenshot();
title = await driver.getTitle();
text_only = await driver.findElement(By.tagName("body")).getText();
if (options.includes("ShowUserProfilesSlow")) {
temp_profile["image"] = "data:image/png;base64,{image}".replace("{image}", data);
}
if (site.selected == "true" && site.detections.length > 0 && options.includes("FindUserProfilesSlow")) {
await Promise.all(site.detections.map(async detection => {
if ("status" in detection) {
if (detection.status == "bad") {
return;
}
}
var temp_found = "false"
if (detection.type == "ocr" && data != "") {
tmpobj = tmp.fileSync();
fs.writeFileSync(tmpobj.name, Buffer.from(data, "base64"));
await tesseract.recognize(tmpobj.name, {
lang: "eng",
oem: 1,
psm: 3,
})
.then(text => {
text = text.replace(/[^A-Za-z0-9]/gi, "");
detection.string = detection.string.replace(/[^A-Za-z0-9]/gi, "");
if (text != "") {
if (text.toLowerCase().includes(detection.string.toLowerCase())) {
temp_found = "true";
}
if (detection.return == temp_found) {
//console.log(text);
//console.log(detection.string," > Found ocr");
temp_profile.found += 1;
}
}
})
.catch(error => {
console.log(error.message);
})
tmpobj.removeCallback();
} else if (detection.type == "normal" && source != "") {
if (source.toLowerCase().includes(detection.string.replace("{username}", username).toLowerCase())) {
temp_found = "true";
}
if (detection.return == temp_found) {
//console.log(detection.string," > normal");
temp_profile.found += 1
}
}
}));
}
if (temp_profile.found > 0 || temp_profile.image != "") {
temp_profile.text = sanitizeHtml(text_only);
temp_profile.title = sanitizeHtml(title);
temp_profile.rate = "%" + ((temp_profile.found / site.detections.length) * 100).toFixed(2);
temp_profile.link = site.url.replace("{username}", username);
return Promise.resolve(temp_profile);
}
}
return Promise.resolve();
} catch (err) {
return Promise.reject();
}
}
async function find_username_sites(username, options, driver, parsed_sites) {
for (var site of parsed_sites) {
var result = await find_username_site(username, options, driver, site);
detections_result.push(result);
}
return detections_result;
}
let driver = new Builder()
.forBrowser("firefox")
.setFirefoxOptions(new firefox.Options().headless().windowSize({
width: 640,
height: 480
}))
.build();
var timeouts = {
implicit: 0,
pageLoad: 10000,
script: 10000
};
await driver.manage().setTimeouts(timeouts);
var results = await find_username_sites(username, options, driver, parsed_sites);
await driver.quit();
return results.filter(item => item !== undefined);
}
app.get("/get_settings", async function(req, res, next) {
temp_list = [];
temp_list = await Promise.all(parsed_sites.map(async (site, index) => {
var temp_url = "";
if ("status" in site) {
if (site.status == "bad") {
return Promise.resolve();
}
}
if (site.detections.length > 0) {
temp_url = url.parse(site.url.replace("{username}", "nothinghere")).hostname
temp_url = temp_url.replace("nothinghere.", "");
if (temp_url != "nothinghere") {
temp_selected = "false";
if ("selected" in site) {
if (site.selected == "true") {
temp_selected = "true";
}
}
return Promise.resolve({
"index": index,
"url": temp_url,
"selected": temp_selected
});
}
}
return Promise.resolve();
}));
temp_list = temp_list.filter(item => item !== undefined);
temp_list.sort(function(a, b) {
var keyA = a.url,
keyB = b.url;
// Compare the 2 dates
if (keyA < keyB) return -1;
if (keyA > keyB) return 1;
return 0;
});
res.json({
user_agent:header_options['headers']['User-Agent'],
google: [google_api_key.substring(0, 10) + "******", google_api_cs.substring(0, 10) + "******"],
detections: temp_list
});
});
app.post("/save_settings", async function(req, res, next) {
await parsed_sites.forEach(function(value, i) {
parsed_sites[i].selected = "false"
});
if ("detections" in req.body) {
if (req.body.detections.length > 0) {
await req.body.detections.split(',').forEach(item => {
parsed_sites[Number(item)].selected = "true";
});
}
}
if (req.body.google_key != google_api_key.substring(0, 10) + "******") {
google_api_key = req.body.google_key;
}
if (req.body.google_cv != google_api_cs.substring(0, 10) + "******") {
google_api_cs = req.body.google_cv;
}
if (req.body.user_agent != header_options['headers']['User-Agent']){
header_options['headers']['User-Agent'] = req.body.user_agent;
}
res.json("Done");
});
app.get("/generate", async function(req, res, next) {
var list_of_combinations = []
if (req.body.option == "Generate") {
if (req.body.words != undefined && req.body.words.length > 1 && req.body.words.length < 8) {
for (var perm of generatorics.permutationCombination(req.body.words)) {
if (perm.join("") !== "") {
list_of_combinations.push(perm.join(""));
}
}
}
}
res.json({
combinations: list_of_combinations
});
});
async function get_words_info(all_words, words_info) {
var temp_added = []
for (let all_words_key of Object.keys(all_words)) {
for (let all_words_word of all_words[all_words_key]) {
if (!temp_added.includes(all_words_word)) {
temp_added.push(all_words_word);
var temp_words_info = {
"word": all_words_word,
"text": "",
"results": []
}
try {
var url1 = "https://api.duckduckgo.com/?q={0}&format=json&pretty=1&no_html=1&skip_disambig=1".replace("{0}", all_words_word);
var url2 = "https://api.duckduckgo.com/?q={0}&format=json&pretty=1".replace("{0}", all_words_word);
var response1 = await axios.get(url1);
var response2 = await axios.get(url2);
if (response2.status === 200) {
if ("RelatedTopics" in response2.data) {
if (response2.data.RelatedTopics.length > 0) {
if (response1.status === 200) {
if ("AbstractText" in response1.data && response1.data.AbstractText != "") {
temp_words_info.text = response1.data.AbstractText;
} else if ("Abstract" in response1.data && response1.data.AbstractText != "") {
temp_words_info.text = response1.data.Abstract;
} else {
temp_words_info.text = "unknown";
}
}
response2.data.RelatedTopics.forEach(function(item) {
if ("Name" in item) {
item.Topics.forEach(function(topic) {
temp_words_info.results.push({
"type": item.Name,
"text": topic.Text,
"url": topic.FirstURL
});
});
} else {
temp_words_info.results.push({
"type": "Related",
"text": item.Text,
"url": item.FirstURL
});
}
});
}
}
}
if (temp_words_info.results.length > 0) {
words_info.push(temp_words_info);
}
} catch (error) {
console.log(error);
}
}
}
}
}
async function check_engines(req, info) {
try {
if (google_api_key == "" || google_api_cs == "") {
return
}
var url = "https://www.googleapis.com/customsearch/v1?key={0}&cx={1}&q={2}".replace("{0}", google_api_key).replace("{1}", google_api_cs).replace("{2}", req.body.string);
var response = await axios.get(url);
if (response.status === 200) {
try {
info.original = response.data.queries.request[0].searchTerms
} catch (e) {}
try {
info.corrected = response.data.spelling.correctedQuery
} catch (e) {}
try {
info.total = response.data.searchInformation.totalResults
} catch (e) {}
try {
response.data.items.forEach(function(item) {
info["items"].push({
"title": item.title,
"snippet": item.snippet
});
});
} catch (e) {}
try {
if (info.total == 0 && info.corrected != "") {
info.checking = info.original + " [Error]<br>Try this: " + info.corrected;
} else if (info.total > 0 && info.corrected != "") {
info.checking = info.original + " [Good]<br>Suggested word: " + info.corrected + "<br>Total lookups: " + info.total;
} else if (info.total > 0 && info.corrected == "") {
info.checking = info.original + " [Good]<br>Total lookups: " + info.total;
} else {
info.checking = "Using " + info.original + " with no lookups";
}
} catch (e) {}
}
} catch (error) {
console.log(error);
}
}
function most_common1(all_words, temp_words) {
var temp_list = []
Object.keys(all_words).forEach(function(key) {
all_words[key].forEach(function(item) {
if (!temp_list.includes(item) && item.length > 1) {
temp_list.push(item);
var temp = findWord(item);
if (Object.keys(temp).length != 0) {
var languages = Object.keys(temp).map(function(key) {
return [key, temp[key]];
});
languages.sort(function(first, second) {
return second[1] - first[1]
}).reverse();
temp_words.push({
"word": item,
"languages": languages.map(e => e.join(":")).join(" ")
});
}
}
});
});
}
async function most_common(all_words, temp_words) {
var temp_list = []
Object.keys(all_words).forEach(function(key) {
all_words[key].forEach(function(item) {
if (!temp_list.includes(item) && item.length > 1) {
temp_list.push(item);
var temp = findWord(item);
if (Object.keys(temp).length != 0) {
var languages = Object.keys(temp).map(function(key) {
return [key, temp[key]];
});
languages.sort(function(first, second) {
return second[1] - first[1]
}).reverse();
temp_words.push({
"word": item,
"languages": languages.map(e => e[0]).join(", ")
});
}
}
});
});
}
function find_other(all_words) {
var words = WordsNinja.splitSentence(req.body.string);
words.forEach(function(word) {
var value = false
Object.keys(all_words).forEach(function(key) {
if (all_words[key].includes(word)) {
value = true
}
});
if (!value && !all_words.maybe.includes(word)) {
all_words.maybe.push(word);
}
});
}
function remove_word(str, sub_string) {
part1 = str.substring(0, str.indexOf(sub_string));
part2 = str.substring(str.indexOf(sub_string) + sub_string.length, str.length);
temp = (part1 + part2).replace(/[ \[\]:"\\|,.<>\/?~`!@#$%^&*()_+\-={};"]/gi, "");
return temp;
}
async function analyze_name(req, all_words) {
log_to_file_queue(req.body.uuid, "[Starting] String analysis")
temp_rr_names = []
string_to_check = req.body.string
parsed_json.prefix.forEach(function(item, index) {
if (string_to_check.indexOf(item) == 0 && !all_words.prefix.includes(item)) {
all_words.prefix.push(item);
temp = remove_word(string_to_check, item);
if (temp !== null && temp !== "" && !all_words.unknown.includes(temp) && !all_words.maybe.includes(temp) && temp.length > 1) {
all_words.unknown.push(temp);
}
}
});
parsed_json.m_names.forEach(function(item, index) {
if (string_to_check.indexOf(item) >= 0 && !all_words.name.includes(item)) {
all_words.name.push(item);
temp = remove_word(string_to_check, item);
if (temp !== null && temp !== "" && !all_words.unknown.includes(temp) && !all_words.maybe.includes(temp) && temp.length > 1) {
all_words.unknown.push(temp);
}
}
});
parsed_json.f_names.forEach(function(item, index) {
if (string_to_check.indexOf(item) >= 0 && !all_words.name.includes(item)) {
all_words.name.push(item);
temp = remove_word(string_to_check, item);
if (temp !== null && temp !== "" && !all_words.unknown.includes(temp) && !all_words.maybe.includes(temp) && temp.length > 1) {
all_words.unknown.push(temp);
}
}
});
all_words.prefix.forEach(function(h_item, index) {
all_words.unknown.forEach(function(r_item, index) {
if (r_item.indexOf(h_item) == 0) {
temp = remove_word(r_item, h_item);
if (temp !== null && temp !== "" && !temp_rr_names.includes(temp) && !all_words.maybe.includes(temp) && temp.length > 1) {
temp_rr_names.push(temp);
}
}
});
});
var temp_r_concat = all_words.unknown.concat(temp_rr_names.filter((item) => all_words.unknown.indexOf(item) < 0));
all_words.unknown = temp_r_concat
temp_rr_names = []
all_words.number.forEach(function(n_item, index) {
all_words.unknown.forEach(function(r_item, index) {
if (r_item.indexOf(n_item) >= 0) {
temp = remove_word(r_item, n_item);
if (temp !== null && temp !== "" && !temp_rr_names.includes(temp) && !all_words.maybe.includes(temp) && temp.length > 1) {
temp_rr_names.push(temp);
}
}
});
});
var temp_r_concat = all_words.unknown.concat(temp_rr_names.filter((item) => all_words.unknown.indexOf(item) < 0));
all_words.unknown = temp_r_concat
log_to_file_queue(req.body.uuid, "[Done] String analysis")
}
app.post("/url", async function(req, res, next) {
await WordsNinja.loadDictionary();
var info = {
"items": [],
"original": "",
"corrected": "",
"total": 0,
"checking": "Using " + req.body.string + " with no lookups"
}
var user_info_normal = {
data: {},
type: "all"
}
var user_info_advanced = {
data: {},
type: "all"
}
var user_info_special = {
data: {},
type: "all"
}
var all_words = {
"prefix": [],
"name": [],
"number": [],
"symbol": [],
"unknown": [],
"maybe": []
}
var words_info = []
var temp_words = []
if (req.body.string == null || req.body.string == "") {
res.json("Error");
} else {
req.body.uuid = req.body.uuid.replace(/[^a-zA-Z0-9\-]+/g, '');
if (req.body.option.includes("FindUserProfilesSpecial")) {
log_to_file_queue(req.body.uuid, "[Starting] Checking user profiles special")
user_info_special.data = await find_username_special(req);
log_to_file_queue(req.body.uuid, "[Done] Checking user profiles special")
}
if (req.body.option.includes("FindUserProfilesFast")) {
log_to_file_queue(req.body.uuid, "[Starting] Checking user profiles normal")
user_info_advanced.data = await find_username_normal(req);
log_to_file_queue(req.body.uuid, "[Done] Checking user profiles normal")
}
if (req.body.option.includes("FindUserProfilesSlow") || req.body.option.includes("ShowUserProfilesSlow")) {
if (!req.body.option.includes("FindUserProfilesSlow")) {
user_info_normal.type = "show"
} else if (!req.body.option.includes("ShowUserProfilesSlow")) {
user_info_normal.type = "noshow"
}
log_to_file_queue(req.body.uuid, "[Starting] Checking user profiles advanced")
user_info_normal.data = await find_username_advanced(req);
log_to_file_queue(req.body.uuid, "[Done] Checking user profiles advanced")
}
if (req.body.option.includes("LookUps")) {
log_to_file_queue(req.body.uuid, "[Starting] Lookup")
await check_engines(req, info);
log_to_file_queue(req.body.uuid, "[Done] Lookup")
}
if (req.body.option.includes("SplitWordsByUpperCase")) {
try {
req.body.string.match(/[A-Z][a-z]+/g).forEach((item) => {
if (item.length > 1 && !all_words.unknown.includes(item) && !all_words.maybe.includes(item)) {
all_words.unknown.push(item.toLowerCase());
}
});
log_to_file_queue(req.body.uuid, "[Done] Split by UpperCase")
} catch (err) {}
}
if (req.body.option.includes("SplitWordsByAlphabet")) {
try {
req.body.string.match(/[A-Za-z]+/g).forEach((item) => {
if (item.length > 1 && !all_words.unknown.includes(item) && !all_words.maybe.includes(item)) {
all_words.unknown.push(item.toLowerCase());
}
});
log_to_file_queue(req.body.uuid, "[Done] Split by Alphabet")
} catch (err) {}
}
req.body.string = req.body.string.toLowerCase();
if (req.body.option.includes("ConvertNumbers")) {
numbers_to_letters = {
"4": "a",
"8": "b",
"3": "e",
"1": "l",
"0": "o",
"5": "s",
"7": "t",
"2": "z"
}
temp_value = ""
for (i = 0; i < req.body.string.length; i++) {
_temp = numbers_to_letters[req.body.string.charAt(i)]
if (_temp != undefined) {
temp_value += numbers_to_letters[req.body.string.charAt(i)];
} else {
temp_value += req.body.string.charAt(i);
}