2015-08-12 02:12:09 +00:00
|
|
|
var map = null
|
2016-07-12 03:11:40 +00:00
|
|
|
var doPoll = true;
|
2015-07-29 00:31:12 +00:00
|
|
|
|
2015-08-12 02:12:09 +00:00
|
|
|
// statuses is a helper map to point result statuses to ui classes
|
|
|
|
var statuses = {
|
2016-08-26 01:56:05 +00:00
|
|
|
"HTML Opened": {
|
|
|
|
slice: "ct-slice-donut-opened",
|
|
|
|
legend: "ct-legend-opened",
|
|
|
|
label: "label-danger",
|
|
|
|
icon: "fa-file",
|
|
|
|
point: "ct-point-opened"
|
|
|
|
},
|
|
|
|
"WORD Opened": {
|
|
|
|
slice: "ct-slice-donut-opened",
|
|
|
|
legend: "ct-legend-opened",
|
|
|
|
label: "label-danger",
|
|
|
|
icon: "fa-file",
|
|
|
|
point: "ct-point-opened"
|
|
|
|
},
|
2016-01-17 04:59:40 +00:00
|
|
|
"Email Sent": {
|
2015-08-05 02:27:04 +00:00
|
|
|
slice: "ct-slice-donut-sent",
|
2015-08-12 02:12:09 +00:00
|
|
|
legend: "ct-legend-sent",
|
2016-01-29 15:55:49 +00:00
|
|
|
label: "label-success",
|
2016-03-09 03:37:30 +00:00
|
|
|
icon: "fa-envelope",
|
|
|
|
point: "ct-point-sent"
|
2015-08-05 02:27:04 +00:00
|
|
|
},
|
2016-01-17 04:59:40 +00:00
|
|
|
"Email Opened": {
|
2015-08-05 02:27:04 +00:00
|
|
|
slice: "ct-slice-donut-opened",
|
2015-08-12 02:12:09 +00:00
|
|
|
legend: "ct-legend-opened",
|
2016-01-29 15:55:49 +00:00
|
|
|
label: "label-warning",
|
2016-03-09 03:37:30 +00:00
|
|
|
icon: "fa-envelope",
|
|
|
|
point: "ct-point-opened"
|
2015-08-05 02:27:04 +00:00
|
|
|
},
|
2016-01-17 04:59:40 +00:00
|
|
|
"Clicked Link": {
|
2015-08-05 02:27:04 +00:00
|
|
|
slice: "ct-slice-donut-clicked",
|
2015-08-12 02:12:09 +00:00
|
|
|
legend: "ct-legend-clicked",
|
2016-01-29 15:55:49 +00:00
|
|
|
label: "label-danger",
|
2016-03-09 03:37:30 +00:00
|
|
|
icon: "fa-mouse-pointer",
|
|
|
|
point: "ct-point-clicked"
|
2015-08-12 02:12:09 +00:00
|
|
|
},
|
2016-01-17 04:59:40 +00:00
|
|
|
"Success": {
|
2015-08-12 02:12:09 +00:00
|
|
|
slice: "ct-slice-donut-clicked",
|
|
|
|
legend: "ct-legend-clicked",
|
2016-01-29 15:55:49 +00:00
|
|
|
label: "label-danger",
|
2016-03-09 03:37:30 +00:00
|
|
|
icon: "fa-exclamation",
|
|
|
|
point: "ct-point-clicked"
|
2015-08-05 02:27:04 +00:00
|
|
|
},
|
2016-01-17 04:59:40 +00:00
|
|
|
"Error": {
|
2015-08-05 02:27:04 +00:00
|
|
|
slice: "ct-slice-donut-error",
|
2015-08-12 02:12:09 +00:00
|
|
|
legend: "ct-legend-error",
|
2016-01-29 15:55:49 +00:00
|
|
|
label: "label-default",
|
2016-03-09 03:37:30 +00:00
|
|
|
icon: "fa-times",
|
|
|
|
point: "ct-point-error"
|
2015-09-28 03:25:38 +00:00
|
|
|
},
|
2016-01-29 18:34:29 +00:00
|
|
|
"Error Sending Email": {
|
|
|
|
slice: "ct-slice-donut-error",
|
|
|
|
legend: "ct-legend-error",
|
|
|
|
label: "label-default",
|
2016-03-09 03:37:30 +00:00
|
|
|
icon: "fa-times",
|
|
|
|
point: "ct-point-error"
|
2016-01-29 18:34:29 +00:00
|
|
|
},
|
2016-02-03 04:49:30 +00:00
|
|
|
"Submitted Data": {
|
2016-02-01 01:50:41 +00:00
|
|
|
slice: "ct-slice-donut-clicked",
|
|
|
|
legend: "ct-legend-clicked",
|
|
|
|
label: "label-danger",
|
2016-03-09 03:37:30 +00:00
|
|
|
icon: "fa-exclamation",
|
|
|
|
point: "ct-point-clicked"
|
2016-02-01 01:50:41 +00:00
|
|
|
},
|
2016-01-17 04:59:40 +00:00
|
|
|
"Unknown": {
|
|
|
|
slice: "ct-slice-donut-error",
|
|
|
|
legend: "ct-legend-error",
|
2016-01-29 15:55:49 +00:00
|
|
|
label: "label-default",
|
2016-03-09 03:37:30 +00:00
|
|
|
icon: "fa-question",
|
|
|
|
point: "ct-point-error"
|
2016-01-29 15:55:49 +00:00
|
|
|
},
|
2016-02-02 02:42:46 +00:00
|
|
|
"Sending": {
|
2016-03-09 03:37:30 +00:00
|
|
|
slice: "ct-slice-donut-sending",
|
|
|
|
legend: "ct-legend-sending",
|
2016-02-02 02:42:46 +00:00
|
|
|
label: "label-primary",
|
2016-03-09 03:37:30 +00:00
|
|
|
icon: "fa-spinner",
|
|
|
|
point: "ct-point-sending"
|
2016-02-02 02:42:46 +00:00
|
|
|
},
|
2016-01-29 15:55:49 +00:00
|
|
|
"Campaign Created": {
|
|
|
|
label: "label-success",
|
|
|
|
icon: "fa-rocket"
|
2015-08-05 02:27:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-29 00:31:12 +00:00
|
|
|
var campaign = {}
|
2016-02-24 00:50:07 +00:00
|
|
|
var bubbles = []
|
2015-07-29 00:31:12 +00:00
|
|
|
|
2016-01-17 04:59:40 +00:00
|
|
|
function dismiss() {
|
2015-07-29 00:31:12 +00:00
|
|
|
$("#modal\\.flashes").empty()
|
|
|
|
$("#modal").modal('hide')
|
2015-07-30 03:31:39 +00:00
|
|
|
$("#resultsTable").dataTable().DataTable().clear().draw()
|
2015-07-29 00:31:12 +00:00
|
|
|
}
|
|
|
|
|
2015-07-30 03:31:39 +00:00
|
|
|
// Deletes a campaign after prompting the user
|
2016-01-17 04:59:40 +00:00
|
|
|
function deleteCampaign() {
|
2016-07-12 04:31:11 +00:00
|
|
|
swal({
|
|
|
|
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,
|
|
|
|
preConfirm: function() {
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
api.campaignId.delete(campaign.id)
|
|
|
|
.success(function(msg) {
|
|
|
|
resolve()
|
|
|
|
})
|
|
|
|
.error(function(data) {
|
|
|
|
reject(data.responseJSON.message)
|
|
|
|
})
|
2016-01-17 04:59:40 +00:00
|
|
|
})
|
2016-07-12 04:31:11 +00:00
|
|
|
}
|
|
|
|
}).then(function() {
|
|
|
|
swal(
|
|
|
|
'Campaign Deleted!',
|
|
|
|
'This campaign has been deleted!',
|
|
|
|
'success'
|
|
|
|
);
|
|
|
|
$('button:contains("OK")').on('click', function() {
|
|
|
|
location.href = '/campaigns'
|
|
|
|
})
|
|
|
|
})
|
2015-07-29 00:31:12 +00:00
|
|
|
}
|
|
|
|
|
2016-07-12 03:11:40 +00:00
|
|
|
// Completes a campaign after prompting the user
|
|
|
|
function completeCampaign() {
|
|
|
|
swal({
|
2016-07-12 04:31:11 +00:00
|
|
|
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,
|
|
|
|
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() {
|
|
|
|
swal(
|
|
|
|
'Campaign Completed!',
|
|
|
|
'This campaign has been completed!',
|
|
|
|
'success'
|
|
|
|
);
|
|
|
|
$('#complete_button')[0].disabled = true;
|
|
|
|
$('#complete_button').text('Completed!')
|
|
|
|
doPoll = false;
|
|
|
|
})
|
2016-07-12 03:11:40 +00:00
|
|
|
}
|
|
|
|
|
2016-01-21 00:45:53 +00:00
|
|
|
// Exports campaign results as a CSV file
|
2016-01-29 19:18:06 +00:00
|
|
|
function exportAsCSV(scope) {
|
2016-01-21 00:45:53 +00:00
|
|
|
exportHTML = $("#exportButton").html()
|
2016-01-29 19:18:06 +00:00
|
|
|
var csvScope = null
|
|
|
|
switch (scope) {
|
2016-02-03 04:49:30 +00:00
|
|
|
case "results":
|
|
|
|
csvScope = campaign.results
|
|
|
|
break;
|
|
|
|
case "events":
|
|
|
|
csvScope = campaign.timeline
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!csvScope) {
|
|
|
|
return
|
2016-01-29 19:18:06 +00:00
|
|
|
}
|
2016-01-21 00:45:53 +00:00
|
|
|
$("#exportButton").html('<i class="fa fa-spinner fa-spin"></i>')
|
2016-01-29 19:18:06 +00:00
|
|
|
var csvString = Papa.unparse(csvScope, {})
|
2016-01-21 00:45:53 +00:00
|
|
|
var csvData = new Blob([csvString], {
|
|
|
|
type: 'text/csv;charset=utf-8;'
|
|
|
|
});
|
|
|
|
if (navigator.msSaveBlob) {
|
2016-01-29 19:18:06 +00:00
|
|
|
navigator.msSaveBlob(csvData, scope + '.csv');
|
2016-01-21 00:45:53 +00:00
|
|
|
} else {
|
|
|
|
var csvURL = window.URL.createObjectURL(csvData);
|
2016-01-29 14:31:58 +00:00
|
|
|
var dlLink = document.createElement('a');
|
|
|
|
dlLink.href = csvURL;
|
2016-01-29 19:18:06 +00:00
|
|
|
dlLink.setAttribute('download', scope + '.csv');
|
2016-02-15 18:18:21 +00:00
|
|
|
document.body.appendChild(dlLink)
|
2016-01-29 14:31:58 +00:00
|
|
|
dlLink.click();
|
2016-02-15 18:18:21 +00:00
|
|
|
document.body.removeChild(dlLink)
|
2016-01-21 00:45:53 +00:00
|
|
|
}
|
|
|
|
$("#exportButton").html(exportHTML)
|
|
|
|
}
|
|
|
|
|
2016-08-06 23:06:18 +00:00
|
|
|
function replay(event_idx) {
|
|
|
|
request = campaign.timeline[event_idx]
|
|
|
|
details = JSON.parse(request.details)
|
|
|
|
url = null
|
|
|
|
form = $('<form>').attr({
|
|
|
|
method: 'POST',
|
|
|
|
target: '_blank',
|
|
|
|
})
|
|
|
|
/* Create a form object and submit it */
|
|
|
|
$.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);
|
|
|
|
})
|
|
|
|
/* Ensure we know where to send the user */
|
|
|
|
// Prompt for the URL
|
|
|
|
swal({
|
|
|
|
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) {
|
|
|
|
url = result
|
|
|
|
submitForm()
|
|
|
|
})
|
|
|
|
return
|
|
|
|
submitForm()
|
|
|
|
|
|
|
|
function submitForm() {
|
|
|
|
form.attr({
|
|
|
|
action: url
|
|
|
|
})
|
|
|
|
form.appendTo('body').submit().remove()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-29 14:31:58 +00:00
|
|
|
function renderTimeline(data) {
|
|
|
|
record = {
|
2016-02-22 02:55:27 +00:00
|
|
|
"first_name": data[2],
|
|
|
|
"last_name": data[3],
|
|
|
|
"email": data[4],
|
|
|
|
"position": data[5]
|
2016-01-29 15:55:49 +00:00
|
|
|
}
|
|
|
|
results = '<div class="timeline col-sm-12 well well-lg">' +
|
2016-03-22 00:30:43 +00:00
|
|
|
'<h6>Timeline for ' + escapeHtml(record.first_name) + ' ' + escapeHtml(record.last_name) +
|
|
|
|
'</h6><span class="subtitle">Email: ' + escapeHtml(record.email) + '</span>' +
|
2016-01-29 15:55:49 +00:00
|
|
|
'<div class="timeline-graph col-sm-6">'
|
2016-01-29 14:31:58 +00:00
|
|
|
$.each(campaign.timeline, function(i, event) {
|
|
|
|
if (!event.email || event.email == record.email) {
|
2016-01-29 15:55:49 +00:00
|
|
|
// Add the event
|
2016-01-29 14:31:58 +00:00
|
|
|
results += '<div class="timeline-entry">' +
|
2016-01-29 15:55:49 +00:00
|
|
|
' <div class="timeline-bar"></div>'
|
|
|
|
results +=
|
|
|
|
' <div class="timeline-icon ' + statuses[event.message].label + '">' +
|
|
|
|
' <i class="fa ' + statuses[event.message].icon + '"></i></div>' +
|
2016-03-22 00:30:43 +00:00
|
|
|
' <div class="timeline-message">' + escapeHtml(event.message) +
|
2016-08-17 00:27:01 +00:00
|
|
|
' <span class="timeline-date">' + moment(event.time).format('MMMM Do YYYY h:mm a') + '</span>'
|
2016-08-08 23:28:19 +00:00
|
|
|
if (event.details && event.message == "Submitted Data") {
|
2016-08-06 23:06:18 +00:00
|
|
|
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>'
|
2016-02-03 04:49:30 +00:00
|
|
|
results += '<div class="timeline-event-details"><i class="fa fa-caret-right"></i> View Details</div>'
|
|
|
|
details = JSON.parse(event.details)
|
2016-02-13 03:25:49 +00:00
|
|
|
if (details.payload) {
|
|
|
|
results += '<div class="timeline-event-results">'
|
|
|
|
results += ' <table class="table table-condensed table-bordered table-striped">'
|
|
|
|
results += ' <thead><tr><th>Parameter</th><th>Value(s)</tr></thead><tbody>'
|
|
|
|
$.each(Object.keys(details.payload), function(i, param) {
|
|
|
|
if (param == "rid") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
results += ' <tr>'
|
2016-03-22 00:30:43 +00:00
|
|
|
results += ' <td>' + escapeHtml(param) + '</td>'
|
|
|
|
results += ' <td>' + escapeHtml(details.payload[param]) + '</td>'
|
2016-02-13 03:25:49 +00:00
|
|
|
results += ' </tr>'
|
|
|
|
})
|
|
|
|
results += ' </tbody></table>'
|
|
|
|
results += '</div>'
|
|
|
|
}
|
|
|
|
if (details.error) {
|
|
|
|
results += '<div class="timeline-event-results">'
|
|
|
|
results += '<span class="label label-default">Error</span> ' + details.error
|
|
|
|
results += '</div>'
|
|
|
|
}
|
2016-02-03 04:49:30 +00:00
|
|
|
}
|
2016-02-01 01:50:41 +00:00
|
|
|
results += '</div></div>'
|
2016-01-29 14:31:58 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
results += '</div></div>'
|
|
|
|
return results
|
|
|
|
}
|
2016-02-22 02:55:27 +00:00
|
|
|
|
2016-02-24 00:50:07 +00:00
|
|
|
|
|
|
|
/* poll - Queries the API and updates the UI with the results
|
|
|
|
*
|
|
|
|
* Updates:
|
|
|
|
* * Timeline Chart
|
|
|
|
* * Email (Donut) Chart
|
|
|
|
* * Map Bubbles
|
|
|
|
* * Datatables
|
|
|
|
*/
|
2016-02-22 02:55:27 +00:00
|
|
|
function poll() {
|
2016-06-08 03:31:55 +00:00
|
|
|
api.campaignId.results(campaign.id)
|
2016-02-22 02:55:27 +00:00
|
|
|
.success(function(c) {
|
|
|
|
campaign = c
|
|
|
|
/* Update the timeline */
|
|
|
|
var timeline_data = {
|
|
|
|
series: [{
|
|
|
|
name: "Events",
|
|
|
|
data: []
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
$.each(campaign.timeline, function(i, event) {
|
|
|
|
timeline_data.series[0].data.push({
|
|
|
|
meta: i,
|
|
|
|
x: new Date(event.time),
|
|
|
|
y: 1
|
|
|
|
})
|
|
|
|
})
|
|
|
|
var timeline_chart = $("#timeline_chart")
|
|
|
|
if (timeline_chart.get(0).__chartist__) {
|
|
|
|
timeline_chart.get(0).__chartist__.update(timeline_data)
|
|
|
|
}
|
|
|
|
/* Update the results donut chart */
|
|
|
|
var email_data = {
|
|
|
|
series: []
|
|
|
|
}
|
|
|
|
var email_series_data = {}
|
|
|
|
$.each(campaign.results, function(i, result) {
|
|
|
|
if (!email_series_data[result.status]) {
|
|
|
|
email_series_data[result.status] = 1
|
|
|
|
} else {
|
|
|
|
email_series_data[result.status]++;
|
|
|
|
}
|
|
|
|
})
|
2016-02-23 17:51:43 +00:00
|
|
|
$("#email_chart_legend").html("")
|
2016-02-22 02:55:27 +00:00
|
|
|
$.each(email_series_data, function(status, count) {
|
|
|
|
email_data.series.push({
|
|
|
|
meta: status,
|
|
|
|
value: count
|
|
|
|
})
|
2016-02-23 17:51:43 +00:00
|
|
|
$("#email_chart_legend").append('<li><span class="' + statuses[status].legend + '"></span>' + status + '</li>')
|
2016-02-22 02:55:27 +00:00
|
|
|
})
|
|
|
|
var email_chart = $("#email_chart")
|
|
|
|
if (email_chart.get(0).__chartist__) {
|
|
|
|
email_chart.get(0).__chartist__.on('draw', function(data) {
|
2016-02-23 17:51:43 +00:00
|
|
|
data.element.addClass(statuses[data.meta].slice)
|
|
|
|
})
|
|
|
|
// Update with the latest data
|
2016-02-22 02:55:27 +00:00
|
|
|
email_chart.get(0).__chartist__.update(email_data)
|
|
|
|
}
|
|
|
|
/* Update the datatable */
|
|
|
|
resultsTable = $("#resultsTable").DataTable()
|
2016-02-23 17:51:43 +00:00
|
|
|
resultsTable.rows().every(function(i, tableLoop, rowLoop) {
|
2016-02-24 23:48:54 +00:00
|
|
|
var row = this.row(i)
|
|
|
|
var rowData = row.data()
|
2016-02-24 00:50:07 +00:00
|
|
|
var rid = rowData[0]
|
|
|
|
$.each(campaign.results, function(j, result) {
|
|
|
|
if (result.id == rid) {
|
|
|
|
var label = statuses[result.status].label || "label-default";
|
|
|
|
rowData[6] = "<span class=\"label " + label + "\">" + result.status + "</span>"
|
2016-03-20 01:51:42 +00:00
|
|
|
resultsTable.row(i).data(rowData).draw(false)
|
2016-02-24 23:48:54 +00:00
|
|
|
if (row.child.isShown()) {
|
|
|
|
row.child(renderTimeline(row.data()))
|
|
|
|
}
|
2016-02-24 00:50:07 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
/* Update the map information */
|
2016-02-24 23:48:54 +00:00
|
|
|
bubbles = []
|
2016-02-24 00:50:07 +00:00
|
|
|
$.each(campaign.results, function(i, result) {
|
|
|
|
// Check that it wasn't an internal IP
|
|
|
|
if (result.latitude == 0 && result.longitude == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
newIP = true
|
|
|
|
$.each(bubbles, function(i, bubble) {
|
|
|
|
if (bubble.ip == result.ip) {
|
|
|
|
bubbles[i].radius += 1
|
|
|
|
newIP = false
|
2016-02-23 04:40:33 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
2016-02-24 00:50:07 +00:00
|
|
|
if (newIP) {
|
|
|
|
bubbles.push({
|
|
|
|
latitude: result.latitude,
|
|
|
|
longitude: result.longitude,
|
|
|
|
name: result.ip,
|
|
|
|
fillKey: "point",
|
|
|
|
radius: 2
|
|
|
|
})
|
|
|
|
}
|
2016-02-22 02:55:27 +00:00
|
|
|
})
|
2016-02-24 00:50:07 +00:00
|
|
|
map.bubbles(bubbles)
|
2016-02-22 02:55:27 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
function load() {
|
2015-07-30 03:31:39 +00:00
|
|
|
campaign.id = window.location.pathname.split('/').slice(-1)[0]
|
2016-06-08 03:31:55 +00:00
|
|
|
api.campaignId.results(campaign.id)
|
2016-01-17 04:59:40 +00:00
|
|
|
.success(function(c) {
|
|
|
|
campaign = c
|
|
|
|
if (campaign) {
|
2016-03-10 00:17:46 +00:00
|
|
|
$("title").text(c.name + " - Gophish")
|
2016-02-23 04:40:33 +00:00
|
|
|
$("#loading").hide()
|
|
|
|
$("#campaignResults").show()
|
2016-02-23 17:51:43 +00:00
|
|
|
// Set the title
|
2016-01-17 04:59:40 +00:00
|
|
|
$("#page-title").text("Results for " + c.name)
|
2016-07-12 03:11:40 +00:00
|
|
|
if (c.status == "Completed") {
|
|
|
|
$('#complete_button')[0].disabled = true;
|
|
|
|
$('#complete_button').text('Completed!');
|
|
|
|
doPoll = false;
|
|
|
|
}
|
|
|
|
// Setup tooltips
|
2016-01-17 04:59:40 +00:00
|
|
|
$('[data-toggle="tooltip"]').tooltip()
|
2016-02-03 04:49:30 +00:00
|
|
|
// Setup viewing the details of a result
|
|
|
|
$("#resultsTable").on("click", ".timeline-event-details", function() {
|
|
|
|
// Show the parameters
|
2016-02-13 03:25:49 +00:00
|
|
|
payloadResults = $(this).parent().find(".timeline-event-results")
|
|
|
|
if (payloadResults.is(":visible")) {
|
2016-02-03 04:49:30 +00:00
|
|
|
$(this).find("i").removeClass("fa-caret-down")
|
|
|
|
$(this).find("i").addClass("fa-caret-right")
|
2016-02-13 03:25:49 +00:00
|
|
|
payloadResults.hide()
|
2016-02-03 04:49:30 +00:00
|
|
|
} else {
|
|
|
|
$(this).find("i").removeClass("fa-caret-right")
|
|
|
|
$(this).find("i").addClass("fa-caret-down")
|
2016-02-13 03:25:49 +00:00
|
|
|
payloadResults.show()
|
2016-02-03 04:49:30 +00:00
|
|
|
}
|
|
|
|
})
|
2016-01-17 04:59:40 +00:00
|
|
|
// Setup our graphs
|
|
|
|
var timeline_data = {
|
|
|
|
series: [{
|
|
|
|
name: "Events",
|
|
|
|
data: []
|
|
|
|
}]
|
2015-08-01 20:35:32 +00:00
|
|
|
}
|
2016-01-17 04:59:40 +00:00
|
|
|
var email_data = {
|
|
|
|
series: []
|
2015-07-31 04:07:54 +00:00
|
|
|
}
|
2016-01-17 04:59:40 +00:00
|
|
|
var email_legend = {}
|
|
|
|
var email_series_data = {}
|
|
|
|
var timeline_opts = {
|
|
|
|
axisX: {
|
|
|
|
showGrid: false,
|
|
|
|
type: Chartist.FixedScaleAxis,
|
|
|
|
divisor: 5,
|
|
|
|
labelInterpolationFnc: function(value) {
|
2016-08-17 00:27:01 +00:00
|
|
|
return moment(value).format('MMMM Do YYYY h:mm a')
|
2016-01-17 04:59:40 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
axisY: {
|
|
|
|
type: Chartist.FixedScaleAxis,
|
|
|
|
ticks: [0, 1, 2],
|
|
|
|
low: 0,
|
|
|
|
showLabel: false
|
|
|
|
},
|
|
|
|
showArea: false,
|
|
|
|
plugins: []
|
2015-08-05 02:27:04 +00:00
|
|
|
}
|
2016-01-17 04:59:40 +00:00
|
|
|
var email_opts = {
|
|
|
|
donut: true,
|
|
|
|
donutWidth: 40,
|
|
|
|
chartPadding: 0,
|
|
|
|
showLabel: false
|
|
|
|
}
|
|
|
|
// Setup the results table
|
2016-01-29 14:31:58 +00:00
|
|
|
resultsTable = $("#resultsTable").DataTable({
|
|
|
|
destroy: true,
|
|
|
|
"order": [
|
2016-02-22 02:55:27 +00:00
|
|
|
[2, "asc"]
|
2016-01-29 14:31:58 +00:00
|
|
|
],
|
|
|
|
columnDefs: [{
|
|
|
|
orderable: false,
|
|
|
|
targets: "no-sort"
|
|
|
|
}, {
|
|
|
|
className: "details-control",
|
2016-02-22 02:55:27 +00:00
|
|
|
"targets": [1]
|
|
|
|
}, {
|
|
|
|
"visible": false,
|
2016-01-29 14:31:58 +00:00
|
|
|
"targets": [0]
|
|
|
|
}]
|
|
|
|
});
|
2016-02-22 02:55:27 +00:00
|
|
|
resultsTable.clear();
|
2016-01-17 04:59:40 +00:00
|
|
|
$.each(campaign.results, function(i, result) {
|
|
|
|
label = statuses[result.status].label || "label-default";
|
|
|
|
resultsTable.row.add([
|
2016-02-22 02:55:27 +00:00
|
|
|
result.id,
|
2016-01-29 14:31:58 +00:00
|
|
|
"<i class=\"fa fa-caret-right\"></i>",
|
2016-03-22 00:30:43 +00:00
|
|
|
escapeHtml(result.first_name) || "",
|
|
|
|
escapeHtml(result.last_name) || "",
|
|
|
|
escapeHtml(result.email) || "",
|
|
|
|
escapeHtml(result.position) || "",
|
2016-01-17 04:59:40 +00:00
|
|
|
"<span class=\"label " + label + "\">" + result.status + "</span>"
|
|
|
|
]).draw()
|
|
|
|
if (!email_series_data[result.status]) {
|
|
|
|
email_series_data[result.status] = 1
|
|
|
|
} else {
|
|
|
|
email_series_data[result.status]++;
|
|
|
|
}
|
|
|
|
})
|
2016-01-29 14:31:58 +00:00
|
|
|
// Setup the individual timelines
|
|
|
|
$('#resultsTable tbody').on('click', 'td.details-control', function() {
|
|
|
|
var tr = $(this).closest('tr');
|
|
|
|
var row = resultsTable.row(tr);
|
|
|
|
if (row.child.isShown()) {
|
|
|
|
// This row is already open - close it
|
|
|
|
row.child.hide();
|
|
|
|
tr.removeClass('shown');
|
2016-01-29 15:55:49 +00:00
|
|
|
$(this).find("i").removeClass("fa-caret-down")
|
|
|
|
$(this).find("i").addClass("fa-caret-right")
|
2016-03-20 01:51:42 +00:00
|
|
|
row.invalidate('dom').draw(false)
|
2016-01-29 14:31:58 +00:00
|
|
|
} else {
|
|
|
|
// Open this row
|
2016-01-29 15:55:49 +00:00
|
|
|
$(this).find("i").removeClass("fa-caret-right")
|
|
|
|
$(this).find("i").addClass("fa-caret-down")
|
2016-01-29 14:31:58 +00:00
|
|
|
row.child(renderTimeline(row.data())).show();
|
|
|
|
tr.addClass('shown');
|
2016-03-20 01:51:42 +00:00
|
|
|
row.invalidate('dom').draw(false)
|
2016-01-29 14:31:58 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
// Setup the graphs
|
2016-01-17 04:59:40 +00:00
|
|
|
$.each(campaign.timeline, function(i, event) {
|
|
|
|
timeline_data.series[0].data.push({
|
|
|
|
meta: i,
|
|
|
|
x: new Date(event.time),
|
|
|
|
y: 1
|
|
|
|
})
|
|
|
|
})
|
2016-02-23 17:51:43 +00:00
|
|
|
$("#email_chart_legend").html("")
|
2016-01-17 04:59:40 +00:00
|
|
|
$.each(email_series_data, function(status, count) {
|
|
|
|
email_data.series.push({
|
|
|
|
meta: status,
|
|
|
|
value: count
|
|
|
|
})
|
2016-02-23 17:51:43 +00:00
|
|
|
$("#email_chart_legend").append('<li><span class="' + statuses[status].legend + '"></span>' + status + '</li>')
|
2016-01-17 04:59:40 +00:00
|
|
|
})
|
|
|
|
var timeline_chart = new Chartist.Line('#timeline_chart', timeline_data, timeline_opts)
|
2016-03-09 03:37:30 +00:00
|
|
|
timeline_chart.on('draw', function(data) {
|
|
|
|
if (data.type === "point") {
|
|
|
|
var point_style = statuses[campaign.timeline[data.meta].message].point
|
|
|
|
var circle = new Chartist.Svg("circle", {
|
|
|
|
cx: [data.x],
|
|
|
|
cy: [data.y],
|
|
|
|
r: 5,
|
|
|
|
fill: "#283F50",
|
|
|
|
meta: data.meta,
|
|
|
|
value: 1,
|
|
|
|
}, point_style + ' ct-timeline-point')
|
|
|
|
data.element.replace(circle)
|
|
|
|
}
|
|
|
|
})
|
2016-01-17 04:59:40 +00:00
|
|
|
// Setup the overview chart listeners
|
|
|
|
$chart = $("#timeline_chart")
|
|
|
|
var $toolTip = $chart
|
|
|
|
.append('<div class="chartist-tooltip"></div>')
|
|
|
|
.find('.chartist-tooltip')
|
|
|
|
.hide();
|
2016-03-09 03:37:30 +00:00
|
|
|
$chart.on('mouseenter', '.ct-timeline-point', function() {
|
2016-01-17 04:59:40 +00:00
|
|
|
var $point = $(this)
|
2016-03-09 03:37:30 +00:00
|
|
|
cidx = $point.attr('meta')
|
2016-01-17 04:59:40 +00:00
|
|
|
html = "Event: " + campaign.timeline[cidx].message
|
|
|
|
if (campaign.timeline[cidx].email) {
|
2016-03-22 00:30:43 +00:00
|
|
|
html += '<br>' + "Email: " + escapeHtml(campaign.timeline[cidx].email)
|
2016-01-17 04:59:40 +00:00
|
|
|
}
|
|
|
|
$toolTip.html(html).show()
|
|
|
|
});
|
2016-03-09 03:37:30 +00:00
|
|
|
$chart.on('mouseleave', '.ct-timeline-point', function() {
|
2016-01-17 04:59:40 +00:00
|
|
|
$toolTip.hide();
|
|
|
|
});
|
|
|
|
$chart.on('mousemove', function(event) {
|
|
|
|
$toolTip.css({
|
|
|
|
left: (event.offsetX || event.originalEvent.layerX) - $toolTip.width() / 2 - 10,
|
|
|
|
top: (event.offsetY + 70 || event.originalEvent.layerY) - $toolTip.height() - 40
|
|
|
|
});
|
|
|
|
});
|
2016-03-09 03:37:30 +00:00
|
|
|
|
2016-01-17 04:59:40 +00:00
|
|
|
var email_chart = new Chartist.Pie("#email_chart", email_data, email_opts)
|
|
|
|
email_chart.on('draw', function(data) {
|
|
|
|
data.element.addClass(statuses[data.meta].slice)
|
|
|
|
})
|
|
|
|
// Setup the average chart listeners
|
|
|
|
$piechart = $("#email_chart")
|
|
|
|
var $pietoolTip = $piechart
|
|
|
|
.append('<div class="chartist-tooltip"></div>')
|
|
|
|
.find('.chartist-tooltip')
|
|
|
|
.hide();
|
2015-08-01 20:35:32 +00:00
|
|
|
|
2016-01-17 04:59:40 +00:00
|
|
|
$piechart.on('mouseenter', '.ct-slice-donut', function() {
|
|
|
|
var $point = $(this)
|
|
|
|
value = $point.attr('ct:value')
|
|
|
|
label = $point.attr('ct:meta')
|
|
|
|
$pietoolTip.html(label + ': ' + value.toString()).show();
|
|
|
|
});
|
2015-08-01 20:35:32 +00:00
|
|
|
|
2016-01-17 04:59:40 +00:00
|
|
|
$piechart.on('mouseleave', '.ct-slice-donut', function() {
|
|
|
|
$pietoolTip.hide();
|
2015-08-01 20:35:32 +00:00
|
|
|
});
|
2016-01-17 04:59:40 +00:00
|
|
|
$piechart.on('mousemove', function(event) {
|
|
|
|
$pietoolTip.css({
|
|
|
|
left: (event.offsetX || event.originalEvent.layerX) - $pietoolTip.width() / 2 - 10,
|
|
|
|
top: (event.offsetY + 40 || event.originalEvent.layerY) - $pietoolTip.height() - 80
|
2016-01-04 06:04:10 +00:00
|
|
|
});
|
2016-01-17 04:59:40 +00:00
|
|
|
});
|
2016-02-22 02:55:27 +00:00
|
|
|
if (!map) {
|
|
|
|
map = new Datamap({
|
|
|
|
element: document.getElementById("resultsMap"),
|
|
|
|
responsive: true,
|
|
|
|
fills: {
|
|
|
|
defaultFill: "#ffffff",
|
|
|
|
point: "#283F50"
|
|
|
|
},
|
|
|
|
geographyConfig: {
|
|
|
|
highlightFillColor: "#1abc9c",
|
|
|
|
borderColor: "#283F50"
|
|
|
|
},
|
|
|
|
bubblesConfig: {
|
|
|
|
borderColor: "#283F50"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-01-17 04:59:40 +00:00
|
|
|
$.each(campaign.results, function(i, result) {
|
|
|
|
// Check that it wasn't an internal IP
|
|
|
|
if (result.latitude == 0 && result.longitude == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
newIP = true
|
|
|
|
$.each(bubbles, function(i, bubble) {
|
|
|
|
if (bubble.ip == result.ip) {
|
|
|
|
bubbles[i].radius += 1
|
|
|
|
newIP = false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (newIP) {
|
|
|
|
bubbles.push({
|
|
|
|
latitude: result.latitude,
|
|
|
|
longitude: result.longitude,
|
|
|
|
name: result.ip,
|
|
|
|
fillKey: "point",
|
|
|
|
radius: 2
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
map.bubbles(bubbles)
|
2016-01-04 06:04:10 +00:00
|
|
|
}
|
2016-01-17 04:59:40 +00:00
|
|
|
// Load up the map data (only once!)
|
|
|
|
$('a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
|
|
|
|
if ($(e.target).attr('href') == "#overview") {
|
|
|
|
if (!map) {
|
|
|
|
map = new Datamap({
|
|
|
|
element: document.getElementById("resultsMap"),
|
|
|
|
responsive: true,
|
|
|
|
fills: {
|
|
|
|
defaultFill: "#ffffff"
|
|
|
|
},
|
|
|
|
geographyConfig: {
|
|
|
|
highlightFillColor: "#1abc9c",
|
|
|
|
borderColor: "#283F50"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.error(function() {
|
|
|
|
$("#loading").hide()
|
|
|
|
errorFlash(" Campaign not found!")
|
2016-01-04 06:04:10 +00:00
|
|
|
})
|
2016-02-22 02:55:27 +00:00
|
|
|
}
|
|
|
|
$(document).ready(function() {
|
|
|
|
load();
|
|
|
|
// Start the polling loop
|
2016-02-23 04:40:33 +00:00
|
|
|
function refresh() {
|
2016-07-12 03:11:40 +00:00
|
|
|
if (!doPoll) {
|
|
|
|
return;
|
|
|
|
}
|
2016-02-22 02:55:27 +00:00
|
|
|
$("#refresh_message").show()
|
|
|
|
poll()
|
|
|
|
$("#refresh_message").hide()
|
|
|
|
setTimeout(refresh, 10000)
|
2016-02-23 04:40:33 +00:00
|
|
|
};
|
|
|
|
// Start the polling loop
|
|
|
|
setTimeout(refresh, 10000)
|
2015-07-29 00:31:12 +00:00
|
|
|
})
|