mirror of https://github.com/gophish/gophish
Add feature to export group targets as CSV
A new feature has been added through which targets in a group can be exported as CSV. For this a new button has been added to the group page for every group. On clicking this button for a group, group targets will be downloaded as CSV file. This will enable an admin to download group targets from one system and import them on other to create a group.pull/2233/head
parent
db63ee978d
commit
99f1b9d3c4
|
@ -239,12 +239,16 @@ function load() {
|
||||||
escapeHtml(group.name),
|
escapeHtml(group.name),
|
||||||
escapeHtml(group.num_targets),
|
escapeHtml(group.num_targets),
|
||||||
moment(group.modified_date).format('MMMM Do YYYY, h:mm:ss a'),
|
moment(group.modified_date).format('MMMM Do YYYY, h:mm:ss a'),
|
||||||
"<div class='pull-right'><button class='btn btn-primary' data-toggle='modal' data-backdrop='static' data-target='#modal' onclick='edit(" + group.id + ")'>\
|
"<div class='pull-right'>\
|
||||||
<i class='fa fa-pencil'></i>\
|
<button class='btn btn-info' id='exportGroupButton" + group.id + "' onclick='exportGroupAsCSV(" + group.id + ',\"' + group.name +"\")'>\
|
||||||
</button>\
|
<i class='fa fa-file-excel-o'></i>\
|
||||||
<button class='btn btn-danger' onclick='deleteGroup(" + group.id + ")'>\
|
</button>\
|
||||||
<i class='fa fa-trash-o'></i>\
|
<button class='btn btn-primary' data-toggle='modal' data-backdrop='static' data-target='#modal' onclick='edit(" + group.id + ")'>\
|
||||||
</button></div>"
|
<i class='fa fa-pencil'></i>\
|
||||||
|
</button>\
|
||||||
|
<button class='btn btn-danger' onclick='deleteGroup(" + group.id + ")'>\
|
||||||
|
<i class='fa fa-trash-o'></i>\
|
||||||
|
</button></div>"
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
groupTable.rows.add(groupRows).draw()
|
groupTable.rows.add(groupRows).draw()
|
||||||
|
@ -292,3 +296,33 @@ $(document).ready(function () {
|
||||||
});
|
});
|
||||||
$("#csv-template").click(downloadCSVTemplate)
|
$("#csv-template").click(downloadCSVTemplate)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Exports group contents as a CSV file
|
||||||
|
function exportGroupAsCSV(groupId, groupName) {
|
||||||
|
var exportHTML = $("#exportGroupButton"+groupId).html()
|
||||||
|
var filename = groupName + '.csv'
|
||||||
|
var groupDetails = api.groupId.get(groupId)
|
||||||
|
if (!groupDetails) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
$("#exportGroupButton"+groupId).html('<i class="fa fa-spinner fa-spin"></i>')
|
||||||
|
var csvString = Papa.unparse(groupDetails.responseJSON.targets, {
|
||||||
|
'escapeFormulae': true
|
||||||
|
})
|
||||||
|
|
||||||
|
var csvData = new Blob([csvString], {
|
||||||
|
type: 'text/csv;charset=utf-8;'
|
||||||
|
});
|
||||||
|
if (navigator.msSaveBlob) {
|
||||||
|
navigator.msSaveBlob(csvData, filename);
|
||||||
|
} else {
|
||||||
|
var csvURL = window.URL.createObjectURL(csvData);
|
||||||
|
var dlLink = document.createElement('a');
|
||||||
|
dlLink.href = csvURL;
|
||||||
|
dlLink.setAttribute('download', filename)
|
||||||
|
document.body.appendChild(dlLink)
|
||||||
|
dlLink.click();
|
||||||
|
document.body.removeChild(dlLink)
|
||||||
|
}
|
||||||
|
$("#exportGroupButton"+groupId).html(exportHTML)
|
||||||
|
}
|
Loading…
Reference in New Issue