github.com/topsteplocal/gophish@v0.6.0/static/js/dist/app/templates.min.js (about)

     1  function save(a){var t={attachments:[]};t.name=$("#name").val(),t.subject=$("#subject").val(),t.html=CKEDITOR.instances.html_editor.getData(),t.html=t.html.replace(/https?:\/\/{{\.URL}}/gi,"{{.URL}}"),$("#use_tracker_checkbox").prop("checked")?t.html.indexOf("{{.Tracker}}")==-1&&t.html.indexOf("{{.TrackingUrl}}")==-1&&(t.html=t.html.replace("</body>","{{.Tracker}}</body>")):t.html=t.html.replace("{{.Tracker}}</body>","</body>"),t.text=$("#text_editor").val(),$.each($("#attachmentsTable").DataTable().rows().data(),function(a,e){t.attachments.push({name:unescapeHtml(e[1]),content:e[3],type:e[4]})}),a!=-1?(t.id=templates[a].id,api.templateId.put(t).success(function(a){successFlash("Template edited successfully!"),load(),dismiss()}).error(function(a){modalError(a.responseJSON.message)})):api.templates.post(t).success(function(a){successFlash("Template added successfully!"),load(),dismiss()}).error(function(a){modalError(a.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(a){confirm("Delete "+templates[a].name+"?")&&api.templateId.delete(templates[a].id).success(function(a){successFlash(a.message),load()})}function attach(a){attachmentsTable=$("#attachmentsTable").DataTable({destroy:!0,order:[[1,"asc"]],columnDefs:[{orderable:!1,targets:"no-sort"},{sClass:"datatable_hidden",targets:[3,4]}]}),$.each(a,function(a,t){var e=new FileReader;e.onload=function(a){var o=icons[t.type]||"fa-file-o";attachmentsTable.row.add(['<i class="fa '+o+'"></i>',escapeHtml(t.name),'<span class="remove-row"><i class="fa fa-trash-o"></i></span>',e.result.split(",")[1],t.type||"application/octet-stream"]).draw()},e.onerror=function(a){console.log(a)},e.readAsDataURL(t)})}function edit(a){$("#modalSubmit").unbind("click").click(function(){save(a)}),$("#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 t={attachments:[]};a!=-1&&(t=templates[a],$("#name").val(t.name),$("#subject").val(t.subject),$("#html_editor").val(t.html),$("#text_editor").val(t.text),$.each(t.attachments,function(a,t){var e=icons[t.type]||"fa-file-o";attachmentsTable.row.add(['<i class="fa '+e+'"></i>',escapeHtml(t.name),'<span class="remove-row"><i class="fa fa-trash-o"></i></span>',t.content,t.type||"application/octet-stream"]).draw()}),t.html.indexOf("{{.Tracker}}")!=-1?$("#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(a){$("#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 t={attachments:[]};t=templates[a],$("#name").val("Copy of "+t.name),$("#subject").val(t.subject),$("#html_editor").val(t.html),$("#text_editor").val(t.text),$.each(t.attachments,function(a,t){var e=icons[t.type]||"fa-file-o";attachmentsTable.row.add(['<i class="fa '+e+'"></i>',escapeHtml(t.name),'<span class="remove-row"><i class="fa fa-trash-o"></i></span>',t.content,t.type||"application/octet-stream"]).draw()}),$("#attachmentsTable").unbind("click").on("click","span>i.fa-trash-o",function(){attachmentsTable.row($(this).parents("tr")).remove().draw()}),t.html.indexOf("{{.Tracker}}")!=-1?$("#use_tracker_checkbox").prop("checked",!0):$("#use_tracker_checkbox").prop("checked",!1)}function importEmail(){raw=$("#email_content").val(),convert_links=$("#convert_links_checkbox").prop("checked"),raw?api.import_email({content:raw,convert_links:convert_links}).success(function(a){$("#text_editor").val(a.text),$("#html_editor").val(a.html),$("#subject").val(a.subject),$("#importEmailModal").modal("hide")}).error(function(a){modalError(a.responseJSON.message)}):modalError("No Content Specified!")}function load(){$("#templateTable").hide(),$("#emptyMessage").hide(),$("#loading").show(),api.templates.get().success(function(a){templates=a,$("#loading").hide(),templates.length>0?($("#templateTable").show(),templateTable=$("#templateTable").DataTable({destroy:!0,columnDefs:[{orderable:!1,targets:"no-sort"}]}),templateTable.clear(),$.each(templates,function(a,t){templateTable.row.add([escapeHtml(t.name),moment(t.modified_date).format("MMMM Do YYYY, h:mm:ss a"),"<div class='pull-right'><span data-toggle='modal' data-target='#modal'><button class='btn btn-primary' data-toggle='tooltip' data-placement='left' title='Edit Template' onclick='edit("+a+")'>                    <i class='fa fa-pencil'></i>                    </button></span>\t\t    <span data-toggle='modal' data-target='#modal'><button class='btn btn-primary' data-toggle='tooltip' data-placement='left' title='Copy Template' onclick='copy("+a+")'>                    <i class='fa fa-copy'></i>                    </button></span>                    <button class='btn btn-danger' data-toggle='tooltip' data-placement='left' title='Delete Template' onclick='deleteTemplate("+a+")'>                    <i class='fa fa-trash-o'></i>                    </button></div>"]).draw()}),$('[data-toggle="tooltip"]').tooltip()):$("#emptyMessage").show()}).error(function(){$("#loading").hide(),errorFlash("Error fetching templates")})}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"};$(document).ready(function(){$(".modal").on("hidden.bs.modal",function(a){$(this).removeClass("fv-modal-stack"),$("body").data("fv_open_modals",$("body").data("fv_open_modals")-1)}),$(".modal").on("shown.bs.modal",function(a){"undefined"==typeof $("body").data("fv_open_modals")&&$("body").data("fv_open_modals",0),$(this).hasClass("fv-modal-stack")||($(this).addClass("fv-modal-stack"),$("body").data("fv_open_modals",$("body").data("fv_open_modals")+1),$(this).css("z-index",1040+10*$("body").data("fv_open_modals")),$(".modal-backdrop").not(".fv-modal-stack").css("z-index",1039+10*$("body").data("fv_open_modals")),$(".modal-backdrop").not("fv-modal-stack").addClass("fv-modal-stack"))}),$.fn.modal.Constructor.prototype.enforceFocus=function(){$(document).off("focusin.bs.modal").on("focusin.bs.modal",$.proxy(function(a){this.$element[0]===a.target||this.$element.has(a.target).length||$(a.target).closest(".cke_dialog, .cke").length||this.$element.trigger("focus")},this))},$(document).on("hidden.bs.modal",".modal",function(){$(".modal:visible").length&&$(document.body).addClass("modal-open")}),$("#modal").on("hidden.bs.modal",function(a){dismiss()}),$("#importEmailModal").on("hidden.bs.modal",function(a){$("#email_content").val("")}),load()});