Skip to content

Commit 2d6a910

Browse files
added geo ip lookup
1 parent 2b29be3 commit 2d6a910

File tree

3 files changed

+165
-0
lines changed

3 files changed

+165
-0
lines changed

src/_nav.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ const _nav = [
156156
name: 'Application Approval',
157157
to: '/tenant/administration/appapproval',
158158
},
159+
{
160+
component: CNavItem,
161+
name: 'Geo IP Lookup',
162+
to: '/tenant/tools/geoiplookup',
163+
},
159164
{
160165
component: CNavItem,
161166
name: 'Tenant Lookup',

src/routes.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const AddGroupTemplates = React.lazy(() =>
1717
const DeployGroupTemplates = React.lazy(() =>
1818
import('src/views/identity/administration/DeployGroupTemplate'),
1919
)
20+
const GeoIPLookup = React.lazy(() => import('src/views/tenant/administration/GeoIPLookup'))
21+
2022
const TenantLookup = React.lazy(() => import('src/views/tenant/administration/TenantLookup'))
2123
const GroupTemplates = React.lazy(() => import('src/views/identity/administration/GroupTemplates'))
2224

@@ -378,6 +380,11 @@ const routes = [
378380
name: 'Tenant Lookup',
379381
component: TenantLookup,
380382
},
383+
{
384+
path: '/tenant/tools/geoiplookup',
385+
name: 'Geo IP Lookup',
386+
component: GeoIPLookup,
387+
},
381388
{ path: '/tenant/standards/alert-list', name: 'Alert List (Alpha)', component: ListAlerts },
382389
{ path: '/endpoint', name: 'Endpoint' },
383390
{ path: '/endpoint/applications', name: 'Applications' },
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
import React, { useEffect, useState } from 'react'
2+
import {
3+
CButton,
4+
CCard,
5+
CCardBody,
6+
CCardHeader,
7+
CCardTitle,
8+
CCol,
9+
CCollapse,
10+
CForm,
11+
CFormInput,
12+
CInputGroup,
13+
CRow,
14+
CSpinner,
15+
} from '@coreui/react'
16+
import useQuery from 'src/hooks/useQuery'
17+
import { Field, Form } from 'react-final-form'
18+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
19+
import { faBook, faSearch } from '@fortawesome/free-solid-svg-icons'
20+
import { useSelector } from 'react-redux'
21+
import { useNavigate } from 'react-router-dom'
22+
import { useLazyGenericGetRequestQuery } from 'src/store/api/app'
23+
import { CippContentCard } from 'src/components/layout'
24+
import Skeleton from 'react-loading-skeleton'
25+
import { domainsApi } from 'src/store/api/domains'
26+
27+
const isValidTenantInput = (value) => {
28+
// Check if the input is a valid IPAddress
29+
const ipRegex = new RegExp('^([0-9]{1,3}\\.){3}[0-9]{1,3}$')
30+
return !ipRegex.test(value)
31+
}
32+
33+
const GeoIPLookup = () => {
34+
let navigate = useNavigate()
35+
const tenant = useSelector((state) => state.app.currentTenant)
36+
let query = useQuery()
37+
const ip = query.get('ip')
38+
const SearchNow = query.get('SearchNow')
39+
const [visibleA, setVisibleA] = useState(true)
40+
const handleSubmit = async (values) => {
41+
setVisibleA(false)
42+
43+
const shippedValues = {
44+
ip: values.domain,
45+
SearchNow: true,
46+
random: (Math.random() + 1).toString(36).substring(7),
47+
}
48+
var queryString = Object.keys(shippedValues)
49+
.map((key) => key + '=' + shippedValues[key])
50+
.join('&')
51+
52+
navigate(`?${queryString}`)
53+
}
54+
const [execGraphRequest, graphrequest] = useLazyGenericGetRequestQuery()
55+
56+
useEffect(() => {
57+
if (ip) {
58+
execGraphRequest({
59+
path: 'api/ExecGeoIPLookup',
60+
params: {
61+
IP: ip,
62+
},
63+
})
64+
}
65+
}, [execGraphRequest, tenant.defaultDomainName, query, ip])
66+
67+
return (
68+
<CRow>
69+
<CCol xs={4}>
70+
<CCard className="content-card">
71+
<CCardHeader>
72+
<CCardTitle>
73+
<FontAwesomeIcon icon={faSearch} className="mx-2" />
74+
Geo IP Lookup
75+
</CCardTitle>
76+
</CCardHeader>
77+
<CCardBody>
78+
<Form
79+
onSubmit={handleSubmit}
80+
render={({ handleSubmit, submitting, pristine }) => {
81+
return (
82+
<CForm onSubmit={handleSubmit}>
83+
<Field name="domain" validate={isValidTenantInput}>
84+
{({ input, meta }) => {
85+
return (
86+
<>
87+
<CInputGroup className="mb-3">
88+
<CFormInput
89+
{...input}
90+
valid={!meta.error && meta.touched}
91+
invalid={meta.error && meta.touched}
92+
type="text"
93+
id="domain"
94+
placeholder="IP Address"
95+
area-describedby="IP Address"
96+
autoCapitalize="none"
97+
autoCorrect="off"
98+
/>
99+
<CButton type="submit" color="primary">
100+
Check{graphrequest.isFetching && <CSpinner size="sm" />}
101+
</CButton>
102+
</CInputGroup>
103+
</>
104+
)
105+
}}
106+
</Field>
107+
</CForm>
108+
)
109+
}}
110+
/>
111+
</CCardBody>
112+
</CCard>
113+
</CCol>
114+
{ip && (
115+
<CCol>
116+
<CippContentCard title="Current IP information" icon={faBook}>
117+
<CRow>
118+
<CCol sm={12} md={4} className="mb-3">
119+
<p className="fw-lighter">IP Address</p>
120+
{graphrequest.isFetching && <Skeleton />}
121+
{ip}
122+
</CCol>
123+
<CCol sm={12} md={4} className="mb-3">
124+
<p className="fw-lighter">Range</p>
125+
{graphrequest.isFetching && <Skeleton />}
126+
{graphrequest.data?.startaddress} - {graphrequest.data?.endAddress}
127+
</CCol>
128+
<CCol sm={12} md={4} className="mb-3">
129+
<p className="fw-lighter">Owner</p>
130+
{graphrequest.isFetching && <Skeleton />}
131+
{graphrequest.data?.OrgRef}
132+
</CCol>
133+
</CRow>
134+
<CRow>
135+
<CCol sm={12} md={4} className="mb-3">
136+
<p className="fw-lighter">Subnet Name</p>
137+
{graphrequest.isFetching && <Skeleton />}
138+
{graphrequest.data?.SubnetName}
139+
</CCol>
140+
<CCol sm={8} md={8} className="mb-3">
141+
<p className="fw-lighter">Geo IP Location</p>
142+
{graphrequest.isFetching && <Skeleton />}
143+
{graphrequest.data?.location?.countryCode} - {graphrequest.data?.location?.cityName}
144+
</CCol>
145+
</CRow>
146+
</CippContentCard>
147+
</CCol>
148+
)}
149+
</CRow>
150+
)
151+
}
152+
153+
export default GeoIPLookup

0 commit comments

Comments
 (0)