mirror of https://github.com/gophish/gophish
parent
42efe1b010
commit
14bb02f2d2
|
@ -198,6 +198,97 @@ function completeCampaign() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
function exportAsCleanCSV(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;
|
||||||
|
case "cleanresults":
|
||||||
|
csvScope = campaign.cleanResults; // Replace with your clean results data
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Example usage:
|
||||||
|
// exportAsCSV('results');
|
||||||
|
// exportAsCSV('events');
|
||||||
|
// exportAsCSV('cleanresults'); // Add this line to export clean results
|
||||||
|
|
||||||
|
|
||||||
// Exports campaign results as a CSV file
|
// Exports campaign results as a CSV file
|
||||||
function exportAsCSV(scope) {
|
function exportAsCSV(scope) {
|
||||||
|
|
Loading…
Reference in New Issue