mirror of https://github.com/gophish/gophish
Can now add/delete pages
Fixed test for importing a site - Now actually performs the right test.pull/64/head
parent
fad36607e4
commit
ba11f6428c
|
@ -283,6 +283,7 @@ func API_Pages(w http.ResponseWriter, r *http.Request) {
|
||||||
JSONResponse(w, models.Response{Success: false, Message: "Invalid request"}, http.StatusBadRequest)
|
JSONResponse(w, models.Response{Success: false, Message: "Invalid request"}, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// Check to make sure the name is unique
|
||||||
_, err = models.GetPageByName(p.Name, ctx.Get(r, "user_id").(int64))
|
_, err = models.GetPageByName(p.Name, ctx.Get(r, "user_id").(int64))
|
||||||
if err != gorm.RecordNotFound {
|
if err != gorm.RecordNotFound {
|
||||||
JSONResponse(w, models.Response{Success: false, Message: "Page name already in use"}, http.StatusConflict)
|
JSONResponse(w, models.Response{Success: false, Message: "Page name already in use"}, http.StatusConflict)
|
||||||
|
@ -293,7 +294,7 @@ func API_Pages(w http.ResponseWriter, r *http.Request) {
|
||||||
p.UserId = ctx.Get(r, "user_id").(int64)
|
p.UserId = ctx.Get(r, "user_id").(int64)
|
||||||
err = models.PostPage(&p)
|
err = models.PostPage(&p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
JSONResponse(w, models.Response{Success: false, Message: "Error inserting page"}, http.StatusInternalServerError)
|
JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
JSONResponse(w, p, http.StatusCreated)
|
JSONResponse(w, p, http.StatusCreated)
|
||||||
|
|
|
@ -2,8 +2,8 @@ package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
|
@ -45,6 +45,7 @@ func (s *ControllersSuite) TestSiteImportBaseHref() {
|
||||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintln(w, h)
|
fmt.Fprintln(w, h)
|
||||||
}))
|
}))
|
||||||
|
hr := fmt.Sprintf("<html><head><base href=\"%s\"/></head><body><img src=\"/test.png\"/>\n</body></html>", ts.URL)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
resp, err := http.Post(fmt.Sprintf("%s/api/import/site?api_key=%s", as.URL, s.ApiKey), "application/json",
|
resp, err := http.Post(fmt.Sprintf("%s/api/import/site?api_key=%s", as.URL, s.ApiKey), "application/json",
|
||||||
bytes.NewBuffer([]byte(fmt.Sprintf(`
|
bytes.NewBuffer([]byte(fmt.Sprintf(`
|
||||||
|
@ -55,9 +56,10 @@ func (s *ControllersSuite) TestSiteImportBaseHref() {
|
||||||
`, ts.URL))))
|
`, ts.URL))))
|
||||||
s.Nil(err)
|
s.Nil(err)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
cs := cloneResponse{}
|
||||||
|
err = json.NewDecoder(resp.Body).Decode(&cs)
|
||||||
s.Nil(err)
|
s.Nil(err)
|
||||||
fmt.Printf("%s", body)
|
s.Equal(cs.HTML, hr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ControllersSuite) TearDownSuite() {
|
func (s *ControllersSuite) TearDownSuite() {
|
||||||
|
|
|
@ -19,7 +19,7 @@ function save(idx){
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// Submit the page
|
// Submit the page
|
||||||
api.landing_pages.post(page)
|
api.pages.post(page)
|
||||||
.success(function(data){
|
.success(function(data){
|
||||||
successFlash("Page added successfully!")
|
successFlash("Page added successfully!")
|
||||||
load()
|
load()
|
||||||
|
@ -37,9 +37,9 @@ function dismiss(){
|
||||||
$("#html_editor").val("")
|
$("#html_editor").val("")
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteTemplate(idx){
|
function deletePage(idx){
|
||||||
if (confirm("Delete " + pages[idx].name + "?")){
|
if (confirm("Delete " + pages[idx].name + "?")){
|
||||||
api.landing_pageId.delete(pages[idx].id)
|
api.pageId.delete(pages[idx].id)
|
||||||
.success(function(data){
|
.success(function(data){
|
||||||
successFlash(data.message)
|
successFlash(data.message)
|
||||||
load()
|
load()
|
||||||
|
@ -79,22 +79,25 @@ function edit(idx){
|
||||||
}
|
}
|
||||||
|
|
||||||
function load(){
|
function load(){
|
||||||
|
/*
|
||||||
|
load() - Loads the current pages using the API
|
||||||
|
*/
|
||||||
$("#pagesTable").hide()
|
$("#pagesTable").hide()
|
||||||
$("#emptyMessage").hide()
|
$("#emptyMessage").hide()
|
||||||
$("#loading").show()
|
$("#loading").show()
|
||||||
api.landing_pages.get()
|
api.pages.get()
|
||||||
.success(function(ps){
|
.success(function(ps){
|
||||||
pages = ps
|
pages = ps
|
||||||
$("#loading").hide()
|
$("#loading").hide()
|
||||||
if (pages.length > 0){
|
if (pages.length > 0){
|
||||||
$("#pagesTable").show()
|
$("#pagesTable").show()
|
||||||
pagesTable = $("#templateTable").DataTable();
|
pagesTable = $("#pagesTable").DataTable();
|
||||||
pagesTable.clear()
|
pagesTable.clear()
|
||||||
$.each(pages, function(i, page){
|
$.each(pages, function(i, page){
|
||||||
pagesTable.row.add([
|
pagesTable.row.add([
|
||||||
page.name,
|
page.name,
|
||||||
moment(page.modified_date).format('MMMM Do YYYY, h:mm:ss a'),
|
moment(page.modified_date).format('MMMM Do YYYY, h:mm:ss a'),
|
||||||
"<div class='pull-right'><button class='btn btn-primary' data-toggle='modal' data-target='#modal' onclick='edit(" + i + ")'>\
|
"<div class='pull-right'><button class='btn btn-primary' data-toggle='modal' data-target='#newLandingPageModal' onclick='edit(" + i + ")'>\
|
||||||
<i class='fa fa-pencil'></i>\
|
<i class='fa fa-pencil'></i>\
|
||||||
</button>\
|
</button>\
|
||||||
<button class='btn btn-danger' onclick='deletePage(" + i + ")'>\
|
<button class='btn btn-danger' onclick='deletePage(" + i + ")'>\
|
||||||
|
@ -110,6 +113,9 @@ function load(){
|
||||||
$("#loading").hide()
|
$("#loading").hide()
|
||||||
errorFlash("Error fetching pages")
|
errorFlash("Error fetching pages")
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function(){
|
||||||
// Setup multiple modals
|
// Setup multiple modals
|
||||||
// Code based on http://miles-by-motorcycle.com/static/bootstrap-modal/index.html
|
// Code based on http://miles-by-motorcycle.com/static/bootstrap-modal/index.html
|
||||||
$('.modal').on('hidden.bs.modal', function( event ) {
|
$('.modal').on('hidden.bs.modal', function( event ) {
|
||||||
|
@ -135,8 +141,5 @@ function load(){
|
||||||
$( '.modal-backdrop' ).not( '.fv-modal-stack' ).css( 'z-index', 1039 + (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' );
|
$( '.modal-backdrop' ).not( 'fv-modal-stack' ).addClass( 'fv-modal-stack' );
|
||||||
});
|
});
|
||||||
}
|
load()
|
||||||
|
|
||||||
$(document).ready(function(){
|
|
||||||
load()
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -114,10 +114,10 @@ function load(){
|
||||||
$("#loading").show()
|
$("#loading").show()
|
||||||
api.groups.get()
|
api.groups.get()
|
||||||
.success(function(gs){
|
.success(function(gs){
|
||||||
|
$("#loading").hide()
|
||||||
if (gs.length > 0){
|
if (gs.length > 0){
|
||||||
groups = gs
|
groups = gs
|
||||||
$("#emptyMessage").hide()
|
$("#emptyMessage").hide()
|
||||||
$("#loading").hide()
|
|
||||||
$("#groupTable").show()
|
$("#groupTable").show()
|
||||||
groupTable = $("#groupTable").DataTable();
|
groupTable = $("#groupTable").DataTable();
|
||||||
groupTable.clear();
|
groupTable.clear();
|
||||||
|
@ -143,7 +143,6 @@ function load(){
|
||||||
]).draw()
|
]).draw()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
$("#loading").hide()
|
|
||||||
$("#emptyMessage").show()
|
$("#emptyMessage").show()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -106,30 +106,30 @@ var api = {
|
||||||
return query("/templates/" + id, "DELETE", {})
|
return query("/templates/" + id, "DELETE", {})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// landing_pages contains the endpoints for /landing_pages
|
// pages contains the endpoints for /pages
|
||||||
landing_pages : {
|
pages : {
|
||||||
// get() - Queries the API for GET /landing_pages
|
// get() - Queries the API for GET /pages
|
||||||
get: function(){
|
get: function(){
|
||||||
return query("/landing_pages/", "GET", {})
|
return query("/pages/", "GET", {})
|
||||||
},
|
},
|
||||||
// post() - Posts a campaign to POST /landing_pages
|
// post() - Posts a campaign to POST /pages
|
||||||
post: function(page){
|
post: function(page){
|
||||||
return query("/landing_pages/", "POST", page)
|
return query("/pages/", "POST", page)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// templateId contains the endpoints for /templates/:id
|
// templateId contains the endpoints for /templates/:id
|
||||||
landing_pageId : {
|
pageId : {
|
||||||
// get() - Queries the API for GET /templates/:id
|
// get() - Queries the API for GET /templates/:id
|
||||||
get: function(id){
|
get: function(id){
|
||||||
return query("/landing_pages/" + id, "GET", {})
|
return query("/pages/" + id, "GET", {})
|
||||||
},
|
},
|
||||||
// put() - Puts a campaign to PUT /templates/:id
|
// put() - Puts a campaign to PUT /templates/:id
|
||||||
put: function (page){
|
put: function (page){
|
||||||
return query("/landing_pages/" + page.id, "PUT", page)
|
return query("/pages/" + page.id, "PUT", page)
|
||||||
},
|
},
|
||||||
// delete() - Deletes a campaign at DELETE /templates/:id
|
// delete() - Deletes a campaign at DELETE /templates/:id
|
||||||
delete: function(id){
|
delete: function(id){
|
||||||
return query("/landing_pages/" + id, "DELETE", {})
|
return query("/pages/" + id, "DELETE", {})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
clone_site : function(req){
|
clone_site : function(req){
|
||||||
|
|
|
@ -33,11 +33,9 @@
|
||||||
<div id="loading">
|
<div id="loading">
|
||||||
<i class="fa fa-spinner fa-spin fa-4x"></i>
|
<i class="fa fa-spinner fa-spin fa-4x"></i>
|
||||||
</div>
|
</div>
|
||||||
<div style="display:none;">
|
<div id="emptyMessage" class="row" style="display:none;">
|
||||||
<div class="row">
|
<div class="alert alert-info">
|
||||||
<div class="alert alert-info">
|
No pages created yet. Let's create one!
|
||||||
No pages created yet. Let's create one!
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
Loading…
Reference in New Issue