diff --git a/web/api/views.py b/web/api/views.py index 27876155..ef5871f9 100644 --- a/web/api/views.py +++ b/web/api/views.py @@ -3,6 +3,7 @@ import json import logging import requests import subprocess +import validators from bs4 import BeautifulSoup from lxml import html @@ -424,6 +425,8 @@ class Whois(APIView): def get(self, request): req = self.request ip_domain = req.query_params.get('ip_domain') + if not validators.domain(ip_domain): + return Response({'status': False, 'message': 'Invalid Domain or IP'}) save_db = True if 'save_db' in req.query_params else False # fetch_from_db query param can be used to pull the whois record directly from db # instead of fetching new diff --git a/web/static/custom/custom.js b/web/static/custom/custom.js index 655ea58b..5a6dca7d 100644 --- a/web/static/custom/custom.js +++ b/web/static/custom/custom.js @@ -1411,7 +1411,7 @@ function fetch_whois(domain_name, save_db){ }); } -function get_domain_whois(domain_name){ +function get_target_whois(domain_name){ // this function will fetch whois from db, if not fetched, will make a fresh // query and will display whois on a modal var url = `/api/tools/whois/?format=json&ip_domain=${domain_name}&fetch_from_db` @@ -1459,6 +1459,36 @@ function get_domain_whois(domain_name){ }); } +function get_domain_whois(domain_name){ + // this function will get whois for domains that are not targets, this will + // not store whois into db nor create target + var url = `/api/tools/whois/?format=json&ip_domain=${domain_name}` + Swal.fire({ + title: `Fetching WHOIS details for ${domain_name}...` + }); + swal.showLoading(); + fetch(url, { + method: 'GET', + credentials: "same-origin", + headers: { + "X-CSRFToken": getCookie("csrftoken"), + 'Content-Type': 'application/json' + }, + }).then(response => response.json()).then(function(response) { + console.log(response); + if (response.status) { + swal.close(); + display_whois_on_modal(response); + } + else{ + Swal.fire({ + title: 'Oops!', + text: `reNgine could not fetch WHOIS records for ${domain_name}! ${response['message']}`, + icon: 'error' + }); + } + }); +} function display_whois_on_modal(response){ // this function will display whois data on modal, should be followed after get_domain_whois() diff --git a/web/targetApp/templates/target/add.html b/web/targetApp/templates/target/add.html index ef63425e..bb6ab105 100644 --- a/web/targetApp/templates/target/add.html +++ b/web/targetApp/templates/target/add.html @@ -62,6 +62,7 @@ Add or Import Targets