models

package
v0.0.0-...-386a0b5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2022 License: MIT Imports: 38 Imported by: 0

Documentation

Overview

Package models implements the types and structs needed in gophish.

Index

Constants

View Source
const (
	CAMPAIGN_IN_PROGRESS string = "In progress"
	CAMPAIGN_QUEUED      string = "Queued"
	CAMPAIGN_CREATED     string = "Created"
	CAMPAIGN_EMAILS_SENT string = "Emails Sent"
	CAMPAIGN_COMPLETE    string = "Completed"
	EVENT_SENT           string = "Email Sent"
	EVENT_SENDING_ERROR  string = "Error Sending Email"
	EVENT_OPENED         string = "Email Opened"
	EVENT_CLICKED        string = "Clicked Link"
	EVENT_DATA_SUBMIT    string = "Submitted Data"
	EVENT_REPORTED       string = "Email Reported"
	EVENT_PROXY_REQUEST  string = "Proxied request"
	STATUS_SUCCESS       string = "Success"
	STATUS_QUEUED        string = "Queued"
	STATUS_SENDING       string = "Sending"
	STATUS_UNKNOWN       string = "Unknown"
	STATUS_SCHEDULED     string = "Scheduled"
	STATUS_RETRY         string = "Retrying"
	STATUS_CANCELLED     string = "Cancelled"
	ERROR                string = "Error"
)
View Source
const (
	Administrator = 1
	Partner       = 2
	Customer      = 3
	ChildUser     = 4
	LMSUser       = 5
)

Roles

View Source
const PreviewPrefix = "preview-"

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

View Source
const RecipientParameter = "rid"

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

Variables

View Source
var ErrCampaignFromAddressNotValid = errors.New("The sender's address is not valid")

ErrCampaignFromAddressNotValid is thrown when the "from" address is not valid

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

ErrCampaignNameNotSpecified indicates there was no template given by the user

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

ErrEmailNotSpecified is thrown when no email is specified for the Target

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

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

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

ErrGroupNameNotSpecified is thrown when a group name is not specified

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

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

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

ErrGroupNotSpecified indicates there was no template given by the user

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

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

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

ErrInvalidHost indicates that the SMTP server string is invalid

View Source
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

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

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

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

ErrNoTargetsSpecified is thrown when no targets are specified by the user

View Source
var ErrPageCategoryNotSpecified = errors.New("Page category not specified")

ErrPageCategoryNotSpecified is thrown if the category of the landing page is blank.

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

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

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

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

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

ErrPageNotSpecified indicates a landing page was not provided for the campaign

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

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

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

ErrSMTPNotSpecified indicates a sending profile was not provided for the campaign

View Source
var ErrTemplateCategoryNotSpecified = errors.New("Template category not specified")

ErrTemplateCategoryNotSpecified is thrown if the category of the template is blank.

View Source
var ErrTemplateFromAddressNotSpecified = errors.New("The sender's address is not specified")

ErrTemplateFromAddressNotSpecified is thrown when the "from" address is not specified

View Source
var ErrTemplateFromAddressNotValid = errors.New("The sender's address is not valid")

ErrTemplateFromAddressNotValid is thrown when the "from" address is not valid

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

ErrTemplateMissingParameter is thrown when a needed parameter is not provided

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

ErrTemplateNameNotSpecified is thrown when a template name is not specified

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

ErrTemplateNotFound indicates the template specified does not exist in the database

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

ErrTemplateNotSpecified indicates there was no template given by the user

View Source
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.

Functions

func CompleteCampaign

func CompleteCampaign(id int64) error

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

func DecryptApiKeys

func DecryptApiKeys()

DecryptApiKeys decrypts api_key column in users table

func DecryptEventEmails

func DecryptEventEmails()

DecryptEventEmails decrypts email column in events table

func DecryptRequestEmails

func DecryptRequestEmails()

DecryptRequestEmails decrypts email column in email_requests table

func DecryptResultEmails

func DecryptResultEmails()

DecryptResultEmails decrypts email column in results table

func DecryptTargetEmails

func DecryptTargetEmails()

DecryptTargetEmails decrypts email column in targets table

func DecryptUserEmails

func DecryptUserEmails()

DecryptUserEmails decrypts email and admin_email columns in users table

func DeleteAvatar

func DeleteAvatar(a *Avatar) error

DeleteAvatar deletes given avatar

func DeleteCampaign

func DeleteCampaign(id int64) error

DeleteCampaign deletes the specified campaign

func DeleteChildUsers

func DeleteChildUsers(uid int64) error

DeleteChildUsers deletes all child users of a user with the given uid

func DeleteCustomers

func DeleteCustomers(uid int64) error

DeleteCustomers deletes all customers of a user with the given uid

func DeleteGroup

func DeleteGroup(g *Group) error

DeleteGroup deletes a given group by group ID and user ID

func DeleteGroupTarget

func DeleteGroupTarget(id int64) error

DeleteGroupTarget deletes a group target identified by the given id if such target belongs to not more than one group, otherwise returns an error.

func DeleteLogo(id int64) error

