From ad2bd9a426178024d8464717a6c42630a94e8b62 Mon Sep 17 00:00:00 2001 From: acidburnmonkey Date: Thu, 7 Aug 2025 01:20:09 -0400 Subject: [PATCH] added ipinfo.is api , fixed innertext on html --- docker-compose.yml | 2 ++ mysite/settings.py | 20 ++---------- mysite/views.py | 17 +++++++---- static/scripts.js | 69 +++++++++++++++++++++++------------------- static/scripts.ts | 74 +++++++++++++++++++-------------------------- templates/home.html | 4 +-- 6 files changed, 86 insertions(+), 100 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 86b5d47..e5d0e75 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,8 @@ --- services: website: + env_file: + - .env build: context: . dockerfile: Dockerfile diff --git a/mysite/settings.py b/mysite/settings.py index 4b7c322..01cfd5b 100644 --- a/mysite/settings.py +++ b/mysite/settings.py @@ -26,9 +26,9 @@ load_dotenv() SECRET_KEY = os.getenv('DJANGO_KEY') # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = False +DEBUG = True -ALLOWED_HOSTS = ['localhost'] +ALLOWED_HOSTS = ['*'] # Application definition @@ -133,19 +133,3 @@ STATIC_ROOT = BASE_DIR / 'staticfiles' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' - - -# Security settings for production -SECURE_SSL_REDIRECT = False -USE_TLS = False -SECURE_BROWSER_XSS_FILTER = True -SECURE_CONTENT_TYPE_NOSNIFF = True -CSRF_COOKIE_SECURE = True -SESSION_COOKIE_SECURE = True - - -REST_FRAMEWORK = { - 'DEFAULT_RENDERER_CLASSES': [ - 'rest_framework.renderers.JSONRenderer', - ], -} diff --git a/mysite/views.py b/mysite/views.py index 8f0deb4..6e75e14 100644 --- a/mysite/views.py +++ b/mysite/views.py @@ -31,11 +31,16 @@ class Doxme(APIView): def get(self, request): client_ip = self.get_client_ip(request) - token = os.getenv('TOKEN') - url = f'http://api.ipinfo.io/lite/{client_ip}?token={token}' - ip_info = requests.get(url) + ipinfo_token = os.getenv('IPINFO_TOKEN') + ipinfo_url = f'http://api.ipinfo.io/lite/{client_ip}?token={ipinfo_token}' + ip_info = requests.get(ipinfo_url) - if ip_info.ok and not ip_info.json().get('bogon'): - print(ip_info) - return Response({'method': 'get', 'ip_info': ip_info.json()}, status=status.HTTP_200_OK) + + ipis_token = os.getenv('IPIS_TOKEN') + ipis_url = f'https://api.ipapi.is?q={client_ip}&key={ipis_token}' + ipis_info = requests.get(ipis_url) + + if ip_info.ok or ipis_info.ok: + print('ipinfo:',ip_info) + return Response({'method': 'get', 'ip_info': ip_info.json(),'ipis':ipis_info.json()}, status=status.HTTP_200_OK) return Response({'message': 'error at ipinfo'}, status=status.HTTP_400_BAD_REQUEST) diff --git a/static/scripts.js b/static/scripts.js index a8df34a..0f4fee5 100644 --- a/static/scripts.js +++ b/static/scripts.js @@ -1,34 +1,41 @@ -var requestOptions = { +document.addEventListener('DOMContentLoaded', function () { + const requestOptions = { method: 'GET', headers: { 'Content-Type': 'application/json' }, -}; -fetch('/doxme/', requestOptions) //call api - .then(function (response) { return response.json(); }) - .then(function (jsonResponse) { - var user_ip = jsonResponse.ip_info.ip; - var user_country = jsonResponse.ip_info.country; - var user_region = jsonResponse.ip_info.country_code; - // Update the HTML elements with the fetched information - document.getElementById('ip').textContent = "".concat(user_ip); - document.getElementById('country').textContent = "".concat(user_country); - document.getElementById('region').textContent = "".concat(user_region); - console.log('user_ip:', user_ip); - console.log('couintry:', user_country); - console.log('region:', user_region); -}) - .catch(function (error) { - console.error('Error fetching IP information:', error); -}); -fetch('http://ip-api.com/json/') - .then(function (response) { return response.json(); }) - .then(function (data) { - var user_city = data.city; - var user_isp = data.isp; - console.log('user_city', user_city); - console.log('user_isp', user_isp); - document.getElementById('city').textContent = "".concat(user_city); - document.getElementById('isp').textContent = "".concat(user_isp); -}) - .catch(function (err) { - console.log('idk error', err); + }; + + fetch('/doxme/', requestOptions) //call api + .then((response) => response.json()) + .then((jsonResponse) => { + const user_ip = jsonResponse.ip_info.ip; + const user_country = jsonResponse.ip_info.country; + const user_region = jsonResponse.ip_info.country_code; + + // Update the HTML elements with the fetched information + document.getElementById('ip').innerText = `${user_ip}`; + document.getElementById('country').innerText = `${user_country}`; + document.getElementById('region').innerText = `${user_region}`; + + console.log('user_ip:', user_ip); + console.log('couintry:', user_country); + console.log('region:', user_region); + + // IPIS api + const city = jsonResponse.ipis.location.city; + const state = jsonResponse.ipis.location.state; + const isp = jsonResponse.ipis.company.name; + const longitude = jsonResponse.ipis.location.longitude; + + console.log('city', city); + console.log('state', state); + console.log('isp', isp); + console.log('longitude', longitude); + + // innerText + document.getElementById('isp').innerText = `${isp}`; + document.getElementById('city').innerText = `${city}`; + }) + .catch((error) => { + console.error('Error fetching IP information:', error); + }); }); diff --git a/static/scripts.ts b/static/scripts.ts index e9ca1e8..646e950 100644 --- a/static/scripts.ts +++ b/static/scripts.ts @@ -1,53 +1,41 @@ -interface ApiResponse { - method: string; - ip_info: { - as_domain: string; - as_name: string; - asn: string; - continent: string; - continent_code: string; - country: string; - country_code: string; - ip: string; - }; -} - -const requestOptions = { +document.addEventListener('DOMContentLoaded', function () { + const requestOptions: RequestInit = { method: 'GET', headers: { 'Content-Type': 'application/json' }, -}; + }; -fetch('/doxme/', requestOptions) //call api + fetch('/doxme/', requestOptions) //call api .then((response) => response.json()) .then((jsonResponse) => { - const user_ip = jsonResponse.ip_info.ip; - const user_country = jsonResponse.ip_info.country; - const user_region = jsonResponse.ip_info.country_code; + const user_ip: string | null = jsonResponse.ip_info.ip; + const user_country: string | null = jsonResponse.ip_info.country; + const user_region: string | null = jsonResponse.ip_info.country_code; - // Update the HTML elements with the fetched information - document.getElementById('ip').textContent = `${user_ip}`; - document.getElementById('country').textContent = `${user_country}`; - document.getElementById('region').textContent = `${user_region}`; + // Update the HTML elements with the fetched information + document.getElementById('ip').textContent = `${user_ip}`; + document.getElementById('country').textContent = `${user_country}`; + document.getElementById('region').textContent = `${user_region}`; - console.log('user_ip:', user_ip); - console.log('couintry:', user_country); - console.log('region:', user_region); + console.log('user_ip:', user_ip); + console.log('couintry:', user_country); + console.log('region:', user_region); + + // IPIS api + const city = jsonResponse.ipis.location.city; + const state = jsonResponse.ipis.location.state; + const isp = jsonResponse.ipis.company.name; + const longitude = jsonResponse.ipis.location.longitude; + + console.log('city', city); + console.log('state', state); + console.log('isp', isp); + console.log('longitude', longitude); + + document.getElementById('city').textContent = `${city}`; + document.getElementById('state').textContent = `${state}`; + // document.getElementById('isp').textContent = `${longitude}`; }) .catch((error) => { - console.error('Error fetching IP information:', error); - }); - -fetch('http://ip-api.com/json/') - .then((response) => response.json()) - .then((data) => { - const user_city = data.city; - const user_isp = data.isp; - console.log('user_city', user_city); - console.log('user_isp', user_isp); - - document.getElementById('city').textContent = `${user_city}`; - document.getElementById('isp').textContent = `${user_isp}`; - }) - .catch((err) => { - console.log('idk error', err); + console.error('Error fetching IP information:', error); }); +}); diff --git a/templates/home.html b/templates/home.html index ce9d858..9f6bbc3 100644 --- a/templates/home.html +++ b/templates/home.html @@ -37,9 +37,9 @@

Internet Provider:

Loading...

- + + -