gophish: github.com/gophish/gophish/models Index | Files

package models

import "github.com/gophish/gophish/models"

Package models implements the types and structs needed in gophish.

Index

Package Files

attachment.go campaign.go doc.go email_request.go group.go imap.go maillog.go models.go page.go rbac.go result.go smtp.go template.go template_context.go user.go webhook.go

Constants

const (
    CampaignInProgress string = "In progress"
    CampaignQueued     string = "Queued"
    CampaignCreated    string = "Created"
    CampaignEmailsSent string = "Emails Sent"
    CampaignComplete   string = "Completed"
    EventSent          string = "Email Sent"
    EventSendingError  string = "Error Sending Email"
    EventOpened        string = "Email Opened"
    EventClicked       string = "Clicked Link"
    EventDataSubmit    string = "Submitted Data"
    EventReported      string = "Email Reported"
    EventProxyRequest  string = "Proxied request"
    StatusSuccess      string = "Success"
    StatusQueued       string = "Queued"
    StatusSending      string = "Sending"
    StatusUnknown      string = "Unknown"
    StatusScheduled    string = "Scheduled"
    StatusRetry        string = "Retrying"
    Error              string = "Error"
)
const (
    // RoleAdmin is used for Gophish system administrators. Users with this
    // role have the ability to manage all objects within Gophish, as well as
    // system-level configuration, such as users and URLs.
    RoleAdmin = "admin"
    // RoleUser is used for standard Gophish users. Users with this role can
    // create, manage, and view Gophish objects and campaigns.
    RoleUser = "user"

    // PermissionViewObjects determines if a role can view standard Gophish
    // objects such as campaigns, groups, landing pages, etc.
    PermissionViewObjects = "view_objects"
    // PermissionModifyObjects determines if a role can create and modify
    // standard Gophish objects.
    PermissionModifyObjects = "modify_objects"
    // PermissionModifySystem determines if a role can manage system-level
    // configuration.
    PermissionModifySystem = "modify_system"
)
const DefaultAdminUsername = "admin"

DefaultAdminUsername is the default username for the administrative user

const DefaultIMAPFolder = "INBOX"
const DefaultIMAPFreq = 60 // Every 60 seconds
const InitialAdminApiToken = "GOPHISH_INITIAL_ADMIN_API_TOKEN"

InitialAdminApiToken is the environment variable that specifies the API token to seed the initial root login instead of generating one randomly

const InitialAdminPassword = "GOPHISH_INITIAL_ADMIN_PASSWORD"

InitialAdminPassword is the environment variable that specifies which password to use for the initial root login instead of generating one randomly

const MaxDatabaseConnectionAttempts int = 10
const PreviewPrefix = "preview-"

PreviewPrefix is the standard prefix added to the rid parameter when sending test emails.

const RecipientParameter = "rid"

RecipientParameter is the URL parameter that points to the result ID for a recipient.

Variables

var ErrCampaignNameNotSpecified = errors.New("Campaign name not specified")

ErrCampaignNameNotSpecified indicates there was no template given by the user

var ErrEmailNotSpecified = errors.New("No email address specified")

ErrEmailNotSpecified is thrown when no email is specified for the Target

var ErrFromAddressNotSpecified = errors.New("No From Address specified")

ErrFromAddressNotSpecified is thrown when there is no "From" address specified in the SMTP configuration

var ErrGroupNameNotSpecified = errors.New("Group name not specified")

ErrGroupNameNotSpecified is thrown when a group name is not specified

var ErrGroupNotFound = errors.New("Group not found")

ErrGroupNotFound indicates a group specified by the user does not exist in the database

var ErrGroupNotSpecified = errors.New("No groups specified")

ErrGroupNotSpecified indicates there was no template given by the user

var ErrHostNotSpecified = errors.New("No SMTP Host specified")

ErrHostNotSpecified is thrown when there is no Host specified in the SMTP configuration

var ErrIMAPHostNotSpecified = errors.New("No IMAP Host specified")

ErrIMAPHostNotSpecified is thrown when there is no Host specified in the IMAP configuration

var ErrIMAPPasswordNotSpecified = errors.New("No Password specified")

ErrIMAPPasswordNotSpecified is thrown when there is no Password specified in the IMAP configuration

var ErrIMAPPortNotSpecified = errors.New("No IMAP Port specified")

ErrIMAPPortNotSpecified is thrown when there is no Port specified in the IMAP configuration

var ErrIMAPUsernameNotSpecified = errors.New("No Username specified")

ErrIMAPUsernameNotSpecified is thrown when there is no Username specified in the IMAP configuration

var ErrInvalidHost = errors.New("Invalid SMTP server address")

ErrInvalidHost indicates that the SMTP server string is invalid