DeleteLogo deletes logo specified by the given id

func DeletePage

func DeletePage(id int64) error

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

func DeleteSMTP

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 DeleteSubscription

func DeleteSubscription(s *Subscription) error

DeleteSubscription deletes given subscription

func DeleteTags

func DeleteTags(id int64) error

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

func DeleteTemplate

func DeleteTemplate(id int64) error

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

func DeleteUser

func DeleteUser(uid int64) (int64, error)

DeleteUser deletes the specified user and in case of success returns a bakery user id associated with the given uid or 0 if there's no such id.

func DeleteUserAvatar

func DeleteUserAvatar(uid int64) error

DeleteUserAvatar deletes avatar of a given uid

func DeleteUserBakeryID

func DeleteUserBakeryID(uid int64) error

DeleteUserBakeryID deletes bakery master user id for the given uid

func DeleteUserCampaigns

func DeleteUserCampaigns(uid int64) error

DeleteUserCampaigns deletes campaigns created by user with the given uid

func DeleteUserEmailRequests

func DeleteUserEmailRequests(uid int64) error

DeleteUserEmailRequests deletes email requests created by user with the given uid

func DeleteUserGroups

func DeleteUserGroups(uid int64) error

DeleteUserGroups deletes groups created by user with the given uid

func DeleteUserLogo(uid int64) error

DeleteUserLogo deletes logo created by user with the given uid

func DeleteUserPages

func DeleteUserPages(uid int64) error

DeleteUserPages deletes pages created by user with the given uid

func DeleteUserRoles

func DeleteUserRoles(uid int64) error

DeleteUserRoles deletes all roles of a given uid

func DeleteUserSubscriptions

func DeleteUserSubscriptions(uid int64) error

DeleteUserSubscriptions deletes all subscriptions of a given uid

func DeleteUserTemplates

func DeleteUserTemplates(uid int64) error

DeleteUserTemplates deletes templates created by user with the given uid

func EncryptApiKeys

func EncryptApiKeys()

func EncryptEventEmails

func EncryptEventEmails()

EncryptEventEmails encrypts email column in events table

func EncryptRequestEmails

func EncryptRequestEmails()

EncryptRequestEmails encrypts email column in email_requests table

func EncryptResultEmails

func EncryptResultEmails()

EncryptResultEmails encrypts email column in results table

func EncryptTargetEmails

func EncryptTargetEmails()

EncryptTargetEmails encrypts email column in targets table

func EncryptUserEmails

func EncryptUserEmails()

EncryptUserEmails encrypts email and admin_email columns in users table

func ExecuteTemplate

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

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

func GenerateMailLog

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 GetCampaignOwnerId

func GetCampaignOwnerId(id int64) (int64, error)

GetCampaignOwnerId returns user id of creator of the campaign identified by id

func GetChildUserIds

func GetChildUserIds(uid int64) ([]int64, error)

GetChildUserIds returns user ids of all child users bound to the given uid

func GetCustomerIds

func GetCustomerIds(uid int64) ([]int64, error)

GetCustomerIds returns user ids of customers directly or indirectly related to the given uid

func GetDirectCustomerIds

func GetDirectCustomerIds(uid int64) ([]int64, error)

GetDirectCustomerIds returns user ids of all customers directly bound to the given uid

func GetGroupOwnerId

func GetGroupOwnerId(id int64) (int64, error)

GetGroupOwnerId returns user id of creator of the group identified by id

func GetPageOwnerId

func GetPageOwnerId(id int64) (int64, error)

GetPageOwnerId returns user id of creator of the page identified by id

func GetPlanNameById

func GetPlanNameById(id int64) string

GetPlanNameById returns plan name for the given plan id or an empty string if no plan found

func GetTargetsFullName

func GetTargetsFullName(email string, oid int64) string

GetTargetsFullName finds and returns full name of a target user with the given email which is in a user group owned by the given user (oid). If no matching target user found then an empty string will be returned.

func GetTemplateOwnerId

func GetTemplateOwnerId(id int64) (int64, error)

GetTemplateOwnerId returns user id of creator of the template identified by id

func GetUserBakeryID

func GetUserBakeryID(uid int64) int64

GetUserBakeryID returns bakery user id associated with the given uid or 0 if not found

func GetUserIds

func GetUserIds(uid int64) ([]int64, error)

GetUserIds returns the user ids owned by the given user.

func IsCampaignAccessibleByUser

func IsCampaignAccessibleByUser(cid, uid int64) bool

IsCampaignAccessibleByUser tells if a campaign (identified by cid) is accessible by a user (identified by uid)

func IsCampaignLockedForUser

func IsCampaignLockedForUser(cid, uid int64) bool

IsCampaignLockedForUser tells if a campaign with the given cid is locked for user identified by uid

func IsGroupAccessibleByUser

func IsGroupAccessibleByUser(gid, uid int64) bool

IsGroupAccessibleByUser tells if a group (identified by gid) is accessible by a user (identified by uid)

func IsGroupLockedForUser

func IsGroupLockedForUser(gid, uid int64) bool

