forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDomainCard.js
More file actions
127 lines (122 loc) · 3.51 KB
/
DomainCard.js
File metadata and controls
127 lines (122 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import React from 'react'
import { t, Trans } from '@lingui/macro'
import {
Text,
ListItem,
PseudoBox,
Box,
Icon,
Stack,
Divider,
} from '@chakra-ui/core'
import { useLingui } from '@lingui/react'
import { useHistory } from 'react-router-dom'
import { string } from 'prop-types'
import { slugify } from './slugify'
export function DomainCard({ url, lastRan, ...rest }) {
const history = useHistory()
const { i18n } = useLingui()
const webProtocols = [
'HTTPS',
'HSTS',
i18n._(t`HSTS Preloaded`),
'SSL',
i18n._(t`Protocols & Ciphers`),
i18n._(t`Certificate Use`),
]
const emailProtocols = ['SPF', 'DKIM', 'DMARC']
const generateWebStatusIcon = () => {
const randNum = Math.floor(Math.random() * 100 + 1)
let statusIcon
if (randNum < 70) {
statusIcon = <Icon name="check-circle" color="strong" size="icons.sm" />
} else {
statusIcon = <Icon name="warning" color="weak" size="icons.sm" />
}
return statusIcon
}
const generateEmailStatusIcon = () => {
const randNum = Math.floor(Math.random() * 100 + 1)
let statusIcon
if (randNum < 33) {
statusIcon = <Icon name="check-circle" color="strong" size="icons.sm" />
} else if (randNum >= 33 && randNum < 66) {
statusIcon = <Icon name="warning-2" color="moderate" size="icons.sm" />
} else {
statusIcon = <Icon name="warning" color="weak" size="icons.sm" />
}
return statusIcon
}
return (
<ListItem {...rest}>
<PseudoBox
width="100%"
display={{ md: 'flex' }}
alignItems="center"
onClick={() => {
history.push(`/domains/${slugify(url)}`)
}}
_hover={{ bg: 'gray.100' }}
p="8"
tabIndex={0}
>
<Box flexShrink="0" minW="12%">
<Text fontWeight="semibold">
<Trans>Domain:</Trans>
</Text>
{url}
</Box>
<Divider orientation={['horizontal', 'vertical']} />
<Box flexShrink="0" ml={{ md: 2 }} mr={{ md: 2 }}>
{lastRan ? (
<Box>
<Text fontWeight="bold">
<Trans>Last scanned:</Trans>
</Text>
{lastRan}
</Box>
) : (
<Text fontWeight="bold" fontSize="sm">
<Trans>Not scanned yet.</Trans>
</Text>
)}
</Box>
<Divider orientation={['horizontal', 'vertical']} />
{webProtocols.map((protocol) => {
return (
<Box flexShrink="0" ml={{ md: 2 }} mr={{ md: 2 }} key={protocol}>
<Stack
align={['right', 'center']}
flexDirection={['row', 'column']}
>
<Text fontWeight="bold" fontSize="sm" mr={['2', '0']}>
{protocol}:
</Text>
{generateWebStatusIcon()}
</Stack>
</Box>
)
})}
{emailProtocols.map((protocol) => {
return (
<Box flexShrink="0" ml={{ md: 2 }} mr={{ md: 2 }} key={protocol}>
<Stack
align={['right', 'center']}
flexDirection={['row', 'column']}
>
<Text fontWeight="bold" fontSize="sm" mr={['2', '0']}>
{protocol}:
</Text>
{generateEmailStatusIcon()}
</Stack>
</Box>
)
})}
</PseudoBox>
</ListItem>
)
}
DomainCard.propTypes = {
url: string.isRequired,
lastRan: string.isRequired,
}