function dismiss(){$("#modal\\.flashes").empty(),$("#modal").modal("hide"),$("#resultsTable").dataTable().DataTable().clear().draw()}function deleteCampaign(){swal({title:"Are you sure?",text:"This will delete the campaign. This can't be undone!",type:"warning",animation:!1,showCancelButton:!0,confirmButtonText:"Delete Campaign",confirmButtonColor:"#428bca",reverseButtons:!0,allowOutsideClick:!1,preConfirm:function(){return new Promise(function(a,b){api.campaignId.delete(campaign.id).success(function(b){a()}).error(function(a){b(a.responseJSON.message)})})}}).then(function(){swal("Campaign Deleted!","This campaign has been deleted!","success"),$('button:contains("OK")').on("click",function(){location.href="/campaigns"})})}function completeCampaign(){swal({title:"Are you sure?",text:"Gophish will stop processing events for this campaign",type:"warning",animation:!1,showCancelButton:!0,confirmButtonText:"Complete Campaign",confirmButtonColor:"#428bca",reverseButtons:!0,allowOutsideClick:!1,preConfirm:function(){return new Promise(function(a,b){api.campaignId.complete(campaign.id).success(function(b){a()}).error(function(a){b(a.responseJSON.message)})})}}).then(function(){swal("Campaign Completed!","This campaign has been completed!","success"),$("#complete_button")[0].disabled=!0,$("#complete_button").text("Completed!"),doPoll=!1})}function exportAsCSV(a){exportHTML=$("#exportButton").html();var b=null;switch(a){case"results":b=campaign.results;break;case"events":b=campaign.timeline}if(b){$("#exportButton").html('');var c=Papa.unparse(b,{}),d=new Blob([c],{type:"text/csv;charset=utf-8;"});if(navigator.msSaveBlob)navigator.msSaveBlob(d,a+".csv");else{var e=window.URL.createObjectURL(d),f=document.createElement("a");f.href=e,f.setAttribute("download",a+".csv"),document.body.appendChild(f),f.click(),document.body.removeChild(f)}$("#exportButton").html(exportHTML)}}function replay(a){function b(){form.attr({action:url}),form.appendTo("body").submit().remove()}request=campaign.timeline[a],details=JSON.parse(request.details),url=null,form=$("
").attr({method:"POST",target:"_blank"}),$.each(Object.keys(details.payload),function(a,b){return"rid"==b||("__original_url"==b?(url=details.payload[b],!0):void $("").attr({name:b}).val(details.payload[b]).appendTo(form))}),swal({title:"Where do you want the credentials submitted to?",input:"text",showCancelButton:!0,inputPlaceholder:"http://example.com/login",inputValue:url||"",inputValidator:function(a){return new Promise(function(b,c){a?b():c("Invalid URL.")})}}).then(function(a){url=a,b()})}function renderTimeline(a){return record={first_name:a[2],last_name:a[3],email:a[4],position:a[5]},results='
Timeline for '+escapeHtml(record.first_name)+" "+escapeHtml(record.last_name)+'
Email: '+escapeHtml(record.email)+'
',$.each(campaign.timeline,function(a,b){b.email&&b.email!=record.email||(results+='
',results+='
'+escapeHtml(b.message)+' '+moment(b.time).format("MMMM Do YYYY h:mm a")+"",b.details&&("Submitted Data"==b.message&&(results+='
',results+='
View Details
'),details=JSON.parse(b.details),details.payload&&(results+='
',results+=' ',results+=" ",$.each(Object.keys(details.payload),function(a,b){return"rid"==b||(results+=" ",results+=" ",results+=" ",void(results+=" "))}),results+="
ParameterValue(s)
"+escapeHtml(b)+""+escapeHtml(details.payload[b])+"
",results+="
"),details.error&&(results+='
View Details
',results+='
',results+='Error '+details.error,results+="
")),results+="
")}),results+="
",results}function poll(){api.campaignId.results(campaign.id).success(function(a){campaign=a;var b={series:[{name:"Events",data:[]}]};$.each(campaign.timeline,function(a,c){b.series[0].data.push({meta:a,x:new Date(c.time),y:1})});var c=$("#timeline_chart");c.get(0).__chartist__&&c.get(0).__chartist__.update(b);var d={series:[]},e={};$.each(campaign.results,function(a,b){e[b.status]?e[b.status]++:e[b.status]=1}),$("#email_chart_legend").html(""),$.each(e,function(a,b){d.series.push({meta:a,value:b}),$("#email_chart_legend").append('
  • '+a+"
  • ")});var f=$("#email_chart");f.get(0).__chartist__&&(f.get(0).__chartist__.on("draw",function(a){a.element.addClass(statuses[a.meta].slice)}),f.get(0).__chartist__.update(d)),resultsTable=$("#resultsTable").DataTable(),resultsTable.rows().every(function(a,b,c){var d=this.row(a),e=d.data(),f=e[0];$.each(campaign.results,function(b,c){if(c.id==f){var g=statuses[c.status].label||"label-default";return e[6]=''+c.status+"",resultsTable.row(a).data(e).draw(!1),d.child.isShown()&&d.child(renderTimeline(d.data())),!1}})}),bubbles=[],$.each(campaign.results,function(a,b){return 0==b.latitude&&0==b.longitude||(newIP=!0,$.each(bubbles,function(a,c){if(c.ip==b.ip)return bubbles[a].radius+=1,newIP=!1,!1}),void(newIP&&bubbles.push({latitude:b.latitude,longitude:b.longitude,name:b.ip,fillKey:"point",radius:2})))}),map.bubbles(bubbles)})}function load(){campaign.id=window.location.pathname.split("/").slice(-1)[0],api.campaignId.results(campaign.id).success(function(a){if(campaign=a){$("title").text(a.name+" - Gophish"),$("#loading").hide(),$("#campaignResults").show(),$("#page-title").text("Results for "+a.name),"Completed"==a.status&&($("#complete_button")[0].disabled=!0,$("#complete_button").text("Completed!"),doPoll=!1),$('[data-toggle="tooltip"]').tooltip(),$("#resultsTable").on("click",".timeline-event-details",function(){payloadResults=$(this).parent().find(".timeline-event-results"),payloadResults.is(":visible")?($(this).find("i").removeClass("fa-caret-down"),$(this).find("i").addClass("fa-caret-right"),payloadResults.hide()):($(this).find("i").removeClass("fa-caret-right"),$(this).find("i").addClass("fa-caret-down"),payloadResults.show())});var b={series:[{name:"Events",data:[]}]},c={series:[]},e={},f={axisX:{showGrid:!1,type:Chartist.FixedScaleAxis,divisor:5,labelInterpolationFnc:function(a){return moment(a).format("MMMM Do YYYY h:mm a")}},axisY:{type:Chartist.FixedScaleAxis,ticks:[0,1,2],low:0,showLabel:!1},showArea:!1,plugins:[]},g={donut:!0,donutWidth:40,chartPadding:0,showLabel:!1};resultsTable=$("#resultsTable").DataTable({destroy:!0,order:[[2,"asc"]],columnDefs:[{orderable:!1,targets:"no-sort"},{className:"details-control",targets:[1]},{visible:!1,targets:[0]}]}),resultsTable.clear(),$.each(campaign.results,function(a,b){label=statuses[b.status].label||"label-default",resultsTable.row.add([b.id,'',escapeHtml(b.first_name)||"",escapeHtml(b.last_name)||"",escapeHtml(b.email)||"",escapeHtml(b.position)||"",''+b.status+""]).draw(),e[b.status]?e[b.status]++:e[b.status]=1}),$("#resultsTable tbody").on("click","td.details-control",function(){var a=$(this).closest("tr"),b=resultsTable.row(a);b.child.isShown()?(b.child.hide(),a.removeClass("shown"),$(this).find("i").removeClass("fa-caret-down"),$(this).find("i").addClass("fa-caret-right"),b.invalidate("dom").draw(!1)):($(this).find("i").removeClass("fa-caret-right"),$(this).find("i").addClass("fa-caret-down"),b.child(renderTimeline(b.data())).show(),a.addClass("shown"),b.invalidate("dom").draw(!1))}),$.each(campaign.timeline,function(a,c){b.series[0].data.push({meta:a,x:new Date(c.time),y:1})}),$("#email_chart_legend").html(""),$.each(e,function(a,b){c.series.push({meta:a,value:b}),$("#email_chart_legend").append('
  • '+a+"
  • ")});var h=new Chartist.Line("#timeline_chart",b,f);h.on("draw",function(a){if("point"===a.type){var b=statuses[campaign.timeline[a.meta].message].point,c=new Chartist.Svg("circle",{cx:[a.x],cy:[a.y],r:5,fill:"#283F50",meta:a.meta,value:1},b+" ct-timeline-point");a.element.replace(c)}}),$chart=$("#timeline_chart");var i=$chart.append('
    ').find(".chartist-tooltip").hide();$chart.on("mouseenter",".ct-timeline-point",function(){var a=$(this);cidx=a.attr("meta"),html="Event: "+campaign.timeline[cidx].message,campaign.timeline[cidx].email&&(html+="
    Email: "+escapeHtml(campaign.timeline[cidx].email)),i.html(html).show()}),$chart.on("mouseleave",".ct-timeline-point",function(){i.hide()}),$chart.on("mousemove",function(a){i.css({left:(a.offsetX||a.originalEvent.layerX)-i.width()/2-10,top:(a.offsetY+70||a.originalEvent.layerY)-i.height()-40})});var j=new Chartist.Pie("#email_chart",c,g);j.on("draw",function(a){a.element.addClass(statuses[a.meta].slice)}),$piechart=$("#email_chart");var k=$piechart.append('
    ').find(".chartist-tooltip").hide();$piechart.on("mouseenter",".ct-slice-donut",function(){var a=$(this);value=a.attr("ct:value"),label=a.attr("ct:meta"),k.html(label+": "+value.toString()).show()}),$piechart.on("mouseleave",".ct-slice-donut",function(){k.hide()}),$piechart.on("mousemove",function(a){k.css({left:(a.offsetX||a.originalEvent.layerX)-k.width()/2-10,top:(a.offsetY+40||a.originalEvent.layerY)-k.height()-80})}),map||(map=new Datamap({element:document.getElementById("resultsMap"),responsive:!0,fills:{defaultFill:"#ffffff",point:"#283F50"},geographyConfig:{highlightFillColor:"#1abc9c",borderColor:"#283F50"},bubblesConfig:{borderColor:"#283F50"}})),$.each(campaign.results,function(a,b){return 0==b.latitude&&0==b.longitude||(newIP=!0,$.each(bubbles,function(a,c){if(c.ip==b.ip)return bubbles[a].radius+=1,newIP=!1,!1}),void(newIP&&bubbles.push({latitude:b.latitude,longitude:b.longitude,name:b.ip,fillKey:"point",radius:2})))}),map.bubbles(bubbles)}$('a[data-toggle="tab"]').on("shown.bs.tab",function(a){"#overview"==$(a.target).attr("href")&&(map||(map=new Datamap({element:document.getElementById("resultsMap"),responsive:!0,fills:{defaultFill:"#ffffff"},geographyConfig:{highlightFillColor:"#1abc9c",borderColor:"#283F50"}})))})}).error(function(){$("#loading").hide(),errorFlash(" Campaign not found!")})}var map=null,doPoll=!0,statuses={"Email Sent":{slice:"ct-slice-donut-sent",legend:"ct-legend-sent",label:"label-success",icon:"fa-envelope",point:"ct-point-sent"},"Email Opened":{slice:"ct-slice-donut-opened",legend:"ct-legend-opened",label:"label-warning",icon:"fa-envelope",point:"ct-point-opened"},"Clicked Link":{slice:"ct-slice-donut-clicked",legend:"ct-legend-clicked",label:"label-clicked",icon:"fa-mouse-pointer",point:"ct-point-clicked"},"Content Enabled":{slice:"ct-slice-donut-enabled",legend:"ct-legend-enabled",label:"label-danger",icon:"fa-exclamation",point:"ct-point-enabled"},Success:{slice:"ct-slice-donut-success",legend:"ct-legend-success",label:"label-danger",icon:"fa-exclamation",point:"ct-point-success"},Error:{slice:"ct-slice-donut-error",legend:"ct-legend-error",label:"label-default",icon:"fa-times",point:"ct-point-error"},"Error Sending Email":{slice:"ct-slice-donut-error",legend:"ct-legend-error",label:"label-default",icon:"fa-times",point:"ct-point-error"},"Submitted Data":{slice:"ct-slice-donut-success",legend:"ct-legend-success",label:"label-danger",icon:"fa-exclamation",point:"ct-point-success"},Unknown:{slice:"ct-slice-donut-error",legend:"ct-legend-error",label:"label-default",icon:"fa-question",point:"ct-point-error"},Sending:{slice:"ct-slice-donut-sending",legend:"ct-legend-sending",label:"label-primary",icon:"fa-spinner",point:"ct-point-sending"},"Campaign Created":{label:"label-success",icon:"fa-rocket"}},campaign={},bubbles=[];$(document).ready(function(){function a(){doPoll&&($("#refresh_message").show(),poll(),$("#refresh_message").hide(),setTimeout(a,1e4))}load(),setTimeout(a,1e4)});