var ErrInvalidIMAPFreq = errors.New("Invalid polling frequency")

ErrInvalidIMAPFreq is thrown when the frequency for polling the IMAP server is invalid

var ErrInvalidIMAPHost = errors.New("Invalid IMAP server address")

ErrInvalidIMAPHost indicates that the IMAP server string is invalid

var ErrInvalidIMAPPort = errors.New("Invalid IMAP Port")

ErrInvalidIMAPPort indicates that the IMAP Port is invalid

var ErrInvalidSendByDate = errors.New("The launch date must be before the \"send emails by\" date")

ErrInvalidSendByDate indicates that the user specified a send by date that occurs before the launch date

var ErrMaxSendAttempts = errors.New("max send attempts exceeded")

ErrMaxSendAttempts is thrown when the maximum number of sending attempts for a given MailLog is exceeded.

var ErrModifyingOnlyAdmin = errors.New("Cannot remove the only administrator")

ErrModifyingOnlyAdmin occurs when there is an attempt to modify the only user account with the Admin role in such a way that there will be no user accounts left in Gophish with that role.

var ErrNameNotSpecified = errors.New("Name can't be empty")

ErrNameNotSpecified indicates there was no name specified

var ErrNoTargetsSpecified = errors.New("No targets specified")

ErrNoTargetsSpecified is thrown when no targets are specified by the user

var ErrPageNameNotSpecified = errors.New("Page Name not specified")

ErrPageNameNotSpecified is thrown if the name of the landing page is blank.

var ErrPageNotFound = errors.New("Page not found")

ErrPageNotFound indicates a page specified by the user does not exist in the database

var ErrPageNotSpecified = errors.New("No landing page specified")

ErrPageNotSpecified indicates a landing page was not provided for the campaign

var ErrSMTPNotFound = errors.New("Sending profile not found")

ErrSMTPNotFound indicates a sending profile specified by the user does not exist in the database

var ErrSMTPNotSpecified = errors.New("No sending profile specified")

ErrSMTPNotSpecified indicates a sending profile was not provided for the campaign

var ErrTemplateMissingParameter = errors.New("Need to specify at least plaintext or HTML content")

ErrTemplateMissingParameter is thrown when a needed parameter is not provided

var ErrTemplateNameNotSpecified = errors.New("Template name not specified")

ErrTemplateNameNotSpecified is thrown when a template name is not specified

var ErrTemplateNotFound = errors.New("Template not found")

ErrTemplateNotFound indicates the template specified does not exist in the database

var ErrTemplateNotSpecified = errors.New("No email template specified")

ErrTemplateNotSpecified indicates there was no template given by the user

var ErrURLNotSpecified = errors.New("URL can't be empty")

ErrURLNotSpecified indicates there was no URL specified

var MaxSendAttempts = 8

MaxSendAttempts set to 8 since we exponentially backoff after each failed send attempt. This will give us a maximum send delay of 256 minutes, or about 4.2 hours.

func AddEvent Uses

func AddEvent(e *Event, campaignID int64) error

AddEvent creates a new campaign event in the database

func CompleteCampaign Uses

func CompleteCampaign(id int64, uid int64) error

CompleteCampaign effectively "ends" a campaign. Any future emails clicked will return a simple "404" page.

func DeleteCampaign Uses

func DeleteCampaign(id int64) error

DeleteCampaign deletes the specified campaign

func DeleteGroup Uses

func DeleteGroup(g *Group) error

DeleteGroup deletes a given group by group ID and user ID

func DeleteIMAP Uses

func DeleteIMAP(uid int64) error

DeleteIMAP deletes the existing IMAP in the database.

func DeletePage Uses

func DeletePage(id int64, uid int64) error

DeletePage deletes an existing page in the database. An error is returned if a page with the given user id and page id is not found.

func DeleteSMTP Uses

func DeleteSMTP(id int64, uid int64) error

DeleteSMTP deletes an existing SMTP in the database. An error is returned if a SMTP with the given user id and SMTP id is not found.

func DeleteTemplate Uses

func DeleteTemplate(id int64, uid int64) error

DeleteTemplate deletes an existing template in the database. An error is returned if a template with the given user id and template id is not found.

func DeleteUser Uses

func DeleteUser(id int64) error

DeleteUser deletes the given user. To ensure that there is always at least one user account with the Admin role, this function will refuse to delete the last Admin.

func DeleteWebhook Uses

func DeleteWebhook(id int64) error

DeleteWebhook deletes an existing webhook in the database. An error is returned if a webhook with the given id isn't found.

func EnsureEnoughAdmins Uses

func EnsureEnoughAdmins() error

EnsureEnoughAdmins ensures that there is more than one user account in Gophish with the Admin role. This function is meant to be called before modifying a user account with the Admin role in a non-revokable way.

