diff --git a/auth/auth.go b/auth/auth.go index ca2b2c6b..af8327f5 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -22,10 +22,12 @@ func init() { gob.Register(&models.Flash{}) } +// Store contains the session information for the request var Store = sessions.NewCookieStore( []byte(securecookie.GenerateRandomKey(64)), //Signing key []byte(securecookie.GenerateRandomKey(32))) +// ErrInvalidPassword is thrown when a user provides an incorrect password. var ErrInvalidPassword = errors.New("Invalid Password") // Login attempts to login the user given a request. @@ -71,6 +73,8 @@ func Register(r *http.Request) (bool, error) { return true, nil } +// GenerateSecureKey creates a secure key to use +// as an API key func GenerateSecureKey() string { // Inspired from gorilla/securecookie k := make([]byte, 32) diff --git a/config/config.go b/config/config.go index 669de289..d4062050 100644 --- a/config/config.go +++ b/config/config.go @@ -38,6 +38,7 @@ type Config struct { MigrationsPath string `json:"migrations_path"` } +// Conf contains the initialized configuration struct var Conf Config func init() { diff --git a/controllers/api.go b/controllers/api.go index 6ca0baca..8c009f11 100644 --- a/controllers/api.go +++ b/controllers/api.go @@ -185,6 +185,7 @@ func API_Groups_Id(w http.ResponseWriter, r *http.Request) { } } +// API_Templates handles the functionality for the /api/templates endpoint func API_Templates(w http.ResponseWriter, r *http.Request) { switch { case r.Method == "GET": @@ -227,6 +228,7 @@ func API_Templates(w http.ResponseWriter, r *http.Request) { } } +// API_Templates_Id handles the functions for the /api/templates/:id endpoint func API_Templates_Id(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) id, _ := strconv.ParseInt(vars["id"], 0, 64) @@ -302,6 +304,8 @@ func API_Pages(w http.ResponseWriter, r *http.Request) { } } +// API_Pages_Id contains functions to handle the GET'ing, DELETE'ing, and PUT'ing +// of a Page object func API_Pages_Id(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) id, _ := strconv.ParseInt(vars["id"], 0, 64) diff --git a/middleware/middleware.go b/middleware/middleware.go index 8239087c..f33c6f87 100644 --- a/middleware/middleware.go +++ b/middleware/middleware.go @@ -5,9 +5,9 @@ import ( "fmt" "net/http" - ctx "github.com/gorilla/context" "github.com/gophish/gophish/auth" "github.com/gophish/gophish/models" + ctx "github.com/gorilla/context" ) // GetContext wraps each request in a function which fills in the context for a given request. @@ -79,6 +79,8 @@ func RequireLogin(handler http.Handler) http.HandlerFunc { } } +// JSONError returns an error in JSON format with the given +// status code and message func JSONError(w http.ResponseWriter, c int, m string) { w.WriteHeader(c) w.Header().Set("Content-Type", "application/json") diff --git a/models/attachment.go b/models/attachment.go index 996c3ea6..d5ab3374 100644 --- a/models/attachment.go +++ b/models/attachment.go @@ -1,5 +1,7 @@ package models +// Attachment contains the fields and methods for +// an email attachment type Attachment struct { Id int64 `json:"-"` TemplateId int64 `json:"-"` diff --git a/models/campaign.go b/models/campaign.go index 524da7f0..644f3868 100644 --- a/models/campaign.go +++ b/models/campaign.go @@ -100,6 +100,8 @@ func (c *Campaign) AddEvent(e Event) error { return db.Debug().Save(&e).Error } +// Event contains the fields for an event +// that occurs during the campaign type Event struct { Id int64 `json:"-"` CampaignId int64 `json:"-"` diff --git a/models/result.go b/models/result.go index bcaf9ee7..c7ab8575 100644 --- a/models/result.go +++ b/models/result.go @@ -20,6 +20,8 @@ type mmGeoPoint struct { Longitude float64 `maxminddb:"longitude"` } +// Result contains the fields for a result object, +// which is a representation of a target in a campaign. type Result struct { Id int64 `json:"-"` CampaignId int64 `json:"-"` @@ -34,10 +36,13 @@ type Result struct { Longitude float64 `json:"longitude"` } +// UpdateStatus updates the status of the result in the database func (r *Result) UpdateStatus(s string) error { return db.Table("results").Where("id=?", r.Id).Update("status", s).Error } +// UpdateGeo updates the latitude and longitude of the result in +// the database given an IP address func (r *Result) UpdateGeo(addr string) error { // Open a connection to the maxmind db mmdb, err := maxminddb.Open("static/db/geolite2-city.mmdb") @@ -60,6 +65,8 @@ func (r *Result) UpdateGeo(addr string) error { }).Error } +// GenerateId generates a unique key to represent the result +// in the database func (r *Result) GenerateId() { // Keep trying until we generate a unique key (shouldn't take more than one or two iterations) k := make([]byte, 32) @@ -73,6 +80,8 @@ func (r *Result) GenerateId() { } } +// GetResult returns the Result object from the database +// given the ResultId func GetResult(rid string) (Result, error) { r := Result{} err := db.Where("r_id=?", rid).First(&r).Error diff --git a/util/doc.go b/util/doc.go index b68e3aec..ed190b49 100644 --- a/util/doc.go +++ b/util/doc.go @@ -24,5 +24,5 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -// Package util provides misc. utility functions for gophish +// Package util provides misc utility functions for gophish package util