mirror of
https://github.com/Lissy93/web-check.git
synced 2025-02-20 04:10:49 +01:00
Makes components itteratable
This commit is contained in:
parent
595a6833db
commit
c83419cfd2
@ -47,9 +47,8 @@ const ListRow = (props: { list: Technology[], title: string }) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const BuiltWithCard = (props: { technologies: TechnologyGroup[] }): JSX.Element => {
|
const BuiltWithCard = (technologies: TechnologyGroup[]): JSX.Element => {
|
||||||
// const { created, updated, expires, nameservers } = whois;
|
// const { created, updated, expires, nameservers } = whois;
|
||||||
const { technologies } = props;
|
|
||||||
return (
|
return (
|
||||||
<Outer>
|
<Outer>
|
||||||
<Heading as="h3" align="left" color={colors.primary}>Technologies</Heading>
|
<Heading as="h3" align="left" color={colors.primary}>Technologies</Heading>
|
||||||
|
@ -7,16 +7,15 @@ import { ExpandableRow } from 'components/Form/Row';
|
|||||||
|
|
||||||
const Outer = styled(Card)``;
|
const Outer = styled(Card)``;
|
||||||
|
|
||||||
const CookiesCard = (props: { cookies: any }): JSX.Element => {
|
const CookiesCard = (cookies: { cookies: any }): JSX.Element => {
|
||||||
const cookies = props.cookies;
|
|
||||||
return (
|
return (
|
||||||
<Outer>
|
<Outer>
|
||||||
<Heading as="h3" align="left" color={colors.primary}>Cookies</Heading>
|
<Heading as="h3" align="left" color={colors.primary}>Cookies</Heading>
|
||||||
{
|
{
|
||||||
cookies.length === 0 && <p>No cookies found.</p>
|
cookies.cookies.length === 0 && <p>No cookies found.</p>
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
cookies.map((cookie: any, index: number) => {
|
cookies.cookies.map((cookie: any, index: number) => {
|
||||||
const attributes = Object.keys(cookie.attributes).map((key: string) => {
|
const attributes = Object.keys(cookie.attributes).map((key: string) => {
|
||||||
return { lbl: key, val: cookie.attributes[key] }
|
return { lbl: key, val: cookie.attributes[key] }
|
||||||
});
|
});
|
||||||
|
@ -3,7 +3,7 @@ import styled from 'styled-components';
|
|||||||
import colors from 'styles/colors';
|
import colors from 'styles/colors';
|
||||||
import Card from 'components/Form/Card';
|
import Card from 'components/Form/Card';
|
||||||
import Heading from 'components/Form/Heading';
|
import Heading from 'components/Form/Heading';
|
||||||
import Row, { ListRow, RowProps } from 'components/Form/Row';
|
import Row, { ListRow } from 'components/Form/Row';
|
||||||
|
|
||||||
const Outer = styled(Card)`
|
const Outer = styled(Card)`
|
||||||
.content {
|
.content {
|
||||||
@ -12,8 +12,7 @@ const Outer = styled(Card)`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const DnsRecordsCard = (props: { dnsRecords: any }): JSX.Element => {
|
const DnsRecordsCard = (dnsRecords: any): JSX.Element => {
|
||||||
const dnsRecords = props.dnsRecords;
|
|
||||||
return (
|
return (
|
||||||
<Outer>
|
<Outer>
|
||||||
<Heading as="h3" align="left" color={colors.primary}>DNS Records</Heading>
|
<Heading as="h3" align="left" color={colors.primary}>DNS Records</Heading>
|
||||||
|
@ -9,8 +9,7 @@ const Outer = styled(Card)`
|
|||||||
grid-row: span 2;
|
grid-row: span 2;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const HeadersCard = (props: { headers: any }): JSX.Element => {
|
const HeadersCard = (headers: any): JSX.Element => {
|
||||||
const headers = props.headers;
|
|
||||||
return (
|
return (
|
||||||
<Outer>
|
<Outer>
|
||||||
<Heading as="h3" align="left" color={colors.primary}>Headers</Heading>
|
<Heading as="h3" align="left" color={colors.primary}>Headers</Heading>
|
||||||
|
@ -32,8 +32,7 @@ const HostListSection = (props: { list: string[], title: string }) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const HostNamesCard = (props: { hosts: HostNames }): JSX.Element => {
|
const HostNamesCard = (hosts: HostNames): JSX.Element => {
|
||||||
const hosts = props.hosts;
|
|
||||||
return (
|
return (
|
||||||
<Outer>
|
<Outer>
|
||||||
{ hosts.domains.length > 0 &&
|
{ hosts.domains.length > 0 &&
|
||||||
|
@ -12,44 +12,6 @@ const processScore = (percentile: number) => {
|
|||||||
|
|
||||||
const Outer = styled(Card)``;
|
const Outer = styled(Card)``;
|
||||||
|
|
||||||
const Row = styled.div`
|
|
||||||
details summary {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
padding: 0.25rem;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
&:not(:last-child) { border-bottom: 1px solid ${colors.primary}; }
|
|
||||||
span.lbl {
|
|
||||||
font-weight: bold;
|
|
||||||
text-transform: capitalize;
|
|
||||||
}
|
|
||||||
span.val {
|
|
||||||
max-width: 200px;
|
|
||||||
white-space: nowrap;
|
|
||||||
overflow: hidden;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const ScoreRow = styled.li`
|
|
||||||
list-style: none;
|
|
||||||
margin: 0;
|
|
||||||
display: flex;
|
|
||||||
gap: 0.25rem;
|
|
||||||
padding: 0.25rem 0;
|
|
||||||
justify-content: space-between;
|
|
||||||
span { min-width: 5rem; max-width: 8rem; }
|
|
||||||
border-bottom: 1px dashed ${colors.primaryTransparent};
|
|
||||||
`;
|
|
||||||
|
|
||||||
const ScoreList = styled.ul`
|
|
||||||
margin: 0;
|
|
||||||
padding: 0.25rem;
|
|
||||||
border-top: 1px solid ${colors.primary};
|
|
||||||
background: ${colors.primaryTransparent};
|
|
||||||
`;
|
|
||||||
|
|
||||||
interface Audit {
|
interface Audit {
|
||||||
id: string,
|
id: string,
|
||||||
score?: number | string,
|
score?: number | string,
|
||||||
@ -59,26 +21,6 @@ interface Audit {
|
|||||||
displayValue?: string,
|
displayValue?: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
const ScoreItem = (props: { scoreId: any, audits: Audit[] }) => {
|
|
||||||
const { scoreId, audits } = props;
|
|
||||||
const audit = audits[scoreId];
|
|
||||||
if (!audit.score) return null;
|
|
||||||
|
|
||||||
let score = audit.score;
|
|
||||||
if (audit.displayValue) {
|
|
||||||
score = audit.displayValue;
|
|
||||||
} else if (audit.scoreDisplayMode) {
|
|
||||||
score = audit.score === 1 ? '✅ Pass' : '❌ Fail';
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ScoreRow title={audit.description}>
|
|
||||||
<b>{ audit.title }</b>
|
|
||||||
<span>{score}</span>
|
|
||||||
</ScoreRow>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const makeValue = (audit: Audit) => {
|
const makeValue = (audit: Audit) => {
|
||||||
let score = audit.score;
|
let score = audit.score;
|
||||||
if (audit.displayValue) {
|
if (audit.displayValue) {
|
||||||
@ -89,9 +31,9 @@ const makeValue = (audit: Audit) => {
|
|||||||
return score;
|
return score;
|
||||||
};
|
};
|
||||||
|
|
||||||
const LighthouseCard = (props: { lighthouse: any }): JSX.Element => {
|
const LighthouseCard = (lighthouse: any): JSX.Element => {
|
||||||
const categories = props.lighthouse?.categories || {};
|
const categories = lighthouse?.categories || {};
|
||||||
const audits = props.lighthouse?.audits || [];
|
const audits = lighthouse?.audits || [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Outer>
|
<Outer>
|
||||||
|
@ -12,16 +12,16 @@ const Outer = styled(Card)`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const RobotsTxtCard = (props: { robotTxt: RowProps[] }): JSX.Element => {
|
const RobotsTxtCard = ( robots: { robots: RowProps[]}): JSX.Element => {
|
||||||
return (
|
return (
|
||||||
<Outer>
|
<Outer>
|
||||||
<Heading as="h3" align="left" color={colors.primary}>Crawl Rules</Heading>
|
<Heading as="h3" align="left" color={colors.primary}>Crawl Rules</Heading>
|
||||||
<div className="content">
|
<div className="content">
|
||||||
{
|
{
|
||||||
props.robotTxt.length === 0 && <p>No crawl rules found.</p>
|
robots.robots.length === 0 && <p>No crawl rules found.</p>
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
props.robotTxt.map((row: RowProps, index: number) => {
|
robots.robots.map((row: RowProps, index: number) => {
|
||||||
return (
|
return (
|
||||||
<Row key={`${row.lbl}-${index}`} lbl={row.lbl} val={row.val} />
|
<Row key={`${row.lbl}-${index}`} lbl={row.lbl} val={row.val} />
|
||||||
)
|
)
|
||||||
|
@ -14,11 +14,11 @@ img {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const ScreenshotCard = (props: { screenshot: string }): JSX.Element => {
|
const ScreenshotCard = (screenshot: string): JSX.Element => {
|
||||||
return (
|
return (
|
||||||
<Outer>
|
<Outer>
|
||||||
<Heading as="h3" align="left" color={colors.primary}>Screenshot</Heading>
|
<Heading as="h3" align="left" color={colors.primary}>Screenshot</Heading>
|
||||||
<img src={props.screenshot} alt="Full page screenshot" />
|
<img src={screenshot} alt="Full page screenshot" />
|
||||||
</Outer>
|
</Outer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -79,8 +79,8 @@ const ListRow = (props: { list: string[], title: string }) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const SslCertCard = (props: { sslCert: any }): JSX.Element => {
|
const SslCertCard = (sslCert: any): JSX.Element => {
|
||||||
const { subject, issuer, fingerprint, serialNumber, asn1Curve, nistCurve, valid_to, valid_from, ext_key_usage } = props.sslCert;
|
const { subject, issuer, fingerprint, serialNumber, asn1Curve, nistCurve, valid_to, valid_from, ext_key_usage } = sslCert;
|
||||||
return (
|
return (
|
||||||
<Outer>
|
<Outer>
|
||||||
<Heading as="h3" align="left" color={colors.primary}>SSL Info</Heading>
|
<Heading as="h3" align="left" color={colors.primary}>SSL Info</Heading>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useState, useEffect, useCallback, SetStateAction, Dispatch } from 'react';
|
import { useState, useEffect, useCallback } from 'react';
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ const Results = (): JSX.Element => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Fetch and parse cookies info
|
// Fetch and parse cookies info
|
||||||
const [cookieResults] = useMotherHook<Cookie[]>({
|
const [cookieResults] = useMotherHook<{cookies: Cookie[]}>({
|
||||||
jobId: 'cookies',
|
jobId: 'cookies',
|
||||||
updateLoadingJobs,
|
updateLoadingJobs,
|
||||||
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
|
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
|
||||||
@ -131,7 +131,7 @@ const Results = (): JSX.Element => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Fetch and parse crawl rules from robots.txt
|
// Fetch and parse crawl rules from robots.txt
|
||||||
const [robotsTxtResults] = useMotherHook<RowProps[]>({
|
const [robotsTxtResults] = useMotherHook<{robots: RowProps[]}>({
|
||||||
jobId: 'robots-txt',
|
jobId: 'robots-txt',
|
||||||
updateLoadingJobs,
|
updateLoadingJobs,
|
||||||
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
|
addressInfo: { address, addressType, expectedAddressTypes: urlTypeOnly },
|
||||||
@ -230,6 +230,22 @@ const Results = (): JSX.Element => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A list of state sata, corresponding component and title for each card
|
||||||
|
const resultCardData = [
|
||||||
|
{ title: 'Server Location', result: locationResults, Component: ServerLocationCard },
|
||||||
|
{ title: 'SSL Info', result: sslResults, Component: SslCertCard },
|
||||||
|
{ title: 'Headers', result: headersResults, Component: HeadersCard },
|
||||||
|
{ title: 'Host Names', result: shoadnResults?.hostnames, Component: HostNamesCard },
|
||||||
|
{ title: 'Domain Info', result: whoIsResults, Component: WhoIsCard },
|
||||||
|
{ title: 'DNS Records', result: dnsResults, Component: DnsRecordsCard },
|
||||||
|
{ title: 'Performance', result: lighthouseResults, Component: LighthouseCard },
|
||||||
|
{ title: 'Cookies', result: cookieResults, Component: CookiesCard },
|
||||||
|
{ title: 'Screenshot', result: lighthouseResults?.fullPageScreenshot?.screenshot?.data, Component: ScreenshotCard },
|
||||||
|
{ title: 'Technologies', result: technologyResults, Component: BuiltWithCard },
|
||||||
|
{ title: 'Crawl Rules', result: robotsTxtResults, Component: RobotsTxtCard },
|
||||||
|
{ title: 'Server Info', result: shoadnResults?.serverInfo, Component: ServerInfoCard },
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ResultsOuter>
|
<ResultsOuter>
|
||||||
<Header as="header">
|
<Header as="header">
|
||||||
@ -244,43 +260,17 @@ const Results = (): JSX.Element => {
|
|||||||
}
|
}
|
||||||
</Header>
|
</Header>
|
||||||
<ProgressBar loadStatus={loadingJobs} />
|
<ProgressBar loadStatus={loadingJobs} />
|
||||||
|
|
||||||
<ResultsContent>
|
<ResultsContent>
|
||||||
<ErrorBoundary title="Server Location">
|
{
|
||||||
{ locationResults && <ServerLocationCard {...locationResults} />}
|
resultCardData.map(({ title, result, Component }) => (
|
||||||
</ErrorBoundary>
|
(result) ? (
|
||||||
<ErrorBoundary title="SSL Info">
|
<ErrorBoundary title={title} key={title}>
|
||||||
{ sslResults && <SslCertCard sslCert={sslResults} />}
|
<Component {...result} />
|
||||||
</ErrorBoundary>
|
|
||||||
<ErrorBoundary title="Headers">
|
|
||||||
{ headersResults && <HeadersCard headers={headersResults} />}
|
|
||||||
</ErrorBoundary>
|
|
||||||
<ErrorBoundary title="Host Names">
|
|
||||||
{ shoadnResults?.hostnames && <HostNamesCard hosts={shoadnResults.hostnames} />}
|
|
||||||
</ErrorBoundary>
|
|
||||||
<ErrorBoundary title="Domain Info">
|
|
||||||
{ whoIsResults && <WhoIsCard {...whoIsResults} />}
|
|
||||||
</ErrorBoundary>
|
|
||||||
<ErrorBoundary title="DNS Records">
|
|
||||||
{ dnsResults && <DnsRecordsCard dnsRecords={dnsResults} />}
|
|
||||||
</ErrorBoundary>
|
|
||||||
<ErrorBoundary title="Performance">
|
|
||||||
{ lighthouseResults && <LighthouseCard lighthouse={lighthouseResults} />}
|
|
||||||
</ErrorBoundary>
|
|
||||||
<ErrorBoundary title="Cookies">
|
|
||||||
{ cookieResults && <CookiesCard cookies={cookieResults} />}
|
|
||||||
</ErrorBoundary>
|
|
||||||
<ErrorBoundary title="Screenshot">
|
|
||||||
{ lighthouseResults?.fullPageScreenshot?.screenshot?.data && <ScreenshotCard screenshot={lighthouseResults.fullPageScreenshot.screenshot.data} />}
|
|
||||||
</ErrorBoundary>
|
|
||||||
<ErrorBoundary title="Technologies">
|
|
||||||
{ technologyResults && <BuiltWithCard technologies={technologyResults} />}
|
|
||||||
</ErrorBoundary>
|
|
||||||
<ErrorBoundary title="Crawl Rules">
|
|
||||||
{ robotsTxtResults && <RobotsTxtCard robotTxt={robotsTxtResults} />}
|
|
||||||
</ErrorBoundary>
|
|
||||||
<ErrorBoundary title="Server Info">
|
|
||||||
{ shoadnResults?.serverInfo && <ServerInfoCard {...shoadnResults.serverInfo} />}
|
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
|
) : <></>
|
||||||
|
))
|
||||||
|
}
|
||||||
</ResultsContent>
|
</ResultsContent>
|
||||||
<Footer />
|
<Footer />
|
||||||
</ResultsOuter>
|
</ResultsOuter>
|
||||||
|
@ -140,9 +140,9 @@ export type Cookie = {
|
|||||||
attributes: Record<string, string>;
|
attributes: Record<string, string>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const parseCookies = (cookiesHeader: string): Cookie[] => {
|
export const parseCookies = (cookiesHeader: string): {cookies: Cookie[]} => {
|
||||||
if (!cookiesHeader) return [];
|
if (!cookiesHeader) return {cookies: []};
|
||||||
return cookiesHeader.split(/,(?=\s[A-Za-z0-9]+=)/).map(cookieString => {
|
const cookies = cookiesHeader.split(/,(?=\s[A-Za-z0-9]+=)/).map(cookieString => {
|
||||||
const [nameValuePair, ...attributePairs] = cookieString.split('; ').map(part => part.trim());
|
const [nameValuePair, ...attributePairs] = cookieString.split('; ').map(part => part.trim());
|
||||||
const [name, value] = nameValuePair.split('=');
|
const [name, value] = nameValuePair.split('=');
|
||||||
const attributes: Record<string, string> = {};
|
const attributes: Record<string, string> = {};
|
||||||
@ -152,9 +152,10 @@ export const parseCookies = (cookiesHeader: string): Cookie[] => {
|
|||||||
});
|
});
|
||||||
return { name, value, attributes };
|
return { name, value, attributes };
|
||||||
});
|
});
|
||||||
|
return { cookies }
|
||||||
}
|
}
|
||||||
|
|
||||||
export const parseRobotsTxt = (content: string): RowProps[] => {
|
export const parseRobotsTxt = (content: string): { robots: RowProps[] } => {
|
||||||
const lines = content.split('\n');
|
const lines = content.split('\n');
|
||||||
const rules: RowProps[] = [];
|
const rules: RowProps[] = [];
|
||||||
|
|
||||||
@ -182,7 +183,7 @@ export const parseRobotsTxt = (content: string): RowProps[] => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return rules;
|
return { robots: rules };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const applyWhoIsResults = (response: any) => {
|
export const applyWhoIsResults = (response: any) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user