From 8d8307e60e9893bc177b36cc0a23abad851d2eae Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sat, 24 Jun 2023 16:43:07 +0100 Subject: [PATCH] Adds component for displaying DNS results --- src/pages/Results.tsx | 17 +++++++++++++++++ src/utils/result-processor.ts | 18 +++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/pages/Results.tsx b/src/pages/Results.tsx index 19f0cbc..7d18da0 100644 --- a/src/pages/Results.tsx +++ b/src/pages/Results.tsx @@ -16,6 +16,7 @@ import SslCertCard from 'components/Results/SslCert'; import HeadersCard from 'components/Results/Headers'; import CookiesCard from 'components/Results/Cookies'; import RobotsTxtCard from 'components/Results/RobotsTxt'; +import DnsRecordsCard from 'components/Results/DnsRecords'; import keys from 'utils/get-keys'; import { determineAddressType, AddressType } from 'utils/address-type-checker'; @@ -43,6 +44,7 @@ const ResultsContent = styled.section` gap: 1rem; margin: auto; width: calc(100% - 2rem); + padding-bottom: 1rem; `; const Header = styled(Card)` @@ -63,6 +65,7 @@ const Results = (): JSX.Element => { const [ lighthouseResults, setLighthouseResults ] = useState(); const [ sslResults, setSslResults ] = useState(); const [ headersResults, setHeadersResults ] = useState(); + const [ dnsResults, setDnsResults ] = useState(); const [ robotsTxtResults, setRobotsTxtResults ] = useState(); const [ cookieResults, setCookieResults ] = useState(null); const [ screenshotResult, setScreenshotResult ] = useState(); @@ -81,6 +84,7 @@ const Results = (): JSX.Element => { const jobNames = [ 'get-ip', 'ssl', + 'dns', 'cookies', 'robots-txt', 'headers', @@ -197,6 +201,18 @@ const Results = (): JSX.Element => { .catch(err => updateLoadingJobs('headers', 'error', err)); }, [address, addressType]) + /* Get DNS records */ + useEffect(() => { + if (addressType !== 'url') return; + fetch(`/get-dns?url=${address}`) + .then(response => response.json()) + .then(response => { + setDnsResults(response); + updateLoadingJobs('dns', 'success'); + }) + .catch(err => updateLoadingJobs('dns', 'error', err)); + }, [address, addressType]) + /* Get Lighthouse report */ useEffect(() => { if (addressType !== 'url') return; @@ -337,6 +353,7 @@ const Results = (): JSX.Element => { { headersResults && } { hostNames && } { whoIsResults && } + { dnsResults && } { lighthouseResults && } { cookieResults && } { screenshotResult && } diff --git a/src/utils/result-processor.ts b/src/utils/result-processor.ts index 2a5e48b..d814609 100644 --- a/src/utils/result-processor.ts +++ b/src/utils/result-processor.ts @@ -148,8 +148,11 @@ type RobotsRule = { export const parseRobotsTxt = (content: string): RobotsRule[] => { const lines = content.split('\n'); const rules: RobotsRule[] = []; + lines.forEach(line => { - const match = line.match(/^(Allow|Disallow):\s*(\S*)$/); + line = line.trim(); // This removes trailing and leading whitespaces + + let match = line.match(/^(Allow|Disallow):\s*(\S*)$/i); if (match) { const rule: RobotsRule = { lbl: match[1], @@ -157,7 +160,20 @@ export const parseRobotsTxt = (content: string): RobotsRule[] => { }; rules.push(rule); + } else { + match = line.match(/^(User-agent):\s*(\S*)$/i); + if (match) { + const rule: RobotsRule = { + lbl: match[1], + val: match[2], + }; + + rules.push(rule); + } } }); + return rules; } + +