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
{{ form.name }} + (View WHOIS) {% if form.errors %}
{{ form.errors.name|striptags }} @@ -304,9 +305,11 @@ Add or Import Targets $('#domainName').on('change keyup',function(){ if ($('#domainName').val().length) { $("#add-single-target").removeAttr("disabled"); + $("#btn_view_whois").removeClass("btn disabled"); } else{ $("#add-single-target").prop("disabled", true); + $("#btn_view_whois").addClass("btn disabled"); } }); }); @@ -315,5 +318,13 @@ Add or Import Targets $(id).html('Selected file: ' + file.files.item(0).name); }; + function show_whois(){ + // check if target exists or not + var domain = document.getElementById("domainName").value; + if (domain) { + get_domain_whois(domain); + } + } + {% endblock page_level_script %} diff --git a/web/targetApp/templates/target/list.html b/web/targetApp/templates/target/list.html index 4fe5c933..949f45b9 100644 --- a/web/targetApp/templates/target/list.html +++ b/web/targetApp/templates/target/list.html @@ -74,7 +74,7 @@ Targets {{ domain.id }} {{ domain.id }} - {{ domain.name }}  (view whois) + {{ domain.name }}  (view whois)
Added {{ domain.insert_date|naturaltime }} {% if domain.get_organization %}