github.com/Ne0nd0g/gophish@v0.7.1-0.20190220040016-11493024a07d/static/js/src/app/gophish.js (about) 1 function errorFlash(message) { 2 $("#flashes").empty() 3 $("#flashes").append("<div style=\"text-align:center\" class=\"alert alert-danger\">\ 4 <i class=\"fa fa-exclamation-circle\"></i> " + message + "</div>") 5 } 6 7 function successFlash(message) { 8 $("#flashes").empty() 9 $("#flashes").append("<div style=\"text-align:center\" class=\"alert alert-success\">\ 10 <i class=\"fa fa-check-circle\"></i> " + message + "</div>") 11 } 12 13 function modalError(message) { 14 $("#modal\\.flashes").empty().append("<div style=\"text-align:center\" class=\"alert alert-danger\">\ 15 <i class=\"fa fa-exclamation-circle\"></i> " + message + "</div>") 16 } 17 18 function query(endpoint, method, data, async) { 19 return $.ajax({ 20 url: "/api" + endpoint + "?api_key=" + user.api_key, 21 async: async, 22 method: method, 23 data: JSON.stringify(data), 24 dataType: "json", 25 contentType: "application/json" 26 }) 27 } 28 29 function escapeHtml(text) { 30 return $("<div/>").text(text).html() 31 } 32 33 function unescapeHtml(html) { 34 return $("<div/>").html(html).text() 35 } 36 37 /** 38 * 39 * @param {string} string - The input string to capitalize 40 * 41 */ 42 var capitalize = function (string) { 43 return string.charAt(0).toUpperCase() + string.slice(1); 44 } 45 46 /* 47 Define our API Endpoints 48 */ 49 var api = { 50 // campaigns contains the endpoints for /campaigns 51 campaigns: { 52 // get() - Queries the API for GET /campaigns 53 get: function () { 54 return query("/campaigns/", "GET", {}, false) 55 }, 56 // post() - Posts a campaign to POST /campaigns 57 post: function (data) { 58 return query("/campaigns/", "POST", data, false) 59 }, 60 // summary() - Queries the API for GET /campaigns/summary 61 summary: function () { 62 return query("/campaigns/summary", "GET", {}, false) 63 } 64 }, 65 // campaignId contains the endpoints for /campaigns/:id 66 campaignId: { 67 // get() - Queries the API for GET /campaigns/:id 68 get: function (id) { 69 return query("/campaigns/" + id, "GET", {}, true) 70 }, 71 // delete() - Deletes a campaign at DELETE /campaigns/:id 72 delete: function (id) { 73 return query("/campaigns/" + id, "DELETE", {}, false) 74 }, 75 // results() - Queries the API for GET /campaigns/:id/results 76 results: function (id) { 77 return query("/campaigns/" + id + "/results", "GET", {}, true) 78 }, 79 // complete() - Completes a campaign at POST /campaigns/:id/complete 80 complete: function (id) { 81 return query("/campaigns/" + id + "/complete", "GET", {}, true) 82 }, 83 // summary() - Queries the API for GET /campaigns/summary 84 summary: function (id) { 85 return query("/campaigns/" + id + "/summary", "GET", {}, true) 86 } 87 }, 88 // groups contains the endpoints for /groups 89 groups: { 90 // get() - Queries the API for GET /groups 91 get: function () { 92 return query("/groups/", "GET", {}, false) 93 }, 94 // post() - Posts a group to POST /groups 95 post: function (group) { 96 return query("/groups/", "POST", group, false) 97 }, 98 // summary() - Queries the API for GET /groups/summary 99 summary: function () { 100 return query("/groups/summary", "GET", {}, true) 101 } 102 }, 103 // groupId contains the endpoints for /groups/:id 104 groupId: { 105 // get() - Queries the API for GET /groups/:id 106 get: function (id) { 107 return query("/groups/" + id, "GET", {}, false) 108 }, 109 // put() - Puts a group to PUT /groups/:id 110 put: function (group) { 111 return query("/groups/" + group.id, "PUT", group, false) 112 }, 113 // delete() - Deletes a group at DELETE /groups/:id 114 delete: function (id) { 115 return query("/groups/" + id, "DELETE", {}, false) 116 } 117 }, 118 // templates contains the endpoints for /templates 119 templates: { 120 // get() - Queries the API for GET /templates 121 get: function () { 122 return query("/templates/", "GET", {}, false) 123 }, 124 // post() - Posts a template to POST /templates 125 post: function (template) { 126 return query("/templates/", "POST", template, false) 127 } 128 }, 129 // templateId contains the endpoints for /templates/:id 130 templateId: { 131 // get() - Queries the API for GET /templates/:id 132 get: function (id) { 133 return query("/templates/" + id, "GET", {}, false) 134 }, 135 // put() - Puts a template to PUT /templates/:id 136 put: function (template) { 137 return query("/templates/" + template.id, "PUT", template, false) 138 }, 139 // delete() - Deletes a template at DELETE /templates/:id 140 delete: function (id) { 141 return query("/templates/" + id, "DELETE", {}, false) 142 } 143 }, 144 // pages contains the endpoints for /pages 145 pages: { 146 // get() - Queries the API for GET /pages 147 get: function () { 148 return query("/pages/", "GET", {}, false) 149 }, 150 // post() - Posts a page to POST /pages 151 post: function (page) { 152 return query("/pages/", "POST", page, false) 153 } 154 }, 155 // pageId contains the endpoints for /pages/:id 156 pageId: { 157 // get() - Queries the API for GET /pages/:id 158 get: function (id) { 159 return query("/pages/" + id, "GET", {}, false) 160 }, 161 // put() - Puts a page to PUT /pages/:id 162 put: function (page) { 163 return query("/pages/" + page.id, "PUT", page, false) 164 }, 165 // delete() - Deletes a page at DELETE /pages/:id 166 delete: function (id) { 167 return query("/pages/" + id, "DELETE", {}, false) 168 } 169 }, 170 // SMTP contains the endpoints for /smtp 171 SMTP: { 172 // get() - Queries the API for GET /smtp 173 get: function () { 174 return query("/smtp/", "GET", {}, false) 175 }, 176 // post() - Posts a SMTP to POST /smtp 177 post: function (smtp) { 178 return query("/smtp/", "POST", smtp, false) 179 } 180 }, 181 // SMTPId contains the endpoints for /smtp/:id 182 SMTPId: { 183 // get() - Queries the API for GET /smtp/:id 184 get: function (id) { 185 return query("/smtp/" + id, "GET", {}, false) 186 }, 187 // put() - Puts a SMTP to PUT /smtp/:id 188 put: function (smtp) { 189 return query("/smtp/" + smtp.id, "PUT", smtp, false) 190 }, 191 // delete() - Deletes a SMTP at DELETE /smtp/:id 192 delete: function (id) { 193 return query("/smtp/" + id, "DELETE", {}, false) 194 } 195 }, 196 // import handles all of the "import" functions in the api 197 import_email: function (req) { 198 return query("/import/email", "POST", req, false) 199 }, 200 // clone_site handles importing a site by url 201 clone_site: function (req) { 202 return query("/import/site", "POST", req, false) 203 }, 204 // send_test_email sends an email to the specified email address 205 send_test_email: function (req) { 206 return query("/util/send_test_email", "POST", req, true) 207 }, 208 reset: function () { 209 return query("/reset", "POST", {}, true) 210 } 211 } 212 213 // Register our moment.js datatables listeners 214 $(document).ready(function () { 215 // Setup nav highlighting 216 var path = location.pathname; 217 $('.nav-sidebar li').each(function () { 218 var $this = $(this); 219 // if the current path is like this link, make it active 220 if ($this.find("a").attr('href') === path) { 221 $this.addClass('active'); 222 } 223 }) 224 $.fn.dataTable.moment('MMMM Do YYYY, h:mm:ss a'); 225 // Setup tooltips 226 $('[data-toggle="tooltip"]').tooltip() 227 });