gophish/static/js/dist/app/campaigns.min.js

1 line
No EOL
7.8 KiB
JavaScript

function launch(){swal({title:"Are you sure?",text:"This will schedule the campaign to be launched.",type:"question",animation:!1,showCancelButton:!0,confirmButtonText:"Launch",confirmButtonColor:"#428bca",reverseButtons:!0,allowOutsideClick:!1,showLoaderOnConfirm:!0,preConfirm:function(){return new Promise(function(a,e){groups=[],$("#users").select2("data").forEach(function(a){groups.push({name:a.text})}),campaign={name:$("#name").val(),template:{name:$("#template").select2("data")[0].text},url:$("#url").val(),page:{name:$("#page").select2("data")[0].text},smtp:{name:$("#profile").select2("data")[0].text},launch_date:moment($("#launch_date").val(),"MM/DD/YYYY hh:mm a").utc().format(),groups:groups},console.log("Launching campaign at time: "+campaign.launch_date),api.campaigns.post(campaign).success(function(e){a(),campaign=e}).error(function(a){$("#modal\\.flashes").empty().append('<div style="text-align:center" class="alert alert-danger"> <i class="fa fa-exclamation-circle"></i> '+a.responseJSON.message+"</div>"),swal.close()})})}}).then(function(){swal("Campaign Scheduled!","This campaign has been scheduled for launch!","success"),$('button:contains("OK")').on("click",function(){window.location="/campaigns/"+campaign.id.toString()})})}function sendTestEmail(){var a={template:{name:$("#template").select2("data")[0].text},first_name:$("input[name=to_first_name]").val(),last_name:$("input[name=to_last_name]").val(),email:$("input[name=to_email]").val(),position:$("input[name=to_position]").val(),url:$("#url").val(),page:{name:$("#page").select2("data")[0].text},smtp:{name:$("#profile").select2("data")[0].text}};btnHtml=$("#sendTestModalSubmit").html(),$("#sendTestModalSubmit").html('<i class="fa fa-spinner fa-spin"></i> Sending'),api.send_test_email(a).success(function(a){$("#sendTestEmailModal\\.flashes").empty().append('<div style="text-align:center" class="alert alert-success"> <i class="fa fa-check-circle"></i> Email Sent!</div>'),$("#sendTestModalSubmit").html(btnHtml)}).error(function(a){$("#sendTestEmailModal\\.flashes").empty().append('<div style="text-align:center" class="alert alert-danger"> <i class="fa fa-exclamation-circle"></i> '+a.responseJSON.message+"</div>"),$("#sendTestModalSubmit").html(btnHtml)})}function dismiss(){$("#modal\\.flashes").empty(),$("#name").val(""),$("#template").val("").change(),$("#page").val("").change(),$("#url").val(""),$("#profile").val("").change(),$("#users").val("").change(),$("#modal").modal("hide")}function deleteCampaign(a){swal({title:"Are you sure?",text:"This will delete the campaign. This can't be undone!",type:"warning",animation:!1,showCancelButton:!0,confirmButtonText:"Delete "+campaigns[a].name,confirmButtonColor:"#428bca",reverseButtons:!0,allowOutsideClick:!1,preConfirm:function(){return new Promise(function(e,t){api.campaignId.delete(campaigns[a].id).success(function(a){e()}).error(function(a){t(a.responseJSON.message)})})}}).then(function(){swal("Campaign Deleted!","This campaign has been deleted!","success"),$('button:contains("OK")').on("click",function(){location.reload()})})}function setupOptions(){api.groups.get().success(function(a){if(0==a.length)return modalError("No groups found!"),!1;var e=$.map(a,function(a){return a.text=a.name,a});$("#users.form-control").select2({placeholder:"Select Groups",data:e})}),api.templates.get().success(function(a){if(0==a.length)return modalError("No templates found!"),!1;var e=$.map(a,function(a){return a.text=a.name,a});$("#template.form-control").select2({placeholder:"Select a Template",data:e})}),api.pages.get().success(function(a){if(0==a.length)return modalError("No pages found!"),!1;var e=$.map(a,function(a){return a.text=a.name,a});$("#page.form-control").select2({placeholder:"Select a Landing Page",data:e})}),api.SMTP.get().success(function(a){if(0==a.length)return modalError("No profiles found!"),!1;var e=$.map(a,function(a){return a.text=a.name,a});$("#profile.form-control").select2({placeholder:"Select a Sending Profile",data:e})})}function edit(a){setupOptions()}function copy(a){setupOptions(),api.campaignId.get(campaigns[a].id).success(function(a){$("#name").val("Copy of "+a.name),a.template.id?$("#template").select2("val",a.template.id.toString()):$("#template").select2({placeholder:a.template.name}),a.page.id?$("#page").select2("val",a.page.id.toString()):$("#page").select2({placeholder:a.page.name}),a.smtp.id?$("#profile").select2("val",a.smtp.id.toString()):$("#profile").select2({placeholder:a.smtp.name}),$("#url").val(a.url)}).error(function(a){$("#modal\\.flashes").empty().append('<div style="text-align:center" class="alert alert-danger"> <i class="fa fa-exclamation-circle"></i> '+a.responseJSON.message+"</div>")})}var labels={"In progress":"label-primary",Queued:"label-info",Completed:"label-success","Emails Sent":"label-success",Error:"label-danger"},campaigns=[],campaign={};$(document).ready(function(){$("#launch_date").datetimepicker({widgetPositioning:{vertical:"bottom"},showTodayButton:!0,defaultDate:moment()}),$(".modal").on("hidden.bs.modal",function(a){$(this).removeClass("fv-modal-stack"),$("body").data("fv_open_modals",$("body").data("fv_open_modals")-1)}),$(".modal").on("shown.bs.modal",function(a){"undefined"==typeof $("body").data("fv_open_modals")&&$("body").data("fv_open_modals",0),$(this).hasClass("fv-modal-stack")||($(this).addClass("fv-modal-stack"),$("body").data("fv_open_modals",$("body").data("fv_open_modals")+1),$(this).css("z-index",1040+10*$("body").data("fv_open_modals")),$(".modal-backdrop").not(".fv-modal-stack").css("z-index",1039+10*$("body").data("fv_open_modals")),$(".modal-backdrop").not("fv-modal-stack").addClass("fv-modal-stack"))}),$(document).on("hidden.bs.modal",".modal",function(){$(".modal:visible").length&&$(document.body).addClass("modal-open")}),$("#modal").on("hidden.bs.modal",function(a){dismiss()}),api.campaigns.summary().success(function(a){campaigns=a.campaigns,$("#loading").hide(),campaigns.length>0?($("#campaignTable").show(),campaignTable=$("#campaignTable").DataTable({columnDefs:[{orderable:!1,targets:"no-sort"}],order:[[1,"desc"]]}),$.each(campaigns,function(a,e){console.log(e),console.log(e.created_date),label=labels[e.status]||"label-default";var t;if(moment(e.launch_date).isAfter(moment())){t="Scheduled to start: "+moment(e.launch_date).format("MMMM Do YYYY, h:mm:ss a");var n=t+"<br><br>Number of recipients: "+e.stats.total}else{t="Launch Date: "+moment(e.launch_date).format("MMMM Do YYYY, h:mm:ss a");var n=t+"<br><br>Number of recipients: "+e.stats.total+"<br><br>Emails opened: "+e.stats.opened+"<br><br>Emails clicked: "+e.stats.clicked+"<br><br>Submitted Credentials: "+e.stats.submitted_data+"<br><br>Errors : "+e.stats.error}campaignTable.row.add([escapeHtml(e.name),moment(e.created_date).format("MMMM Do YYYY, h:mm:ss a"),'<span class="label '+label+'" data-toggle="tooltip" data-placement="right" data-html="true" title="'+n+'">'+e.status+"</span>","<div class='pull-right'><a class='btn btn-primary' href='/campaigns/"+e.id+"' data-toggle='tooltip' data-placement='left' title='View Results'> <i class='fa fa-bar-chart'></i> </a> <span data-toggle='modal' data-target='#modal'><button class='btn btn-primary' data-toggle='tooltip' data-placement='left' title='Copy Campaign' onclick='copy("+a+")'> <i class='fa fa-copy'></i> </button></span> <button class='btn btn-danger' onclick='deleteCampaign("+a+")' data-toggle='tooltip' data-placement='left' title='Delete Campaign'> <i class='fa fa-trash-o'></i> </button></div>"]).draw(),$('[data-toggle="tooltip"]').tooltip()})):$("#emptyMessage").show()}).error(function(){$("#loading").hide(),errorFlash("Error fetching campaigns")}),$.fn.select2.defaults.set("width","100%"),$.fn.select2.defaults.set("dropdownParent",$("#modal_body")),$.fn.select2.defaults.set("theme","bootstrap")});