mirror of https://github.com/gophish/gophish
1 line
12 KiB
JavaScript
1 line
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,showLoaderOnConfirm:!0,preConfirm:function(){return new Promise(function(e,t){api.campaignId.delete(campaign.id).success(function(t){e()}).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.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,showLoaderOnConfirm:!0,preConfirm:function(){return new Promise(function(e,t){api.campaignId.complete(campaign.id).success(function(t){e()}).error(function(e){t(e.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(e){exportHTML=$("#exportButton").html();var t=null;switch(e){case"results":t=campaign.results;break;case"events":t=campaign.timeline}if(t){$("#exportButton").html('<i class="fa fa-spinner fa-spin"></i>');var a=Papa.unparse(t,{}),i=new Blob([a],{type:"text/csv;charset=utf-8;"});if(navigator.msSaveBlob)navigator.msSaveBlob(i,e+".csv");else{var s=window.URL.createObjectURL(i),l=document.createElement("a");l.href=s,l.setAttribute("download",e+".csv"),document.body.appendChild(l),l.click(),document.body.removeChild(l)}$("#exportButton").html(exportHTML)}}function replay(e){function t(){form.attr({action:url}),form.appendTo("body").submit().remove()}request=campaign.timeline[e],details=JSON.parse(request.details),url=null,form=$("<form>").attr({method:"POST",target:"_blank"}),$.each(Object.keys(details.payload),function(e,t){return"rid"==t||("__original_url"==t?(url=details.payload[t],!0):void $("<input>").attr({name:t}).val(details.payload[t]).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(e){return new Promise(function(t,a){e?t():a("Invalid URL.")})}}).then(function(e){url=e,t()})}function renderTimeline(e){return record={first_name:e[2],last_name:e[3],email:e[4],position:e[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(e,t){t.email&&t.email!=record.email||(results+='<div class="timeline-entry"> <div class="timeline-bar"></div>',results+=' <div class="timeline-icon '+statuses[t.message].label+'"> <i class="fa '+statuses[t.message].icon+'"></i></div> <div class="timeline-message">'+escapeHtml(t.message)+' <span class="timeline-date">'+moment(t.time).format("MMMM Do YYYY h:mm a")+"</span>",t.details&&("Submitted Data"==t.message&&(results+='<div class="timeline-replay-button"><button onclick="replay('+e+')" 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(t.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(e,t){return"rid"==t||(results+=" <tr>",results+=" <td>"+escapeHtml(t)+"</td>",results+=" <td>"+escapeHtml(details.payload[t])+"</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(e){campaign=e;var t=[];$.each(campaign.timeline,function(e,a){var i=moment(a.time);t.push({email:a.email,x:i.valueOf(),y:1})});var t=[];$.each(campaign.timeline,function(e,a){var i=moment(a.time);t.push({email:a.email,message:a.message,x:i.valueOf(),y:1,marker:{fillColor:statuses[a.message].color}})});var a=$("#timeline_chart").highcharts();a.series[0].update({data:t});var i={};Object.keys(statusMapping).forEach(function(e){i[e]=0}),$.each(campaign.results,function(e,t){i[t.status]++;for(var a=progressListing.indexOf(t.status),e=0;e<a;e++)i[progressListing[e]]++}),$.each(i,function(e,t){var a=[];if(!(e in statusMapping))return!0;a.push({name:e,y:t}),a.push({name:"",y:campaign.results.length-t});var i=$("#"+statusMapping[e]+"_chart").highcharts();i.series[0].update({data:a})}),resultsTable=$("#resultsTable").DataTable(),resultsTable.rows().every(function(e,t,a){var i=this.row(e),s=i.data(),l=s[0];$.each(campaign.results,function(t,a){if(a.id==l){var n=statuses[a.status].label||"label-default";return s[6]='<span class="label '+n+'">'+a.status+"</span>",resultsTable.row(e).data(s).draw(!1),i.child.isShown()&&i.child(renderTimeline(i.data())),!1}})}),bubbles=[],$.each(campaign.results,function(e,t){return 0==t.latitude&&0==t.longitude||(newIP=!0,$.each(bubbles,function(e,a){if(a.ip==t.ip)return bubbles[e].radius+=1,newIP=!1,!1}),void(newIP&&bubbles.push({latitude:t.latitude,longitude:t.longitude,name:t.ip,fillKey:"point",radius:2})))}),map.bubbles(bubbles),$("#refresh_message").hide(),$("#refresh_btn").show()})}function load(){campaign.id=window.location.pathname.split("/").slice(-1)[0],api.campaignId.results(campaign.id).success(function(e){if(campaign=e){$("title").text(e.name+" - Gophish"),$("#loading").hide(),$("#campaignResults").show(),$("#page-title").text("Results for "+e.name),"Completed"==e.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())}),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();var t={},a=[];Object.keys(statusMapping).forEach(function(e){t[e]=0}),$.each(campaign.results,function(e,a){label=statuses[a.status].label||"label-default",resultsTable.row.add([a.id,'<i class="fa fa-caret-right"></i>',escapeHtml(a.first_name)||"",escapeHtml(a.last_name)||"",escapeHtml(a.email)||"",escapeHtml(a.position)||"",'<span class="label '+label+'">'+a.status+"</span>"]).draw(),t[a.status]++;for(var i=progressListing.indexOf(a.status),e=0;e<i;e++)t[progressListing[e]]++}),$("#resultsTable tbody").on("click","td.details-control",function(){var e=$(this).closest("tr"),t=resultsTable.row(e);t.child.isShown()?(t.child.hide(),e.removeClass("shown"),$(this).find("i").removeClass("fa-caret-down"),$(this).find("i").addClass("fa-caret-right"),t.invalidate("dom").draw(!1)):($(this).find("i").removeClass("fa-caret-right"),$(this).find("i").addClass("fa-caret-down"),t.child(renderTimeline(t.data())).show(),e.addClass("shown"),t.invalidate("dom").draw(!1))}),$.each(campaign.timeline,function(e,t){var i=moment(t.time);a.push({email:t.email,message:t.message,x:i.valueOf(),y:1,marker:{fillColor:statuses[t.message].color}})}),renderTimelineChart({data:a}),$.each(t,function(e,t){var a=[];if(!(e in statusMapping))return!0;a.push({name:e,y:t}),a.push({name:"",y:campaign.results.length-t});renderPieChart({elemId:statusMapping[e]+"_chart",title:e,name:e,data:a,colors:[statuses[e].color,"#dddddd"]})}),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(e,t){return 0==t.latitude&&0==t.longitude||(newIP=!0,$.each(bubbles,function(e,a){if(a.ip==t.ip)return bubbles[e].radius+=1,newIP=!1,!1}),void(newIP&&bubbles.push({latitude:t.latitude,longitude:t.longitude,name:t.ip,fillKey:"point",radius:2})))}),map.bubbles(bubbles)}$('a[data-toggle="tab"]').on("shown.bs.tab",function(e){"#overview"==$(e.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!")})}function refresh(){doPoll&&($("#refresh_message").show(),$("#refresh_btn").hide(),poll(),clearTimeout(setRefresh),setRefresh=setTimeout(refresh,6e4))}var map=null,doPoll=!0,statuses={"Email Sent":{color:"#1abc9c",label:"label-success",icon:"fa-envelope",point:"ct-point-sent"},"Emails Sent":{color:"#1abc9c",label:"label-success",icon:"fa-envelope",point:"ct-point-sent"},"In progress":{label:"label-primary"},Queued:{label:"label-info"},Completed:{label:"label-success"},"Email Opened":{color:"#f9bf3b",label:"label-warning",icon:"fa-envelope",point:"ct-point-opened"},"Clicked Link":{color:"#F39C12",label:"label-clicked",icon:"fa-mouse-pointer",point:"ct-point-clicked"},Success:{color:"#f05b4f",label:"label-danger",icon:"fa-exclamation",point:"ct-point-clicked"},Error:{color:"#6c7a89",label:"label-default",icon:"fa-times",point:"ct-point-error"},"Error Sending Email":{color:"#6c7a89",label:"label-default",icon:"fa-times",point:"ct-point-error"},"Submitted Data":{color:"#f05b4f",label:"label-danger",icon:"fa-exclamation",point:"ct-point-clicked"},Unknown:{color:"#6c7a89",label:"label-default",icon:"fa-question",point:"ct-point-error"},Sending:{color:"#428bca",label:"label-primary",icon:"fa-spinner",point:"ct-point-sending"},"Campaign Created":{label:"label-success",icon:"fa-rocket"}},statusMapping={"Email Sent":"sent","Email Opened":"opened","Clicked Link":"clicked","Submitted Data":"submitted_data"},progressListing=["Email Sent","Email Opened","Clicked Link","Submitted Data"],campaign={},bubbles=[],renderTimelineChart=function(e){return Highcharts.chart("timeline_chart",{chart:{zoomType:"x",type:"line",height:"200px"},title:{text:"Campaign Timeline"},xAxis:{type:"datetime",dateTimeLabelFormats:{second:"%l:%M:%S",minute:"%l:%M",hour:"%l:%M",day:"%b %d, %Y",week:"%b %d, %Y",month:"%b %Y"}},yAxis:{min:0,max:2,visible:!1,tickInterval:1,labels:{enabled:!1},title:{text:""}},tooltip:{formatter:function(){return Highcharts.dateFormat("%A, %b %d %l:%M:%S %P",new Date(this.x))+"<br>Event: "+this.point.message+"<br>Email: <b>"+this.point.email+"</b>"}},legend:{enabled:!1},plotOptions:{series:{marker:{enabled:!0,symbol:"circle",radius:3},cursor:"pointer"},line:{states:{hover:{lineWidth:1}}}},credits:{enabled:!1},series:[{data:e.data,dashStyle:"shortdash",color:"#cccccc",lineWidth:1}]})},renderPieChart=function(e){return Highcharts.chart(e.elemId,{chart:{type:"pie",events:{load:function(){var t=this,a=t.renderer,i=t.series[0],s=t.plotLeft+i.center[0],l=t.plotTop+i.center[1];this.innerText=a.text(e.data[0].y,s,l).attr({"text-anchor":"middle","font-size":"24px","font-weight":"bold",fill:e.colors[0],"font-family":"Helvetica,Arial,sans-serif"}).add()},render:function(){this.innerText.attr({text:e.data[0].y})}}},title:{text:e.title},plotOptions:{pie:{innerSize:"80%",dataLabels:{enabled:!1}}},credits:{enabled:!1},tooltip:{formatter:function(){return void 0!=this.key&&'<span style="color:'+this.color+'">●</span>'+this.point.name+": <b>"+this.y+"</b><br/>"}},series:[{data:e.data,colors:e.colors}]})},setRefresh;$(document).ready(function(){Highcharts.setOptions({global:{useUTC:!1}}),load(),setRefresh=setTimeout(refresh,6e4)}); |