-
Notifications
You must be signed in to change notification settings - Fork 0
/
jack.js
182 lines (155 loc) · 6.47 KB
/
jack.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
var csv = require('csv-parser')
var fs = require('fs')
var dict = require("dict");
var Regex = require("regex");
var d = dict({});
var missing = dict({});
var proxyiedResources;
var outcomes = "OutComes: ";
//check for missing arguments
if (process.argv.length !== 4) {
console.error('Exactly two argument required');
process.exit(1);
}
//notice that processing has started
console.log("Processing . . .");
//create handles for files
var input = process.argv[2];
var input2 = process.argv[3];
function CompareLists() {
//console.log("2nd Last");
//console.log(d.size);
var found = 0;
var notfound = 0;
var lvl1MatchFailures = 0;
var lvl2MatchFailures = 0;
var lvl3MatchFailures = 0;
var proxiedUrlCount = 0;
d.forEach(function (value, key) {
//console.log("URL: " + key);
//var myRegexp = /(https?:\/\/0-)(([a-zA-Z\-]*\.)?[^/]+\.[a-zA-Z]{2,}(\.[a-zA-Z]{2})*)(\.patris\.apu\.edu)/gm;
if (key == "http://0-www.ipasource.com.patris.apu.edu") {
console.log("processing specific key: ");
var myRegexp = /(https?:\/\/0-)(([a-zA-Z\-]*\.)?[^\/]+\.[a-zA-Z]{2,}(\.[a-zA-Z]{2})*)(\.patris\.apu\.edu)/gm;
//var matches = key.match(myRegexp);
var matches = myRegexp.exec(key);
//console.log(key);
if (matches !== null) {
proxiedUrlCount++;
//var contstructedRegex = /ipasource.com/gm;
var contstructedRegex = new RegExp(matches[2], 'gm');
//console.log(matches[2])
var matchResults = proxyiedResources.match(contstructedRegex);
if (matchResults !== null) {
// outcomes += "Match found for " + key + "\n";
// outcomes += "Using " + contstructedRegex + "\n";
//console.log(matchResults[0]);
found++
} else {
//console.log("Level 2 Match Failure matching against: " + contstructedRegex);
lvl2MatchFailures++;
//outcomes += "Match not found for " + key + "\n";
if (matches[3]) {
var refineddRegex = new RegExp("\\*\\." + matches[2].slice(matches[3].length), 'gm');
//console.log("Refined Regex: " + matches[2].slice(matches[3].length))
var refinedMatchResults = proxyiedResources.match(refineddRegex);
if (refinedMatchResults !== null) {
//outcomes += "Match found for " + key + "\n";
//console.log(refinedMatchResults[0]);
found++
} else {
//console.log("Level 3 Match Failure matching against: " + refineddRegex);
lvl3MatchFailures++;
notfound++
outcomes += "Match not found for " + key + "\n";
}
} else {
//inital was not found and there is no match 3 to slice off the start
notfound++
outcomes += "Match not found for " + key + "\n";
}
}
} else {
//console.log("Level 1 Match Failure : " + key);
lvl1MatchFailures++;
}
}
});
console.log(outcomes);
console.log("Found: " + found);
console.log("Not Found: " + notfound);
console.log("Unique URLs in KB " + d.size);
console.log("Proxied Items to be Checked " + proxiedUrlCount);
//console.log("LEVEL 1 Match Failures " + lvl1MatchFailures);
//console.log("LEVEL 2 Match Failures " + lvl2MatchFailures);
//console.log("LEVEL 3 Match Failures " + lvl3MatchFailures);
//console.log(proxyiedResources);
}
// while ((m = regex.exec(str)) !== null) {
// // This is necessary to avoid infinite loops with zero-width matches
// if (m.index === regex.lastIndex) {
// regex.lastIndex++;
// }
// // The result can be accessed through the `m`-variable.
// m.forEach((match, groupIndex) => {
// console.log(`Found match, group ${groupIndex}: ${match}`);
// });
// }
var progressTicker = 0;
var progressBar = "*"
fs.createReadStream(input)
.pipe(csv())
.on('data', function (data) {
if (typeof data.ProxiedURL === 'string') {
var myRegexp = /^https?:\/\/([a-zA-Z\-]*\.)?[^/]+\.[a-zA-Z]{2,}/gm;
var res = data.ProxiedURL.match(myRegexp);
if (res !== null) {
d.set(res[0], "0");
progressTicker++;
if (progressTicker >= 20000) {
console.log(progressBar);
progressBar += "*";
progressTicker = 0;
}
}
// if (res !== null) {
// console.log(res[0]);
// }
}
//console.log(typeof data.ProxiedURL);
//console.log(data.ProxiedURL);
//console.log(d.size);
}).on('end', CompileProxyList);
function CompileProxyList() {
fs.createReadStream(input2)
.pipe(csv())
.on('data', function (data) {
if (typeof data.IP === 'string') {
proxyiedResources += data.IP
// var myRegexp = /^([a-zA-Z\-]*\.)?[^/]+\.[a-zA-Z]{2,}/gm;
// var res = data.IP.match(myRegexp);
// if (res !== null) {
// d.set(res[0], "0");
// progressTicker++;
// if (progressTicker >= 20000) {
// console.log(progressBar);
// progressBar += "*";
// progressTicker = 0;
// }
}
// if (res !== null) {
// console.log(res[0]);
// }
//}
//console.log(typeof data.ProxiedURL);
//console.log(data.ProxiedURL);
//console.log(d.size);
}).on('end', CompareLists);
}
// d.forEach(function (value, key) {
// console.log("Proxied URL: " + key);
// });
//************************ */
//regex that breaks apart APU urls into protocal+0-, full resource domaine, resource subdomains, apu suffixs
//(https ?:\/\/0-)(([a-zA-Z\-]*\.)?[^/]+\.[a-zA-Z]{2,}(\.[a-zA-Z]{2})*)(\.patris\.apu\.edu)(https?:\/\/0-)(([a-zA-Z\-]*\.)?[^/]+\.[a-zA-Z]{2,}(\.[a-zA-Z]{2})*)(\.patris\.apu\.edu)
//************************ */