mirror of https://github.com/gophish/gophish
Updated campaign creation and send_test_email to use settings from sending profile
parent
b2eafd07c3
commit
9818410fcf
|
@ -535,6 +535,16 @@ func API_Send_Test_Email(w http.ResponseWriter, r *http.Request) {
|
||||||
JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusBadRequest)
|
JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// Get the sending profile requested by name
|
||||||
|
s.SMTP, err = models.GetSMTPByName(s.SMTP.Name, ctx.Get(r, "user_id").(int64))
|
||||||
|
if err == gorm.RecordNotFound {
|
||||||
|
Logger.Printf("Error - Sending profile %s does not exist", s.SMTP.Name)
|
||||||
|
JSONResponse(w, models.Response{Success: false, Message: models.ErrSMTPNotFound.Error()}, http.StatusBadRequest)
|
||||||
|
} else if err != nil {
|
||||||
|
Logger.Println(err)
|
||||||
|
JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
// Send the test email
|
// Send the test email
|
||||||
err = worker.SendTestEmail(s)
|
err = worker.SendTestEmail(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -10,21 +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"`
|
||||||
SMTP SMTP `json:"smtp"`
|
SMTPId int64 `json:"-"`
|
||||||
URL string `json:"url"`
|
SMTP SMTP `json:"smtp"`
|
||||||
|
URL string `json:"url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrCampaignNameNotSpecified indicates there was no template given by the user
|
// ErrCampaignNameNotSpecified indicates there was no template given by the user
|
||||||
|
@ -39,6 +40,9 @@ var ErrTemplateNotSpecified = errors.New("No email template specified")
|
||||||
// ErrPageNotSpecified indicates a landing page was not provided for the campaign
|
// ErrPageNotSpecified indicates a landing page was not provided for the campaign
|
||||||
var ErrPageNotSpecified = errors.New("No landing page specified")
|
var ErrPageNotSpecified = errors.New("No landing page specified")
|
||||||
|
|
||||||
|
// ErrSMTPNotSpecified indicates a sending profile was not provided for the campaign
|
||||||
|
var ErrSMTPNotSpecified = errors.New("No sending profile specified")
|
||||||
|
|
||||||
// ErrTemplateNotFound indicates the template specified does not exist in the database
|
// ErrTemplateNotFound indicates the template specified does not exist in the database
|
||||||
var ErrTemplateNotFound = errors.New("Template not found")
|
var ErrTemplateNotFound = errors.New("Template not found")
|
||||||
|
|
||||||
|
@ -48,6 +52,9 @@ var ErrGroupNotFound = errors.New("Group not found")
|
||||||
// ErrPageNotFound indicates a page specified by the user does not exist in the database
|
// ErrPageNotFound indicates a page specified by the user does not exist in the database
|
||||||
var ErrPageNotFound = errors.New("Page not found")
|
var ErrPageNotFound = errors.New("Page not found")
|
||||||
|
|
||||||
|
// ErrSMTPNotFound indicates a sending profile specified by the user does not exist in the database
|
||||||
|
var ErrSMTPNotFound = errors.New("Sending profile not found")
|
||||||
|
|
||||||
// Validate checks to make sure there are no invalid fields in a submitted campaign
|
// Validate checks to make sure there are no invalid fields in a submitted campaign
|
||||||
func (c *Campaign) Validate() error {
|
func (c *Campaign) Validate() error {
|
||||||
switch {
|
switch {
|
||||||
|
@ -59,8 +66,10 @@ func (c *Campaign) Validate() error {
|
||||||
return ErrTemplateNotSpecified
|
return ErrTemplateNotSpecified
|
||||||
case c.Page.Name == "":
|
case c.Page.Name == "":
|
||||||
return ErrPageNotSpecified
|
return ErrPageNotSpecified
|
||||||
|
case c.SMTP.Name == "":
|
||||||
|
return ErrSMTPNotSpecified
|
||||||
}
|
}
|
||||||
return c.SMTP.Validate()
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendTestEmailRequest is the structure of a request
|
// SendTestEmailRequest is the structure of a request
|
||||||
|
@ -84,9 +93,10 @@ func (s *SendTestEmailRequest) Validate() error {
|
||||||
return ErrTemplateNotSpecified
|
return ErrTemplateNotSpecified
|
||||||
case s.Email == "":
|
case s.Email == "":
|
||||||
return ErrEmailNotSpecified
|
return ErrEmailNotSpecified
|
||||||
}
|
case s.SMTP.Name == "":
|
||||||
// Finally, check the SMTP settings
|
return ErrSMTPNotSpecified
|
||||||
return s.SMTP.Validate()
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateStatus changes the campaign status appropriately
|
// UpdateStatus changes the campaign status appropriately
|
||||||
|
@ -168,6 +178,10 @@ func GetCampaign(id int64, uid int64) (Campaign, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
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
|
||||||
|
if err != nil {
|
||||||
|
Logger.Printf("%s: sending profile not found for campaign\n", err)
|
||||||
|
}
|
||||||
return c, err
|
return c, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,6 +228,17 @@ 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
|
||||||
|
s, err := GetSMTPByName(c.SMTP.Name, uid)
|
||||||
|
if err == gorm.RecordNotFound {
|
||||||
|
Logger.Printf("Error - Sending profile %s does not exist", s.Name)
|
||||||
|
return ErrPageNotFound
|
||||||
|
} else if err != nil {
|
||||||
|
Logger.Println(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
c.SMTP = s
|
||||||
|
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 {
|
||||||
|
|
Loading…
Reference in New Issue