From a1b621847366f5c07dc62d355e9dff646b17c18d Mon Sep 17 00:00:00 2001 From: Jordan Date: Wed, 4 Jun 2014 23:54:46 -0500 Subject: [PATCH] Refined models Added *basic* worker functionality - emails get sent now! woo hoo! --- models/campaign.go | 5 ++-- models/smtp.go | 10 ++----- models/template.go | 5 ++-- .../js/app/partials/modals/campaignModal.html | 9 +++---- .../js/app/partials/modals/templateModal.html | 4 +++ worker/worker.go | 27 ++++++++++++++++--- 6 files changed, 38 insertions(+), 22 deletions(-) diff --git a/models/campaign.go b/models/campaign.go index bf4e6f97..ea605e88 100644 --- a/models/campaign.go +++ b/models/campaign.go @@ -17,9 +17,10 @@ type Campaign struct { TemplateId int64 `json:"-"` Template Template `json:"template"` //This may change Status string `json:"status"` + EmailsSent string `json:"emails_sent"` Results []Result `json:"results,omitempty"` Groups []Group `json:"groups,omitempty"` - SMTP SMTP `json:"options,omitempty"` + SMTP SMTP `json:"smtp"` } func (c *Campaign) Validate() (string, bool) { @@ -90,8 +91,8 @@ func PostCampaign(c *Campaign, uid int64) error { Logger.Println(err) return err } + c.Template = t c.TemplateId = t.Id - // Insert into the DB err = db.Save(c).Error if err != nil { diff --git a/models/smtp.go b/models/smtp.go index 0015bb94..81ce037b 100644 --- a/models/smtp.go +++ b/models/smtp.go @@ -3,9 +3,7 @@ package models type SMTP struct { SMTPId int64 `json:"-"` CampaignId int64 `json:"-"` - Hostname string `json:"hostname"` - Port int `json:"port"` - UseAuth bool `json:"use_auth"` + Host string `json:"host"` Username string `json:"username,omitempty"` Password string `json:"password,omitempty" sql:"-"` FromAddress string `json:"from_address"` @@ -13,14 +11,10 @@ type SMTP struct { func (s *SMTP) Validate() (string, bool) { switch { - case s.UseAuth == false && (s.Username == "" && s.Password == ""): - return "Auth requested, but username or password blank", false case s.FromAddress == "": return "No from address specified", false - case s.Hostname == "": + case s.Host == "": return "No hostname specified", false - case s.Port == 0: - return "No port specified", false } return "", true } diff --git a/models/template.go b/models/template.go index b62ed4f5..d28f35dd 100644 --- a/models/template.go +++ b/models/template.go @@ -6,8 +6,9 @@ type Template struct { Id int64 `json:"id"` UserId int64 `json:"-"` Name string `json:"name"` + Subject string `json:"subject"` Text string `json:"text"` - Html string `json:"html"` + HTML string `json:"html"` ModifiedDate time.Time `json:"modified_date"` } @@ -15,7 +16,7 @@ func (t *Template) Validate() (string, bool) { switch { case t.Name == "": return "Template Name not specified", false - case t.Text == "" && t.Html == "": + case t.Text == "" && t.HTML == "": return "Need to specify at least plaintext or HTML format", false } return "", true diff --git a/static/js/app/partials/modals/campaignModal.html b/static/js/app/partials/modals/campaignModal.html index 70d20d75..1f32a5f3 100644 --- a/static/js/app/partials/modals/campaignModal.html +++ b/static/js/app/partials/modals/campaignModal.html @@ -17,13 +17,10 @@ SMTP Options - +
- - -
- - + +
diff --git a/static/js/app/partials/modals/templateModal.html b/static/js/app/partials/modals/templateModal.html index dddf7b6d..c4dfdc75 100644 --- a/static/js/app/partials/modals/templateModal.html +++ b/static/js/app/partials/modals/templateModal.html @@ -9,6 +9,10 @@
+ +
+ +
diff --git a/worker/worker.go b/worker/worker.go index 64c5b177..e6d5de39 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -2,8 +2,11 @@ package worker import ( "log" + "net/smtp" "os" + "strings" + "github.com/jordan-wright/email" "github.com/jordan-wright/gophish/models" ) @@ -34,12 +37,28 @@ func processCampaign(c *models.Campaign) { if err != nil { Logger.Println(err) } + e := email.Email{ + Subject: c.Template.Subject, + From: c.SMTP.FromAddress, + Text: []byte(c.Template.Text), + HTML: []byte(c.Template.HTML), + } + Logger.Println(c.SMTP.Username) + Logger.Println(c.SMTP.Password) + Logger.Println(c.SMTP.FromAddress) + var auth smtp.Auth + if c.SMTP.Username != "" && c.SMTP.Password != "" { + auth = smtp.PlainAuth("", c.SMTP.Username, c.SMTP.Password, strings.Split(c.SMTP.Host, ":")[0]) + } for _, t := range c.Results { Logger.Println("Creating email using template") - /*e := email.Email{ - Text: []byte(c.Template.Text), - HTML: []byte(c.Template.Html), - }*/ + e.To = []string{t.Email} + Logger.Println(e.To) + Logger.Println(e.From) + err := e.Send(c.SMTP.Host, auth) + if err != nil { + Logger.Println(err) + } Logger.Printf("Sending Email to %s\n", t.Email) } }