Adds component for displaying DNS results

This commit is contained in:
Alicia Sykes 2023-06-24 16:43:07 +01:00
parent e0ffc8e418
commit 8d8307e60e
2 changed files with 34 additions and 1 deletions

View File

@ -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<any>();
const [ sslResults, setSslResults ] = useState<any>();
const [ headersResults, setHeadersResults ] = useState<any>();
const [ dnsResults, setDnsResults ] = useState<any>();
const [ robotsTxtResults, setRobotsTxtResults ] = useState<any>();
const [ cookieResults, setCookieResults ] = useState<Cookie[] | null>(null);
const [ screenshotResult, setScreenshotResult ] = useState<string>();
@ -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 && <HeadersCard headers={headersResults} />}
{ hostNames && <HostNamesCard hosts={hostNames} />}
{ whoIsResults && <WhoIsCard {...whoIsResults} />}
{ dnsResults && <DnsRecordsCard dnsRecords={dnsResults} />}
{ lighthouseResults && <LighthouseCard lighthouse={lighthouseResults} />}
{ cookieResults && <CookiesCard cookies={cookieResults} />}
{ screenshotResult && <ScreenshotCard screenshot={screenshotResult} />}

View File

@ -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;
}