diff --git a/static/js/app/campaigns.js b/static/js/app/campaigns.js index 47f5f867..7a310a27 100644 --- a/static/js/app/campaigns.js +++ b/static/js/app/campaigns.js @@ -240,12 +240,18 @@ function copy(idx) { } }) // Set our initial values - var campaign = campaigns[idx] - $("#name").val("Copy of " + campaign.name) - $("#template").val(campaign.template.name) - $("#page").val(campaign.page.name) - $("#profile").val(campaign.smtp.name) - $("#url").val(campaign.url) + api.campaignId.get(campaigns[idx].id) + .success(function(campaign){ + $("#name").val("Copy of " + campaign.name) + $("#template").val(campaign.template.name) + $("#page").val(campaign.page.name) + $("#profile").val(campaign.smtp.name) + $("#url").val(campaign.url) + }) + .error(function(data){ + $("#modal\\.flashes").empty().append("
\ + " + data.responseJSON.message + "
") + }) } $(document).ready(function() { @@ -296,9 +302,9 @@ $(document).ready(function() { $('#modal').on('hidden.bs.modal', function(event) { dismiss() }); - api.campaigns.get() - .success(function(cs) { - campaigns = cs + api.campaigns.summary() + .success(function(data) { + campaigns = data.campaigns $("#loading").hide() if (campaigns.length > 0) { $("#campaignTable").show() @@ -484,4 +490,4 @@ $(document).ready(function() { .bind('typeahead:autocomplete', function(ev, profile) { $("#profile").typeahead('val', profile.name) }); -}) \ No newline at end of file +}) diff --git a/static/js/app/dashboard.js b/static/js/app/dashboard.js index e9670474..4ced94cf 100644 --- a/static/js/app/dashboard.js +++ b/static/js/app/dashboard.js @@ -20,10 +20,10 @@ function deleteCampaign(idx) { } $(document).ready(function() { - api.campaigns.get() - .success(function(cs) { + api.campaigns.summary() + .success(function(data) { $("#loading").hide() - campaigns = cs + campaigns = data.campaigns if (campaigns.length > 0) { $("#dashboard").show() // Create the overview chart data @@ -41,7 +41,9 @@ $(document).ready(function() { showGrid: false }, showArea: true, - plugins: [] + plugins: [], + low: 0, + high: 100 } var average_opts = { donut: true, @@ -73,12 +75,8 @@ $(document).ready(function() { ]).draw() // Add it to the chart data campaign.y = 0 - $.each(campaign.results, function(j, result) { - if (result.status == "Clicked Link" || result.status == "Submitted Data") { - campaign.y++; - } - }) - campaign.y = Math.floor((campaign.y / campaign.results.length) * 100) + campaign.y += campaign.stats.clicked + campaign.stats.submitted_data + campaign.y = Math.floor((campaign.y / campaign.stats.total) * 100) average += campaign.y // Add the data to the overview chart overview_data.labels.push(campaign_date) @@ -87,7 +85,7 @@ $(document).ready(function() { value: campaign.y }) }) - average = Math.floor(average / campaigns.length); + average = Math.floor(average / data.total); average_data.series.push({ meta: "Unsuccessful Phishes", value: 100 - average diff --git a/static/js/gophish.js b/static/js/gophish.js index 21cfc2a3..0169cf78 100644 --- a/static/js/gophish.js +++ b/static/js/gophish.js @@ -47,6 +47,10 @@ var api = { // post() - Posts a campaign to POST /campaigns post: function(data) { return query("/campaigns/", "POST", data, false) + }, + // summary() - Queries the API for GET /campaigns/summary + summary: function() { + return query("/campaigns/summary", "GET", {}, false) } }, // campaignId contains the endpoints for /campaigns/:id @@ -66,6 +70,10 @@ var api = { // complete() - Completes a campaign at POST /campaigns/:id/complete complete: function(id) { return query("/campaigns/" + id + "/complete", "GET", {}, true) + }, + // summary() - Queries the API for GET /campaigns/summary + summary: function(id) { + return query("/campaigns/" + id + "/summary", "GET", {}, true) } }, // groups contains the endpoints for /groups