func ExecuteTemplate Uses

func ExecuteTemplate(text string, data interface{}) (string, error)

ExecuteTemplate creates a templated string based on the provided template body and data.

func GenerateMailLog Uses

func GenerateMailLog(c *Campaign, r *Result, sendDate time.Time) error

GenerateMailLog creates a new maillog for the given campaign and result. It sets the initial send date to match the campaign's launch date.

func LockMailLogs Uses

func LockMailLogs(ms []*MailLog, lock bool) error

LockMailLogs locks or unlocks a slice of maillogs for processing.

func PostCampaign Uses

func PostCampaign(c *Campaign, uid int64) error

PostCampaign inserts a campaign and all associated records into the database.

func PostEmailRequest Uses

func PostEmailRequest(s *EmailRequest) error

PostEmailRequest stores a SendTestEmailRequest in the database.

func PostGroup Uses

func PostGroup(g *Group) error

PostGroup creates a new group in the database.

func PostIMAP Uses

func PostIMAP(im *IMAP, uid int64) error

PostIMAP updates IMAP settings for a user in the database.

func PostPage Uses

func PostPage(p *Page) error

PostPage creates a new page in the database.

func PostSMTP Uses

func PostSMTP(s *SMTP) error

PostSMTP creates a new SMTP in the database.

func PostTemplate Uses

func PostTemplate(t *Template) error

PostTemplate creates a new template in the database.

func PostWebhook Uses

func PostWebhook(wh *Webhook) error

PostWebhook creates a new webhook in the database.

func PutGroup Uses

func PutGroup(g *Group) error

PutGroup updates the given group if found in the database.

func PutPage Uses

func PutPage(p *Page) error

PutPage edits an existing Page in the database. Per the PUT Method RFC, it presumes all data for a page is provided.

func PutSMTP Uses

func PutSMTP(s *SMTP) error

PutSMTP edits an existing SMTP in the database. Per the PUT Method RFC, it presumes all data for a SMTP is provided.

func PutTemplate Uses

func PutTemplate(t *Template) error

PutTemplate edits an existing template in the database. Per the PUT Method RFC, it presumes all data for a template is provided.

func PutUser Uses

func PutUser(u *User) error

PutUser updates the given user

func PutWebhook Uses

func PutWebhook(wh *Webhook) error

PutWebhook edits an existing webhook in the database.

func Setup Uses

func Setup(c *config.Config) error

Setup initializes the database and runs any needed migrations.

First, it establishes a connection to the database, then runs any migrations newer than the version the database is on.

Once the database is up-to-date, we create an admin user (if needed) that has a randomly generated API key and password.

func SuccessfulLogin Uses

func SuccessfulLogin(im *IMAP) error

func UnlockAllMailLogs Uses

func UnlockAllMailLogs() error

UnlockAllMailLogs removes the processing lock for all maillogs in the database. This is intended to be called when Gophish is started so that any previously locked maillogs can resume processing.

func UpdateTarget Uses

func UpdateTarget(tx *gorm.DB, target Target) error

UpdateTarget updates the given target information in the database.

func ValidateTemplate Uses

func ValidateTemplate(text string) error

ValidateTemplate ensures that the provided text in the page or template uses the supported template variables correctly.

type Attachment Uses

type Attachment struct {
    Id         int64  `json:"-"`
    TemplateId int64  `json:"-"`
    Content    string `json:"content"`
    Type       string `json:"type"`
    Name       string `json:"name"`
}

Attachment contains the fields and methods for an email attachment

type BaseRecipient Uses

type BaseRecipient struct {
    Email     string `json:"email"`
    FirstName string `json:"first_name"`
    LastName  string `json:"last_name"`
    Position  string `json:"position"`
}

BaseRecipient contains the fields for a single recipient. This is the base struct used in members of groups and campaign results.

func (*BaseRecipient) FormatAddress Uses

func (r *BaseRecipient) FormatAddress() string

FormatAddress returns the email address to use in the "To" header of the email

type Campaign Uses

type Campaign struct {
    Id            int64     `json:"id"`
    UserId        int64     `json:"-"`
    Name          string    `json:"name" sql:"not null"`
    CreatedDate   time.Time `json:"created_date"`
    LaunchDate    time.Time `json:"launch_date"`
    SendByDate    time.Time `json:"send_by_date"`
    CompletedDate time.Time `json:"completed_date"`
    TemplateId    int64     `json:"-"`
    Template      Template  `json:"template"`
    PageId        int64     `json:"-"`
    Page          Page      `json:"page"`
    Status        string    `json:"status"`
    Results       []Result  `json:"results,omitempty"`
    Groups        []Group   `json:"groups,omitempty"`
    Events        []Event   `json:"timeline,omitempty"`
    SMTPId        int64     `json:"-"`
    SMTP          SMTP      `json:"smtp"`
    URL           string    `json:"url"`
}