IsGroupLockedForUser tells if a group with the given gid is locked for user identified by uid

func IsPageAccessibleByUser

func IsPageAccessibleByUser(pid, uid int64) bool

IsPageAccessibleByUser tells if a page (identified by pid) is accessible by a user (identified by uid)

func IsPageWritableByUser

func IsPageWritableByUser(pid, uid int64) bool

IsPageWritableByUser tell if a page (identified by pid) can be modified by a user (identified by uid)

func IsTemplateAccessibleByUser

func IsTemplateAccessibleByUser(tid, uid int64) bool

IsTemplateAccessibleByUser tells if a template (identified by tid) is accessible by a user (identified by uid)

func IsTemplateWritableByUser

func IsTemplateWritableByUser(tid, uid int64) bool

IsTemplateWritableByUser tell if a template (identified by tid) can be modified by a user (identified by uid)

func IsUniqueDomain

func IsUniqueDomain(domain string) bool

IsUniqueDomain tells if the given domain is unique among all other domains stored in the db

func LockMailLogs

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

LockMailLogs locks or unlocks a slice of maillogs for processing.

func PostCampaign

func PostCampaign(c *Campaign, uid int64) (err error)

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

func PostEmailRequest

func PostEmailRequest(s *EmailRequest) error

PostEmailRequest stores a SendTestEmailRequest in the database.

func PostGroup

func PostGroup(g *Group) error

PostGroup creates a new group in the database.

func PostPage

func PostPage(p *Page) error

PostPage creates a new page in the database.

func PostPlan

func PostPlan(p *Plan) error

PostPlan creates a new plan

func PostSMTP

func PostSMTP(s *SMTP) error

PostSMTP creates a new SMTP in the database.

func PostSubscription

func PostSubscription(s *Subscription) error

PostSubscription creates a new subscription

func PostTags

func PostTags(t *Tags) error

PostTemplate creates a new template in the database.

func PostTemplate

func PostTemplate(t *Template) error

PostTemplate creates a new template in the database.

func ProcessCampaignTargets

func ProcessCampaignTargets(id int64) error

ProcessCampaignTargets moves or copies clickers and non-clickers into different groups according to settings of a campaign with the given id

func PutAvatar

func PutAvatar(l *Avatar) error

PutAvatar craetes or updates the given avatar

func PutGroup

func PutGroup(g *Group) error

PutGroup updates the given group if found in the database.

func PutLogo(l *Logo) error

PutLogo craetes or updates the given logo

func PutPage

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 PutRole

func PutRole(r *Role) error

PutRole updates role

func PutSMTP

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 PutTags

func PutTags(t *Tags) error

PutTags edits an existing tag in the database. Per the PUT Method RFC, it presumes all data for tag is provided.

func PutTemplate

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

func PutUser(u *User) error

PutUser updates the given user

func PutUserRole

func PutUserRole(ur *UserRole) error

PutUserRole updates role of the given user

func SetUserRole

func SetUserRole(uid, rid int64) error

SetUserRole sets role of the given uid to the given rid

func Setup

func Setup() error

Setup initializes the Conn object It also populates the Gophish Config object

func UnlockAllMailLogs

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

func UpdateTarget(target Target) error

UpdateTarget updates the given target information in the database.

func UpdateUser

func UpdateUser(u *User) error

UpdateUser update the given user (only non-empty fields will be updated)

func UserExists

func UserExists(username string) bool

UserExists tells if a user with the given username exists

func ValidateTemplate

func ValidateTemplate(text string) error

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

func WarmUpCache

func WarmUpCache()

WarmUpCache pre-caches frequently used models and associations

Types

type Attachment

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 Avatar

type Avatar struct {
	Id     int64 `gorm:"column:id; primary_key:yes"`
	UserId int64
	Data   string
}

Avatar is a custom avatar image

func GetAvatar

func GetAvatar(id int64) (*Avatar, error)

GetAvatar returns avatar by id

func (*Avatar) BeforeSave

func (a *Avatar) BeforeSave() (err error)

func (*Avatar) Serve

func (a *Avatar) Serve(w http.ResponseWriter)

Serve writes proper headers and content of this avatar image to the given ResponseWriter

type BakeryUser

type BakeryUser struct {
	UID       int64
	MasterUID int64
}

BakeryUser stores relations between local user ids and bakery master user ids

func (BakeryUser) TableName

func (bu BakeryUser) TableName() string

type BaseRecipient

type BaseRecipient struct {
	Email     encryption.EncryptedString `json:"email"`
	FirstName string                     `json:"first_name"`
	LastName  string                     `json:"last_name"`
	Position  string                     `json:"position"`
	IsLMSUser bool                       `json:"is_lms_user" gorm:"-"`
}

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

func (*BaseRecipient) FormatAddress

func (r *BaseRecipient) FormatAddress() string

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

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache wrapper around go-cache

func GetCache

func GetCache() *Cache

GetCache returns singleton instance of the model cache

func (*Cache) AddEntry

func (cache *Cache) AddEntry(prefix string, id int64, suffix string, val interface{})

