Skip to content

[pull] dev from KelvinTegelaar:dev #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/_nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ const _nav = [
name: 'Application Approval',
to: '/tenant/administration/appapproval',
},
{
component: CNavItem,
name: 'Geo IP Lookup',
to: '/tenant/tools/geoiplookup',
},
{
component: CNavItem,
name: 'Tenant Lookup',
Expand Down
7 changes: 7 additions & 0 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const AddGroupTemplates = React.lazy(() =>
const DeployGroupTemplates = React.lazy(() =>
import('src/views/identity/administration/DeployGroupTemplate'),
)
const GeoIPLookup = React.lazy(() => import('src/views/tenant/administration/GeoIPLookup'))

const TenantLookup = React.lazy(() => import('src/views/tenant/administration/TenantLookup'))
const GroupTemplates = React.lazy(() => import('src/views/identity/administration/GroupTemplates'))

Expand Down Expand Up @@ -378,6 +380,11 @@ const routes = [
name: 'Tenant Lookup',
component: TenantLookup,
},
{
path: '/tenant/tools/geoiplookup',
name: 'Geo IP Lookup',
component: GeoIPLookup,
},
{ path: '/tenant/standards/alert-list', name: 'Alert List (Alpha)', component: ListAlerts },
{ path: '/endpoint', name: 'Endpoint' },
{ path: '/endpoint/applications', name: 'Applications' },
Expand Down
3 changes: 2 additions & 1 deletion src/views/cipp/CIPPSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ const NotificationsSettings = () => {
]}
/>
</CCol>
<CCol>
<CCol className="mb-3">
<RFFSelectSearch
multi={true}
label="Choose which severity of alert you want to be notified for."
Expand All @@ -1143,6 +1143,7 @@ const NotificationsSettings = () => {
{ value: 'Alert', name: 'Alert' },
{ value: 'Error', name: 'Error' },
{ value: 'Info', name: 'Info' },
{ value: 'Warn', name: 'Warn' },
]}
/>
</CCol>
Expand Down
153 changes: 153 additions & 0 deletions src/views/tenant/administration/GeoIPLookup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import React, { useEffect, useState } from 'react'
import {
CButton,
CCard,
CCardBody,
CCardHeader,
CCardTitle,
CCol,
CCollapse,
CForm,
CFormInput,
CInputGroup,
CRow,
CSpinner,
} from '@coreui/react'
import useQuery from 'src/hooks/useQuery'
import { Field, Form } from 'react-final-form'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faBook, faSearch } from '@fortawesome/free-solid-svg-icons'
import { useSelector } from 'react-redux'
import { useNavigate } from 'react-router-dom'
import { useLazyGenericGetRequestQuery } from 'src/store/api/app'
import { CippContentCard } from 'src/components/layout'
import Skeleton from 'react-loading-skeleton'
import { domainsApi } from 'src/store/api/domains'

const isValidTenantInput = (value) => {
// Check if the input is a valid IPAddress
const ipRegex = new RegExp('^([0-9]{1,3}\\.){3}[0-9]{1,3}$')
return !ipRegex.test(value)
}

const GeoIPLookup = () => {
let navigate = useNavigate()
const tenant = useSelector((state) => state.app.currentTenant)
let query = useQuery()
const ip = query.get('ip')
const SearchNow = query.get('SearchNow')
const [visibleA, setVisibleA] = useState(true)
const handleSubmit = async (values) => {
setVisibleA(false)

const shippedValues = {
ip: values.domain,
SearchNow: true,
random: (Math.random() + 1).toString(36).substring(7),
}
var queryString = Object.keys(shippedValues)
.map((key) => key + '=' + shippedValues[key])
.join('&')

navigate(`?${queryString}`)
}
const [execGraphRequest, graphrequest] = useLazyGenericGetRequestQuery()

useEffect(() => {
if (ip) {
execGraphRequest({
path: 'api/ExecGeoIPLookup',
params: {
IP: ip,
},
})
}
}, [execGraphRequest, tenant.defaultDomainName, query, ip])

return (
<CRow>
<CCol xs={4}>
<CCard className="content-card">
<CCardHeader>
<CCardTitle>
<FontAwesomeIcon icon={faSearch} className="mx-2" />
Geo IP Lookup
</CCardTitle>
</CCardHeader>
<CCardBody>
<Form
onSubmit={handleSubmit}
render={({ handleSubmit, submitting, pristine }) => {
return (
<CForm onSubmit={handleSubmit}>
<Field name="domain" validate={isValidTenantInput}>
{({ input, meta }) => {
return (
<>
<CInputGroup className="mb-3">
<CFormInput
{...input}
valid={!meta.error && meta.touched}
invalid={meta.error && meta.touched}
type="text"
id="domain"
placeholder="IP Address"
area-describedby="IP Address"
autoCapitalize="none"
autoCorrect="off"
/>
<CButton type="submit" color="primary">
Check{graphrequest.isFetching && <CSpinner size="sm" />}
</CButton>
</CInputGroup>
</>
)
}}
</Field>
</CForm>
)
}}
/>
</CCardBody>
</CCard>
</CCol>
{ip && (
<CCol>
<CippContentCard title="Current IP information" icon={faBook}>
<CRow>
<CCol sm={12} md={4} className="mb-3">
<p className="fw-lighter">IP Address</p>
{graphrequest.isFetching && <Skeleton />}
{ip}
</CCol>
<CCol sm={12} md={4} className="mb-3">
<p className="fw-lighter">Range</p>
{graphrequest.isFetching && <Skeleton />}
{graphrequest.data?.startaddress} - {graphrequest.data?.endAddress}
</CCol>
<CCol sm={12} md={4} className="mb-3">
<p className="fw-lighter">Owner</p>
{graphrequest.isFetching && <Skeleton />}
{graphrequest.data?.OrgRef}
</CCol>
</CRow>
<CRow>
<CCol sm={12} md={4} className="mb-3">
<p className="fw-lighter">Subnet Name</p>
{graphrequest.isFetching && <Skeleton />}
{graphrequest.data?.SubnetName}
</CCol>
<CCol sm={8} md={8} className="mb-3">
<p className="fw-lighter">Geo IP Location</p>
{graphrequest.isFetching && <Skeleton />}
{graphrequest.data?.location?.countryCode} - {graphrequest.data?.location?.cityName}
</CCol>
</CRow>
</CippContentCard>
</CCol>
)}
</CRow>
)
}

export default GeoIPLookup