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

1 line
8.7 KiB
JavaScript
Raw Normal View History

var templates=[],icons={"application/vnd.ms-excel":"fa-file-excel-o","text/plain":"fa-file-text-o","image/gif":"fa-file-image-o","image/png":"fa-file-image-o","application/pdf":"fa-file-pdf-o","application/x-zip-compressed":"fa-file-archive-o","application/x-gzip":"fa-file-archive-o","application/vnd.openxmlformats-officedocument.presentationml.presentation":"fa-file-powerpoint-o","application/vnd.openxmlformats-officedocument.wordprocessingml.document":"fa-file-word-o","application/octet-stream":"fa-file-o","application/x-msdownload":"fa-file-o"};function save(e){var a={attachments:[]};a.name=$("#name").val(),a.subject=$("#subject").val(),a.envelope_sender=$("#envelope-sender").val(),a.html=CKEDITOR.instances.html_editor.getData(),a.html=a.html.replace(/https?:\/\/{{\.URL}}/gi,"{{.URL}}"),$("#use_tracker_checkbox").prop("checked")?-1==a.html.indexOf("{{.Tracker}}")&&-1==a.html.indexOf("{{.TrackingUrl}}")&&(a.html=a.html.replace("</body>","{{.Tracker}}</body>")):a.html=a.html.replace("{{.Tracker}}</body>","</body>"),a.text=$("#text_editor").val(),$.each($("#attachmentsTable").DataTable().rows().data(),function(e,t){a.attachments.push({name:unescapeHtml(t[1]),content:t[3],type:t[4]})}),-1!=e?(a.id=templates[e].id,api.templateId.put(a).success(function(e){successFlash("Template edited successfully!"),load(),dismiss()}).error(function(e){modalError(e.responseJSON.message)})):api.templates.post(a).success(function(e){successFlash("Template added successfully!"),load(),dismiss()}).error(function(e){modalError(e.responseJSON.message)})}function dismiss(){$("#modal\\.flashes").empty(),$("#attachmentsTable").dataTable().DataTable().clear().draw(),$("#name").val(""),$("#subject").val(""),$("#text_editor").val(""),$("#html_editor").val(""),$("#modal").modal("hide")}var deleteTemplate=function(e){Swal.fire({title:"Are you sure?",text:"This will delete the template. This can't be undone!",type:"warning",animation:!1,showCancelButton:!0,confirmButtonText:"Delete "+escapeHtml(templates[e].name),confirmButtonColor:"#428bca",reverseButtons:!0,allowOutsideClick:!1,preConfirm:function(){return new Promise(function(t,a){api.templateId.delete(templates[e].id).success(function(e){t()}).error(function(e){a(e.responseJSON.message)})})}}).then(function(e){e.value&&Swal.fire("Template Deleted!","This template has been deleted!","success"),$('button:contains("OK")').on("click",function(){location.reload()})})};function deleteTemplate(e){confirm("Delete "+templates[e].name+"?")&&api.templateId.delete(templates[e].id).success(function(e){successFlash(e.message),load()})}function attach(e){attachmentsTable=$("#attachmentsTable").DataTable({destroy:!0,order:[[1,"asc"]],columnDefs:[{orderable:!1,targets:"no-sort"},{sClass:"datatable_hidden",targets:[3,4]}]}),$.each(e,function(e,a){var o=new FileReader;o.onload=function(e){var t=icons[a.type]||"fa-file-o";attachmentsTable.row.add(['<i class="fa '+t+'"></i>',escapeHtml(a.name),'<span class="remove-row"><i class="fa fa-trash-o"></i></span>',o.result.split(",")[1],a.type||"application/octet-stream"]).draw()},o.onerror=function(e){console.log(e)},o.readAsDataURL(a)})}function edit(e){$("#modalSubmit").unbind("click").click(function(){save(e)}),$("#attachmentUpload").unbind("click").click(function(){this.value=null}),$("#html_editor").ckeditor(),setupAutocomplete(CKEDITOR.instances.html_editor),$("#attachmentsTable").show(),attachmentsTable=$("#attachmentsTable").DataTable({destroy:!0,order:[[1,"asc"]],columnDefs:[{orderable:!1,targets:"no-sort"},{sClass:"datatable_hidden",targets:[3,4]}]});var t={attachments:[]};-1!=e&&(t=templates[e],$("#name").val(t.name),$("#subject").val(t.subject),$("#envelope-sender").val(t.envelope_sender),$("#html_editor").val(t.html),$("#text_editor").val(t.text),attachmentRows=[],$.each(t.attachments,function(e,t){var a=icons[t.type]||"fa-file-o";attachmentRows.push(['<i class="fa '+a+'"></i>',escapeHtml(t.name),'<span class="remove-row"><i class="fa fa-trash-o"></i></span>',t.content,t.type||"application/octet-stream"])}),attachmentsTable.rows.add(attachmentRows).draw(),-1!=t.h