AddEntry adds given value to the cache with the key built from prefix, id and suffix

func (*Cache) AddRoleDisplayName

func (cache *Cache) AddRoleDisplayName(rid int64, name string)

AddRoleDisplayName adds a given role display name to the cache

func (*Cache) AddUser

func (cache *Cache) AddUser(u *User)

AddUser adds a given user to the cache

func (*Cache) AddUserAvatar

func (cache *Cache) AddUserAvatar(a *Avatar)

AddUserAvatar adds a given avatar to the cache

func (*Cache) AddUserRole

func (cache *Cache) AddUserRole(r *UserRole)

AddUserRole adds a given user role to the cache

func (*Cache) AddUserSubscription

func (cache *Cache) AddUserSubscription(s *Subscription)

AddUserSubscription adds a given subscription to the cache

func (*Cache) DeleteEntry

func (cache *Cache) DeleteEntry(prefix string, id int64, suffix string)

DeleteEntry deletes an entry from the cache using the key built from prefix, id and suffix

func (*Cache) DeleteUser

func (cache *Cache) DeleteUser(u *User)

DeleteUser removes a given user from the cache

func (*Cache) DeleteUserAvatar

func (cache *Cache) DeleteUserAvatar(a *Avatar)

DeleteUserAvatar removes a given avatar from the cache

func (*Cache) DeleteUserRole

func (cache *Cache) DeleteUserRole(r *UserRole)

DeleteUserRole removes a given role from the cache

func (*Cache) DeleteUserSubscription

func (cache *Cache) DeleteUserSubscription(s *Subscription)

DeleteUserSubscription removes a given subscription from the cache

func (*Cache) GetRoleDisplayName

func (cache *Cache) GetRoleDisplayName(rid int64) (string, bool)

GetRoleDisplayName finds and returns cached display name of a role with the given rid

func (*Cache) GetUserAvatar

func (cache *Cache) GetUserAvatar(uid int64) (*Avatar, bool)

GetUserAvatar finds and returns cached avatar by its user id

func (*Cache) GetUserById

func (cache *Cache) GetUserById(uid int64) (*User, bool)

GetUserById finds and returns cached user with a given id

func (*Cache) GetUserRole

func (cache *Cache) GetUserRole(uid int64) (*UserRole, bool)

GetUserRole finds and returns cached role by its user id

func (*Cache) GetUserSubscription

func (cache *Cache) GetUserSubscription(uid int64) (*Subscription, bool)

GetUserSubscription finds and returns cached subscription by its user id

type Campaign

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"`
	StartTime         string    `json:"start_time"`
	EndTime           string    `json:"end_time"`
	TimeZone          string    `json:"time_zone"`
	CompletedDate     time.Time `json:"completed_date"`
	TemplateId        int64     `json:"-"`
	Template          Template  `json:"template"`
	FromAddress       string    `json:"from_address"`
	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,omitemtpy"`
	SMTPId            int64     `json:"-"`
	SMTP              SMTP      `json:"smtp"`
	URL               string    `json:"url"`
	GroupId           int64     `json:"group_id"`
	RemoveNonClickers bool      `json:"remove_non_clickers"`
	ClickersGroupId   int64     `json:"clickers_group_id"`
	ClickersGroup     string    `json:"clickers_group,omitemtpy" gorm:"-"`
	CreatorId         int64     `json:"creator,omitemtpy" gorm:"-"`
}

Campaign is a struct representing a created campaign

func GetCampaign

func GetCampaign(id int64) (Campaign, error)

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

func GetCampaigns

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

GetCampaigns returns the campaigns owned by the given user.

func GetQueuedCampaigns

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

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

func (*Campaign) AddEvent

func (c *Campaign) AddEvent(e *Event) error

AddEvent creates a new campaign event in the database

func (*Campaign) GetClickers

func (c *Campaign) GetClickers() ([]Target, error)

GetClickers returns target users who clicked at least one phishing link during this campaign

func (*Campaign) GetNonClickers

func (c *Campaign) GetNonClickers() ([]Target, error)

GetNonClickers returns target users who never clicked a phishing link during this campaign

func (*Campaign) UpdateStatus

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

UpdateStatus changes the campaign status appropriately

func (*Campaign) Validate

func (c *Campaign) Validate() error

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

type CampaignResults

type CampaignResults struct {
	Id           int64     `json:"id"`
	Name         string    `json:"name"`
	LaunchDate   time.Time `json:"launch_date"`
	TemplateID   int64     `json:"template_id"`
	TemplateName string    `json:"template_name"`
	PageID       int64     `json:"page_id"`
	PageName     string    `json:"page_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

func GetCampaignResults(id int64) (CampaignResults, error)

GetCampaignResults returns just the campaign results for the given campaign

type CampaignStats

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

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

CampaignSummaries is a struct representing the overview of campaigns

func GetCampaignSummaries

func GetCampaignSummaries(uid int64, filter string) (CampaignSummaries, error)

GetCampaignSummaries gets the summary objects for all the campaigns owned by the current user and optionally (depending on the user role) campaigns of all other users (for admins) or the respective child users (for partners). Optionally "filter" can be one of: own, customers. Where: own - return items that belong to this user, customers - customers' items Note: empty "filter" will be treated as "own"

type CampaignSummary

type CampaignSummary struct {
	Id            int64         `json:"id"`
	UserId        int64         `json:"user_id"`
	Username      string        `json:"username"`
	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"`
	Locked        bool          `json:"locked"`
}

CampaignSummary is a struct representing the overview of a single camaign

func GetCampaignSummary

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

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

type Dialer

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

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

Dial wraps the gomail dialer's Dial command

type EmailRequest

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:"from_address"`
	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

func GetEmailRequestByResultId(id string) (EmailRequest, error)

GetEmailRequestByResultId retrieves the EmailRequest by the underlying rid parameter.

func (*EmailRequest) Backoff

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

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

Error returns an error on the ErrorChan.

func (*EmailRequest) Generate

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

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

GetDialer returns the mailer.Dialer for the underlying SMTP object

func (*EmailRequest) Success

func (s *EmailRequest) Success(details interface{}) error

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

func (*EmailRequest) Validate

func (s *EmailRequest) Validate() error

Validate ensures the SendTestEmailRequest structure is valid.

type Event

type Event struct {
	Id         int64                      `json:"-"`
	CampaignId int64                      `json:"-"`
	Email      encryption.EncryptedString `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

func (*Event) AfterCreate

func (e *Event) AfterCreate(tx *gorm.DB) error

AfterCreate creates a new user with "lms_user" role whenever EVENT_CLICKED event occurs, additionally links newly created LMS users to relevant LMS campaigns.

type EventDetails

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

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

type Flash struct {
	Type    string
	Message string
}

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

type Group

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:"-"`
	CreatorId    int64     `json:"creator,omitemtpy" gorm:"-"`
}

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

func CreateEmptyGroup

func CreateEmptyGroup(name string, uid int64) (Group, error)

CreateEmptyGroup creates a new empty group with the given name owned by uid.

func GetGroup

func GetGroup(id int64) (Group, error)

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

func GetGroupByName

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

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

GetGroups returns the groups owned by the given user.

func (*Group) AddTargets

func (g *Group) AddTargets(targets []Target) (err error)

AddTargets adds the given targets to this group

func (*Group) ContainsTargetsOutsideOfDomain

func (g *Group) ContainsTargetsOutsideOfDomain(domain string) bool

ContainsTargetsOutsideOfDomain tells if this group's targets contain one or more email addresses outside of the given domain. If domain is blank then it always returns false.

func (*Group) HasTargets

func (g *Group) HasTargets(tids []int64) bool

HasTargets tells if this group contains all given target ids. If at least one target id doesn't belong to this group then false will be returned.

func (*Group) RemoveTargets

func (g *Group) RemoveTargets(targets []Target) (err error)

RemoveTargets removes the given targets from this group. After removal, targets that won't belong to at least one another group will be deleted.

func (*Group) Validate

func (g *Group) Validate() error

Validate performs validation on a group given by the user

type GroupSummaries

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

GroupSummaries is a struct representing the overview of Groups.

func GetGroupSummaries

func GetGroupSummaries(uid int64, filter string) (GroupSummaries, error)

GetGroupSummaries returns the summaries for the groups created and/or accessible (in case of admin and partner) by the given uid. Optionally "filter" can be one of: own, customers. Where: own - return items that belong to this user, customers - customers' items uid-xxx - items of user with uid xxx Note: empty "filter" will be treated as "own"

type GroupSummary

type GroupSummary struct {
	Id           int64     `json:"id"`
	UserId       int64     `json:"user_id"`
	Username     string    `json:"username"`
	Name         string    `json:"name"`
	ModifiedDate time.Time `json:"modified_date"`
	NumTargets   int64     `json:"num_targets"`
	Locked       bool      `json:"locked"`
}

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

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

GetGroupSummary returns the summary for the requested group

type GroupTarget

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 LMSCampaign

type LMSCampaign struct {
	Id                int64     `json:"id"`
	Title             string    `json:"title"`
	AuthorId          int64     `json:"author_id"`
	PubliclyAvailable bool      `json:"publicly_available"`
	QAPassPercentage  int64     `json:"qa_pass_percentage"`
	PhishingCampaign  int64     `json:"phishing_campaign"`
	EnableQA          bool      `json:"enable_qa"`
	CreatedAt         time.Time `json:"created_at"`
	UpdatedAt         time.Time `json:"updated_at"`
}

LMSCampaign struct represents an LMS campaign

func GetLinkedLMSCampaigns

func GetLinkedLMSCampaigns(cid int64) ([]LMSCampaign, error)

GetLinkedLMSCampaigns finds and returns LMS campaigns linked to a given campaign id

func (*LMSCampaign) AddUser

func (c *LMSCampaign) AddUser(uid int64) error

AddUser creates a record in lms_campaign_users table linking the given user id to this LMS campaign

func (*LMSCampaign) HasUser

func (c *LMSCampaign) HasUser(uid int64) bool

HasUser tells if this LMS campaign has user with the given id linked to it

type LMSCampaignUser

type LMSCampaignUser struct {
	Id         int64     `json:"id"`
	UserId     int64     `json:"user_id"`
	CampaignId int64     `json:"campaign_id"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
}

