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,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,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={series:[{name:"Events",data:[]}]};$.each(campaign.timeline,function(e,a){t.series[0].data.push({meta:e,x:new Date(a.time),y:1})});var a=$("#timeline_chart");a.get(0).__chartist__&&a.get(0).__chartist__.update(t);var i={series:[]},s={};$.each(campaign.results,function(e,t){s[t.status]?s[t.status]++:s[t.status]=1}),$("#email_chart_legend").html(""),$.each(s,function(e,t){i.series.push({meta:e,value:t}),$("#email_chart_legend").append('<li><span class="'+statuses[e].legend+'"></span>'+e+"</li>")});var l=$("#email_chart");l.get(0).__chartist__&&(l.get(0).__chartist__.on("draw",function(e){e.element.addClass(statuses[e.meta].slice)}),l.get(0).__chartist__.update(i)),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())});var t={series:[{name:"Events",data:[]}]},a={series:[]},i={},s={axisX:{showGrid:!1,type:Chartist.FixedScaleAxis,divisor:5,labelInterpolationFnc:function(e){return moment(e).format("MMMM Do YYYY h:mm a")}},axisY:{type:Chartist.FixedScaleAxis,ticks:[0,1,2],low:0,showLabel:!1},showArea:!1,plugins:[]},l={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(e,t){label=statuses[t.status].label||"label-default",resultsTable.row.add([t.id,'<i class="fa fa-caret-right"></i>',escapeHtml(t.first_name)||"",escapeHtml(t.last_name)||"",escapeHtml(t.email)||"",escapeHtml(t.position)||"",'<span class="label '+label+'">'+t.status+"</span>"]).draw(),i[t.status]?i[t.status]++:i[t.status]=1}),$("#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,a){t.series[0].data.push({meta:e,x:new Date(a.time),y:1})}),$("#email_chart_legend").html(""),$.each(i,function(e,t){a.series.push({meta:e,value:t}),$("#email_chart_legend").append('<li><span class="'+statuses[e].legend+'"></span>'+e+"</li>")});var n=new Chartist.Line("#timeline_chart",t,s);n.on("draw",function(e){if("point"===e.type){var t=statuses[campaign.timeline[e.meta].message].point,a=new Chartist.Svg("circle",{cx:[e.x],cy:[e.y],r:5,fill:"#283F50",meta:e.meta,value:1},t+" ct-timeline-point");e.element.replace(a)}}),$chart=$("#timeline_chart");var o=$chart.append('<div class="chartist-tooltip"></div>').find(".chartist-tooltip").hide();$chart.on("mouseenter",".ct-timeline-point",function(){var e=$(this);cidx=e.attr("meta"),html="Event: "+campaign.timeline[cidx].message,campaign.timeline[cidx].email&&(html+="<br>Email: "+escapeHtml(campaign.timeline[cidx].email)),o.html(html).show()}),$chart.on("mouseleave",".ct-timeline-point",function(){o.hide()}),$chart.on("mousemove",function(e){o.css({left:(e.offsetX||e.originalEvent.layerX)-o.width()/2-10,top:(e.offsetY+70||e.originalEvent.layerY)-o.height()-40})});var r=new Chartist.Pie("#email_chart",a,l);r.on("draw",function(e){e.element.addClass(statuses[e.meta].slice)}),$piechart=$("#email_chart");var c=$piechart.append('<div class="chartist-tooltip"></div>').find(".chartist-tooltip").hide();$piechart.on("mouseenter",".ct-slice-donut",function(){var e=$(this);value=e.attr("ct:value"),label=e.attr("ct:meta"),c.html(label+": "+value.toString()).show()}),$piechart.on("mouseleave",".ct-slice-donut",function(){c.hide()}),$piechart.on("mousemove",function(e){c.css({left:(e.offsetX||e.originalEvent.layerX)-c.width()/2-10,top:(e.offsetY+40||e.originalEvent.layerY)-c.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(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":{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"},Success:{slice:"ct-slice-donut-success",legend:"ct-legend-success",label:"label-danger",icon:"fa-exclamation",point:"ct-point-clicked"},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-clicked"},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=[],setRefresh;$(document).ready(function(){load(),setRefresh=setTimeout(refresh,6e4)}); |