Added view whois on target add

This commit is contained in:
Yogesh Ojha
2022-04-24 22:57:31 +05:30
parent ee41751325
commit fe95523fcb
4 changed files with 46 additions and 2 deletions
+3
View File
@@ -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
+31 -1
View File
@@ -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()
+11
View File
@@ -62,6 +62,7 @@ Add or Import Targets
<div>
<label for="simpleinput" class="form-label">Domain name</label>
{{ form.name }}
<span class="float-end"><a href="#" onclick="show_whois()" class="btn disabled" id="btn_view_whois">(View WHOIS)</a></span>
{% if form.errors %}
<div class="invalid-feedback" style="display: block;">
{{ 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);
}
}
</script>
{% endblock page_level_script %}
+1 -1
View File
@@ -74,7 +74,7 @@ Targets
<td class="checkbox-column"> {{ domain.id }} </td>
<td class=""> {{ domain.id }} </td>
<td>
<b>{{ domain.name }}</b>&nbsp;&nbsp;<a href="#" onclick="get_domain_whois('{{domain.name}}')">(view whois)</a>
<b>{{ domain.name }}</b>&nbsp;&nbsp;<a href="#" onclick="get_target_whois('{{domain.name}}')">(view whois)</a>
<br>
<small class="text-muted">Added {{ domain.insert_date|naturaltime }}</small>
{% if domain.get_organization %}