LMSCampaignUser stuct represents a relation between a gophish "lms_user" and an LMS campaign

type Logo struct {
	Id     int64 `gorm:"column:id; primary_key:yes"`
	UserId int64
	Data   string
}

Logo is a custom logo image

func (*Logo) Serve

func (l *Logo) Serve(w http.ResponseWriter)

Serve writes proper headers and content of this logo image to the given ResponseWriter

type MailLog

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:"-"`
}

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

func GetMailLogsByCampaign

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

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

func (*MailLog) Backoff

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) Error

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

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

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

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

func (*MailLog) IsTimeToSend

func (m *MailLog) IsTimeToSend(t time.Time) bool

IsTimeToSend tells if this e-mail should be sent right now, current UTC time (t) and campaign business hours (if any) are taken into account

func (*MailLog) Lock

func (m *MailLog) Lock() error

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

func (*MailLog) Success

func (m *MailLog) Success(details interface{}) error

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

func (*MailLog) Unlock

func (m *MailLog) Unlock() error

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

type MailLogs

type MailLogs []*MailLog

MailLogs is a list of MailLog's

func GetQueuedMailLogs

func GetQueuedMailLogs(t time.Time) (MailLogs, error)

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

func (MailLogs) WithinBusinessHours

func (mls MailLogs) WithinBusinessHours(t time.Time) MailLogs

WithinBusinessHours returns mail logs with "send_date" within respective campaign's business hours

type Page

type Page struct {
	Id                 int64     `json:"id" gorm:"column:id; primary_key:yes"`
	UserId             int64     `json:"user_id" gorm:"column:user_id"`
	Username           string    `json:"username" gorm:"-"`
	Name               string    `json:"name"`
	TagsId             int64     `json:"tag" gorm:"column:tag"`
	Tags               Tags      `json:"tags"`
	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"`
	Public             bool      `json:"public" gorm:"column:public"`
	Shared             bool      `json:"shared" gorm:"column:shared"`
	RedirectURL        string    `json:"redirect_url" gorm:"column:redirect_url"`
	ModifiedDate       time.Time `json:"modified_date"`
	Writable           bool      `json:"writable" gorm:"-"`
}

Page contains the fields used for a Page model

func GetPage

func GetPage(id int64) (Page, error)

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

func GetPageByName

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

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

GetPages returns the pages owned by the given user. Optionally "filter" can be one of: own, public ,customers. Where: all - all items own - return items that belong to this user, public - public items customers - customers' items own-and-public - own and public items public-and-uid-xxx - public and items of user with uid xxx Note: empty "filter" will be treated as "own"

func (*Page) IsWritableByUser

func (p *Page) IsWritableByUser(uid int64) bool

IsWritableByUser tells if this page can be modified by a user with the given uid

func (*Page) Validate

func (p *Page) Validate() error

Validate ensures that a page contains the appropriate details

type PhishingTemplateContext

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

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 Plan

type Plan struct {
	Id   int64  `json:"id" gorm:"column:id; primary_key:yes"`
	Name string `json:"name"`
}

Plan is a subscription plan

func GetPlanByName

func GetPlanByName(name string) (Plan, error)

GetPlanByName returns the plan, if it exists, specified by the given name

func GetPlans

func GetPlans() ([]Plan, error)

GetPlans returns all plans

type Response

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

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

func GetResult(rid string) (Result, error)

GetResult returns the Result object from the database given the ResultId

func (*Result) GenerateId

func (r *Result) GenerateId() 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

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

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

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

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

func (*Result) HandleEmailReport

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

func (r *Result) HandleEmailSent(details interface{}) error

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

func (*Result) HandleFormSubmit

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

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

type Role struct {
	Rid         int64  `json:"rid"`
	Name        string `json:"name" sql:"not null;unique"`
	DisplayName string `json:"display_name" sql:"not null"`
	Weight      string `json:"weight" sql:"not null;unique"`
}

Role represents the role model for gophish.

func (Role) Is

func (r Role) Is(rid int64) bool

Is tells if this role id matches the given one

type Roles

type Roles []Role

Roles is a list of roles

func GetRoles

func GetRoles() (Roles, error)

GetRoles returns all available roles

func (Roles) AvailableFor

func (roles Roles) AvailableFor(role UserRole) Roles

AvailableFor returns roles which a user with the given role can create users with

type SMTP

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 GetAllSMTPs

func GetAllSMTPs() ([]SMTP, error)

GetAllSMTPs returns all SMTPs

func GetSMTP

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

func GetSMTPByName(n string) (SMTP, error)

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

func GetSMTPs

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

GetSMTPs returns the SMTPs owned by the given user.

func (*SMTP) GetDialer

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

GetDialer returns a dialer for the given SMTP profile

func (SMTP) TableName