Campaign is a struct representing a created campaign

func GetCampaign Uses

func GetCampaign(id int64, uid int64) (Campaign, error)

GetCampaign returns the campaign, if it exists, specified by the given id and user_id.

func GetCampaignMailContext Uses

func GetCampaignMailContext(id int64, uid int64) (Campaign, error)

GetCampaignMailContext returns a campaign object with just the relevant data needed to generate and send emails. This includes the top-level metadata, the template, and the sending profile.

This should only ever be used if you specifically want this lightweight context, since it returns a non-standard campaign object. ref: #1726

func GetCampaigns Uses

func GetCampaigns(uid int64) ([]Campaign, error)

GetCampaigns returns the campaigns owned by the given user.

func GetQueuedCampaigns Uses

func GetQueuedCampaigns(t time.Time) ([]Campaign, error)

GetQueuedCampaigns returns the campaigns that are queued up for this given minute

func (*Campaign) UpdateStatus Uses

func (c *Campaign) UpdateStatus(s string) error

UpdateStatus changes the campaign status appropriately

func (*Campaign) Validate Uses

func (c *Campaign) Validate() error

Validate checks to make sure there are no invalid fields in a submitted campaign

type CampaignResults Uses

type CampaignResults struct {
    Id      int64    `json:"id"`
    Name    string   `json:"name"`
    Status  string   `json:"status"`
    Results []Result `json:"results,omitempty"`
    Events  []Event  `json:"timeline,omitempty"`
}

CampaignResults is a struct representing the results from a campaign

func GetCampaignResults Uses

func GetCampaignResults(id int64, uid int64) (CampaignResults, error)

GetCampaignResults returns just the campaign results for the given campaign

type CampaignStats Uses

type CampaignStats struct {
    Total         int64 `json:"total"`
    EmailsSent    int64 `json:"sent"`
    OpenedEmail   int64 `json:"opened"`
    ClickedLink   int64 `json:"clicked"`
    SubmittedData int64 `json:"submitted_data"`
    EmailReported int64 `json:"email_reported"`
    Error         int64 `json:"error"`
}

CampaignStats is a struct representing the statistics for a single campaign

type CampaignSummaries Uses

type CampaignSummaries struct {
    Total     int64             `json:"total"`
    Campaigns []CampaignSummary `json:"campaigns"`
}

CampaignSummaries is a struct representing the overview of campaigns

func GetCampaignSummaries Uses

func GetCampaignSummaries(uid int64) (CampaignSummaries, error)

GetCampaignSummaries gets the summary objects for all the campaigns owned by the current user

type CampaignSummary Uses

type CampaignSummary struct {
    Id            int64         `json:"id"`
    CreatedDate   time.Time     `json:"created_date"`
    LaunchDate    time.Time     `json:"launch_date"`
    SendByDate    time.Time     `json:"send_by_date"`
    CompletedDate time.Time     `json:"completed_date"`
    Status        string        `json:"status"`
    Name          string        `json:"name"`
    Stats         CampaignStats `json:"stats"`
}

CampaignSummary is a struct representing the overview of a single camaign

func GetCampaignSummary Uses

func GetCampaignSummary(id int64, uid int64) (CampaignSummary, error)

GetCampaignSummary gets the summary object for a campaign specified by the campaign ID

type Dialer Uses

type Dialer struct {
    *gomail.Dialer
}

Dialer is a wrapper around a standard gomail.Dialer in order to implement the mailer.Dialer interface. This allows us to better separate the mailer package as opposed to forcing a connection between mailer and gomail.

func (*Dialer) Dial Uses

func (d *Dialer) Dial() (mailer.Sender, error)

Dial wraps the gomail dialer's Dial command

type EmailRequest Uses

type EmailRequest struct {
    Id          int64        `json:"-"`
    Template    Template     `json:"template"`
    TemplateId  int64        `json:"-"`
    Page        Page         `json:"page"`
    PageId      int64        `json:"-"`
    SMTP        SMTP         `json:"smtp"`
    URL         string       `json:"url"`
    Tracker     string       `json:"tracker" gorm:"-"`
    TrackingURL string       `json:"tracking_url" gorm:"-"`
    UserId      int64        `json:"-"`
    ErrorChan   chan (error) `json:"-" gorm:"-"`
    RId         string       `json:"id"`
    FromAddress string       `json:"-"`
    BaseRecipient
}

EmailRequest is the structure of a request to send a test email to test an SMTP connection. This type implements the mailer.Mail interface.

func GetEmailRequestByResultId Uses

func GetEmailRequestByResultId(id string) (EmailRequest, error)

GetEmailRequestByResultId retrieves the EmailRequest by the underlying rid parameter.

