2022-04-25 14:29:55 +02:00
|
|
|
import React, { Fragment } from 'react';
|
2022-01-17 19:50:14 +01:00
|
|
|
import ReactDOM from 'react-dom';
|
2022-04-13 11:44:59 +02:00
|
|
|
import { getMemory } from '../../memory';
|
|
|
|
import { useEmitter } from '../../util';
|
2021-11-07 13:57:24 +01:00
|
|
|
|
2022-02-02 10:33:09 +01:00
|
|
|
import './report-window.scss';
|
2022-02-07 21:11:25 +01:00
|
|
|
import Questions from './questions';
|
|
|
|
import EmailContent from './email-content';
|
|
|
|
import { parseAnswers, ParsedAnswers } from './parse-answers';
|
2022-02-02 10:33:09 +01:00
|
|
|
|
2021-11-07 13:57:24 +01:00
|
|
|
function Report() {
|
2022-04-24 22:11:33 +02:00
|
|
|
try {
|
|
|
|
const url = new URL(document.location.toString());
|
|
|
|
const origin = url.searchParams.get('origin');
|
|
|
|
const [counter] = useEmitter(getMemory());
|
|
|
|
const [answers, setAnswers] = React.useState<ParsedAnswers>(
|
|
|
|
url.searchParams.get('answers') ? JSON.parse(url.searchParams.get('answers')) : null
|
|
|
|
);
|
|
|
|
const [mode, setMode] = React.useState(url.searchParams.get('mode') || 'survey');
|
|
|
|
const clusters = getMemory().getClustersForOrigin(origin);
|
2022-05-02 13:06:44 +02:00
|
|
|
/* const [entries, setEntries] = React.useState<StolenDataEntry[]>([]); */
|
|
|
|
/* React.useEffect(() => {
|
|
|
|
* setEntries(
|
|
|
|
* Object.values(clusters)
|
|
|
|
* .map((cluster) => {
|
|
|
|
* cluster.calculateRepresentativeStolenData();
|
|
|
|
* return cluster.representativeStolenData;
|
|
|
|
* })
|
|
|
|
* .reduce(reduceConcat, [])
|
|
|
|
* .filter((entry) => entry.isMarked)
|
|
|
|
* );
|
|
|
|
* }, []); */
|
|
|
|
/* if (entries.length == 0) {
|
|
|
|
* return <>Wczytywanie...</>;
|
|
|
|
* } */
|
2022-02-08 22:27:12 +01:00
|
|
|
|
2022-04-24 22:11:33 +02:00
|
|
|
React.useEffect(() => {
|
|
|
|
const url = new URL(document.location.toString());
|
|
|
|
url.searchParams.set('origin', origin);
|
|
|
|
url.searchParams.set('answers', JSON.stringify(answers));
|
|
|
|
url.searchParams.set('mode', mode);
|
|
|
|
history.pushState({}, 'Rentgen', url.toString());
|
|
|
|
}, [mode, answers, origin]);
|
|
|
|
const visited_url = Object.values(clusters)
|
|
|
|
.find((cluster) => cluster.getMarkedRequests().length > 0)
|
|
|
|
?.getMarkedRequests()[0].originalURL;
|
2022-02-10 20:03:48 +01:00
|
|
|
|
2022-04-24 22:11:33 +02:00
|
|
|
const result = (
|
|
|
|
<div {...{ 'data-version': counter }}>
|
|
|
|
{mode === 'survey' ? (
|
|
|
|
<Questions
|
2022-05-02 13:06:44 +02:00
|
|
|
hosts={Object.values(clusters)
|
|
|
|
.filter((cluster) => cluster.getMarkedRequests().length > 0)
|
|
|
|
.map((cluster) => cluster.id)}
|
2022-04-24 22:11:33 +02:00
|
|
|
onComplete={(answers) => {
|
|
|
|
setAnswers(parseAnswers(answers));
|
|
|
|
setMode('preview');
|
|
|
|
}}
|
|
|
|
></Questions>
|
|
|
|
) : (
|
|
|
|
''
|
|
|
|
)}
|
|
|
|
{mode === 'preview' ? <EmailContent {...{ answers, visited_url, clusters }} /> : ''}
|
|
|
|
{/* <HARConverter {...{ entries }} /> */}
|
|
|
|
</div>
|
|
|
|
);
|
2022-04-25 14:29:55 +02:00
|
|
|
return (
|
2022-05-02 13:06:44 +02:00
|
|
|
<Fragment>
|
2022-04-25 14:29:55 +02:00
|
|
|
<header className="header">
|
|
|
|
<img src="../../assets/icon-addon.svg" height={32}></img>
|
|
|
|
<div className="webpage-metadata">
|
2022-05-02 13:06:44 +02:00
|
|
|
{origin ? (
|
|
|
|
<>
|
|
|
|
<span>Generowanie raportu </span>
|
|
|
|
<span className="webpage-metadata--hyperlink">{origin}</span>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<span>Przejdź do wybranej strony internetowej</span>
|
|
|
|
)}
|
2022-04-25 14:29:55 +02:00
|
|
|
</div>
|
|
|
|
</header>
|
2022-05-02 13:06:44 +02:00
|
|
|
<section>{result}</section>
|
|
|
|
</Fragment>
|
2022-04-25 14:29:55 +02:00
|
|
|
);
|
2022-04-24 22:11:33 +02:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
return <div>ERROR! {JSON.stringify(e)}</div>;
|
|
|
|
}
|
2021-11-07 13:57:24 +01:00
|
|
|
}
|
|
|
|
|
2022-01-17 19:50:14 +01:00
|
|
|
ReactDOM.render(<Report />, document.getElementById('app'));
|