Moved connection functions to main

This commit is contained in:
z0ccc 2021-08-26 13:52:15 -04:00
parent ba1a7d07d1
commit 4eb65a0c91
2 changed files with 57 additions and 51 deletions

View file

@ -1,16 +1,17 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import ScanBlock from './ScanBlock'; import ScanBlock from './ScanBlock';
import Table from './Table'; import Table from './Table';
import { getConnection } from './main';
const ConnectionBlock = () => { const ConnectionBlock = () => {
const [connectData, setConnectData] = useState(''); const [data, setData] = useState('');
const [display, setDisplay] = useState(''); const [display, setDisplay] = useState('');
useEffect(() => { useEffect(() => {
fetch('https://api.vytal.io/ip/') fetch('https://api.vytal.io/ip/')
.then((response) => response.json()) .then((response) => response.json())
.then((data) => { .then((json) => {
setConnectData(data); setData(getConnection(json));
setDisplay(1); setDisplay(1);
}) })
.catch(() => { .catch(() => {
@ -18,47 +19,6 @@ const ConnectionBlock = () => {
}); });
}, []); }, []);
const detectTor = () => {
const date = new Date();
if (
navigator.plugins.length === 0 &&
date.getTimezoneOffset() === 0 &&
window.outerWidth === window.screen.availWidth &&
window.outerHeight === window.screen.availHeight
) {
return true;
}
return false;
};
const data = [
{
key: 'ipAddress',
title: 'IP address',
value: connectData.query,
},
{
key: 'isp',
title: 'ISP',
value: connectData.isp,
},
{
key: 'org',
title: 'Organization',
value: connectData.org,
},
{
key: 'asn',
title: 'ASN',
value: connectData.as,
},
{
key: 'tor',
title: 'Tor browser detected',
value: detectTor() ? 'True' : 'False',
},
];
return ( return (
<ScanBlock> <ScanBlock>
<h1>Connection</h1> <h1>Connection</h1>

View file

@ -4,6 +4,8 @@ import axios from 'axios';
export { export {
getLocation, getLocation,
getConnection,
detectTor,
getSoftware, getSoftware,
getHardware, getHardware,
getWebGL, getWebGL,
@ -14,42 +16,86 @@ export {
handleSave, handleSave,
}; };
const getLocation = (locationData) => { const getLocation = (json) => {
const data = [ const data = [
{ {
key: 'country', key: 'country',
title: 'Country', title: 'Country',
value: locationData.country, value: json.country,
}, },
{ {
key: 'regionName', key: 'regionName',
title: 'Region', title: 'Region',
value: locationData.regionName, value: json.regionName,
}, },
{ {
key: 'lat', key: 'lat',
title: 'City', title: 'City',
value: locationData.city, value: json.city,
}, },
{ {
key: 'zip', key: 'zip',
title: 'Zip code', title: 'Zip code',
value: locationData.zip, value: json.zip,
}, },
{ {
key: 'lat', key: 'lat',
title: 'Latitude', title: 'Latitude',
value: locationData.lat, value: json.lat,
}, },
{ {
key: 'lon', key: 'lon',
title: 'Longitude', title: 'Longitude',
value: locationData.lon, value: json.lon,
}, },
]; ];
return data; return data;
}; };
const getConnection = (json) => {
const data = [
{
key: 'ipAddress',
title: 'IP address',
value: json.query,
},
{
key: 'isp',
title: 'ISP',
value: json.isp,
},
{
key: 'org',
title: 'Organization',
value: json.org,
},
{
key: 'asn',
title: 'ASN',
value: json.as,
},
{
key: 'tor',
title: 'Tor browser detected',
value: detectTor() ? 'True' : 'False',
},
];
return data;
};
const detectTor = () => {
const date = new Date();
if (
navigator.plugins.length === 0 &&
date.getTimezoneOffset() === 0 &&
window.outerWidth === window.screen.availWidth &&
window.outerHeight === window.screen.availHeight
) {
return true;
}
return false;
};
const getHardware = () => { const getHardware = () => {
const data = [ const data = [
{ {