func (*EmailRequest) Backoff Uses

func (s *EmailRequest) Backoff(reason error) error

Backoff treats temporary errors as permanent since this is expected to be a synchronous operation. It returns any errors given back to the ErrorChan

func (*EmailRequest) Error Uses

func (s *EmailRequest) Error(err error) error

Error returns an error on the ErrorChan.

func (*EmailRequest) Generate Uses

func (s *EmailRequest) Generate(msg *gomail.Message) error

Generate fills in the details of a gomail.Message with the contents from the SendTestEmailRequest.

func (*EmailRequest) GetDialer Uses

func (s *EmailRequest) GetDialer() (mailer.Dialer, error)

GetDialer returns the mailer.Dialer for the underlying SMTP object

func (*EmailRequest) Success Uses

func (s *EmailRequest) Success() error

Success returns nil on the ErrorChan to indicate that the email was sent successfully.

func (*EmailRequest) Validate Uses

func (s *EmailRequest) Validate() error

Validate ensures the SendTestEmailRequest structure is valid.

type Event Uses

type Event struct {
    Id         int64     `json:"-"`
    CampaignId int64     `json:"campaign_id"`
    Email      string    `json:"email"`
    Time       time.Time `json:"time"`
    Message    string    `json:"message"`
    Details    string    `json:"details"`
}

Event contains the fields for an event that occurs during the campaign

type EventDetails Uses

type EventDetails struct {
    Payload url.Values        `json:"payload"`
    Browser map[string]string `json:"browser"`
}

EventDetails is a struct that wraps common attributes we want to store in an event

type EventError Uses

type EventError struct {
    Error string `json:"error"`
}

EventError is a struct that wraps an error that occurs when sending an email to a recipient

type Flash Uses

type Flash struct {
    Type    string
    Message string
}

Flash is used to hold flash information for use in templates.

type Group Uses

type Group struct {
    Id           int64     `json:"id"`
    UserId       int64     `json:"-"`
    Name         string    `json:"name"`
    ModifiedDate time.Time `json:"modified_date"`
    Targets      []Target  `json:"targets" sql:"-"`
}

Group contains the fields needed for a user -> group mapping Groups contain 1..* Targets

func GetGroup Uses

func GetGroup(id int64, uid int64) (Group, error)

GetGroup returns the group, if it exists, specified by the given id and user_id.

func GetGroupByName Uses

func GetGroupByName(n string, uid int64) (Group, error)

GetGroupByName returns the group, if it exists, specified by the given name and user_id.

func GetGroups Uses

func GetGroups(uid int64) ([]Group, error)

GetGroups returns the groups owned by the given user.

func (*Group) Validate Uses

func (g *Group) Validate() error

Validate performs validation on a group given by the user

type GroupSummaries Uses

type GroupSummaries struct {
    Total  int64          `json:"total"`
    Groups []GroupSummary `json:"groups"`
}

GroupSummaries is a struct representing the overview of Groups.

func GetGroupSummaries Uses

func GetGroupSummaries(uid int64) (GroupSummaries, error)

GetGroupSummaries returns the summaries for the groups created by the given uid.

type GroupSummary Uses

type GroupSummary struct {
    Id           int64     `json:"id"`
    Name         string    `json:"name"`
    ModifiedDate time.Time `json:"modified_date"`
    NumTargets   int64     `json:"num_targets"`
}

GroupSummary represents a summary of the Group model. The only difference is that, instead of listing the Targets (which could be expensive for large groups), it lists the target count.

func GetGroupSummary Uses

func GetGroupSummary(id int64, uid int64) (GroupSummary, error)

GetGroupSummary returns the summary for the requested group

type GroupTarget Uses

type GroupTarget struct {
    GroupId  int64 `json:"-"`
    TargetId int64 `json:"-"`
}

GroupTarget is used for a many-to-many relationship between 1..* Groups and 1..* Targets

type Header struct {
    Id     int64  `json:"-"`
    SMTPId int64  `json:"-"`
    Key    string `json:"key"`
    Value  string `json:"value"`
}

Header contains the fields and methods for a sending profile to have custom headers

type IMAP Uses

type IMAP struct {
    UserId                      int64     `json:"-" gorm:"column:user_id"`
    Enabled                     bool      `json:"enabled"`
    Host                        string    `json:"host"`
    Port                        uint16    `json:"port,string,omitempty"`
    Username                    string    `json:"username"`
    Password                    string    `json:"password"`
    TLS                         bool      `json:"tls"`
    IgnoreCertErrors            bool      `json:"ignore_cert_errors"`
    Folder                      string    `json:"folder"`
    RestrictDomain              string    `json:"restrict_domain"`
    DeleteReportedCampaignEmail bool      `json:"delete_reported_campaign_email"`
    LastLogin                   time.Time `json:"last_login,omitempty"`
    ModifiedDate                time.Time `json:"modified_date"`
    IMAPFreq                    uint32    `json:"imap_freq,string,omitempty"`
}

