2021-11-21 18:21:31 +01:00
|
|
|
import React, { useEffect, useState } from "react";
|
2021-11-08 20:14:28 +01:00
|
|
|
import { HAREntry } from "../extended-request";
|
2021-11-22 17:54:15 +01:00
|
|
|
import { StolenDataEntry } from "../stolen-data-entry";
|
2021-11-09 17:47:42 +01:00
|
|
|
import { getshorthost, unique } from "../util";
|
2021-11-08 20:14:28 +01:00
|
|
|
|
|
|
|
function handleNewFile(
|
|
|
|
element: HTMLInputElement,
|
2021-11-22 17:54:15 +01:00
|
|
|
entries: StolenDataEntry[],
|
2021-11-08 20:14:28 +01:00
|
|
|
setFiltered: (Blob) => void
|
2021-11-09 17:47:42 +01:00
|
|
|
): void {
|
2021-11-08 20:14:28 +01:00
|
|
|
const reader = new FileReader();
|
|
|
|
reader.addEventListener("load", () => {
|
|
|
|
const content = JSON.parse(reader.result as string);
|
|
|
|
content.log.entries = content.log.entries.filter((har_entry: HAREntry) =>
|
2021-11-22 17:54:15 +01:00
|
|
|
entries.some((entry) => entry.matchesHAREntry(har_entry))
|
2021-11-08 20:14:28 +01:00
|
|
|
);
|
|
|
|
setFiltered(
|
|
|
|
new Blob([JSON.stringify(content)], { type: "application/json" })
|
|
|
|
);
|
|
|
|
});
|
|
|
|
reader.readAsText(element.files[0]);
|
|
|
|
}
|
|
|
|
|
2021-11-22 17:54:15 +01:00
|
|
|
function generateFakeHAR(entries: StolenDataEntry[]) {
|
2021-11-25 21:13:15 +01:00
|
|
|
const requests = unique(entries.map((entry) => entry.request))
|
|
|
|
.sort((request1, request2) => {
|
|
|
|
if (request1.shorthost < request2.shorthost) {
|
|
|
|
return -1;
|
|
|
|
} else if (request1.shorthost > request2.shorthost) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
2021-11-26 19:15:43 +01:00
|
|
|
return request2.getBalancedPriority() - request1.getBalancedPriority();
|
2021-11-25 21:13:15 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.filter((_, index, array) => {
|
2021-11-26 19:15:43 +01:00
|
|
|
if (index == 0) return true;
|
|
|
|
if (array[index].shorthost == array[index - 1].shorthost) {
|
2021-11-25 21:13:15 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
.sort(
|
2021-11-26 19:15:43 +01:00
|
|
|
(entry1, entry2) =>
|
|
|
|
entry2.getBalancedPriority() - entry1.getBalancedPriority()
|
2021-11-25 21:13:15 +01:00
|
|
|
);
|
|
|
|
|
2021-11-09 17:47:42 +01:00
|
|
|
return {
|
|
|
|
log: {
|
|
|
|
version: "1.2",
|
|
|
|
creator: {
|
|
|
|
name: "Firefox",
|
|
|
|
version: "94.0",
|
|
|
|
},
|
|
|
|
browser: {
|
|
|
|
name: "Firefox",
|
|
|
|
version: "94.0",
|
|
|
|
},
|
|
|
|
pages: [
|
|
|
|
{
|
|
|
|
startedDateTime: "2021-11-08T20:27:23.195+01:00",
|
|
|
|
id: "page_1",
|
|
|
|
title: "HAR DUmp",
|
|
|
|
pageTimings: {
|
|
|
|
onContentLoad: 467,
|
|
|
|
onLoad: 4226,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2021-11-25 21:13:15 +01:00
|
|
|
entries: requests.map((r) => r.toHAR()),
|
2021-11-09 17:47:42 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-11-22 17:54:15 +01:00
|
|
|
export default function HARConverter({
|
|
|
|
entries,
|
|
|
|
}: {
|
|
|
|
entries: StolenDataEntry[];
|
|
|
|
}) {
|
2021-11-08 20:14:28 +01:00
|
|
|
const [filtered, setFiltered] = useState<Blob | null>(null);
|
|
|
|
const [filename, setFilename] = useState("");
|
2021-11-21 18:21:31 +01:00
|
|
|
const [fakeHAR, setFakeHAR] = useState<ReturnType<typeof generateFakeHAR>>();
|
|
|
|
useEffect(() => {
|
2021-11-22 17:54:15 +01:00
|
|
|
setFakeHAR(generateFakeHAR(entries));
|
2021-11-21 18:21:31 +01:00
|
|
|
}, []);
|
|
|
|
|
2021-11-08 20:14:28 +01:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<input
|
|
|
|
type="file"
|
|
|
|
accept=".har"
|
|
|
|
onChange={(e) => {
|
|
|
|
setFilename(e.target.files[0].name);
|
2021-11-22 17:54:15 +01:00
|
|
|
handleNewFile(e.target, entries, setFiltered);
|
2021-11-08 20:14:28 +01:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{(filtered && (
|
|
|
|
<a
|
|
|
|
href={URL.createObjectURL(filtered)}
|
|
|
|
download={filename.replace(".har", "-filtered.har")}
|
|
|
|
>
|
|
|
|
Pobierz wyfiltrowany HAR
|
|
|
|
</a>
|
|
|
|
)) ||
|
|
|
|
null}
|
2021-11-09 17:47:42 +01:00
|
|
|
<a
|
|
|
|
href={URL.createObjectURL(
|
|
|
|
new Blob([JSON.stringify(fakeHAR)], { type: "application/json" })
|
|
|
|
)}
|
|
|
|
download={`${getshorthost(
|
2021-11-22 17:54:15 +01:00
|
|
|
entries[0].request.originalURL
|
2021-11-10 14:59:08 +01:00
|
|
|
)}-${new Date().toJSON()}-trimmed.har`}
|
2021-11-09 17:47:42 +01:00
|
|
|
>
|
|
|
|
Pobierz "zfałszowany" HAR
|
|
|
|
</a>
|
2021-11-08 20:14:28 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|