Full Toolkit for Next-Level Domain Analysis
Dynamically interpolate lookup buttons in RecordRow 🔍
Felix Wotschofskybb5d93edb03d
diff --git a/components/RecordRow.tsx b/components/RecordRow.tsxindex 5a41ac8..37159d9 100644--- a/components/RecordRow.tsx+++ b/components/RecordRow.tsx@@ -2,47 +2,72 @@ import { ExternalLinkIcon } from '@chakra-ui/icons';import { FaInfoCircle } from 'react-icons/fa';import { IconButton, Td, Tooltip, Tr, useDisclosure } from '@chakra-ui/react';import { useRouter } from 'next/router';-import isFQDN from 'validator/lib/isFQDN';+import { useState, ReactNodeArray } from 'react';import isIP from 'validator/lib/isIP';+import reactStringReplace from 'react-string-replace';import { RawRecord } from '@/utils/DnsLookup';import IpDetailsModal from '@/components/IpDetailsModal';+const domainRegex =+ /(_)*(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/g;+const RecordRow = ({ record }: { record: RawRecord }) => {const router = useRouter();++ const [detailedIp, setDetailedIp] = useState<string | null>(null);const { isOpen, onOpen, onClose } = useDisclosure();- let specialAction = null;- if (isIP(record.data)) {- specialAction = (- <>- <Tooltip label="View IP Info">- <IconButton- variant="link"- size="sm"- ml={1}- aria-label="View IP Info"- icon={<FaInfoCircle />}- onClick={onOpen}- />- </Tooltip>- <IpDetailsModal ip={record.data} isOpen={isOpen} onClose={onClose} />- </>- );- } else if (isFQDN(record.data.slice(0, -1))) {- const targetDomain = record.data.slice(0, -1);- specialAction = (- <Tooltip label="View Domain Records">- <IconButton- variant="link"- size="sm"- ml={1}- aria-label="View Domain Records"- icon={<ExternalLinkIcon />}- onClick={() => router.push(`/lookup/${targetDomain}`)}- />- </Tooltip>- );+ let interpolatedValue: ReactNodeArray | null = null;++ const domainMatches = record.data.match(domainRegex);+ if (domainMatches) {+ for (const domain of domainMatches) {+ interpolatedValue = reactStringReplace(+ interpolatedValue ? interpolatedValue : record.data,+ domain,+ (match) => {+ if (isIP(match)) {+ return (+ <>+ <span>{match}</span>{' '}+ <Tooltip label="View IP Info">+ <IconButton+ variant="link"+ size="sm"+ ml={-2.5}+ mr={-1.5}+ aria-label="View IP Info"+ icon={<FaInfoCircle />}+ onClick={() => {+ setDetailedIp(match);+ onOpen();+ }}+ />+ </Tooltip>+ </>+ );+ }++ return (+ <>+ <span>{match}</span>{' '}+ <Tooltip label="View Domain Records">+ <IconButton+ variant="link"+ size="sm"+ ml={-2.5}+ mr={-1.5}+ aria-label="View Domain Records"+ icon={<ExternalLinkIcon />}+ onClick={() => router.push(`/lookup/${match}`)}+ />+ </Tooltip>+ </>+ );+ }+ );+ }}return (@@ -50,11 +75,14 @@ const RecordRow = ({ record }: { record: RawRecord }) => {<Tr><Td>{record.name}</Td><Td>{record.TTL}</Td>- <Td>- {record.data}- {specialAction}- </Td>+ <Td>{interpolatedValue ? interpolatedValue : record.data}</Td></Tr>++ <IpDetailsModal+ ip={detailedIp as string}+ isOpen={isOpen}+ onClose={onClose}+ /></>);};diff --git a/package.json b/package.jsonindex b3849a6..d65696a 100644--- a/package.json+++ b/package.json@@ -28,6 +28,7 @@"react-dom": "17.0.2","react-icons": "^4.2.0","react-leaflet": "^3.2.0",+ "react-string-replace": "^0.4.4","swr": "^0.5.6","validator": "^13.6.0","whois": "^2.13.5"diff --git a/yarn.lock b/yarn.lockindex 072eebd..97c9d7b 100644--- a/yarn.lock+++ b/yarn.lock@@ -2783,7 +2783,7 @@ lodash.truncate@^4.4.2:resolved "https://registry.yarnpkg.com/lodash.truncate/-/lodash.truncate-4.4.2.tgz#5a350da0b1113b837ecfffd5812cbe58d6eae193"integrity sha1-WjUNoLERO4N+z//VgSy+WNbq4ZM=-lodash@^4.17.13:+lodash@^4.17.13, lodash@^4.17.4:version "4.17.21"resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==@@ -3498,6 +3498,13 @@ [email protected]:use-callback-ref "^1.2.3"use-sidecar "^1.0.1"+react-string-replace@^0.4.4:+ version "0.4.4"+ resolved "https://registry.yarnpkg.com/react-string-replace/-/react-string-replace-0.4.4.tgz#24006fbe0db573d5be583133df38b1a735cb4225"+ integrity sha512-FAMkhxmDpCsGTwTZg7p/2v+/GTmxAp73so3fbSvlAcBBX36ujiGRNEaM/1u+jiYQrArhns+7eE92g2pi5E5FUA==+ dependencies:+ lodash "^4.17.4"+react-style-singleton@^2.1.0:version "2.1.1"resolved "https://registry.yarnpkg.com/react-style-singleton/-/react-style-singleton-2.1.1.tgz#ce7f90b67618be2b6b94902a30aaea152ce52e66"