mirror of https://github.com/gophish/gophish
Refined models
Added *basic* worker functionality - emails get sent now! woo hoo!pull/24/head
parent
db24496fb0
commit
a1b6218473
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -17,13 +17,10 @@
|
|||
SMTP Options <i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': isOpen, 'glyphicon-chevron-right': !isOpen}"></i>
|
||||
</accordion-heading>
|
||||
<label class="control-label" for="from">From:</label>
|
||||
<input type="text" class="form-control" placeholder="First Last <test@example.com>" id="form">
|
||||
<input type="text" class="form-control" ng-model="campaign.smtp.from_address" placeholder="First Last <test@example.com>" id="form">
|
||||
<br />
|
||||
<label class="control-label" for="smtp_server">Hostname:</label>
|
||||
<input type="text" class="form-control" ng-model="campaign.smtp.hostname" placeholder="host:port" id="smtp_server">
|
||||
<br />
|
||||
<label class="control-label" for="smtp_server">Port:</label>
|
||||
<input type="text" class="form-control" ng-model="campaign.smtp.port" placeholder="host:port" id="smtp_server">
|
||||
<label class="control-label" for="smtp_server">Host:</label>
|
||||
<input type="text" class="form-control" ng-model="campaign.smtp.host" placeholder="smtp.example.com:25" id="smtp_server">
|
||||
<br />
|
||||
<label class="control-label" for="smtp_server">Username:</label>
|
||||
<input type="text" class="form-control" ng-model="campaign.smtp.username" placeholder="host:port" id="smtp_server">
|
||||
|
|
|
@ -9,6 +9,10 @@
|
|||
<div class="form-group">
|
||||
<input type="text" class="form-control" ng-model="template.name" placeholder="Template name" id="name" autofocus/>
|
||||
</div>
|
||||
<label class="control-label" for="subject">Subject:</label>
|
||||
<div class="form-group">
|
||||
<input type="text" class="form-control" ng-model="template.subject" placeholder="Email Subject" id="subject"/>
|
||||
</div>
|
||||
<fieldset disabled>
|
||||
<div class="form-group">
|
||||
<button class="btn btn-danger btn-disabled"><i class="fa fa-envelope"></i> Import Email (Coming Soon!)</button>
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue