mirror of https://github.com/gophish/gophish
gofmt'ing
parent
9c7adb9941
commit
7bf2c00356
|
@ -352,84 +352,84 @@ func API_Pages_Id(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// API_SMTP handles requests for the /api/smtp/ endpoint
|
// API_SMTP handles requests for the /api/smtp/ endpoint
|
||||||
func API_SMTP(w http.ResponseWriter, r *http.Request) {
|
func API_SMTP(w http.ResponseWriter, r *http.Request) {
|
||||||
switch {
|
switch {
|
||||||
case r.Method == "GET":
|
case r.Method == "GET":
|
||||||
ss, err := models.GetSMTPs(ctx.Get(r, "user_id").(int64))
|
ss, err := models.GetSMTPs(ctx.Get(r, "user_id").(int64))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
JSONResponse(w, ss, http.StatusOK)
|
JSONResponse(w, ss, http.StatusOK)
|
||||||
//POST: Create a new SMTP and return it as JSON
|
//POST: Create a new SMTP and return it as JSON
|
||||||
case r.Method == "POST":
|
case r.Method == "POST":
|
||||||
s := models.SMTP{}
|
s := models.SMTP{}
|
||||||
// Put the request into a page
|
// Put the request into a page
|
||||||
err := json.NewDecoder(r.Body).Decode(&s)
|
err := json.NewDecoder(r.Body).Decode(&s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
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
|
// Check to make sure the name is unique
|
||||||
_, err = models.GetSMTPByName(s.Name, ctx.Get(r, "user_id").(int64))
|
_, err = models.GetSMTPByName(s.Name, ctx.Get(r, "user_id").(int64))
|
||||||
if err != gorm.RecordNotFound {
|
if err != gorm.RecordNotFound {
|
||||||
JSONResponse(w, models.Response{Success: false, Message: "SMTP name already in use"}, http.StatusConflict)
|
JSONResponse(w, models.Response{Success: false, Message: "SMTP name already in use"}, http.StatusConflict)
|
||||||
Logger.Println(err)
|
Logger.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.ModifiedDate = time.Now()
|
s.ModifiedDate = time.Now()
|
||||||
s.UserId = ctx.Get(r, "user_id").(int64)
|
s.UserId = ctx.Get(r, "user_id").(int64)
|
||||||
err = models.PostSMTP(&s)
|
err = models.PostSMTP(&s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusInternalServerError)
|
JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
JSONResponse(w, s, http.StatusCreated)
|
JSONResponse(w, s, http.StatusCreated)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// API_SMTP_Id contains functions to handle the GET'ing, DELETE'ing, and PUT'ing
|
// API_SMTP_Id contains functions to handle the GET'ing, DELETE'ing, and PUT'ing
|
||||||
// of a SMTP object
|
// of a SMTP object
|
||||||
func API_SMTP_Id(w http.ResponseWriter, r *http.Request) {
|
func API_SMTP_Id(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
id, _ := strconv.ParseInt(vars["id"], 0, 64)
|
id, _ := strconv.ParseInt(vars["id"], 0, 64)
|
||||||
s, err := models.GetSMTP(id, ctx.Get(r, "user_id").(int64))
|
s, err := models.GetSMTP(id, ctx.Get(r, "user_id").(int64))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
JSONResponse(w, models.Response{Success: false, Message: "SMTP not found"}, http.StatusNotFound)
|
JSONResponse(w, models.Response{Success: false, Message: "SMTP not found"}, http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case r.Method == "GET":
|
case r.Method == "GET":
|
||||||
JSONResponse(w, s, http.StatusOK)
|
JSONResponse(w, s, http.StatusOK)
|
||||||
case r.Method == "DELETE":
|
case r.Method == "DELETE":
|
||||||
err = models.DeleteSMTP(id, ctx.Get(r, "user_id").(int64))
|
err = models.DeleteSMTP(id, ctx.Get(r, "user_id").(int64))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
JSONResponse(w, models.Response{Success: false, Message: "Error deleting SMTP"}, http.StatusInternalServerError)
|
JSONResponse(w, models.Response{Success: false, Message: "Error deleting SMTP"}, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
JSONResponse(w, models.Response{Success: true, Message: "SMTP Deleted Successfully"}, http.StatusOK)
|
JSONResponse(w, models.Response{Success: true, Message: "SMTP Deleted Successfully"}, http.StatusOK)
|
||||||
case r.Method == "PUT":
|
case r.Method == "PUT":
|
||||||
s = models.SMTP{}
|
s = models.SMTP{}
|
||||||
err = json.NewDecoder(r.Body).Decode(&s)
|
err = json.NewDecoder(r.Body).Decode(&s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Println(err)
|
Logger.Println(err)
|
||||||
}
|
}
|
||||||
if s.Id != id {
|
if s.Id != id {
|
||||||
JSONResponse(w, models.Response{Success: false, Message: "/:id and /:smtp_id mismatch"}, http.StatusBadRequest)
|
JSONResponse(w, models.Response{Success: false, Message: "/:id and /:smtp_id mismatch"}, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = s.Validate()
|
err = s.Validate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
JSONResponse(w, models.Response{Success: false, Message: "Invalid attributes given"}, http.StatusBadRequest)
|
JSONResponse(w, models.Response{Success: false, Message: "Invalid attributes given"}, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.ModifiedDate = time.Now()
|
s.ModifiedDate = time.Now()
|
||||||
s.UserId = ctx.Get(r, "user_id").(int64)
|
s.UserId = ctx.Get(r, "user_id").(int64)
|
||||||
err = models.PutSMTP(&s)
|
err = models.PutSMTP(&s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
JSONResponse(w, models.Response{Success: false, Message: "Error updating page"}, http.StatusInternalServerError)
|
JSONResponse(w, models.Response{Success: false, Message: "Error updating page"}, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
JSONResponse(w, s, http.StatusOK)
|
JSONResponse(w, s, http.StatusOK)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// API_Import_Group imports a CSV of group members
|
// API_Import_Group imports a CSV of group members
|
||||||
|
@ -536,15 +536,15 @@ func API_Send_Test_Email(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Get the sending profile requested by name
|
// Get the sending profile requested by name
|
||||||
s.SMTP, err = models.GetSMTPByName(s.SMTP.Name, ctx.Get(r, "user_id").(int64))
|
s.SMTP, err = models.GetSMTPByName(s.SMTP.Name, ctx.Get(r, "user_id").(int64))
|
||||||
if err == gorm.RecordNotFound {
|
if err == gorm.RecordNotFound {
|
||||||
Logger.Printf("Error - Sending profile %s does not exist", s.SMTP.Name)
|
Logger.Printf("Error - Sending profile %s does not exist", s.SMTP.Name)
|
||||||
JSONResponse(w, models.Response{Success: false, Message: models.ErrSMTPNotFound.Error()}, http.StatusBadRequest)
|
JSONResponse(w, models.Response{Success: false, Message: models.ErrSMTPNotFound.Error()}, http.StatusBadRequest)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
Logger.Println(err)
|
Logger.Println(err)
|
||||||
JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusBadRequest)
|
JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Send the test email
|
// Send the test email
|
||||||
err = worker.SendTestEmail(s)
|
err = worker.SendTestEmail(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -316,14 +316,14 @@ func LandingPages(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// SendingProfiles handles the default path and template execution
|
// SendingProfiles handles the default path and template execution
|
||||||
func SendingProfiles(w http.ResponseWriter, r *http.Request) {
|
func SendingProfiles(w http.ResponseWriter, r *http.Request) {
|
||||||
// Example of using session - will be removed.
|
// Example of using session - will be removed.
|
||||||
params := struct {
|
params := struct {
|
||||||
User models.User
|
User models.User
|
||||||
Title string
|
Title string
|
||||||
Flashes []interface{}
|
Flashes []interface{}
|
||||||
Token string
|
Token string
|
||||||
}{Title: "Sending Profiles", User: ctx.Get(r, "user").(models.User), Token: nosurf.Token(r)}
|
}{Title: "Sending Profiles", User: ctx.Get(r, "user").(models.User), Token: nosurf.Token(r)}
|
||||||
getTemplate(w, "sending_profiles").ExecuteTemplate(w, "base", params)
|
getTemplate(w, "sending_profiles").ExecuteTemplate(w, "base", params)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Settings handles the changing of settings
|
// Settings handles the changing of settings
|
||||||
|
|
|
@ -10,22 +10,22 @@ import (
|
||||||
|
|
||||||
//Campaign is a struct representing a created campaign
|
//Campaign is a struct representing a created campaign
|
||||||
type Campaign struct {
|
type Campaign struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
UserId int64 `json:"-"`
|
UserId int64 `json:"-"`
|
||||||
Name string `json:"name" sql:"not null"`
|
Name string `json:"name" sql:"not null"`
|
||||||
CreatedDate time.Time `json:"created_date"`
|
CreatedDate time.Time `json:"created_date"`
|
||||||
CompletedDate time.Time `json:"completed_date"`
|
CompletedDate time.Time `json:"completed_date"`
|
||||||
TemplateId int64 `json:"-"`
|
TemplateId int64 `json:"-"`
|
||||||
Template Template `json:"template"`
|
Template Template `json:"template"`
|
||||||
PageId int64 `json:"-"`
|
PageId int64 `json:"-"`
|
||||||
Page Page `json:"page"`
|
Page Page `json:"page"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Results []Result `json:"results,omitempty"`
|
Results []Result `json:"results,omitempty"`
|
||||||
Groups []Group `json:"groups,omitempty"`
|
Groups []Group `json:"groups,omitempty"`
|
||||||
Events []Event `json:"timeline,omitemtpy"`
|
Events []Event `json:"timeline,omitemtpy"`
|
||||||
SMTPId int64 `json:"-"`
|
SMTPId int64 `json:"-"`
|
||||||
SMTP SMTP `json:"smtp"`
|
SMTP SMTP `json:"smtp"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrCampaignNameNotSpecified indicates there was no template given by the user
|
// ErrCampaignNameNotSpecified indicates there was no template given by the user
|
||||||
|
@ -95,7 +95,7 @@ func (s *SendTestEmailRequest) Validate() error {
|
||||||
return ErrEmailNotSpecified
|
return ErrEmailNotSpecified
|
||||||
case s.SMTP.Name == "":
|
case s.SMTP.Name == "":
|
||||||
return ErrSMTPNotSpecified
|
return ErrSMTPNotSpecified
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,9 +179,9 @@ func GetCampaign(id int64, uid int64) (Campaign, error) {
|
||||||
Logger.Printf("%s: page not found for campaign\n", err)
|
Logger.Printf("%s: page not found for campaign\n", err)
|
||||||
}
|
}
|
||||||
err = db.Table("SMTP").Where("id=?", c.SMTPId).Find(&c.SMTP).Error
|
err = db.Table("SMTP").Where("id=?", c.SMTPId).Find(&c.SMTP).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Printf("%s: sending profile not found for campaign\n", err)
|
Logger.Printf("%s: sending profile not found for campaign\n", err)
|
||||||
}
|
}
|
||||||
return c, err
|
return c, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,16 +229,16 @@ func PostCampaign(c *Campaign, uid int64) error {
|
||||||
c.Page = p
|
c.Page = p
|
||||||
c.PageId = p.Id
|
c.PageId = p.Id
|
||||||
// Check to make sure the sending profile exists
|
// Check to make sure the sending profile exists
|
||||||
s, err := GetSMTPByName(c.SMTP.Name, uid)
|
s, err := GetSMTPByName(c.SMTP.Name, uid)
|
||||||
if err == gorm.RecordNotFound {
|
if err == gorm.RecordNotFound {
|
||||||
Logger.Printf("Error - Sending profile %s does not exist", s.Name)
|
Logger.Printf("Error - Sending profile %s does not exist", s.Name)
|
||||||
return ErrPageNotFound
|
return ErrPageNotFound
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
Logger.Println(err)
|
Logger.Println(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.SMTP = s
|
c.SMTP = s
|
||||||
c.SMTPId = s.Id
|
c.SMTPId = s.Id
|
||||||
// Insert into the DB
|
// Insert into the DB
|
||||||
err = db.Save(c).Error
|
err = db.Save(c).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SMTP contains the attributes needed to handle the sending of campaign emails
|
// SMTP contains the attributes needed to handle the sending of campaign emails
|
||||||
type SMTP struct {
|
type SMTP struct {
|
||||||
Id int64 `json:"id" gorm:"column:id; primary_key:yes"`
|
Id int64 `json:"id" gorm:"column:id; primary_key:yes"`
|
||||||
UserId int64 `json:"-" gorm:"column:user_id"`
|
UserId int64 `json:"-" gorm:"column:user_id"`
|
||||||
Interface string `json:"interface_type" gorm:"column:interface_type"`
|
Interface string `json:"interface_type" gorm:"column:interface_type"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Host string `json:"host"`
|
Host string `json:"host"`
|
||||||
Username string `json:"username,omitempty"`
|
Username string `json:"username,omitempty"`
|
||||||
Password string `json:"password,omitempty"`
|
Password string `json:"password,omitempty"`
|
||||||
FromAddress string `json:"from_address"`
|
FromAddress string `json:"from_address"`
|
||||||
IgnoreCertErrors bool `json:"ignore_cert_errors"`
|
IgnoreCertErrors bool `json:"ignore_cert_errors"`
|
||||||
ModifiedDate time.Time `json:"modified_date"`
|
ModifiedDate time.Time `json:"modified_date"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrFromAddressNotSpecified is thrown when there is no "From" address
|
// ErrFromAddressNotSpecified is thrown when there is no "From" address
|
||||||
|
|
Loading…
Reference in New Issue