From 1d8ac6f9f341c8be1924f939b68492531ebc7192 Mon Sep 17 00:00:00 2001 From: Jordan Wright Date: Sat, 16 Jan 2016 23:51:01 -0600 Subject: [PATCH] Added better logging for campaign retrieval --- controllers/api.go | 9 +++++---- models/campaign.go | 8 ++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/controllers/api.go b/controllers/api.go index 46bb87b7..589b92e5 100644 --- a/controllers/api.go +++ b/controllers/api.go @@ -10,14 +10,14 @@ import ( "time" "github.com/PuerkitoBio/goquery" - ctx "github.com/gorilla/context" - "github.com/gorilla/mux" - "github.com/jinzhu/gorm" - "github.com/jordan-wright/email" "github.com/gophish/gophish/auth" "github.com/gophish/gophish/models" "github.com/gophish/gophish/util" "github.com/gophish/gophish/worker" + ctx "github.com/gorilla/context" + "github.com/gorilla/mux" + "github.com/jinzhu/gorm" + "github.com/jordan-wright/email" ) // Worker is the worker that processes phishing events and updates campaigns. @@ -92,6 +92,7 @@ func API_Campaigns_Id(w http.ResponseWriter, r *http.Request) { id, _ := strconv.ParseInt(vars["id"], 0, 64) c, err := models.GetCampaign(id, ctx.Get(r, "user_id").(int64)) if err != nil { + Logger.Println(err) JSONResponse(w, models.Response{Success: false, Message: "Campaign not found"}, http.StatusNotFound) return } diff --git a/models/campaign.go b/models/campaign.go index bab7bedf..3d701d92 100644 --- a/models/campaign.go +++ b/models/campaign.go @@ -117,21 +117,28 @@ func GetCampaign(id int64, uid int64) (Campaign, error) { c := Campaign{} err := db.Where("id = ?", id).Where("user_id = ?", uid).Find(&c).Error if err != nil { + Logger.Printf("%s: campaign not found\n", err) return c, err } err = db.Model(&c).Related(&c.Results).Error if err != nil { + Logger.Printf("%s: results not found for campaign\n", err) return c, err } err = db.Model(&c).Related(&c.Events).Error if err != nil { + Logger.Printf("%s: events not found for campaign\n", err) return c, err } err = db.Table("templates").Where("id=?", c.TemplateId).Find(&c.Template).Error if err != nil { + Logger.Printf("%s: template not found for campaign\n", err) return c, err } err = db.Table("pages").Where("id=?", c.PageId).Find(&c.Page).Error + if err != nil { + Logger.Printf("%s: page not found for campaign\n", err) + } return c, err } @@ -207,6 +214,7 @@ func PostCampaign(c *Campaign, uid int64) error { //DeleteCampaign deletes the specified campaign func DeleteCampaign(id int64) error { + Logger.Printf("Deleting campaign %d\n", id) // Delete all the campaign results err := db.Where("campaign_id=?", id).Delete(&Result{}).Error if err != nil {