-
Notifications
You must be signed in to change notification settings - Fork 0
/
harProcess.js
279 lines (173 loc) · 8.35 KB
/
harProcess.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
//KSEKINAME ME TA CALLBACK GIA NA APROUME TA DEDOMENA TOU XRHSTH SXETIKA ME TIN IP TOU
//XRISIMOPOIOUME TO IP-API
//efarmozw to ip-api gia na parw ta network data mesw ths ip
fetch('http://ip-api.com/json/').then(function(response) {
response.json().then(jsonData => {
console.log(jsonData);
userIsp = jsonData.isp;
console.log(userIsp);
userLat = jsonData.lat;
console.log(userLat);
userLon = jsonData.lon;
console.log(userLon);
userServer = jsonData.query;
console.log(userServer);
ipUserData = [userIsp, userServer, userLat, userLon];
document.getElementById('myField2').value = JSON.stringify(ipUserData);
});
})
.catch(function(error) {
console.log(error)
});
//PERNOUME TO HAR POU EVALE O XRISTIS ASUGXRONA TO HAR FILE POU EVALE O XRHSTES
const input = document.getElementById('HarFile')
//ORIZOUME OLES TI METAVLITES POU THA XREIASTOUME
var i;
var Method = [];
var startedDateTime = [];
var Status = [];
var statusText = [];
var serverIP = [];
var timings = [];
var DomainUrl = [];
var serverIp_visited = [];
var serverLat_visited = [];
var serverLon_visited = [];
var Visited_servers_Data = [];
var inputFileName;
//MAS ENDIAFEROUN TA ENTRIES OPOTE STO TELOS THELOUME NA EXOUME ENA MAIN OBJECT POU NA EXEI MONO TA ENTRIES FILTRARISMENA
var MainObject = {
entries : []
};
//KSEKINAEI H EPEJERGASIA TOU ARXEIOU
input.addEventListener('change', function(e) {
inputFileName = input.files[0].name;
console.log("Arxeio pou mpike " + inputFileName);
//XRISIMOPOIOUME TON FILE READER KAI ME TH SUNARTHSH ONLOAD KANOUME OLI THN DOULEIA
const reader = new FileReader()
reader.onload = function(){
//PAIRNOUME TO HAS KAI TO PARSAROUME
var periexomeno = reader.result;
var data = JSON.parse(periexomeno);
console.log(data);
//KAI PERNOUME TA ENTRIES
var harEntries = data.log.entries;
//APO EDW KAI PERA EINAI O KATHARISMOS TWN DEDOMENWN OPOU APO TO KATHE ENTRIE KATHARIZOUME OTI DEN MAS EPITREPETE
//KATHWS KAI PERNOUME OTI XREIAZETAI.
for(i = 0; i< harEntries.length; i++){
if(harEntries[i].startedDateTime){
startedDateTime.push(harEntries[i].startedDateTime);
}
//GIA KATHE PEDIO PERNOUME OLA TA DEDOMENA POY EXEI
Method.push(harEntries[i].request.method);
Status.push(harEntries[i].response.status);
statusText.push(harEntries[i].response.statusText);
serverIP.push(harEntries[i].serverIPAddress);
timings.push(harEntries[i].timings.wait);
DomainUrl.push(extractHostname(harEntries[i].request.url));
//GIA NA PAROUME TA DEDOMENA TON SERVER POU EPISKEFTIKE O XRISTIS KANOUME XRISH ENOS ALLOU API
//TO FREEGEOIP APODIKTIKE TO KALITERO GIATI EPITREPEI TA PERISSOTERA REQUEST GIA DEDOMENA ANA WRA SE SXESI ME TA ALLA API
fetch('https://freegeoip.app/json/' + serverIP[i])
.then(function(response) {
response.json().then(jsonData => {
console.log(jsonData);
Visited_servers_Data.push({
serverIp_visited : jsonData.ip,
serverLat_visited : jsonData.latitude,
serverLon_visited : jsonData.longitude
});
if(i = harEntries.length -1 ){
document.getElementById('myField3').value = JSON.stringify(Visited_servers_Data);
}
});
})
.catch(function(error) {
console.log(error)
});
}
//AFOU EXOUME PAREI OTI XREIAZOMASTE FTIAXNOUME MIA LOOPA GIA NA PERNAME ENA ENA TA ENTRIES
//MESA STO MAIN OBJECT
//SXIMATIZOUME MIA TOPIKI METAVLITI TYPOU JS
//KAI ME FOR GEMIZOUME SIGA SIGA TO MAIN OBJECT.
for(var r=0; r<harEntries.length; r++){
//magic
var AnEntrie = {
request : {},
response : {},
Ip : {},
timings : {},
startedDateTime : {},
Headers_request : [{}],
Headers_response : [{}]
};
var temp_req = {};
var temp_res = {};
var counter_res = 0;
AnEntrie.request.method = Method[r];
AnEntrie.request.url = DomainUrl[r];
AnEntrie.response.status = Status[r];
AnEntrie.response.statusText = statusText[r];
AnEntrie.Ip.serverIPAddress = serverIP[r];
AnEntrie.timings.wait = timings[r];
AnEntrie.startedDateTime.startedDateTime = startedDateTime[r];
//GIA TA HEADER XRIASTIKE H XRHSH REGEX
for(var t=0; t< harEntries[r].request.headers.length;t++){
var typeOfHeader = data.log.entries[r].request.headers[t].name.match(/^(Cache-Control|Pragma|Host|Content-Type|Last-Modified|Expires|Age|content-Type|pragma|expires|cache-control|host|content-type|last-modified|age|:method)$/);
if(typeOfHeader != null && typeOfHeader[0] != undefined){
temp_req.name = typeOfHeader[0];
temp_req.value = harEntries[r].request.headers[t].value;
//console.log(temp_req);
console.log(y +". STO " +temp_req.name + " einai toso ===>" +temp_req.value);
AnEntrie.Headers_request[counter_res] = temp_req;
counter_res = counter_res + 1;
}
}
for(var y=0; y< harEntries[r].response.headers.length; y++){
var typeOfHeader = data.log.entries[r].response.headers[y].name.match(/^(Cache-Control|Pragma|Host|Content-Type|Last-Modified|Expires|Age|content-Type|pragma|expires|cache-control|host|content-type|last-modified|age|:method)$/);
if(typeOfHeader != null){
//console.log(typeOfHeader);
temp_res.name = harEntries[r].response.headers[y].name;
temp_res.value = harEntries[r].response.headers[y].value;
AnEntrie.Headers_response[counter_res] = JSON.parse(JSON.stringify(temp_res));
counter_res = counter_res + 1;
}
}
MainObject.entries[r] = AnEntrie;
}
//GIA TIN METAFORA TOU OBJECT TO KANOUME STRINGIFY WSTE NA MPOREI NA METAFERTHEI STO SAVETODB GIA NA GINEI EPEKSERGASIA ANEVASMATOS STHN VASI
console.log(MainObject);
el = JSON.stringify(MainObject);
//console.log(el)
document.getElementById('myField1').value = el;
}
reader.readAsText(input.files[0]);
}, false)
// ME AUTH THN SUNARTISI KATHARIZOUME TA URL GIA NA PERNOUME KATHARA TA DOMAIN OPOU UPARXOUN DEDOMENA
function extractHostname(url) {
var hostname;
if (url.indexOf("//") > -1) {
hostname = url.split('/')[2];
}
else {
hostname = url.split('/')[0];
}
hostname = hostname.split(':')[0];
hostname = hostname.split('?')[0];
return hostname;
}
//GIA TO ACTION TOU DOWNLOAD XREIAZETAI I METATROPI TOU ARXEIOY SE BLOB
//GINETAI I XRISI TON DYO PARAKATV SUNARTISEWN
//FTIAXNOUME TO BLOB STIN PRWTI KAI STHN DEUTERI GIA NA TO KATEVASI O XRISTI PREPEI NA GINEI STHN MORFI URL
//TOU DINOUME ONOMA KAI PERIEXOMAI KAI ME TO CLICK GINETAI TO DOWNLOAD
function download(filename, dataShit){
//create a blob
const blob = new Blob([dataShit], {type: "text/har"});
downloadFile(blob, filename);
}
function downloadFile(blob, filename){
const url = window.URL.createObjectURL(blob, filename);
const a = document.createElement("a");
a.href = url;
a.download = filename;
a.click();
}