rentgen/components/sidebar/stolen-data-cluster.tsx

189 lines
6.6 KiB
TypeScript
Raw Normal View History

2022-01-27 22:30:57 +01:00
import React from 'react';
import { getMemory } from '../../memory';
import { StolenDataEntry } from '../../stolen-data-entry';
import { maskString, useEmitter } from '../../util';
2022-01-20 19:03:03 +01:00
import './stolen-data-cluster.scss';
const MAX_STRING_VALUE_LENGTH = 100;
function StolenDataValue({ entry }: { entry: StolenDataEntry; prefixKey?: string }) {
2022-01-19 14:12:52 +01:00
const [version] = useEmitter(entry);
let body = null;
if (!entry.value) {
body = <></>;
} else {
2022-04-25 14:29:55 +02:00
body = <div data-version={version}>{entry.value}</div>;
2022-01-19 14:12:52 +01:00
}
return (
2022-01-20 19:03:03 +01:00
<td
className="value"
2022-01-19 14:12:52 +01:00
onClick={(e) => {
entry.toggleMark();
2022-05-02 17:04:56 +02:00
getMemory().emit('change', entry.request.shorthost);
2022-01-19 14:12:52 +01:00
e.stopPropagation();
}}
2022-04-24 22:11:33 +02:00
title={entry.value}
2022-01-19 14:12:52 +01:00
>
{body}
2022-01-20 19:03:03 +01:00
</td>
2021-11-07 13:01:01 +01:00
);
}
2021-11-07 09:17:19 +01:00
function StolenDataRow({ entry }: { entry: StolenDataEntry }) {
2022-01-19 14:12:52 +01:00
const [version] = useEmitter(entry);
return (
2022-01-20 19:03:03 +01:00
<tr
data-key={entry.id}
data-version={version}
className={`${entry.isMarked ? 'toggled' : 'untoggled'}`}
>
2022-05-02 13:46:53 +02:00
<td className="checkbox">
<input
type="checkbox"
checked={entry.isMarked}
id={entry.id.toString()}
2022-05-02 13:46:53 +02:00
onChange={() => {
entry.toggleMark();
2022-05-02 17:04:56 +02:00
getMemory().emit('change', entry.request.shorthost);
2022-05-02 13:46:53 +02:00
}}
/>
</td>
<th title={`Nazwa: ${entry.name}\nŹródło: ${entry.source}`}>
<label htmlFor={entry.id.toString()}>{entry.name}</label>
</th>
2022-01-20 19:03:03 +01:00
<td className="icons">
2022-01-19 14:12:52 +01:00
{entry.source === 'cookie' ? (
2022-01-20 19:03:03 +01:00
<span title="Dane przechowywane w Cookies">
2022-01-29 20:41:03 +01:00
<img
src="/assets/icons/cookie.svg"
2022-01-20 19:03:03 +01:00
height={16}
width={16}
className="cookie-data"
/>
</span>
2022-01-19 14:12:52 +01:00
) : entry.request.hasCookie() ? (
<span title="Wysłane w zapytaniu opatrzonym Cookies" style={{ opacity: 0.25 }}>
2022-01-29 20:41:03 +01:00
<img
src="/assets/icons/cookie.svg"
2022-01-20 19:03:03 +01:00
height={16}
width={16}
className="request-with-cookie"
/>
2022-01-19 14:12:52 +01:00
</span>
) : null}
{entry.exposesOrigin() ? (
2022-01-20 19:03:03 +01:00
<span title="Pokazuje część historii przeglądania">
2022-01-29 20:41:03 +01:00
<img
src="/assets/icons/warning.svg"
2022-01-20 19:03:03 +01:00
height={16}
width={16}
className="show-history-part"
/>
</span>
2022-01-19 14:12:52 +01:00
) : entry.request.exposesOrigin() ? (
<span
title="Jest częścią zapytania, które ujawnia historię przeglądania"
2022-01-20 19:03:03 +01:00
style={{ opacity: 0.25 }}
2022-01-19 14:12:52 +01:00
>
2022-01-29 20:41:03 +01:00
<img
src="/assets/icons/warning.svg"
2022-01-20 19:03:03 +01:00
height={16}
width={16}
className="request-with-history-part"
/>
2022-01-19 14:12:52 +01:00
</span>
) : null}
</td>
<StolenDataValue entry={entry} />
2022-01-19 14:12:52 +01:00
</tr>
);
2021-11-21 23:00:55 +01:00
}
export default function StolenDataCluster({
2022-01-19 14:12:52 +01:00
origin,
shorthost,
minValueLength,
cookiesOnly,
refreshToken,
2022-01-19 14:12:52 +01:00
cookiesOrOriginOnly,
2022-04-15 13:58:29 +02:00
detailsVisibility,
2021-11-07 09:17:19 +01:00
}: {
2022-01-19 14:12:52 +01:00
origin: string;
shorthost: string;
refreshToken: number;
minValueLength: number;
cookiesOnly: boolean;
cookiesOrOriginOnly: boolean;
2022-04-15 13:58:29 +02:00
detailsVisibility: boolean;
2021-11-07 09:17:19 +01:00
}) {
2022-01-19 14:12:52 +01:00
const cluster = getMemory().getClustersForOrigin(origin)[shorthost];
2022-01-20 19:03:03 +01:00
const fullHosts = cluster.getFullHosts();
2022-05-02 13:46:53 +02:00
const [version] = useEmitter(cluster);
2022-01-20 19:03:03 +01:00
2022-01-19 14:12:52 +01:00
return (
2022-01-20 19:03:03 +01:00
<div className="stolen-data-cluster-container">
<header className="domains-container">
2022-05-02 13:46:53 +02:00
<div>
<input
type="checkbox"
className="domain-checkbox"
data-version={version}
checked={cluster.hasMarks()}
onChange={() => {
cluster.hasMarks() ? cluster.undoMark() : cluster.autoMark();
2022-05-02 17:04:56 +02:00
getMemory().emit('change', cluster.id);
2022-05-02 13:46:53 +02:00
}}
/>
2022-07-06 19:03:15 +02:00
<a className="domain" href={'https://' + cluster.id} target="_blank">
2022-05-02 13:46:53 +02:00
{cluster.id}
</a>
</div>
2022-01-20 19:03:03 +01:00
<div className="subdomains-container">
{fullHosts.map((host, index) => (
2022-07-06 19:03:15 +02:00
<a
className="subdomain"
key={host}
href={`https://${host}`}
target="_blank"
>
{host} {`${fullHosts.length - 1 !== index ? '· ' : ''}`}
2022-01-20 19:03:03 +01:00
</a>
))}
</div>
</header>
2022-04-15 13:58:29 +02:00
{detailsVisibility ? (
<section>
<table>
<thead>
<tr>
<th className="table-header" colSpan={4}>
Wysłane dane:
</th>
</tr>
</thead>
<tbody>
{cluster
.calculateRepresentativeStolenData({
minValueLength,
cookiesOnly,
cookiesOrOriginOnly,
})
.map((entry) => (
<StolenDataRow
{...{
entry,
key: entry.id,
}}
/>
))}
</tbody>
</table>
</section>
) : null}
2022-01-19 14:12:52 +01:00
</div>
);
2021-11-07 09:17:19 +01:00
}