Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): bulk remove vulnerabilities #168

Merged
merged 17 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/startScan/templates/startScan/detail_scan.html
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@ <h4 class="header-title mb-0"><span id="endpoint_change_count"><span class="spin
});

$('#vulnerability_results').on('click', 'tr' , function (e) {
if ($(e.target).is('input[type="checkbox"]') || $(e.target).is('svg') || $(e.target).is('a')) {
if ($(e.target).is('input[type="checkbox"]') || $(e.target).is('svg') || $(e.target).is('a') || $(e.target).is('span')) {
return;
}
var data = vulnerability_table.row(this).data();
Expand Down
17 changes: 6 additions & 11 deletions web/startScan/templates/startScan/vulnerabilities.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,27 +78,22 @@
{"className": "text-center", "targets": []},
{
"render": function ( data, type, row ) {
if(row['open_status']){
return `<div class="form-check mb-2 form-check-primary"><input type="checkbox" name="targets_checkbox['+ e + ']" class="float-start form-check-input" onchange="vuln_status_change(this, `+data+`);">\n<span class="new-control-indicator"></span><span style="visibility:hidden">c</span></div>`;
}
else{
return `<div class="form-check mb-2 form-check-primary"><input type="checkbox" checked name="targets_checkbox['+ e + ']" class="float-start form-check-input" onchange="vuln_status_change(this, `+data+`);">\n<span class="new-control-indicator"></span><span style="visibility:hidden">c</span></div>`;
}
return `<div class="form-check mb-2 form-check-primary"><input type="checkbox" name="targets_checkbox['+ e + ']" class="float-start form-check-input vulnerability_checkbox">\n<span class="new-control-indicator"></span><span style="visibility:hidden">c</span></div>`;
},
"targets": 0,
},
{
"render": function ( data, type, row ) {
if (data) {
return `<span class="badge badge-outline-primary">&nbsp;&nbsp;${data.toUpperCase()}&nbsp;&nbsp;</span>`;
return `<span class="badge badge-outline-primary">${data.toUpperCase()}</span>`;
}
},
"targets": 1,
},
{
"render": function ( data, type, row ) {
if (data) {
return `<span class="badge badge-soft-primary">&nbsp;&nbsp;${data.toUpperCase()}&nbsp;&nbsp;</span>`;
return `<span class="badge badge-soft-primary">${data.toUpperCase()}</span>`;
}
},
"targets": 2,
Expand Down Expand Up @@ -205,10 +200,10 @@
{
"render": function ( data, type, row ) {
if (data){
return '<span class="badge badge-soft-danger">&nbsp;&nbsp;OPEN&nbsp;&nbsp;</span>'
return '<span class="vuln-status badge badge-soft-danger" role="button" onclick="vuln_status_change(this, '+row.id+', '+row.open_status+');">OPEN</span>'
}
else{
return '<span class="badge badge-soft-success">&nbsp;&nbsp;RESOLVED&nbsp;&nbsp;</span>'
return '<span class="vuln-status badge badge-soft-success" role="button" onclick="vuln_status_change(this, '+row.id+', '+row.open_status+');">RESOLVED</span>'
}
},
"targets": 15,
Expand Down Expand Up @@ -298,7 +293,7 @@

$('#vulnerability_results').on('click', 'tr' , function (e) {
console.log(e.target);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove this console log

if ($(e.target).is('input[type="checkbox"]') || $(e.target).is('svg') || $(e.target).is('a') || $(e.target).is('th')) {
if ($(e.target).is('input[type="checkbox"]') || $(e.target).is('svg') || $(e.target).is('a') || $(e.target).is('th') || $(e.target).is('span')) {
return;
}
var data = vulnerability_table.row(this).data();
Expand Down
2 changes: 1 addition & 1 deletion web/static/custom/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ form-control:disabled, .form-control[readonly]{
.badge {
font-weight: 600 !important;
line-height: 1.4 !important;
padding: 3px 6px !important;
padding: 3px 12px !important;
font-size: 13px !important;
font-weight: 600 !important;
transition: all 0.3s ease-out !important;
Expand Down
95 changes: 90 additions & 5 deletions web/static/custom/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,46 @@ function download(filename, text) {
document.body.removeChild(element);
}

function vuln_status_change(checkbox, id) {
if (checkbox.checked) {
checkbox.parentNode.parentNode.parentNode.className = "table-success text-strike";
function vuln_status_change(element, id, status) {
psyray marked this conversation as resolved.
Show resolved Hide resolved
if (status) {
$(element).closest("tr").addClass("table-success text-strike");
$(element).text('RESOLVED')
$(element).removeClass('badge-soft-danger').addClass('badge-soft-success');
$(element).attr('onclick','vuln_status_change(this, '+id+', false)')
} else {
checkbox.parentNode.parentNode.parentNode.classList.remove("table-success");
checkbox.parentNode.parentNode.parentNode.classList.remove("text-strike");
$(element).closest("tr").removeClass("table-success text-strike")
$(element).text('OPEN')
$(element).removeClass('badge-soft-success').addClass('badge-soft-danger');
$(element).attr('onclick','vuln_status_change(this, '+id+', true)')
}
change_vuln_status(id);
}

function bulk_vuln_status_change(status){
var vulnStatusArray = $('.vulnerability_checkbox:checked').parents("tr").find('.vuln-status')
Array.from(vulnStatusArray).forEach(vulnStatus => {
if(status==true){
if($(vulnStatus).text()=="OPEN"){
$(vulnStatus).trigger('click')
}
}else{
if($(vulnStatus).text()=="RESOLVED"){
$(vulnStatus).trigger('click')
}
}
});

}

$('#select_all_checkbox').on('click',function(){
if($(this).is(':checked')){
$("tr").find("[type=checkbox]").prop('checked', false);
$("tr").find("[type=checkbox]").prop('checked', true);
}else{
$("tr").find("[type=checkbox]").prop('checked', true);
$("tr").find("[type=checkbox]").prop('checked', false); }
});

$("#vulnerability_results").on('click', '.btn-delete-vulnerability', function () {
var vulnerability_id = $(this).attr('id');
var data = {'vulnerability_ids': [vulnerability_id]};
Expand Down Expand Up @@ -450,6 +480,61 @@ $("#vulnerability_results").on('click', '.btn-delete-vulnerability', function ()
});


$("#bulk_delete_vulnerabilities").on('click', function () {
//btn-delete-vulnerability contains vuln id to delete
var vulnerabilities = $('.vulnerability_checkbox:checked').parents("tr").find('.btn-delete-vulnerability')
var vulnerabilities_ids = Array();
Array.from(vulnerabilities).forEach(vuln => {
vulnerabilities_ids.push($(vuln).attr('id'));
});
var data = {'vulnerability_ids': vulnerabilities_ids};
Swal.fire({
showCancelButton: true,
title: 'Bulk Delete Vulnerabilities!',
text: 'Do you really want to delete all those Vulnerabilities? This action cannot be undone.',
icon: 'error',
confirmButtonText: 'Delete',
}).then((result) => {
if (result.isConfirmed) {
Swal.fire({
title: 'Deleting Vulnerabilities...',
allowOutsideClick: false
});
swal.showLoading();
fetch('/api/action/vulnerability/delete/', {
method: 'POST',
credentials: "same-origin",
psyray marked this conversation as resolved.
Show resolved Hide resolved
headers: {
"X-CSRFToken": getCookie("csrftoken"),
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(function (response) {
swal.close();
if (response['status']) {
Array.from(vulnerabilities).forEach(vuln => {
$(vuln).parents('tr').remove();
});
Snackbar.show({
text: 'Vulnerabilities successfully deleted!',
pos: 'top-right',
duration: 2500
});
}
else{
Swal.fire({
title: 'Could not delete Vulnerabilities!',
icon: 'fail',
});
}
});
}
});;
$('a[data-toggle="tooltip').tooltip("hide")
});

function report_hackerone(vulnerability_id, severity) {
message = ""
if (severity == 'Info' || severity == 'Low' || severity == 'Medium') {
Expand Down
2 changes: 1 addition & 1 deletion web/targetApp/templates/target/summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -1649,7 +1649,7 @@ <h4 class="header-title mb-0"><span id="technologies-count"><span class="spinner
});

$('#vulnerability_results').on('click', 'tr' , function (e) {
if ($(e.target).is('input[type="checkbox"]') || $(e.target).is('svg') || $(e.target).is('a')) {
if ($(e.target).is('input[type="checkbox"]') || $(e.target).is('svg') || $(e.target).is('a') || $(e.target).is('span')) {
return;
}
var data = vulnerability_table.row(this).data();
Expand Down
21 changes: 21 additions & 0 deletions web/templates/base/_items/vulnerability_tab_content.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@
<div class="card-body">
<div class="row">
<div class="col-12">
psyray marked this conversation as resolved.
Show resolved Hide resolved
<div class="btn-group mb-2 float-start dropstart">
<div class="form-check">
<input type="checkbox" id="select_all_checkbox" name="select_all_checkbox">
<label class="form-check-label" for="select_all_checkbox">Select All</label>
</div>
</div>
<div class="btn-group mb-2 float-end dropstart">
<button id="bulk_delete_vulnerabilities" class="btn btn-danger ms-1" aria-haspopup="true" aria-expanded="false" data-toggle="tooltip" data-placement="left" title="Bulk Delete Vulnerabilities">
<i class="fe-regular fe-trash"></i>
</button>
</div>
<div class="btn-group mb-2 float-end dropstart">
<button id="" class="btn btn-success ms-1" onclick="bulk_vuln_status_change(true)" aria-haspopup="true" aria-expanded="false" data-toggle="tooltip" data-placement="left" title="Resolve All">
<span>Resolve All<span>
</button>
</div>
<div class="btn-group mb-2 float-end dropstart">
<button id="" class="btn btn-danger ms-1" onclick="bulk_vuln_status_change(false)" aria-haspopup="true" aria-expanded="false" data-toggle="tooltip" data-placement="left" title="Open All">
<span>Open All<span>
</button>
</div>
<div class="btn-group mb-2 float-end dropstart">
<button class="btn btn-soft-primary dropdown-toggle ms-1" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-toggle="tooltip" data-placement="left" title="Filter Columns">
<i class="fe-filter"></i>
Expand Down