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

1 line
8.4 KiB
JavaScript
Raw Normal View History

function save(t){var e={attachments:[]};e.name=$("#name").val(),e.subject=$("#subject").val(),e.html=CKEDITOR.instances.html_editor.getData(),e.html=e.html.replace(/https?:\/\/{{\.URL}}/gi,"{{.URL}}"),$("#use_tracker_checkbox").prop("checked")?-1==e.html.indexOf("{{.Tracker}}")&&-1==e.html.indexOf("{{.TrackingUrl}}")&&(e.html=e.html.replace("</body>","{{.Tracker}}</body>")):e.html=e.html.replace("{{.Tracker}}</body>","</body>"),e.text=$("#text_editor").val(),$.each($("#attachmentsTable").DataTable().rows().data(),function(t,a){e.attachments.push({name:unescapeHtml(a[1]),content:a[3],type:a[4]})}),-1!=t?(e.id=templates[t].id,api.templateId.put(e).success(function(t){successFlash("Template edited successfully!"),load(),dismiss()}).error(function(t){modalError(t.responseJSON.message)})):api.templates.post(e).success(function(t){successFlash("Template added successfully!"),load(),dismiss()}).error(function(t){modalError(t.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")}function deleteTemplate(t){confirm("Delete "+templates[t].name+"?")&&api.templateId.delete(templates[t].id).success(function(t){successFlash(t.message),load()})}function attach(t){attachmentsTable=$("#attachmentsTable").DataTable({destroy:!0,order:[[1,"asc"]],columnDefs:[{orderable:!1,targets:"no-sort"},{sClass:"datatable_hidden",targets:[3,4]}]}),$.each(t,function(t,e){var a=new FileReader;a.onload=function(t){var o=icons[e.type]||"fa-file-o";attachmentsTable.row.add(['<i class="fa '+o+'"></i>',escapeHtml(e.name),'<span class="remove-row"><i class="fa fa-trash-o"></i></span>',a.result.split(",")[1],e.type||"application/octet-stream"]).draw()},a.onerror=function(t){console.log(t)},a.readAsDataURL(e)})}function edit(t){$("#modalSubmit").unbind("click").click(function(){save(t)}),$("#attachmentUpload").unbind("click").click(function(){this.value=null}),$("#html_editor").ckeditor(),$("#attachmentsTable").show(),attachmentsTable=$("#attachmentsTable").DataTable({destroy:!0,order:[[1,"asc"]],columnDefs:[{orderable:!1,targets:"no-sort"},{sClass:"datatable_hidden",targets:[3,4]}]});var e={attachments:[]};-1!=t&&(e=templates[t],$("#name").val(e.name),$("#subject").val(e.subject),$("#html_editor").val(e.html),$("#text_editor").val(e.text),$.each(e.attachments,function(t,e){var a=icons[e.type]||"fa-file-o";attachmentsTable.row.add(['<i class="fa '+a+'"></i>',escapeHtml(e.name),'<span class="remove-row"><i class="fa fa-trash-o"></i></span>',e.content,e.type||"application/octet-stream"]).draw()}),-1!=e.html.indexOf("{{.Tracker}}")?$("#use_tracker_checkbox").prop("checked",!0):$("#use_tracker_checkbox").prop("checked",!1)),$("#attachmentsTable").unbind("click").on("click","span>i.fa-trash-o",function(){attachmentsTable.row($(this).parents("tr")).remove().draw()})}function copy(t){$("#modalSubmit").unbind("click").click(function(){save(-1)}),$("#attachmentUpload").unbind("click").click(function(){this.value=null}),$("#html_editor").ckeditor(),$("#attachmentsTable").show(),attachmentsTable=$("#attachmentsTable").DataTable({destroy:!0,order:[[1,"asc"]],columnDefs:[{orderable:!1,targets:"no-sort"},{sClass:"datatable_hidden",targets:[3,4]}]});var e={attachments:[]};e=templates[t],$("#name").val("Copy of "+e.name),$("#subject").val(e.subject),$("#html_editor").val(e.html),$("#text_editor").val(e.text),$.each(e.attachments,function(t,e){var a=icons[e.type]||"fa-file-o";attachmentsTable.row.add(['<i class="fa '+a+'"></i>',escapeHtml(e.name),'<span class="remove-row"><i class="fa fa-trash-o"></i></span>',e.content,e.type||"application/octet-stream"]).draw()}),$("#attachmentsTable").unbind("click").on("click","span>i.fa-trash-o",function(){attachmentsTable.row($(this).parents("tr")).remove().draw()}),-1!=e.html.indexOf("{{.Tracker}}")?$("#use_tracker_checkbox").prop("checked",!0):$("#use_tracker_checkbox").prop("checked",!1)}function importEmail(){raw=$("#email_content").val(),co