\
+ .success(function(campaigns) {
+ $("#loading").hide()
+ if (campaigns.length > 0) {
+ $("#campaignTable").show()
+ campaignTable = $("#campaignTable").DataTable();
+ $.each(campaigns, function(i, campaign) {
+ label = labels[campaign.status] || "label-default";
+ campaignTable.row.add([
+ campaign.name,
+ moment(campaign.created_date).format('MMMM Do YYYY, h:mm:ss a'),
+ "" + campaign.status + "",
+ ""
- ]).draw()
- })
- } else {
- $("#emptyMessage").show()
- }
- })
- .error(function(){
- $("#loading").hide()
- errorFlash("Error fetching campaigns")
- })
- $("#groupForm").submit(function(){
- groupTable.row.add([
- $("#groupSelect").val(),
- ''
- ]).draw()
- $("#groupTable").on("click", "span>i.fa-trash-o", function(){
- groupTable.row( $(this).parents('tr') )
- .remove()
- .draw();
+ ]).draw()
+ })
+ } else {
+ $("#emptyMessage").show()
+ }
})
- return false;
- })
- // Create the group typeahead objects
+ .error(function() {
+ $("#loading").hide()
+ errorFlash("Error fetching campaigns")
+ })
+ $("#groupForm").submit(function() {
+ groupTable.row.add([
+ $("#groupSelect").val(),
+ ''
+ ]).draw()
+ $("#groupTable").on("click", "span>i.fa-trash-o", function() {
+ groupTable.row($(this).parents('tr'))
+ .remove()
+ .draw();
+ })
+ return false;
+ })
+ // Create the group typeahead objects
groupTable = $("#groupTable").DataTable()
group_bh = new Bloodhound({
- datumTokenizer: function(g) { return Bloodhound.tokenizers.whitespace(g.name) },
+ datumTokenizer: function(g) {
+ return Bloodhound.tokenizers.whitespace(g.name)
+ },
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: []
})
group_bh.initialize()
$("#groupSelect.typeahead.form-control").typeahead({
- hint: true,
- highlight: true,
- minLength: 1
- },
- {
- name: "groups",
- source: group_bh,
- templates: {
- empty: function(data) {return 'No groups matched that query
' },
- suggestion: function(data){ return '' + data.name + '
' }
- }
- })
- .bind('typeahead:select', function(ev, group){
- $("#groupSelect").typeahead('val', group.name)
- })
- .bind('typeahead:autocomplete', function(ev, group){
- $("#groupSelect").typeahead('val', group.name)
- });
+ hint: true,
+ highlight: true,
+ minLength: 1
+ }, {
+ name: "groups",
+ source: group_bh,
+ templates: {
+ empty: function(data) {
+ return 'No groups matched that query
'
+ },
+ suggestion: function(data) {
+ return '' + data.name + '
'
+ }
+ }
+ })
+ .bind('typeahead:select', function(ev, group) {
+ $("#groupSelect").typeahead('val', group.name)
+ })
+ .bind('typeahead:autocomplete', function(ev, group) {
+ $("#groupSelect").typeahead('val', group.name)
+ });
// Create the template typeahead objects
template_bh = new Bloodhound({
- datumTokenizer: function(t) { return Bloodhound.tokenizers.whitespace(t.name) },
+ datumTokenizer: function(t) {
+ return Bloodhound.tokenizers.whitespace(t.name)
+ },
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: []
})
template_bh.initialize()
$("#template.typeahead.form-control").typeahead({
- hint: true,
- highlight: true,
- minLength: 1
- },
- {
- name: "templates",
- source: template_bh,
- templates: {
- empty: function(data) {return 'No templates matched that query
' },
- suggestion: function(data){ return '' + data.name + '
' }
- }
- })
- .bind('typeahead:select', function(ev, template){
- $("#template").typeahead('val', template.name)
- })
- .bind('typeahead:autocomplete', function(ev, template){
- $("#template").typeahead('val', template.name)
- });
+ hint: true,
+ highlight: true,
+ minLength: 1
+ }, {
+ name: "templates",
+ source: template_bh,
+ templates: {
+ empty: function(data) {
+ return 'No templates matched that query
'
+ },
+ suggestion: function(data) {
+ return '' + data.name + '
'
+ }
+ }
+ })
+ .bind('typeahead:select', function(ev, template) {
+ $("#template").typeahead('val', template.name)
+ })
+ .bind('typeahead:autocomplete', function(ev, template) {
+ $("#template").typeahead('val', template.name)
+ });
// Create the landing page typeahead objects
page_bh = new Bloodhound({
- datumTokenizer: function(p) { return Bloodhound.tokenizers.whitespace(p.name) },
+ datumTokenizer: function(p) {
+ return Bloodhound.tokenizers.whitespace(p.name)
+ },
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: []
})
page_bh.initialize()
$("#page.typeahead.form-control").typeahead({
- hint: true,
- highlight: true,
- minLength: 1
- },
- {
- name: "pages",
- source: page_bh,
- templates: {
- empty: function(data) {return 'No pages matched that query
' },
- suggestion: function(data){ return '' + data.name + '
' }
- }
- })
- .bind('typeahead:select', function(ev, page){
- $("#page").typeahead('val', page.name)
- })
- .bind('typeahead:autocomplete', function(ev, page){
- $("#page").typeahead('val', page.name)
- });
+ hint: true,
+ highlight: true,
+ minLength: 1
+ }, {
+ name: "pages",
+ source: page_bh,
+ templates: {
+ empty: function(data) {
+ return 'No pages matched that query
'
+ },
+ suggestion: function(data) {
+ return '' + data.name + '
'
+ }
+ }
+ })
+ .bind('typeahead:select', function(ev, page) {
+ $("#page").typeahead('val', page.name)
+ })
+ .bind('typeahead:autocomplete', function(ev, page) {
+ $("#page").typeahead('val', page.name)
+ });
})
diff --git a/static/js/app/dashboard.js b/static/js/app/dashboard.js
index c8445b9f..23ed7752 100644
--- a/static/js/app/dashboard.js
+++ b/static/js/app/dashboard.js
@@ -1,129 +1,145 @@
var campaigns = []
-// labels is a map of campaign statuses to
-// CSS classes
+ // labels is a map of campaign statuses to
+ // CSS classes
var labels = {
- "In progress" : "label-primary",
- "Queued" : "label-info",
- "Completed" : "label-success",
- "Emails Sent" : "label-success",
- "Error" : "label-danger"
+ "In progress": "label-primary",
+ "Queued": "label-info",
+ "Completed": "label-success",
+ "Emails Sent": "label-success",
+ "Error": "label-danger"
}
-$(document).ready(function(){
+$(document).ready(function() {
api.campaigns.get()
- .success(function(cs){
- $("#loading").hide()
- campaigns = cs
- if (campaigns.length > 0){
- $("#dashboard").show()
- // Create the overview chart data
- var overview_data = {labels:[],series:[[]]}
- var average_data = {series:[]}
- var overview_opts = {
- axisX: {
- showGrid: false
- },
- showArea: true,
- plugins: []
- }
- var average_opts = {
- donut : true,
- donutWidth: 40,
- chartPadding: 0,
- showLabel: false
- }
- var average = 0
- campaignTable = $("#campaignTable").DataTable();
- $.each(campaigns, function(i, campaign){
- var campaign_date = moment(campaign.created_date).format('MMMM Do YYYY h:mm:ss a')
- var label = labels[campaign.status] || "label-default";
- // Add it to the table
- campaignTable.row.add([
- campaign.name,
- campaign_date,
- "" + campaign.status + "",
- "\
+ .success(function(cs) {
+ $("#loading").hide()
+ campaigns = cs
+ if (campaigns.length > 0) {
+ $("#dashboard").show()
+ // Create the overview chart data
+ var overview_data = {
+ labels: [],
+ series: [
+ []
+ ]
+ }
+ var average_data = {
+ series: []
+ }
+ var overview_opts = {
+ axisX: {
+ showGrid: false
+ },
+ showArea: true,
+ plugins: []
+ }
+ var average_opts = {
+ donut: true,
+ donutWidth: 40,
+ chartPadding: 0,
+ showLabel: false
+ }
+ var average = 0
+ campaignTable = $("#campaignTable").DataTable();
+ $.each(campaigns, function(i, campaign) {
+ var campaign_date = moment(campaign.created_date).format('MMMM Do YYYY h:mm:ss a')
+ var label = labels[campaign.status] || "label-default";
+ // Add it to the table
+ campaignTable.row.add([
+ campaign.name,
+ campaign_date,
+ "" + campaign.status + "",
+ ""
- ]).draw()
- // Add it to the chart data
- campaign.y = 0
- $.each(campaign.results, function(j, result){
- if (result.status == "Success"){
- campaign.y++;
- }
+ ]).draw()
+ // Add it to the chart data
+ campaign.y = 0
+ $.each(campaign.results, function(j, result) {
+ if (result.status == "Success") {
+ campaign.y++;
+ }
+ })
+ campaign.y = Math.floor((campaign.y / campaign.results.length) * 100)
+ average += campaign.y
+ // Add the data to the overview chart
+ overview_data.labels.push(campaign_date)
+ overview_data.series[0].push({
+ meta: i,
+ value: campaign.y
+ })
})
- campaign.y = Math.floor((campaign.y / campaign.results.length) * 100)
- average += campaign.y
- // Add the data to the overview chart
- overview_data.labels.push(campaign_date)
- overview_data.series[0].push({meta : i, value: campaign.y})
- })
- average = Math.floor(average / campaigns.length);
- average_data.series.push({meta: "Unsuccessful Phishes", value: 100 - average})
- average_data.series.push({meta: "Successful Phishes", value: average})
- // Build the charts
- var average_chart = new Chartist.Pie("#average_chart", average_data, average_opts)
- var overview_chart = new Chartist.Line('#overview_chart', overview_data, overview_opts)
- // Setup the average chart listeners
- $piechart = $("#average_chart")
- var $pietoolTip = $piechart
- .append('')
- .find('.chartist-tooltip')
- .hide();
+ average = Math.floor(average / campaigns.length);
+ average_data.series.push({
+ meta: "Unsuccessful Phishes",
+ value: 100 - average
+ })
+ average_data.series.push({
+ meta: "Successful Phishes",
+ value: average
+ })
+ // Build the charts
+ var average_chart = new Chartist.Pie("#average_chart", average_data, average_opts)
+ var overview_chart = new Chartist.Line('#overview_chart', overview_data, overview_opts)
+ // Setup the average chart listeners
+ $piechart = $("#average_chart")
+ var $pietoolTip = $piechart
+ .append('')
+ .find('.chartist-tooltip')
+ .hide();
- $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();
- });
-
- $piechart.on('mouseleave', '.ct-slice-donut', function() {
- $pietoolTip.hide();
- });
- $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
+ $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();
});
- });
- // Setup the overview chart listeners
- $chart = $("#overview_chart")
- var $toolTip = $chart
- .append('')
- .find('.chartist-tooltip')
- .hide();
-
- $chart.on('mouseenter', '.ct-point', function() {
- var $point = $(this)
- value = $point.attr('ct:value') || 0
- cidx = $point.attr('ct:meta')
- $toolTip.html(campaigns[cidx].name + '
' + "Successes: " + value.toString() + "%").show();
- });
-
- $chart.on('mouseleave', '.ct-point', function() {
- $toolTip.hide();
- });
- $chart.on('mousemove', function(event) {
- $toolTip.css({
- left: (event.offsetX || event.originalEvent.layerX) - $toolTip.width() / 2 - 10,
- top: (event.offsetY + 40 || event.originalEvent.layerY) - $toolTip.height() - 40
+ $piechart.on('mouseleave', '.ct-slice-donut', function() {
+ $pietoolTip.hide();
});
- });
- $("#overview_chart").on("click", ".ct-point", function(e) {
- var $cidx = $(this).attr('ct:meta');
- window.location.href = "/campaigns/" + campaigns[cidx].id
- });
- } else {
- $("#emptyMessage").show()
- }
- })
- .error(function(){
- errorFlash("Error fetching campaigns")
- })
+ $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
+ });
+ });
+
+ // Setup the overview chart listeners
+ $chart = $("#overview_chart")
+ var $toolTip = $chart
+ .append('')
+ .find('.chartist-tooltip')
+ .hide();
+
+ $chart.on('mouseenter', '.ct-point', function() {
+ var $point = $(this)
+ value = $point.attr('ct:value') || 0
+ cidx = $point.attr('ct:meta')
+ $toolTip.html(campaigns[cidx].name + '
' + "Successes: " + value.toString() + "%").show();
+ });
+
+ $chart.on('mouseleave', '.ct-point', function() {
+ $toolTip.hide();
+ });
+ $chart.on('mousemove', function(event) {
+ $toolTip.css({
+ left: (event.offsetX || event.originalEvent.layerX) - $toolTip.width() / 2 - 10,
+ top: (event.offsetY + 40 || event.originalEvent.layerY) - $toolTip.height() - 40
+ });
+ });
+ $("#overview_chart").on("click", ".ct-point", function(e) {
+ var $cidx = $(this).attr('ct:meta');
+ window.location.href = "/campaigns/" + campaigns[cidx].id
+ });
+ } else {
+ $("#emptyMessage").show()
+ }
+ })
+ .error(function() {
+ errorFlash("Error fetching campaigns")
+ })
})
diff --git a/static/js/app/landing_pages.js b/static/js/app/landing_pages.js
index dd7b30cb..c2df241e 100644
--- a/static/js/app/landing_pages.js
+++ b/static/js/app/landing_pages.js
@@ -4,72 +4,75 @@
Author: Jordan Wright
*/
var pages = []
+
// Save attempts to POST to /templates/
-function save(idx){
+function save(idx) {
var page = {}
page.name = $("#name").val()
page.html = CKEDITOR.instances["html_editor"].getData();
- if (idx != -1){
+ if (idx != -1) {
page.id = pages[idx].id
api.pageId.put(page)
- .success(function(data){
- successFlash("Page edited successfully!")
- load()
- dismiss()
- })
+ .success(function(data) {
+ successFlash("Page edited successfully!")
+ load()
+ dismiss()
+ })
} else {
// Submit the page
api.pages.post(page)
- .success(function(data){
- successFlash("Page added successfully!")
- load()
- dismiss()
- })
- .error(function(data){
- modalError(data.responseJSON.message)
- })
+ .success(function(data) {
+ successFlash("Page added successfully!")
+ load()
+ dismiss()
+ })
+ .error(function(data) {
+ modalError(data.responseJSON.message)
+ })
}
}
-function dismiss(){
+function dismiss() {
$("#modal\\.flashes").empty()
$("#name").val("")
$("#html_editor").val("")
$("#newLandingPageModal").modal('hide')
}
-function deletePage(idx){
- if (confirm("Delete " + pages[idx].name + "?")){
+function deletePage(idx) {
+ if (confirm("Delete " + pages[idx].name + "?")) {
api.pageId.delete(pages[idx].id)
- .success(function(data){
- successFlash(data.message)
- load()
- })
+ .success(function(data) {
+ successFlash(data.message)
+ load()
+ })
}
}
-function importSite(){
+function importSite() {
url = $("#url").val()
- if (!url){
+ if (!url) {
modalError("No URL Specified!")
} else {
api.clone_site({
- url: url,
- include_resources: false
- })
- .success(function(data){
- console.log($("#html_editor"))
- $("#html_editor").val(data.html)
- $("#importSiteModal").modal("hide")
- })
- .error(function(data){
- modalError(data.responseJSON.message)
- })
+ url: url,
+ include_resources: false
+ })
+ .success(function(data) {
+ console.log($("#html_editor"))
+ $("#html_editor").val(data.html)
+ $("#importSiteModal").modal("hide")
+ })
+ .error(function(data) {
+ modalError(data.responseJSON.message)
+ })
}
}
-function edit(idx){
- $("#modalSubmit").unbind('click').click(function(){save(idx)})
+function edit(idx) {
+ $("#modalSubmit").unbind('click').click(function() {
+ save(idx)
+ })
$("#html_editor").ckeditor()
var page = {}
if (idx != -1) {
@@ -79,82 +82,80 @@ function edit(idx){
}
}
-function load(){
-/*
- load() - Loads the current pages using the API
-*/
+function load() {
+ /*
+ load() - Loads the current pages using the API
+ */
$("#pagesTable").hide()
$("#emptyMessage").hide()
$("#loading").show()
api.pages.get()
- .success(function(ps){
- pages = ps
- $("#loading").hide()
- if (pages.length > 0){
- $("#pagesTable").show()
- pagesTable = $("#pagesTable").DataTable();
- pagesTable.clear()
- $.each(pages, function(i, page){
- pagesTable.row.add([
- page.name,
- moment(page.modified_date).format('MMMM Do YYYY, h:mm:ss a'),
- "