mirror of https://github.com/gophish/gophish
Added ability to delete campaign from campaign results - needs some cleanup, but it works
parent
66dbe2e799
commit
be9064f718
|
@ -99,7 +99,6 @@ func GetGroupByName(n string, uid int64) (Group, error) {
|
||||||
|
|
||||||
// PostGroup creates a new group in the database.
|
// PostGroup creates a new group in the database.
|
||||||
func PostGroup(g *Group) error {
|
func PostGroup(g *Group) error {
|
||||||
Logger.Printf("%v", g.Targets)
|
|
||||||
if err := g.Validate(); err != nil {
|
if err := g.Validate(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,17 +5,17 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/jordan-wright/gophish/config"
|
"github.com/jordan-wright/gophish/config"
|
||||||
"launchpad.net/gocheck"
|
"gopkg.in/check.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Hook up gocheck into the "go test" runner.
|
// Hook up gocheck into the "go test" runner.
|
||||||
func Test(t *testing.T) { gocheck.TestingT(t) }
|
func Test(t *testing.T) { check.TestingT(t) }
|
||||||
|
|
||||||
type ModelsSuite struct{}
|
type ModelsSuite struct{}
|
||||||
|
|
||||||
var _ = gocheck.Suite(&ModelsSuite{})
|
var _ = check.Suite(&ModelsSuite{})
|
||||||
|
|
||||||
func (s *ModelsSuite) SetUpSuite(c *gocheck.C) {
|
func (s *ModelsSuite) SetUpSuite(c *check.C) {
|
||||||
config.Conf.DBPath = "../gophish_test.db"
|
config.Conf.DBPath = "../gophish_test.db"
|
||||||
err := Setup()
|
err := Setup()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -23,22 +23,48 @@ func (s *ModelsSuite) SetUpSuite(c *gocheck.C) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ModelsSuite) TestGetUser(c *gocheck.C) {
|
func (s *ModelsSuite) TestGetUser(c *check.C) {
|
||||||
u, err := GetUser(1)
|
u, err := GetUser(1)
|
||||||
c.Assert(err, gocheck.Equals, nil)
|
c.Assert(err, check.Equals, nil)
|
||||||
c.Assert(u.Username, gocheck.Equals, "admin")
|
c.Assert(u.Username, check.Equals, "admin")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ModelsSuite) TestPutUser(c *gocheck.C) {
|
func (s *ModelsSuite) TestPostGroup(c *check.C) {
|
||||||
|
g := Group{Name: "Test Group"}
|
||||||
|
g.Targets = []Target{Target{Email: "test@example.com"}}
|
||||||
|
g.UserId = 1
|
||||||
|
err := PostGroup(&g)
|
||||||
|
c.Assert(err, check.Equals, nil)
|
||||||
|
c.Assert(g.Name, check.Equals, "Test Group")
|
||||||
|
c.Assert(g.Targets[0].Email, check.Equals, "test@example.com")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ModelsSuite) TestPostGroupNoName(c *check.C) {
|
||||||
|
g := Group{Name: ""}
|
||||||
|
g.Targets = []Target{Target{Email: "test@example.com"}}
|
||||||
|
g.UserId = 1
|
||||||
|
err := PostGroup(&g)
|
||||||
|
c.Assert(err, check.Equals, ErrGroupNameNotSpecified)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ModelsSuite) TestPostGroupNoTargets(c *check.C) {
|
||||||
|
g := Group{Name: "No Target Group"}
|
||||||
|
g.Targets = []Target{}
|
||||||
|
g.UserId = 1
|
||||||
|
err := PostGroup(&g)
|
||||||
|
c.Assert(err, check.Equals, ErrNoTargetsSpecified)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ModelsSuite) TestPutUser(c *check.C) {
|
||||||
u, err := GetUser(1)
|
u, err := GetUser(1)
|
||||||
u.Username = "admin_changed"
|
u.Username = "admin_changed"
|
||||||
err = PutUser(&u)
|
err = PutUser(&u)
|
||||||
c.Assert(err, gocheck.Equals, nil)
|
c.Assert(err, check.Equals, nil)
|
||||||
u, err = GetUser(1)
|
u, err = GetUser(1)
|
||||||
c.Assert(u.Username, gocheck.Equals, "admin_changed")
|
c.Assert(u.Username, check.Equals, "admin_changed")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ModelsSuite) TearDownSuite(c *gocheck.C) {
|
func (s *ModelsSuite) TearDownSuite(c *check.C) {
|
||||||
db.DB().Close()
|
db.DB().Close()
|
||||||
err := os.Remove(config.Conf.DBPath)
|
err := os.Remove(config.Conf.DBPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -290,6 +290,22 @@ app.controller('CampaignResultsCtrl', function($scope, $filter, CampaignService,
|
||||||
"icon": "fa-check-circle"
|
"icon": "fa-check-circle"
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$scope.delete = function(campaign) {
|
||||||
|
if (confirm("Delete campaign?")) {
|
||||||
|
var deleteCampaign = new CampaignService(campaign);
|
||||||
|
deleteCampaign.$delete({
|
||||||
|
id: deleteCampaign.id
|
||||||
|
}, function(response) {
|
||||||
|
if (response.success) {
|
||||||
|
$scope.successFlash(response.message)
|
||||||
|
} else {
|
||||||
|
$scope.errorFlash(response.message)
|
||||||
|
}
|
||||||
|
$scope.mainTableParams.reload();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
$scope.mainTableParams = new ngTableParams({
|
$scope.mainTableParams = new ngTableParams({
|
||||||
page: 1, // show first page
|
page: 1, // show first page
|
||||||
count: 10, // count per page
|
count: 10, // count per page
|
||||||
|
|
|
@ -21,6 +21,12 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main" ng-controller="CampaignResultsCtrl">
|
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main" ng-controller="CampaignResultsCtrl">
|
||||||
|
<div ng-show="campaign">
|
||||||
|
<div class="row">
|
||||||
|
<div class="alert alert-info">
|
||||||
|
No groups created yet. Let's create one!
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<h1 class="page-header">Results for {{campaign.name}}</h1>
|
<h1 class="page-header">Results for {{campaign.name}}</h1>
|
||||||
</div>
|
</div>
|
||||||
|
@ -37,7 +43,7 @@
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<button type="button" class="btn btn-danger" tooltip="Delete Campaign" tooltip-placement="right"><i class="fa fa-times fa-lg"></i>
|
<button type="button" class="btn btn-danger" tooltip="Delete Campaign" tooltip-placement="right" ng-click="delete(campaign)" ng-href="#/dashboard"><i class="fa fa-times fa-lg"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<br />
|
||||||
|
@ -70,3 +76,11 @@
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div ng-show="!campaign">
|
||||||
|
<div class="row">
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<i class="fa fa-exclamation-circle"></i> Campaign not found!
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue