github.com/topsteplocal/gophish@v0.6.0/static/js/src/app/landing_pages.js (about) 1 /* 2 landing_pages.js 3 Handles the creation, editing, and deletion of landing pages 4 Author: Jordan Wright <github.com/jordan-wright> 5 */ 6 var pages = [] 7 8 // Save attempts to POST to /templates/ 9 function save(idx) { 10 var page = {} 11 page.name = $("#name").val() 12 editor = CKEDITOR.instances["html_editor"] 13 page.html = editor.getData() 14 page.capture_credentials = $("#capture_credentials_checkbox").prop("checked") 15 page.capture_passwords = $("#capture_passwords_checkbox").prop("checked") 16 page.redirect_url = $("#redirect_url_input").val() 17 if (idx != -1) { 18 page.id = pages[idx].id 19 api.pageId.put(page) 20 .success(function (data) { 21 successFlash("Page edited successfully!") 22 load() 23 dismiss() 24 }) 25 } else { 26 // Submit the page 27 api.pages.post(page) 28 .success(function (data) { 29 successFlash("Page added successfully!") 30 load() 31 dismiss() 32 }) 33 .error(function (data) { 34 modalError(data.responseJSON.message) 35 }) 36 } 37 } 38 39 function dismiss() { 40 $("#modal\\.flashes").empty() 41 $("#name").val("") 42 $("#html_editor").val("") 43 $("#url").val("") 44 $("#redirect_url_input").val("") 45 $("#modal").find("input[type='checkbox']").prop("checked", false) 46 $("#capture_passwords").hide() 47 $("#redirect_url").hide() 48 $("#modal").modal('hide') 49 } 50 51 function deletePage(idx) { 52 if (confirm("Delete " + pages[idx].name + "?")) { 53 api.pageId.delete(pages[idx].id) 54 .success(function (data) { 55 successFlash(data.message) 56 load() 57 }) 58 } 59 } 60 61 function importSite() { 62 url = $("#url").val() 63 if (!url) { 64 modalError("No URL Specified!") 65 } else { 66 api.clone_site({ 67 url: url, 68 include_resources: false 69 }) 70 .success(function (data) { 71 console.log($("#html_editor")) 72 $("#html_editor").val(data.html) 73 $("#importSiteModal").modal("hide") 74 }) 75 .error(function (data) { 76 modalError(data.responseJSON.message) 77 }) 78 } 79 } 80 81 function edit(idx) { 82 $("#modalSubmit").unbind('click').click(function () { 83 save(idx) 84 }) 85 $("#html_editor").ckeditor() 86 var page = {} 87 if (idx != -1) { 88 page = pages[idx] 89 $("#name").val(page.name) 90 $("#html_editor").val(page.html) 91 $("#capture_credentials_checkbox").prop("checked", page.capture_credentials) 92 $("#capture_passwords_checkbox").prop("checked", page.capture_passwords) 93 $("#redirect_url_input").val(page.redirect_url) 94 if (page.capture_credentials) { 95 $("#capture_passwords").show() 96 $("#redirect_url").show() 97 } 98 } 99 } 100 101 function copy(idx) { 102 $("#modalSubmit").unbind('click').click(function () { 103 save(-1) 104 }) 105 $("#html_editor").ckeditor() 106 var page = pages[idx] 107 $("#name").val("Copy of " + page.name) 108 $("#html_editor").val(page.html) 109 } 110 111 function load() { 112 /* 113 load() - Loads the current pages using the API 114 */ 115 $("#pagesTable").hide() 116 $("#emptyMessage").hide() 117 $("#loading").show() 118 api.pages.get() 119 .success(function (ps) { 120 pages = ps 121 $("#loading").hide() 122 if (pages.length > 0) { 123 $("#pagesTable").show() 124 pagesTable = $("#pagesTable").DataTable({ 125 destroy: true, 126 columnDefs: [{ 127 orderable: false, 128 targets: "no-sort" 129 }] 130 }); 131 pagesTable.clear() 132 $.each(pages, function (i, page) { 133 pagesTable.row.add([ 134 escapeHtml(page.name), 135 moment(page.modified_date).format('MMMM Do YYYY, h:mm:ss a'), 136 "<div class='pull-right'><span data-toggle='modal' data-target='#modal'><button class='btn btn-primary' data-toggle='tooltip' data-placement='left' title='Edit Page' onclick='edit(" + i + ")'>\ 137 <i class='fa fa-pencil'></i>\ 138 </button></span>\ 139 <span data-toggle='modal' data-target='#modal'><button class='btn btn-primary' data-toggle='tooltip' data-placement='left' title='Copy Page' onclick='copy(" + i + ")'>\ 140 <i class='fa fa-copy'></i>\ 141 </button></span>\ 142 <button class='btn btn-danger' data-toggle='tooltip' data-placement='left' title='Delete Page' onclick='deletePage(" + i + ")'>\ 143 <i class='fa fa-trash-o'></i>\ 144 </button></div>" 145 ]).draw() 146 }) 147 $('[data-toggle="tooltip"]').tooltip() 148 } else { 149 $("#emptyMessage").show() 150 } 151 }) 152 .error(function () { 153 $("#loading").hide() 154 errorFlash("Error fetching pages") 155 }) 156 } 157 158 $(document).ready(function () { 159 // Setup multiple modals 160 // Code based on http://miles-by-motorcycle.com/static/bootstrap-modal/index.html 161 $('.modal').on('hidden.bs.modal', function (event) { 162 $(this).removeClass('fv-modal-stack'); 163 $('body').data('fv_open_modals', $('body').data('fv_open_modals') - 1); 164 }); 165 $('.modal').on('shown.bs.modal', function (event) { 166 // Keep track of the number of open modals 167 if (typeof ($('body').data('fv_open_modals')) == 'undefined') { 168 $('body').data('fv_open_modals', 0); 169 } 170 // if the z-index of this modal has been set, ignore. 171 if ($(this).hasClass('fv-modal-stack')) { 172 return; 173 } 174 $(this).addClass('fv-modal-stack'); 175 // Increment the number of open modals 176 $('body').data('fv_open_modals', $('body').data('fv_open_modals') + 1); 177 // Setup the appropriate z-index 178 $(this).css('z-index', 1040 + (10 * $('body').data('fv_open_modals'))); 179 $('.modal-backdrop').not('.fv-modal-stack').css('z-index', 1039 + (10 * $('body').data('fv_open_modals'))); 180 $('.modal-backdrop').not('fv-modal-stack').addClass('fv-modal-stack'); 181 }); 182 $.fn.modal.Constructor.prototype.enforceFocus = function () { 183 $(document) 184 .off('focusin.bs.modal') // guard against infinite focus loop 185 .on('focusin.bs.modal', $.proxy(function (e) { 186 if ( 187 this.$element[0] !== e.target && !this.$element.has(e.target).length 188 // CKEditor compatibility fix start. 189 && !$(e.target).closest('.cke_dialog, .cke').length 190 // CKEditor compatibility fix end. 191 ) { 192 this.$element.trigger('focus'); 193 } 194 }, this)); 195 }; 196 // Scrollbar fix - https://stackoverflow.com/questions/19305821/multiple-modals-overlay 197 $(document).on('hidden.bs.modal', '.modal', function () { 198 $('.modal:visible').length && $(document.body).addClass('modal-open'); 199 }); 200 $('#modal').on('hidden.bs.modal', function (event) { 201 dismiss() 202 }); 203 $("#capture_credentials_checkbox").change(function () { 204 $("#capture_passwords").toggle() 205 $("#redirect_url").toggle() 206 }) 207 load() 208 })