From 5f1bd4334468e32162aaeea82595c736ec90402b Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 13 Mar 2014 15:12:03 -0500 Subject: [PATCH] Working on adding campaign results page --- controllers/route.go | 2 +- db/db.go | 7 +++-- static/js/app/gophish.js | 25 +++++++++++++++ templates/campaign_results.html | 54 +++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 templates/campaign_results.html diff --git a/controllers/route.go b/controllers/route.go index f3b861fd..84923abc 100644 --- a/controllers/route.go +++ b/controllers/route.go @@ -167,7 +167,7 @@ func Campaigns_Id(w http.ResponseWriter, r *http.Request) { Title string Flashes []interface{} }{Title: "Results", User: ctx.Get(r, "user").(models.User)} - getTemplate(w, "dashboard").ExecuteTemplate(w, "base", params) + getTemplate(w, "campaign_results").ExecuteTemplate(w, "base", params) } func Login(w http.ResponseWriter, r *http.Request) { diff --git a/db/db.go b/db/db.go index a8749b98..f28f2652 100644 --- a/db/db.go +++ b/db/db.go @@ -38,7 +38,7 @@ func Setup() error { `CREATE TABLE campaigns (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, created_date TIMESTAMP NOT NULL, completed_date TIMESTAMP, template TEXT, status TEXT NOT NULL);`, `CREATE TABLE targets (id INTEGER PRIMARY KEY AUTOINCREMENT, email TEXT NOT NULL, UNIQUE(email));`, `CREATE TABLE groups (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, modified_date TIMESTAMP NOT NULL);`, - `CREATE TABLE campaign_results (cid INTEGER NOT NULL, email TEXT NOT NULL, result TEXT NOT NULL, FOREIGN KEY (cid) REFERENCES users(id), UNIQUE(cid, email))`, + `CREATE TABLE campaign_results (cid INTEGER NOT NULL, email TEXT NOT NULL, status TEXT NOT NULL, FOREIGN KEY (cid) REFERENCES campaigns(id), UNIQUE(cid, email, status))`, `CREATE TABLE user_campaigns (uid INTEGER NOT NULL, cid INTEGER NOT NULL, FOREIGN KEY (uid) REFERENCES users(id), FOREIGN KEY (cid) REFERENCES campaigns(id), UNIQUE(uid, cid))`, `CREATE TABLE user_groups (uid INTEGER NOT NULL, gid INTEGER NOT NULL, FOREIGN KEY (uid) REFERENCES users(id), FOREIGN KEY (gid) REFERENCES groups(id), UNIQUE(uid, gid))`, `CREATE TABLE group_targets (gid INTEGER NOT NULL, tid INTEGER NOT NULL, FOREIGN KEY (gid) REFERENCES groups(id), FOREIGN KEY (tid) REFERENCES targets(id), UNIQUE(gid, tid));`, @@ -119,6 +119,10 @@ func GetCampaigns(uid int64) ([]models.Campaign, error) { func GetCampaign(id int64, uid int64) (models.Campaign, error) { c := models.Campaign{} err := Conn.SelectOne(&c, "SELECT c.id, name, created_date, completed_date, status, template FROM campaigns c, user_campaigns uc, users u WHERE uc.uid=u.id AND uc.cid=c.id AND c.id=? AND u.id=?", id, uid) + if err != nil { + return c, err + } + _, err = Conn.Select(&c.Results, "SELECT r.email, r.status FROM campaign_results r WHERE r.cid=?", c.Id) return c, err } @@ -155,7 +159,6 @@ func PostCampaign(c *models.Campaign, uid int64) error { } } } - // Now, let's add the user->user_groups->group mapping _, err = Conn.Exec("INSERT OR IGNORE INTO user_campaigns VALUES (?,?)", uid, c.Id) if err != nil { Logger.Printf("Error adding many-many mapping for campaign %s\n", c.Name) diff --git a/static/js/app/gophish.js b/static/js/app/gophish.js index c3bce55a..e766fe13 100644 --- a/static/js/app/gophish.js +++ b/static/js/app/gophish.js @@ -108,6 +108,31 @@ app.controller('CampaignCtrl', function($scope, CampaignService, GroupService, n } }); +app.controller('CampaignResultsCtrl', function($scope, CampaignService, GroupService, ngTableParams, $http, $window) { + id = $window.location.pathname.split( '/' )[2]; + $scope.flashes = [] + $scope.mainTableParams = new ngTableParams({ + page: 1, // show first page + count: 10, // count per page + sorting: { + name: 'asc' // initial sorting + } + }, { + total: 0, // length of data + getData: function($defer, params) { + CampaignService.get({"id" : id}, function(campaign) { + $scope.campaign = campaign + params.total(campaign.results.length) + $defer.resolve(campaign.results.slice((params.page() - 1) * params.count(), params.page() * params.count())); + }) + } + }); + + $scope.errorFlash = function(message) { + $scope.flashes.push({"type" : "danger", "message" : message, "icon" : "fa-exclamation-circle"}) + } +}); + app.controller('GroupCtrl', function($scope, GroupService, ngTableParams) { $scope.mainTableParams = new ngTableParams({ page: 1, // show first page diff --git a/templates/campaign_results.html b/templates/campaign_results.html new file mode 100644 index 00000000..d0c9f0d0 --- /dev/null +++ b/templates/campaign_results.html @@ -0,0 +1,54 @@ +{{% define "content" %}} {{% template "nav" .User %}} +
+
+

+ Dashboard +

+
+
+
+ +
+
+

Results for {{campaign.name}}

+
+
+
+ + +
+ +
+   +
+ + + + + + + +
{{result.email}}{{result.status}}
+
+
+
+{{% end %}}