IMAP contains the attributes needed to handle logging into an IMAP server to check for reported emails

func GetIMAP Uses

func GetIMAP(uid int64) ([]IMAP, error)

GetIMAP returns the IMAP server owned by the given user.

func (IMAP) TableName Uses

func (im IMAP) TableName() string

TableName specifies the database tablename for Gorm to use

func (*IMAP) Validate Uses

func (im *IMAP) Validate() error

Validate ensures that IMAP configs/connections are valid

type MailLog Uses

type MailLog struct {
    Id          int64     `json:"-"`
    UserId      int64     `json:"-"`
    CampaignId  int64     `json:"campaign_id"`
    RId         string    `json:"id"`
    SendDate    time.Time `json:"send_date"`
    SendAttempt int       `json:"send_attempt"`
    Processing  bool      `json:"-"`
    // contains filtered or unexported fields
}

MailLog is a struct that holds information about an email that is to be sent out.

func GetMailLogsByCampaign Uses

func GetMailLogsByCampaign(cid int64) ([]*MailLog, error)

GetMailLogsByCampaign returns all of the mail logs for a given campaign.

func GetQueuedMailLogs Uses

func GetQueuedMailLogs(t time.Time) ([]*MailLog, error)

GetQueuedMailLogs returns the mail logs that are queued up for the given minute.

func (*MailLog) Backoff Uses

func (m *MailLog) Backoff(reason error) error

Backoff sets the MailLog SendDate to be the next entry in an exponential backoff. ErrMaxRetriesExceeded is thrown if this maillog has been retried too many times. Backoff also unlocks the maillog so that it can be processed again in the future.

func (*MailLog) CacheCampaign Uses

func (m *MailLog) CacheCampaign(campaign *Campaign) error

CacheCampaign allows bulk-mail workers to cache the otherwise expensive campaign lookup operation by providing a pointer to the campaign here.

func (*MailLog) Error Uses

func (m *MailLog) Error(e error) error

Error sets the error status on the models.Result that the maillog refers to. Since MailLog errors are permanent, this action also deletes the maillog.

func (*MailLog) Generate Uses

func (m *MailLog) Generate(msg *gomail.Message) error

Generate fills in the details of a gomail.Message instance with the correct headers and body from the campaign and recipient listed in the maillog. We accept the gomail.Message as an argument so that the caller can choose to re-use the message across recipients.

func (*MailLog) GetDialer Uses

func (m *MailLog) GetDialer() (mailer.Dialer, error)

GetDialer returns a dialer based on the maillog campaign's SMTP configuration

func (*MailLog) Lock Uses

func (m *MailLog) Lock() error

Lock sets the processing flag so that other processes cannot modify the maillog

func (*MailLog) Success Uses

func (m *MailLog) Success() error

Success deletes the maillog from the database and updates the underlying campaign result.

func (*MailLog) Unlock Uses

func (m *MailLog) Unlock() error

Unlock removes the processing flag so the maillog can be processed again

type Page Uses

type Page struct {
    Id                 int64     `json:"id" gorm:"column:id; primary_key:yes"`
    UserId             int64     `json:"-" gorm:"column:user_id"`
    Name               string    `json:"name"`
    HTML               string    `json:"html" gorm:"column:html"`
    CaptureCredentials bool      `json:"capture_credentials" gorm:"column:capture_credentials"`
    CapturePasswords   bool      `json:"capture_passwords" gorm:"column:capture_passwords"`
    RedirectURL        string    `json:"redirect_url" gorm:"column:redirect_url"`
    ModifiedDate       time.Time `json:"modified_date"`
}

Page contains the fields used for a Page model

func GetPage Uses

func GetPage(id int64, uid int64) (Page, error)

GetPage returns the page, if it exists, specified by the given id and user_id.

func GetPageByName Uses

func GetPageByName(n string, uid int64) (Page, error)

GetPageByName returns the page, if it exists, specified by the given name and user_id.

func GetPages Uses

func GetPages(uid int64) ([]Page, error)

GetPages returns the pages owned by the given user.

func (*Page) Validate Uses

func (p *Page) Validate() error

Validate ensures that a page contains the appropriate details

type Permission Uses

type Permission struct {
    ID          int64  `json:"id"`
    Slug        string `json:"slug"`
    Name        string `json:"name"`
    Description string `json:"description"`
}

Permission determines what a particular role can do. Each role may have one or more permissions.

type PhishingTemplateContext Uses

