diff --git a/static/js/app/landing_pages.js b/static/js/app/landing_pages.js new file mode 100644 index 00000000..267335b6 --- /dev/null +++ b/static/js/app/landing_pages.js @@ -0,0 +1,98 @@ +/* + landing_pages.js + Handles the creation, editing, and deletion of landing pages + Author: Jordan Wright +*/ +var pages = [] +// Save attempts to POST to /templates/ +function save(idx){ + var page = {} + page.name = $("#name").val() + page.html = CKEDITOR.instances["html_editor"].getData(); + if (idx != -1){ + page.id = page[idx].id + api.landing_pageId.put(page) + .success(function(data){ + successFlash("Page edited successfully!") + load() + dismiss() + }) + } else { + // Submit the page + api.landing_pages.post(page) + .success(function(data){ + successFlash("Page added successfully!") + load() + dismiss() + }) + .error(function(data){ + modalError(data.responseJSON.message) + }) + } +} + +function dismiss(){ + $("#modal\\.flashes").empty() + $("#modal").modal('hide') + $("#name").val("") + $("#html_editor").val("") +} + +function deleteTemplate(idx){ + if (confirm("Delete " + pages[idx].name + "?")){ + api.landing_pageId.delete(pages[idx].id) + .success(function(data){ + successFlash(data.message) + load() + }) + } +} + +function edit(idx){ + $("#modalSubmit").unbind('click').click(function(){save(idx)}) + $("#html_editor").ckeditor() + var page = {} + if (idx != -1) { + page = pages[idx] + $("#name").val(page.name) + $("#html_editor").val(page.html) + } +} + +function load(){ + $("#pagesTable").hide() + $("#emptyMessage").hide() + $("#loading").show() + api.landing_pages.get() + .success(function(ps){ + pages = ps + $("#loading").hide() + if (pages.length > 0){ + $("#pagesTable").show() + pagesTable = $("#templateTable").DataTable(); + pagesTable.clear() + $.each(pages, function(i, page){ + pagesTable.row.add([ + page.name, + moment(page.modified_date).format('MMMM Do YYYY, h:mm:ss a'), + "
\ +
" + ]).draw() + }) + } else { + $("#emptyMessage").show() + } + }) + .error(function(){ + $("#loading").hide() + errorFlash("Error fetching pages") + }) +} + +$(document).ready(function(){ + load() +}) diff --git a/static/js/gophish.js b/static/js/gophish.js index 45d3c2ee..5f0951d6 100644 --- a/static/js/gophish.js +++ b/static/js/gophish.js @@ -105,5 +105,31 @@ var api = { delete: function(id){ return query("/templates/" + id, "DELETE", {}) } + }, + // landing_pages contains the endpoints for /landing_pages + landing_pages : { + // get() - Queries the API for GET /landing_pages + get: function(){ + return query("/landing_pages/", "GET", {}) + }, + // post() - Posts a campaign to POST /landing_pages + post: function(page){ + return query("/landing_pages/", "POST", page) + } + }, + // templateId contains the endpoints for /templates/:id + landing_pageId : { + // get() - Queries the API for GET /templates/:id + get: function(id){ + return query("/landing_pages/" + id, "GET", {}) + }, + // put() - Puts a campaign to PUT /templates/:id + put: function (page){ + return query("/landing_pages/" + page.id, "PUT", page) + }, + // delete() - Deletes a campaign at DELETE /templates/:id + delete: function(id){ + return query("/landing_pages/" + id, "DELETE", {}) + } } } diff --git a/templates/landing_pages.html b/templates/landing_pages.html index 337d0475..c50ebae0 100644 --- a/templates/landing_pages.html +++ b/templates/landing_pages.html @@ -11,7 +11,7 @@
  • Email Templates
  • -
  • Landing Pages +
  • Landing Pages
  • Settings
  • @@ -27,7 +27,7 @@
    - +
     
    @@ -54,8 +54,44 @@
    + +