gophish/static/js/dist/app/campaign_results.min.js

83 lines
20 KiB
JavaScript
Raw Normal View History

2023-10-04 02:38:00 +00:00
var map=null;var doPoll=true;var statuses={"Email Sent":{color:"#1abc9c",label:"label-success",icon:"fa-envelope",point:"ct-point-sent"},"Emails Sent":{color:"#1abc9c",label:"label-success",icon:"fa-envelope",point:"ct-point-sent"},"In progress":{label:"label-primary"},Queued:{label:"label-info"},Completed:{label:"label-success"},"Email Opened":{color:"#f9bf3b",label:"label-warning",icon:"fa-envelope-open",point:"ct-point-opened"},"Clicked Link":{color:"#F39C12",label:"label-clicked",icon:"fa-mouse-pointer",point:"ct-point-clicked"},Success:{color:"#f05b4f",label:"label-danger",icon:"fa-exclamation",point:"ct-point-clicked"},"Email Reported":{color:"#45d6ef",label:"label-info",icon:"fa-bullhorn",point:"ct-point-reported"},Error:{color:"#6c7a89",label:"label-default",icon:"fa-times",point:"ct-point-error"},"Error Sending Email":{color:"#6c7a89",label:"label-default",icon:"fa-times",point:"ct-point-error"},"Submitted Data":{color:"#f05b4f",label:"label-danger",icon:"fa-exclamation",point:"ct-point-clicked"},Unknown:{color:"#6c7a89",label:"label-default",icon:"fa-question",point:"ct-point-error"},Sending:{color:"#428bca",label:"label-primary",icon:"fa-spinner",point:"ct-point-sending"},Retrying:{color:"#6c7a89",label:"label-default",icon:"fa-clock-o",point:"ct-point-error"},Scheduled:{color:"#428bca",label:"label-primary",icon:"fa-clock-o",point:"ct-point-sending"},"Campaign Created":{label:"label-success",icon:"fa-rocket"}};var statusMapping={"Email Sent":"sent","Email Opened":"opened","Clicked Link":"clicked","Submitted Data":"submitted_data","Email Reported":"reported"};var progressListing=["Email Sent","Email Opened","Clicked Link","Submitted Data"];var campaign={};var bubbles=[];function dismiss(){$("#modal\\.flashes").empty();$("#modal").modal("hide");$("#resultsTable").dataTable().DataTable().clear().draw()}function deleteCampaign(){Swal.fire({title:"Are you sure?",text:"This will delete the campaign. This can't be undone!",type:"warning",animation:false,showCancelButton:true,confirmButtonText:"Delete Campaign",confirmButtonColor:"#428bca",reverseButtons:true,allowOutsideClick:false,showLoaderOnConfirm:true,preConfirm:function(){return new Promise(function(resolve,reject){api.campaignId.delete(campaign.id).success(function(msg){resolve()}).error(function(data){reject(data.responseJSON.message)})})}}).then(function(result){if(result.value){Swal.fire("Campaign Deleted!","This campaign has been deleted!","success")}$('button:contains("OK")').on("click",function(){location.href="/campaigns"})})}function completeCampaign(){Swal.fire({title:"Are you sure?",text:"Gophish will stop processing events for this campaign",type:"warning",animation:false,showCancelButton:true,confirmButtonText:"Complete Campaign",confirmButtonColor:"#428bca",reverseButtons:true,allowOutsideClick:false,showLoaderOnConfirm:true,preConfirm:function(){return new Promise(function(resolve,reject){api.campaignId.complete(campaign.id).success(function(msg){resolve()}).error(function(data){reject(data.responseJSON.message)})})}}).then(function(result){if(result.value){Swal.fire("Campaign Completed!","This campaign has been completed!","success");$("#complete_button")[0].disabled=true;$("#complete_button").text("Completed!");doPoll=false}})}function function exportAsCSV(scope) {
var csvScope = null;
var filename = campaign.name + ' - ' + capitalize(scope) + '.csv';
switch (scope) {
case "results":
csvScope = campaign.results;
break;
case "events":
csvScope = campaign.timeline;
break;
}
if (!csvScope) {
return;
}
// Create an array to hold the CSV data
var csvData = [];
// Add the CSV header
var header = ['Email', 'Email Opened', 'Clicked Link', 'Submitted Data'];
csvData.push(header);
// Define a helper function to convert boolean to string
function boolToString(value) {
return value ? 'true' : 'false';
}
// Add CSV rows for each entry in csvScope
csvScope.forEach(function (entry) {
var email = entry.email;
var status = entry.status;
// Initialize status flags
var emailOpened = false;
var clickedLink = false;
var submittedData = false;
// Update status flags based on the status value
switch (status) {
case 'Email Opened':
emailOpened = true;
break;
case 'Clicked Link':
emailOpened = true; // If clicked link, email is also opened
clickedLink = true;
break;
case 'Submitted Data':
emailOpened = true; // If submitted data, email is also opened
clickedLink = true; // If submitted data, link is also clicked
submittedData = true;
break;
}
// Add the CSV row
var csvRow = [email, boolToString(emailOpened), boolToString(clickedLink), boolToString(submittedData)];
csvData.push(csvRow);
});
// Convert the CSV data array to a CSV string
var csvString = csvData.map(function (row) {
return row.join(',');
}).join('\n');
// Create a Blob with the CSV string
var csvBlob = new Blob([csvString], {
type: 'text/csv;charset=utf-8;'
});
// Create a download link
var csvURL = window.URL.createObjectURL(csvBlob);
var dlLink = document.createElement('a');
dlLink.href = csvURL;
dlLink.setAttribute('download', filename);
// Trigger the download
dlLink.click();
// Clean up
window.URL.revokeObjectURL(csvURL);
}function replay(event_idx){request=campaign.timeline[event_idx];details=JSON.parse(request.details);url=null;form=$("<form>").attr({method:"POST",target:"_blank"});$.each(Object.keys(details.payload),function(i,param){if(param=="rid"){return true}if(param=="__original_url"){url=details.payload[param];return true}$("<input>").attr({name:param}).val(details.payload[param]).appendTo(form)});Swal.fire({title:"Where do you want the credentials submitted to?",input:"text",showCancelButton:true,inputPlaceholder:"http://example.com/login",inputValue:url||"",inputValidator:function(value){return new Promise(function(resolve,reject){if(value){resolve()}else{reject("Invalid URL.")}})}}).then(function(result){if(result.value){url=result.value;submitForm()}});return;submitForm();function submitForm(){form.attr({action:url});form.appendTo("body").submit().remove()}}var renderDevice=function(event_details){var ua=UAParser(details.browser["user-agent"]);var detailsString='<div class="timeline-device-details">';var deviceIcon="laptop";if(ua.device.type){if(ua.device.type=="tablet"||ua.device.type=="mobile"){deviceIcon=ua.device.type}}var deviceVendor="";if(ua.device.vendor){deviceVendor=ua.device.vendor.toLowerCase();if(deviceVendor=="microsoft")deviceVendor="windows"}var deviceName="Unknown";if(ua.os.name){deviceName=ua.os.name;if(deviceName=="Mac OS"){deviceVendor="apple"}else if(deviceName=="Windows"){deviceVendor="windows"}if(ua.device.vendor&&ua.device.model){deviceName=ua.device.vendor+" "+ua.device.model}}if(ua.os.version){deviceName=deviceName+" (OS Version: "+ua.os.version+")"}deviceString='<div class="timeline-device-os"><span class="fa fa-stack">'+'<i class="fa fa-'+escapeHtml(deviceIcon)+' fa-stack-2x"></i>'+'<i class="fa fa-vendor-icon fa-'+escapeHtml(deviceVendor)+' fa-stack-1x"></i>'+"</span> "+escapeHtml(deviceName)+"</div>";detailsString+=deviceString;var deviceBrowser="Unknown";var browserIcon="info-circle";var browserVersion="";if(ua.browser&&ua.browser.name){deviceBrowser=ua.browser.name;deviceBrowser=deviceBrowser.replace("Mobile ","");if(deviceBrowser){browserIcon=deviceBrowser.toLowerCase();if(browserIcon=="ie")browserIcon="internet-explorer"}browserVersion="(Version: "+ua.browser.version+")"}var browserString='<div class="timeline-device-browser"><span class="fa fa-stack">'+'<i class="fa fa-'+escapeHtml(browserIcon)+' fa-stack-1x"></i></span> '+deviceBrowser+" "+browserVersion+"</div>";detailsString+=browserString;detailsString+="</div>";return detailsString};function renderTimeline(data){record={id:data[0],first_name:data[2],last_name:data[3],email:data[4],position:data[5],status:data[6],reported:data[7],send_date:data[8]};results='<div class="timeline col-sm-12 well well-lg">'+"<h6>Timeline for "+escapeHtml(record.first_name)+" "+escapeHtml(record.last_name)+'</h6><span class="subtitle">Email: '+escapeHtml(record.email)+"<br>Result ID: "+escapeHtml(record.id)+"</span>"+'<div class="timeline-graph col-sm-6">';$.each(campaign.timeline,function(i,event){if(!event.email||event.email==record.email){results+='<div class="timeline-entry">'+' <div class="timeline-bar"></div>';results+=' <div class="timeline-icon '+statuses[event.message].label+'">'+' <i class="fa '+statuses[event.message].icon+'"></i></div>'+' <div class="timeline-message">'+escapeHtml(event.message)+' <span class="timeline-date">'+moment.utc(event.time).local().format("MMMM Do YYYY h:mm:ss a")+"</span>";if(event.details){details=JSON.parse(event.details);if(event.message=="Clicked Link"||event.message=="Submitted Data"){deviceView=renderDevice(details);if(deviceView){results+=deviceView}}if(event.message=="Submitted Data"){results+='<div class="timeline-replay-button"><button onclick="replay('+i+')" class="btn btn-success">';results+='<i class="fa fa-refresh"></i> Replay Credentials</button></div>';results+='<div class="timeline-event-details"><i class="fa fa-caret-right"></i> View Details</div>'}if(details.payload){results+='<div class="timeline-event-results">';results+=' <table class="table table-condensed table-bordered table-st