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

1 line
9.9 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(e,a){groups=[],$.each($("#groupTable").DataTable().rows().data(),function(e,a){groups.push({name:unescapeHtml(a[0])})}),campaign={name:$("#name").val(),template:{name:$("#template").val()},url:$("#url").val(),page:{name:$("#page").val()},smtp:{name:$("#profile").val()},launch_date:moment($("#launch_date").val(),"MM/DD/YYYY hh:mm a").format(),groups:groups},api.campaigns.post(campaign).success(function(a){e(),campaign=a}).error(function(e){$("#modal\\.flashes").empty().append('<div style="text-align:center" class="alert alert-danger"> <i class="fa fa-exclamation-circle"></i> '+e.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 e={template:{name:$("#template").val()},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").val()},smtp:{name:$("#profile").val()}};btnHtml=$("#sendTestModalSubmit").html(),$("#sendTestModalSubmit").html('<i class="fa fa-spinner fa-spin"></i> Sending'),api.send_test_email(e).success(function(e){$("#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(e){$("#sendTestEmailModal\\.flashes").empty().append('<div style="text-align:center" class="alert alert-danger"> <i class="fa fa-exclamation-circle"></i> '+e.responseJSON.message+"</div>"),$("#sendTestModalSubmit").html(btnHtml)})}function dismiss(){$("#modal\\.flashes").empty(),$("#name").val(""),$("#template").val(""),$("#page").val(""),$("#url").val(""),$("#profile").val(""),$("#groupSelect").val(""),$("#modal").modal("hide"),$("#groupTable").dataTable().DataTable().clear().draw()}function deleteCampaign(e){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[e].name,confirmButtonColor:"#428bca",reverseButtons:!0,allowOutsideClick:!1,preConfirm:function(){return new Promise(function(a,t){api.campaignId.delete(campaigns[e].id).success(function(e){a()}).error(function(e){t(e.responseJSON.message)})})}}).then(function(){swal("Campaign Deleted!","This campaign has been deleted!","success"),$('button:contains("OK")').on("click",function(){location.reload()})})}function edit(e){group_bh.clear(),template_bh.clear(),page_bh.clear(),profile_bh.clear(),"new"==e&&(api.groups.get().success(function(e){return 0==e.length?(modalError("No groups found!"),!1):void group_bh.add(e)}),api.templates.get().success(function(e){return 0==e.length?(modalError("No templates found!"),!1):void template_bh.add(e)}),api.pages.get().success(function(e){return 0==e.length?(modalError("No pages found!"),!1):void page_bh.add(e)}),api.SMTP.get().success(function(e){return 0==e.length?(modalError("No profiles found!"),!1):void profile_bh.add(e)}))}function copy(e){group_bh.clear(),template_bh.clear(),page_bh.clear(),profile_bh.clear(),api.groups.get().success(function(e){return 0==e.length?(modalError("No groups found!"),!1):void group_bh.add(e)}),api.templates.get().success(function(e){return 0==e.length?(modalError("No templates found!"),!1):void template_bh.add(e)}),api.pages.get().success(function(e){return 0==e.length?(modalError("No pages found!"),!1):void page_bh.add(e)}),api.SMTP.get().success(function(e){return 0==e.length?(modalError("No profiles found!"),!1):void profile_bh.add(e)}),api.campaignId.get(campaigns[e].id).success(function(e){$("#name").val("Copy of "+e.name),$("#template").val(e.template.name),$("#page").val(e.page.name),$("#profile").val(e.smtp.name),$("#url").val(e.url)}).error(function(e){$("#modal\\.flashes").empty().append('<div style="text-align:center" class="alert alert-danger"> <i class="fa fa-exclamation-circle"></i> '+e.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(e){$(this).removeClass("fv-modal-stack"),$("body").data("fv_open_modals",$("body").data("fv_open_modals")-1)}),$(".modal").on("shown.bs.modal",function(e){"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"))}),$.fn.modal.Constructor.prototype.enforceFocus=function(){$(document).off("focusin.bs.modal").on("focusin.bs.modal",$.proxy(function(e){this.$element[0]===e.target||this.$element.has(e.target).length||$(e.target).closest(".cke_dialog, .cke").length||this.$element.trigger("focus")},this))},$("#modal").on("hidden.bs.modal",function(e){dismiss()}),api.campaigns.summary().success(function(e){campaigns=e.campaigns,$("#loading").hide(),campaigns.length>0?($("#campaignTable").show(),campaignTable=$("#campaignTable").DataTable({columnDefs:[{orderable:!1,targets:"no-sort"}],order:[[1,"desc"]]}),$.each(campaigns,function(e,a){label=labels[a.status]||"label-default",campaignTable.row.add([escapeHtml(a.name),moment(a.created_date).format("MMMM Do YYYY, h:mm:ss a"),'<span class="label '+label+'">'+a.status+"</span>","<div class='pull-right'><a class='btn btn-primary' href='/campaigns/"+a.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("+e+")'> <i class='fa fa-copy'></i> </button></span> <button class='btn btn-danger' onclick='deleteCampaign("+e+")' 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")}),$("#groupForm").submit(function(){var e=groupTable.row.add([escapeHtml($("#groupSelect").val()),'<span style="cursor:pointer;"><i class="fa fa-trash-o"></i></span>']).draw().node();return $(e).on("click","span>i.fa-trash-o",function(){groupTable.row($(this).parents("tr")).remove().draw()}),$("#groupSelect").typeahead("val",""),!1}),groupTable=$("#groupTable").DataTable({columnDefs:[{orderable:!1,targets:"no-sort"}]}),group_bh=new Bloodhound({datumTokenizer:function(e){return Bloodhound.tokenizers.whitespace(e.name)},queryTokenizer:Bloodhound.tokenizers.whitespace,local:[]}),group_bh.initialize(),$("#groupSelect.typeahead.form-control").typeahead({hint:!0,highlight:!0,minLength:1},{name:"groups",source:group_bh,templates:{empty:function(e){return'<div class="tt-suggestion">No groups matched that query</div>'},suggestion:function(e){return"<div>"+escapeHtml(e.name)+"</div>"}}}).bind("typeahead:select",function(e,a){$("#groupSelect").typeahead("val",a.name),$("#groupForm").submit()}).bind("typeahead:autocomplete",function(e,a){$("#groupSelect").typeahead("val",a.name)}),template_bh=new Bloodhound({datumTokenizer:function(e){return Bloodhound.tokenizers.whitespace(e.name)},queryTokenizer:Bloodhound.tokenizers.whitespace,local:[]}),template_bh.initialize(),$("#template.typeahead.form-control").typeahead({hint:!0,highlight:!0,minLength:1},{name:"templates",source:template_bh,templates:{empty:function(e){return'<div class="tt-suggestion">No templates matched that query</div>'},suggestion:function(e){return"<div>"+escapeHtml(e.name)+"</div>"}}}).bind("typeahead:select",function(e,a){$("#template").typeahead("val",a.name)}).bind("typeahead:autocomplete",function(e,a){$("#template").typeahead("val",a.name)}),page_bh=new Bloodhound({datumTokenizer:function(e){return Bloodhound.tokenizers.whitespace(e.name)},queryTokenizer:Bloodhound.tokenizers.whitespace,local:[]}),page_bh.initialize(),$("#page.typeahead.form-control").typeahead({hint:!0,highlight:!0,minLength:1},{name:"pages",source:page_bh,templates:{empty:function(e){return'<div class="tt-suggestion">No pages matched that query</div>'},suggestion:function(e){return"<div>"+escapeHtml(e.name)+"</div>"}}}).bind("typeahead:select",function(e,a){$("#page").typeahead("val",a.name)}).bind("typeahead:autocomplete",function(e,a){$("#page").typeahead("val",a.name)}),profile_bh=new Bloodhound({datumTokenizer:function(e){return Bloodhound.tokenizers.whitespace(e.name)},queryTokenizer:Bloodhound.tokenizers.whitespace,local:[]}),profile_bh.initialize(),$("#profile.typeahead.form-control").typeahead({hint:!0,highlight:!0,minLength:1},{name:"profiles",source:profile_bh,templates:{empty:function(e){return'<div class="tt-suggestion">No profiles matched that query</div>'},suggestion:function(e){return"<div>"+escapeHtml(e.name)+"</div>"}}}).bind("typeahead:select",function(e,a){$("#profile").typeahead("val",a.name)}).bind("typeahead:autocomplete",function(e,a){$("#profile").typeahead("val",a.name)})});