type PhishingTemplateContext struct {
    From        string
    URL         string
    Tracker     string
    TrackingURL string
    RId         string
    BaseURL     string
    BaseRecipient
}

PhishingTemplateContext is the context that is sent to any template, such as the email or landing page content.

func NewPhishingTemplateContext Uses

func NewPhishingTemplateContext(ctx TemplateContext, r BaseRecipient, rid string) (PhishingTemplateContext, error)

NewPhishingTemplateContext returns a populated PhishingTemplateContext, parsing the correct fields from the provided TemplateContext and recipient.

type Response Uses

type Response struct {
    Message string      `json:"message"`
    Success bool        `json:"success"`
    Data    interface{} `json:"data"`
}

Response contains the attributes found in an API response

type Result Uses

type Result struct {
    Id           int64     `json:"-"`
    CampaignId   int64     `json:"-"`
    UserId       int64     `json:"-"`
    RId          string    `json:"id"`
    Status       string    `json:"status" sql:"not null"`
    IP           string    `json:"ip"`
    Latitude     float64   `json:"latitude"`
    Longitude    float64   `json:"longitude"`
    SendDate     time.Time `json:"send_date"`
    Reported     bool      `json:"reported" sql:"not null"`
    ModifiedDate time.Time `json:"modified_date"`
    BaseRecipient
}

Result contains the fields for a result object, which is a representation of a target in a campaign.

func GetResult Uses

func GetResult(rid string) (Result, error)

GetResult returns the Result object from the database given the ResultId

func (*Result) GenerateId Uses

func (r *Result) GenerateId(tx *gorm.DB) error

GenerateId generates a unique key to represent the result in the database

func (r *Result) HandleClickedLink(details EventDetails) error

HandleClickedLink updates a Result in the case where the recipient clicked the link in an email.

func (*Result) HandleEmailBackoff Uses

func (r *Result) HandleEmailBackoff(err error, sendDate time.Time) error

HandleEmailBackoff updates a Result to indicate that the email received a temporary error and needs to be retried

func (*Result) HandleEmailError Uses

func (r *Result) HandleEmailError(err error) error

HandleEmailError updates a Result to indicate that there was an error when attempting to send the email to the remote SMTP server.

func (*Result) HandleEmailOpened Uses

func (r *Result) HandleEmailOpened(details EventDetails) error

HandleEmailOpened updates a Result in the case where the recipient opened the email.

func (*Result) HandleEmailReport Uses

func (r *Result) HandleEmailReport(details EventDetails) error

HandleEmailReport updates a Result in the case where they report a simulated phishing email using the HTTP handler.

func (*Result) HandleEmailSent Uses

func (r *Result) HandleEmailSent() error

HandleEmailSent updates a Result to indicate that the email has been successfully sent to the remote SMTP server

func (*Result) HandleFormSubmit Uses

func (r *Result) HandleFormSubmit(details EventDetails) error

HandleFormSubmit updates a Result in the case where the recipient submitted credentials to the form on a Landing Page.

func (*Result) UpdateGeo Uses

func (r *Result) UpdateGeo(addr string) error

UpdateGeo updates the latitude and longitude of the result in the database given an IP address

type Role Uses

type Role struct {
    ID          int64        `json:"-"`
    Slug        string       `json:"slug"`
    Name        string       `json:"name"`
    Description string       `json:"description"`
    Permissions []Permission `json:"-" gorm:"many2many:role_permissions;"`
}

Role represents a user role within Gophish. Each user has a single role which maps to a set of permissions.

func GetRoleBySlug Uses

func GetRoleBySlug(slug string) (Role, error)

GetRoleBySlug returns a role that can be assigned to a user.

type SMTP Uses

type SMTP struct {
    Id               int64     `json:"id" gorm:"column:id; primary_key:yes"`
    UserId           int64     `json:"-" gorm:"column:user_id"`
    Interface        string    `json:"interface_type" gorm:"column:interface_type"`
    Name             string    `json:"name"`
    Host             string    `json:"host"`
    Username         string    `json:"username,omitempty"`
    Password         string    `json:"password,omitempty"`
    FromAddress      string    `json:"from_address"`
    IgnoreCertErrors bool      `json:"ignore_cert_errors"`
    Headers          []Header  `json:"headers"`
    ModifiedDate     time.Time `json:"modified_date"`
}

SMTP contains the attributes needed to handle the sending of campaign emails

func GetSMTP Uses

func GetSMTP(id int64, uid int64) (SMTP, error)

GetSMTP returns the SMTP, if it exists, specified by the given id and user_id.

func GetSMTPByName Uses

func GetSMTPByName(n string, uid int64) (SMTP, error)

GetSMTPByName returns the SMTP, if it exists, specified by the given name and user_id.

func GetSMTPs Uses

func GetSMTPs(uid int64) ([]SMTP, error)

