diff --git a/config/config_test.go b/config/config_test.go index 7e164fcd..00f8f402 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -68,7 +68,7 @@ func TestLoadConfig(t *testing.T) { } // Load an invalid config - conf, err = LoadConfig("bogusfile") + _, err = LoadConfig("bogusfile") if err == nil { t.Fatalf("expected error when loading invalid config, but got %v", err) } diff --git a/context/context.go b/context/context.go index 998f4939..b882406a 100644 --- a/context/context.go +++ b/context/context.go @@ -23,6 +23,4 @@ func Set(r *http.Request, key, val interface{}) *http.Request { } // Clear is a null operation, since this is handled automatically in Go > 1.7 -func Clear(r *http.Request) { - return -} +func Clear(r *http.Request) {} diff --git a/controllers/api/api_test.go b/controllers/api/api_test.go index b5dac5fb..35878064 100644 --- a/controllers/api/api_test.go +++ b/controllers/api/api_test.go @@ -42,18 +42,6 @@ func setupTest(t *testing.T) *testContext { return ctx } -func tearDown(t *testing.T, ctx *testContext) { - // Cleanup all users except the original admin - // users, _ := models.GetUsers() - // for _, user := range users { - // if user.Id == 1 { - // continue - // } - // err := models.DeleteUser(user.Id) - // s.Nil(err) - // } -} - func createTestData(t *testing.T) { // Add a group group := models.Group{Name: "Test Group"} diff --git a/controllers/api/group.go b/controllers/api/group.go index 26dcfb39..700fa3e6 100644 --- a/controllers/api/group.go +++ b/controllers/api/group.go @@ -87,6 +87,11 @@ func (as *Server) Group(w http.ResponseWriter, r *http.Request) { // Change this to get from URL and uid (don't bother with id in r.Body) g = models.Group{} err = json.NewDecoder(r.Body).Decode(&g) + if err != nil { + log.Errorf("error decoding group: %v", err) + JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusInternalServerError) + return + } if g.Id != id { JSONResponse(w, models.Response{Success: false, Message: "Error: /:id and group_id mismatch"}, http.StatusInternalServerError) return diff --git a/controllers/api/import.go b/controllers/api/import.go index f1b164d9..7cf96a01 100644 --- a/controllers/api/import.go +++ b/controllers/api/import.go @@ -46,7 +46,6 @@ func (as *Server) ImportGroup(w http.ResponseWriter, r *http.Request) { return } JSONResponse(w, ts, http.StatusOK) - return } // ImportEmail allows for the importing of email. @@ -94,7 +93,6 @@ func (as *Server) ImportEmail(w http.ResponseWriter, r *http.Request) { HTML: string(e.HTML), } JSONResponse(w, er, http.StatusOK) - return } // ImportSite allows for the importing of HTML from a website @@ -153,5 +151,4 @@ func (as *Server) ImportSite(w http.ResponseWriter, r *http.Request) { } cs := cloneResponse{HTML: h} JSONResponse(w, cs, http.StatusOK) - return } diff --git a/controllers/api/util.go b/controllers/api/util.go index 0f6c215c..9ccdc7ed 100644 --- a/controllers/api/util.go +++ b/controllers/api/util.go @@ -118,5 +118,4 @@ func (as *Server) SendTestEmail(w http.ResponseWriter, r *http.Request) { return } JSONResponse(w, models.Response{Success: true, Message: "Email Sent"}, http.StatusOK) - return } diff --git a/controllers/api/webhook.go b/controllers/api/webhook.go index 100a235f..359142fc 100644 --- a/controllers/api/webhook.go +++ b/controllers/api/webhook.go @@ -62,15 +62,20 @@ func (as *Server) Webhook(w http.ResponseWriter, r *http.Request) { JSONResponse(w, models.Response{Success: true, Message: "Webhook deleted Successfully!"}, http.StatusOK) case r.Method == "PUT": - wh2 := models.Webhook{} - err = json.NewDecoder(r.Body).Decode(&wh2) - wh2.Id = id - err = models.PutWebhook(&wh2) + wh = models.Webhook{} + err = json.NewDecoder(r.Body).Decode(&wh) + if err != nil { + log.Errorf("error decoding webhook: %v", err) + JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusBadRequest) + return + } + wh.Id = id + err = models.PutWebhook(&wh) if err != nil { JSONResponse(w, models.Response{Success: false, Message: err.Error()}, http.StatusBadRequest) return } - JSONResponse(w, wh2, http.StatusOK) + JSONResponse(w, wh, http.StatusOK) } } diff --git a/controllers/route.go b/controllers/route.go index fae4ddc7..03bc8e39 100644 --- a/controllers/route.go +++ b/controllers/route.go @@ -285,7 +285,7 @@ func (as *AdminServer) Impersonate(w http.ResponseWriter, r *http.Request) { session.Values["id"] = u.Id session.Save(r, w) } - http.Redirect(w, r, "/", 302) + http.Redirect(w, r, "/", http.StatusFound) } // Login handles the authentication flow for a user. If credentials are valid, @@ -326,7 +326,7 @@ func (as *AdminServer) Login(w http.ResponseWriter, r *http.Request) { next = path } } - http.Redirect(w, r, next, 302) + http.Redirect(w, r, next, http.StatusFound) } else { Flash(w, r, "danger", "Invalid Username/Password") params.Flashes = session.Flashes() @@ -349,7 +349,7 @@ func (as *AdminServer) Logout(w http.ResponseWriter, r *http.Request) { delete(session.Values, "id") Flash(w, r, "success", "You have successfully logged out") session.Save(r, w) - http.Redirect(w, r, "/login", 302) + http.Redirect(w, r, "/login", http.StatusFound) } func getTemplate(w http.ResponseWriter, tmpl string) *template.Template { diff --git a/imap/imap.go b/imap/imap.go index f895aac8..ac2798a4 100644 --- a/imap/imap.go +++ b/imap/imap.go @@ -305,7 +305,6 @@ func getEmails(client Client, cmd *imap.Command, markAsRead, delete bool, respon } } } - return } func deleteEmail(client Client, UID uint32) error { diff --git a/imap/monitor.go b/imap/monitor.go index 4c0a61a9..34b62e79 100644 --- a/imap/monitor.go +++ b/imap/monitor.go @@ -162,7 +162,7 @@ func checkForNewEmails(im models.IMAP) { if err != nil { log.Error("Error updating GoPhish email with rid ", rid, ": ", err.Error()) } else { - if im.DeleteReportedCampaignEmail == true { + if im.DeleteReportedCampaignEmail { campaignEmails = append(campaignEmails, m.UID) } } @@ -180,7 +180,7 @@ func checkForNewEmails(im models.IMAP) { } } // If the DeleteReportedCampaignEmail flag is set, delete reported Gophish campaign emails - if im.DeleteReportedCampaignEmail == true && len(campaignEmails) > 0 { + if im.DeleteReportedCampaignEmail && len(campaignEmails) > 0 { log.Debugf("Deleting %d campaign emails\n", len(campaignEmails)) err := mailServer.DeleteEmails(campaignEmails) // Delete GoPhish campaign emails. if err != nil { diff --git a/mailer/mockmailer.go b/mailer/mockmailer.go index 7226e94f..c39cb305 100644 --- a/mailer/mockmailer.go +++ b/mailer/mockmailer.go @@ -13,11 +13,6 @@ import ( // being unreachable var errHostUnreachable = errors.New("host unreachable") -// errDialerUnavailable is a mock error to represent a dialer -// being unavailable (perhaps an error getting the dialer config -// or a database error) -var errDialerUnavailable = errors.New("dialer unavailable") - // mockDialer keeps track of calls to Dial type mockDialer struct { dialCount int @@ -137,10 +132,6 @@ func (mm *mockMessage) defaultDialer() (Dialer, error) { return newMockDialer(), nil } -func (mm *mockMessage) errorDialer() (Dialer, error) { - return nil, errDialerUnavailable -} - func (mm *mockMessage) GetDialer() (Dialer, error) { return mm.getdialer() } diff --git a/middleware/middleware.go b/middleware/middleware.go index 628763cc..3b7663e9 100644 --- a/middleware/middleware.go +++ b/middleware/middleware.go @@ -120,7 +120,6 @@ func RequireLogin(handler http.Handler) http.HandlerFunc { q := r.URL.Query() q.Set("next", r.URL.Path) http.Redirect(w, r, fmt.Sprintf("/login?%s", q.Encode()), http.StatusTemporaryRedirect) - return } } diff --git a/models/campaign.go b/models/campaign.go index 9e8b4770..a9e24382 100644 --- a/models/campaign.go +++ b/models/campaign.go @@ -27,7 +27,7 @@ type Campaign struct { Status string `json:"status"` Results []Result `json:"results,omitempty"` Groups []Group `json:"groups,omitempty"` - Events []Event `json:"timeline,omitemtpy"` + Events []Event `json:"timeline,omitempty"` SMTPId int64 `json:"-"` SMTP SMTP `json:"smtp"` URL string `json:"url"` diff --git a/models/email_request.go b/models/email_request.go index e4744c93..706fe1dd 100644 --- a/models/email_request.go +++ b/models/email_request.go @@ -103,10 +103,6 @@ func (s *EmailRequest) Generate(msg *gomail.Message) error { if err != nil { return err } - fn := f.Name - if fn == "" { - fn = f.Address - } msg.SetAddressHeader("From", f.Address, f.Name) ptx, err := NewPhishingTemplateContext(s, s.BaseRecipient, s.RId) diff --git a/models/group.go b/models/group.go index 9a5ef39e..5a4c59fd 100644 --- a/models/group.go +++ b/models/group.go @@ -226,7 +226,6 @@ func PutGroup(g *Group) error { return err } // Fetch group's existing targets from database. - ts := []Target{} ts, err := GetTargets(g.Id) if err != nil { log.WithFields(logrus.Fields{ diff --git a/models/imap.go b/models/imap.go index 8218d5ea..e00ceaa4 100644 --- a/models/imap.go +++ b/models/imap.go @@ -53,7 +53,7 @@ var ErrIMAPPasswordNotSpecified = errors.New("No Password specified") // ErrInvalidIMAPFreq is thrown when the frequency for polling the // IMAP server is invalid -var ErrInvalidIMAPFreq = errors.New("Invalid polling frequency.") +var ErrInvalidIMAPFreq = errors.New("Invalid polling frequency") // TableName specifies the database tablename for Gorm to use func (im IMAP) TableName() string { diff --git a/models/maillog.go b/models/maillog.go index 082ddceb..ea56ca13 100644 --- a/models/maillog.go +++ b/models/maillog.go @@ -125,7 +125,7 @@ func (m *MailLog) Success() error { return err } err = db.Delete(m).Error - return nil + return err } // GetDialer returns a dialer based on the maillog campaign's SMTP configuration diff --git a/models/page.go b/models/page.go index 30da2179..ac386ad9 100644 --- a/models/page.go +++ b/models/page.go @@ -138,6 +138,9 @@ func PostPage(p *Page) error { // Per the PUT Method RFC, it presumes all data for a page is provided. func PutPage(p *Page) error { err := p.Validate() + if err != nil { + return err + } err = db.Where("id=?", p.Id).Save(p).Error if err != nil { log.Error(err) diff --git a/models/user_test.go b/models/user_test.go index c869d82e..7c0819a7 100644 --- a/models/user_test.go +++ b/models/user_test.go @@ -27,7 +27,9 @@ func (s *ModelsSuite) TestGetUserByAPIKeyWithExistingAPIKey(c *check.C) { u, err := GetUser(1) c.Assert(err, check.Equals, nil) - u, err = GetUserByAPIKey(u.ApiKey) + got, err := GetUserByAPIKey(u.ApiKey) + c.Assert(err, check.Equals, nil) + c.Assert(got.Id, check.Equals, u.Id) } func (s *ModelsSuite) TestGetUserByAPIKeyWithNotExistingAPIKey(c *check.C) { @@ -46,11 +48,12 @@ func (s *ModelsSuite) TestGetUserByUsernameWithNotExistingUser(c *check.C) { } func (s *ModelsSuite) TestPutUser(c *check.C) { - u, err := GetUser(1) + u, _ := GetUser(1) u.Username = "admin_changed" - err = PutUser(&u) + err := PutUser(&u) c.Assert(err, check.Equals, nil) u, err = GetUser(1) + c.Assert(err, check.Equals, nil) c.Assert(u.Username, check.Equals, "admin_changed") } diff --git a/static/js/dist/app/webhooks.min.js b/static/js/dist/app/webhooks.min.js index 612d3b1f..765cd3e8 100644 --- a/static/js/dist/app/webhooks.min.js +++ b/static/js/dist/app/webhooks.min.js @@ -1 +1 @@ -!function(e){var o={};function n(t){if(o[t])return o[t].exports;var a=o[t]={i:t,l:!1,exports:{}};return e[t].call(a.exports,a,a.exports,n),a.l=!0,a.exports}n.m=e,n.c=o,n.d=function(e,o,t){n.o(e,o)||Object.defineProperty(e,o,{enumerable:!0,get:t})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,o){if(1&o&&(e=n(e)),8&o)return e;if(4&o&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(n.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&o&&"string"!=typeof e)for(var a in e)n.d(t,a,function(o){return e[o]}.bind(null,a));return t},n.n=function(e){var o=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(o,"a",o),o},n.o=function(e,o){return Object.prototype.hasOwnProperty.call(e,o)},n.p="",n(n.s=1)}([,function(e,o){var n=[],t=function(){$("#name").val(""),$("#url").val(""),$("#secret").val(""),$("#is_active").prop("checked",!1),$("#flashes").empty()},a=function(){$("#webhookTable").hide(),$("#loading").show(),api.webhooks.get().success(function(e){n=e,$("#loading").hide(),$("#webhookTable").show();var o=$("#webhookTable").DataTable({destroy:!0,columnDefs:[{orderable:!1,targets:"no-sort"}]});o.clear(),$.each(n,function(e,n){o.row.add([escapeHtml(n.name),escapeHtml(n.url),escapeHtml(n.is_active),'\n