func (s SMTP) TableName() string

TableName specifies the database tablename for Gorm to use

func (*SMTP) Validate

func (s *SMTP) Validate() error

Validate ensures that SMTP configs/connections are valid

type Subscription

type Subscription struct {
	Id             int64     `json:"id" gorm:"column:id; primary_key:yes"`
	UserId         int64     `json:"user_id"`
	PlanId         int64     `json:"plan_id"`
	ExpirationDate time.Time `json:"expiration_date"`
}

Subscription is a paid subscription for a certain plan

func GetSubscriptions

func GetSubscriptions() ([]Subscription, error)

GetSubscriptions returns all subscriptions

func (*Subscription) BeforeSave

func (s *Subscription) BeforeSave() error

func (*Subscription) ChangeExpirationDate

func (s *Subscription) ChangeExpirationDate(expDate time.Time) error

ChangeExpirationDate changes this subscription's expiration date

func (*Subscription) ChangePlan

func (s *Subscription) ChangePlan(planId int64) error

ChangePlan changes this subscription's plan

func (*Subscription) IsActive

func (s *Subscription) IsActive() bool

IsActive tells if this subscription if active (not expired)

func (Subscription) MarshalJSON

func (s Subscription) MarshalJSON() ([]byte, error)

MarshalJSON is a custom JSON marshaller with support of a few computed props

type Tags

type Tags struct {
	Id     int64  `json:"id" gorm:"column:id; primary_key:yes"`
	Name   string `json:"name"`
	Weight int64  `json:"weight"`
}

Tags models hold the attributes for the categories of templates and landing pages

func GetTagById

func GetTagById(id int64) (Tags, error)

Get tags by tag name

func GetTags

func GetTags(uid int64) ([]Tags, error)

GetTags returns the all the tags from the database

type Target

type Target struct {
	Id int64 `json:"id"`
	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 GetTargetByEmail

func GetTargetByEmail(email string) (t Target, err error)

GetTargetByEmail finds and returns target with the given email

func GetTargets

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

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

func GetTargetsByIds

func GetTargetsByIds(tids []int64) ([]Target, error)

GetTargetsByIds returns group targets identified by the given ids

func (*Target) FormatAddress

func (t *Target) FormatAddress() string

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

func (*Target) GetGroupIds

func (t *Target) GetGroupIds() ([]int64, error)

GetGroupIds returns group ids which this target belongs to

type Template

type Template struct {
	Id            int64        `json:"id" gorm:"column:id; primary_key:yes"`
	UserId        int64        `json:"user_id" gorm:"column:user_id"`
	Username      string       `json:"username" gorm:"-"`
	Name          string       `json:"name"`
	Subject       string       `json:"subject"`
	Text          string       `json:"text"`
	HTML          string       `json:"html" gorm:"column:html"`
	FromAddress   string       `json:"from_address"`
	RATING        int64        `json:"rating" gorm:"column:rating"`
	TagsId        int64        `json:"tag" gorm:"column:tag"`
	Tags          Tags         `json:"tags"`
	DefaultPageId int64        `json:"default_page_id" gorm:"column:default_page_id"`
	Public        bool         `json:"public" gorm:"column:public"`
	Shared        bool         `json:"shared" gorm:"column:shared"`
	ModifiedDate  time.Time    `json:"modified_date"`
	Attachments   []Attachment `json:"attachments"`
	Writable      bool         `json:"writable" gorm:"-"`
}

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

func GetRandomTemplate

func GetRandomTemplate(uid, cid int64) (Template, error)

GetRandomTemplate returns one template randomly selected from templates available to the given uid that belong to the given category id

func GetTemplate

func GetTemplate(id int64) (Template, error)

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

func GetTemplateByName

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

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

GetTemplates returns the templates owned by the given user. Optionally "filter" can be one of: own, public ,customers. Where: own - return items that belong to this user, public - public items customers - customers' items own-and-public - own and public items public-and-uid-xxx - public and items of user with uid xxx Note: empty "filter" will be treated as "own"

func (*Template) BeforeUpdate

func (t *Template) BeforeUpdate(scope *gorm.Scope) error

func (*Template) IsWritableByUser

func (t *Template) IsWritableByUser(uid int64) bool

IsWritableByUser tells if this template can be modified by a user with the given uid

func (*Template) Validate

func (t *Template) Validate() error

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

type TemplateContext

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

type User struct {
	Id              int64                      `json:"id"`
	Username        string                     `json:"username" sql:"not null;unique"`
	Email           encryption.EncryptedString `json:"email" sql:"not null;unique"`
	Partner         int64                      `json:"partner" sql:"not null"`
	Hash            string                     `json:"-"`
	ApiKey          encryption.EncryptedString `json:"api_key" sql:"not null;unique"`
	PlainApiKey     string                     `json:"plain_api_key" gorm:"-"`
	FullName        string                     `json:"full_name" sql:"not null"`
	Domain          string                     `json:"domain"`
	TimeZone        string                     `json:"time_zone"`
	NumOfUsers      int64                      `json:"num_of_users"`
	AdminEmail      encryption.EncryptedString `json:"admin_email" sql:"not null"`
	EmailVerifiedAt time.Time                  `json:"email_verified_at"`
	CreatedAt       time.Time                  `json:"created_at"`
	UpdatedAt       time.Time                  `json:"updated_at"`
	LastLoginAt     time.Time                  `json:"last_login_at"`
	LastLoginIp     string                     `json:"last_login_ip" sql:"not null"`
	LastUserAgent   string                     `json:"last_user_agent"`
	ToBeDeleted     bool                       `json:"to_be_deleted"`
}

User represents the user model for gophish.

func CreateUser

func CreateUser(username, fullName, email, password string, rid int64, partner int64) (*User, error)

CreateUser creates a new user with the given props and returns it

func GetLMSUser

func GetLMSUser(email string) (User, error)

GetLMSUser returns a user with LMS role and given email

func GetUser

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

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 GetUserByBakeryID

func GetUserByBakeryID(buid int64) (User, error)

GetUserByBakeryID returns the user that the given bakery user id corresponds to. If no user is found, an error is returned.

func GetUserByDomain

func GetUserByDomain(domain string) (User, error)

GetUserByDomain returns the user with the given domain

func GetUserByUsername

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

func GetUsers(uid int64) ([]User, error)

GetUsers returns the users owned by the given user.

func GetUsersByRoleID

func GetUsersByRoleID(rid int64) ([]User, error)

GetUsersByRole returns all users of the given role (rid)

func (*User) BeforeSave

func (u *User) BeforeSave() (err error)

func (*User) BeforeUpdate

func (u *User) BeforeUpdate(scope *gorm.Scope) error

func (User) CanCreateCampaign

func (u User) CanCreateCampaign() bool

CanCreateCampaign tells if this user is allowed to create a campaign, the decision is made based on user's subscription status and plan

func (User) CanCreateGroup

func (u User) CanCreateGroup() bool

CanCreateGroup tells if this user is allowed to create a group (of target users), the decision is made based on user's subscription status and plan

func (User) CanManageSubscriptions

func (u User) CanManageSubscriptions() bool

CanManageSubscriptions tells if this user is allowed to manage customers' subscriptions, the decision is made based on user's subscription status and plan

func (User) CanManageUserWithId

func (u User) CanManageUserWithId(uid int64) bool

CanManageUserWithId tells if this user can update/delete/impersonate a user with the given uid

func (*User) DecryptApiKey

func (u *User) DecryptApiKey()

DecryptApiKey decrypts encrypted ApiKey field and puts the result into PlainApiKey

func (User) GetAvatar

func (u User) GetAvatar() *Avatar

GetAvatar returns Avatar which was assigned to this user or nil

func (u User) GetLogo() *Logo

GetLogo returns logo which was assigned to this partner/customer account or nil

func (User) GetSubscription

func (u User) GetSubscription() *Subscription

GetSubscription returns user subscription or nil if there is none

func (User) HasPages

func (u User) HasPages() bool

HasPages tells if this user owns any landing pages

func (User) HasTemplates

func (u User) HasTemplates() bool

HasTemplates tells if this user owns any email templates

func (User) IsAdministrator

func (u User) IsAdministrator() bool

IsAdministrator tells if this user is administrator

func (User) IsChildUser

func (u User) IsChildUser() bool

IsChildUser tells if this user is child user

func (User) IsCustomer

func (u User) IsCustomer() bool

IsCustomer tells if this user is customer

func (User) IsLMSUser

func (u User) IsLMSUser() bool

IsLMSUser tells if this user is LMS user

func (User) IsPartner

func (u User) IsPartner() bool

IsPartner tells if this user is partner

func (User) IsSubscribed

func (u User) IsSubscribed() bool

IsSubscribed tells if this user is subscribed to a plan and the subscription is not expired

func (User) SetBakeryUserID

func (u User) SetBakeryUserID(id int64) error

SetBakeryUserID assigns bakery master user id to this user

type UserRole

type UserRole struct {
	Uid int64 `json:"uid"`
	Rid int64 `json:"rid" sql:"not"`
}

UserRole represents the user role model for gophish.

func GetUserRole

func GetUserRole(uid int64) (UserRole, error)

GetUserRole returns a role assigned to the given uid

func (UserRole) DisplayName

func (ur UserRole) DisplayName() string

DisplayName returns this role's display name

func (UserRole) Is

func (ur UserRole) Is(rid int64) bool

Is tells if this user role id matches the given one

func (UserRole) IsOneOf

func (ur UserRole) IsOneOf(rids []int64) bool

IsOneOf tells if this user role id is among the given role ids

func (UserRole) Name

func (ur UserRole) Name() string

Name returns this role's name

func (UserRole) TableName

func (ur UserRole) TableName() string

TableName specifies the database tablename for Gorm to use

type UserRoles

type UserRoles []UserRole

UserRoles is a list of user roles

type ValidationContext

type ValidationContext struct {
	FromAddress string
	BaseURL     string
}

ValidationContext is used for validating templates and pages

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL