From 995755fc97ebe4d7906aae9a1bfd3fc22d2ba613 Mon Sep 17 00:00:00 2001 From: Yogesh Ojha Date: Mon, 25 Sep 2023 08:54:19 +0530 Subject: [PATCH] fix add target modal --- web/api/views.py | 6 +++++- web/static/custom/custom.js | 10 ++++++---- web/templates/base/base.html | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/web/api/views.py b/web/api/views.py index 137cae1e..08ce8f10 100644 --- a/web/api/views.py +++ b/web/api/views.py @@ -543,13 +543,17 @@ class AddTarget(APIView): h1_team_handle = data.get('h1_team_handle') description = data.get('description') domain_name = data.get('domain_name') + slug = data.get('slug') # Validate domain name if not validators.domain(domain_name): return Response({'status': False, 'message': 'Invalid domain or IP'}) + project = Project.objects.get(slug=slug) + # Create domain object in DB - domain, _ = Domain.objets.get_or_create(name=domain_name) + domain, _ = Domain.objects.get_or_create(name=domain_name) + domain.project = project domain.h1_team_handle = h1_team_handle domain.description = description if not domain.insert_date: diff --git a/web/static/custom/custom.js b/web/static/custom/custom.js index 39d41652..991ae6b3 100644 --- a/web/static/custom/custom.js +++ b/web/static/custom/custom.js @@ -1871,18 +1871,20 @@ function add_quick_target() { var domain_name = $('#target_name_modal').val(); var description = $('#target_description_modal').val(); var h1_handle = $('#h1_handle_modal').val(); - add_target(domain_name, h1_handle = h1_handle, description = description); + var current_slug = document.querySelector('input[name="current_project"]').value; + add_target(domain_name, current_slug, h1_handle = h1_handle, description = description); } -function add_target(domain_name, h1_handle = null, description = null) { +function add_target(domain_name, current_slug, h1_handle = null, description = null) { // this function will add domain_name as target console.log('Adding new target ' + domain_name) const add_api = '/api/add/target/?format=json'; const data = { 'domain_name': domain_name, 'h1_team_handle': h1_handle, - 'description': description + 'description': description, + 'slug': current_slug }; swal.queue([{ title: 'Add Target', @@ -1916,7 +1918,7 @@ function add_target(domain_name, h1_handle = null, description = null) { padding: '2em', showLoaderOnConfirm: true, preConfirm: function() { - window.location = `/scan/start/${data.domain_id}`; + window.location = `/scan/${current_slug}/start/${data.domain_id}`; } }]); } else { diff --git a/web/templates/base/base.html b/web/templates/base/base.html index 377a5b32..d49133ec 100644 --- a/web/templates/base/base.html +++ b/web/templates/base/base.html @@ -63,6 +63,7 @@ {# top nav begins #} {% include 'base/_items/top_nav.html' %} {# top nav ends #} +