GetSMTPs returns the SMTPs owned by the given user.

func (*SMTP) GetDialer Uses

func (s *SMTP) GetDialer() (mailer.Dialer, error)

GetDialer returns a dialer for the given SMTP profile

func (SMTP) TableName Uses

func (s SMTP) TableName() string

TableName specifies the database tablename for Gorm to use

func (*SMTP) Validate Uses

func (s *SMTP) Validate() error

Validate ensures that SMTP configs/connections are valid

type Target Uses

type Target struct {
    Id  int64 `json:"-"`
    BaseRecipient
}

Target contains the fields needed for individual targets specified by the user Groups contain 1..* Targets, but 1 Target may belong to 1..* Groups

func GetTargets Uses

func GetTargets(gid int64) ([]Target, error)

GetTargets performs a many-to-many select to get all the Targets for a Group

func (*Target) FormatAddress Uses

func (t *Target) FormatAddress() string

FormatAddress returns the email address to use in the "To" header of the email

type Template Uses

type Template struct {
    Id           int64        `json:"id" gorm:"column:id; primary_key:yes"`
    UserId       int64        `json:"-" gorm:"column:user_id"`
    Name         string       `json:"name"`
    Subject      string       `json:"subject"`
    Text         string       `json:"text"`
    HTML         string       `json:"html" gorm:"column:html"`
    ModifiedDate time.Time    `json:"modified_date"`
    Attachments  []Attachment `json:"attachments"`
}

Template models hold the attributes for an email template to be sent to targets

func GetTemplate Uses

func GetTemplate(id int64, uid int64) (Template, error)

GetTemplate returns the template, if it exists, specified by the given id and user_id.

func GetTemplateByName Uses

func GetTemplateByName(n string, uid int64) (Template, error)

GetTemplateByName returns the template, if it exists, specified by the given name and user_id.

func GetTemplates Uses

func GetTemplates(uid int64) ([]Template, error)

GetTemplates returns the templates owned by the given user.

func (*Template) Validate Uses

func (t *Template) Validate() error

Validate checks the given template to make sure values are appropriate and complete

type TemplateContext Uses

type TemplateContext interface {
    // contains filtered or unexported methods
}

TemplateContext is an interface that allows both campaigns and email requests to have a PhishingTemplateContext generated for them.

type User Uses

type User struct {
    Id                     int64     `json:"id"`
    Username               string    `json:"username" sql:"not null;unique"`
    Hash                   string    `json:"-"`
    ApiKey                 string    `json:"api_key" sql:"not null;unique"`
    Role                   Role      `json:"role" gorm:"association_autoupdate:false;association_autocreate:false"`
    RoleID                 int64     `json:"-"`
    PasswordChangeRequired bool      `json:"password_change_required"`
    AccountLocked          bool      `json:"account_locked"`
    LastLogin              time.Time `json:"last_login"`
}

User represents the user model for gophish.

func GetUser Uses

func GetUser(id int64) (User, error)

GetUser returns the user that the given id corresponds to. If no user is found, an error is thrown.

func GetUserByAPIKey Uses

func GetUserByAPIKey(key string) (User, error)

GetUserByAPIKey returns the user that the given API Key corresponds to. If no user is found, an error is thrown.

func GetUserByUsername Uses

func GetUserByUsername(username string) (User, error)

GetUserByUsername returns the user that the given username corresponds to. If no user is found, an error is thrown.

func GetUsers Uses

func GetUsers() ([]User, error)

GetUsers returns the users registered in Gophish

func (*User) HasPermission Uses

func (u *User) HasPermission(slug string) (bool, error)

HasPermission checks to see if the user has a role with the requested permission.

type ValidationContext Uses

type ValidationContext struct {
    FromAddress string
    BaseURL     string
}

ValidationContext is used for validating templates and pages

type Webhook Uses

type Webhook struct {
    Id       int64  `json:"id" gorm:"column:id; primary_key:yes"`
    Name     string `json:"name"`
    URL      string `json:"url"`
    Secret   string `json:"secret"`
    IsActive bool   `json:"is_active"`
}

Webhook represents the webhook model

func GetActiveWebhooks Uses

func GetActiveWebhooks() ([]Webhook, error)

GetActiveWebhooks returns the active webhooks

func GetWebhook Uses

func GetWebhook(id int64) (Webhook, error)

GetWebhook returns the webhook that the given id corresponds to. If no webhook is found, an error is returned.

func GetWebhooks Uses

func GetWebhooks() ([]Webhook, error)

GetWebhooks returns the webhooks

func (*Webhook) Validate Uses

func (wh *Webhook) Validate() error

Package models imports 35 packages (graph) and is imported by 97 packages. Updated 2020-12-09. Refresh now. Tools for package owners.