Browse Source

Merge pull request #106 from gophish/102-add-raw-export

Added ability to export raw events. Fixes #102
pull/113/head v0.1.1
Jordan Wright 5 years ago
parent
commit
da4d108908
2 changed files with 22 additions and 5 deletions
  1. +14
    -4
      static/js/app/campaign_results.js
  2. +8
    -1
      templates/campaign_results.html

+ 14
- 4
static/js/app/campaign_results.js View File

@ -73,20 +73,30 @@ function deleteCampaign() {
}
// Exports campaign results as a CSV file
function exportAsCSV() {
function exportAsCSV(scope) {
exportHTML = $("#exportButton").html()
var csvScope = null
switch (scope) {
case "results":
csvScope = campaign.results
break;
case "events":
csvScope = campaign.timeline
break;
}
if (!csvScope){return}
$("#exportButton").html('<i class="fa fa-spinner fa-spin"></i>')
var csvString = Papa.unparse(campaign.results, {})
var csvString = Papa.unparse(csvScope, {})
var csvData = new Blob([csvString], {
type: 'text/csv;charset=utf-8;'
});
if (navigator.msSaveBlob) {
navigator.msSaveBlob(csvData, 'results.csv');
navigator.msSaveBlob(csvData, scope + '.csv');
} else {
var csvURL = window.URL.createObjectURL(csvData);
var dlLink = document.createElement('a');
dlLink.href = csvURL;
dlLink.setAttribute('download', 'results.csv');
dlLink.setAttribute('download', scope + '.csv');
dlLink.click();
}
$("#exportButton").html(exportHTML)

+ 8
- 1
templates/campaign_results.html View File

@ -33,9 +33,16 @@
<a href="/campaigns" class="btn btn-default">
<i class="fa fa-arrow-circle-o-left fa-lg"></i> Back
</a>
<button type="button" id="exportButton" class="btn btn-primary" onclick="exportAsCSV()">
<div class="btn-group">
<button type="button" id="exportButton" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<i class="fa fa-file-excel-o"></i> Export CSV
<i class="fa fa-caret-down"></i>
</button>
<ul class="dropdown-menu" aria-labelledby="exportButton">
<li><a href="#" onclick="exportAsCSV('results')">Results</a></li>
<li><a href="#" onclick="exportAsCSV('events')">Raw Events</a></li>
</ul>
</div>
<button type="button" class="btn btn-danger" data-toggle="tooltip" onclick="deleteCampaign()">
<i class="fa fa-trash-o fa-lg"></i> Delete
</button>

Loading…
Cancel
Save