mirror of https://github.com/gophish/gophish
2 lines
12 KiB
JavaScript
2 lines
12 KiB
JavaScript
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('<i class="fa fa-spinner fa-spin"></i>');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=$("<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 $("<input>").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='<div class="timeline col-sm-12 well well-lg"><h6>Timeline for '+escapeHtml(record.first_name)+" "+escapeHtml(record.last_name)+'</h6><span class="subtitle">Email: '+escapeHtml(record.email)+'</span><div class="timeline-graph col-sm-6">',$.each(campaign.timeline,function(a,b){b.email&&b.email!=record.email||(results+='<div class="timeline-entry"> <div class="timeline-bar"></div>',results+=' <div class="timeline-icon '+statuses[b.message].label+'"> <i class="fa '+statuses[b.message].icon+'"></i></div> <div class="timeline-message">'+escapeHtml(b.message)+' <span class="timeline-date">'+moment(b.time).format("MMMM Do YYYY h:mm a")+"</span>",b.details&&("Submitted Data"==b.message&&(results+='<div class="timeline-replay-button"><button onclick="replay('+a+')" class="btn btn-success">',results+='<i class="fa fa-refresh"></i> Replay Credentials</button></div>',results+='<div class="timeline-event-details"><i class="fa fa-caret-right"></i> View Details</div>'),details=JSON.parse(b.details),details.payload&&(results+='<div class="timeline-event-results">',results+=' <table class="table table-condensed table-bordered table-striped">',results+=" <thead><tr><th>Parameter</th><th>Value(s)</tr></thead><tbody>",$.each(Object.keys(details.payload),function(a,b){return"rid"==b||(results+=" <tr>",results+=" <td>"+escapeHtml(b)+"</td>",results+=" <td>"+escapeHtml(details.payload[b])+"</td>",void(results+=" </tr>"))}),results+=" </tbody></table>",results+="</div>"),details.error&&(results+='<div class="timeline-event-details"><i class="fa fa-caret-right"></i> View Details</div>',results+='<div class="timeline-event-results">',results+='<span class="label label-default">Error</span> '+details.error,results+="</div>")),results+="</div></div>")}),results+="</div></div>",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('<li><span class="'+statuses[a].legend+'"></span>'+a+"</li>")});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]='<span class="label '+g+'">'+c.status+"</span>",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,'<i class="fa fa-caret-right"></i>',escapeHtml(b.first_name)||"",escapeHtml(b.last_name)||"",escapeHtml(b.email)||"",escapeHtml(b.position)||"",'<span class="label '+label+'">'+b.status+"</span>"]).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('<li><span class="'+statuses[a].legend+'"></span>'+a+"</li>")});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('<div class="chartist-tooltip"></div>').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+="<br>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('<div class="chartist-tooltip"></div>').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)});
|