Added documentation for multiple endpoints. Fixes #54

pull/98/head
Jordan Wright 2016-01-24 20:47:16 -06:00
parent eb6f3ed62a
commit 32aaa15da7
8 changed files with 26 additions and 2 deletions

View File

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

View File

@ -38,6 +38,7 @@ type Config struct {
MigrationsPath string `json:"migrations_path"`
}
// Conf contains the initialized configuration struct
var Conf Config
func init() {

View File

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

View File

@ -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")

View File

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

View File

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

View File

@ -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

View File

@ -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