diff --git a/controllers/route.go b/controllers/route.go index 9a7f7708..96974fb7 100644 --- a/controllers/route.go +++ b/controllers/route.go @@ -27,6 +27,7 @@ func CreateRouter() *nosurf.CSRFHandler { router.HandleFunc("/campaigns/{id:[0-9]+}", Use(Campaigns_Id, mid.RequireLogin)) router.HandleFunc("/users", Use(Users, mid.RequireLogin)) router.HandleFunc("/settings", Use(Settings, mid.RequireLogin)) + router.HandleFunc("/templates", Use(Templates, mid.RequireLogin)) // Create the API routes api := router.PathPrefix("/api").Subrouter() @@ -137,6 +138,15 @@ func Users(w http.ResponseWriter, r *http.Request) { getTemplate(w, "users").ExecuteTemplate(w, "base", params) } +func Templates(w http.ResponseWriter, r *http.Request) { + params := struct { + User models.User + Title string + Flashes []interface{} + }{Title: "Templates", User: ctx.Get(r, "user").(models.User)} + getTemplate(w, "templates").ExecuteTemplate(w, "base", params) +} + func Settings(w http.ResponseWriter, r *http.Request) { params := struct { User models.User diff --git a/static/js/app/gophish.js b/static/js/app/gophish.js index e766fe13..caa1dc83 100644 --- a/static/js/app/gophish.js +++ b/static/js/app/gophish.js @@ -1,5 +1,11 @@ var app = angular.module('gophish', ['ngTable', 'ngResource', 'ui.bootstrap']); +app.filter('unsafe', function($sce) { + return function(val) { + return $sce.trustAsHtml(val); + }; +}); + app.factory('CampaignService', function($resource) { return $resource('/api/campaigns/:id?api_key=' + API_KEY, { id: "@id" @@ -20,6 +26,16 @@ app.factory('GroupService', function($resource) { }); }); +app.factory('TemplateService', function($resource) { + return $resource('/api/templates/:id?api_key=' + API_KEY, { + id: "@id" + }, { + update: { + method: 'PUT' + } + }); +}); + app.controller('CampaignCtrl', function($scope, CampaignService, GroupService, ngTableParams, $http) { $scope.flashes = [] $scope.mainTableParams = new ngTableParams({ @@ -220,3 +236,64 @@ app.controller('GroupCtrl', function($scope, GroupService, ngTableParams) { }); } }) + +app.controller('TemplateCtrl', function($scope, TemplateService, ngTableParams) { + $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) { + TemplateService.query(function(templates) { + $scope.templates = templates + params.total(templates.length) + $defer.resolve(templates.slice((params.page() - 1) * params.count(), params.page() * params.count())); + }) + } + }); + + $scope.editTemplate = function(template) { + if (template === 'new') { + $scope.newTemplate = true; + $scope.template = { + name: '', + html: '', + text: '', + }; + + } else { + $scope.newTemplate = false; + $scope.template = template; + } + }; + + $scope.saveTemplate = function(template) { + var newTemplate = new TemplateService(template); + if ($scope.newTemplate) { + newTemplate.$save({}, function() { + $scope.templates.push(newTemplate); + $scope.mainTableParams.reload() + }); + } else { + newTemplate.$update({ + id: newTemplate.id + }) + } + $scope.template = { + name: '', + html: '', + text: '', + }; + } + $scope.deleteTemplate = function(template) { + var deleteTemplate = new TemplateService(template); + deleteTemplate.$delete({ + id: deleteTemplate.id + }, function() { + $scope.mainTableParams.reload(); + }); + } +}) \ No newline at end of file diff --git a/templates/campaign_results.html b/templates/campaign_results.html index d0c9f0d0..62cd63d4 100644 --- a/templates/campaign_results.html +++ b/templates/campaign_results.html @@ -13,6 +13,8 @@
  • Users & Groups
  • +
  • Templates +
  • Settings
  • API Documentation diff --git a/templates/dashboard.html b/templates/dashboard.html index fee9aa70..7d5f8bbe 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -13,6 +13,8 @@
  • Users & Groups
  • +
  • Templates +
  • Settings
  • API Documentation @@ -91,7 +93,7 @@ diff --git a/templates/settings.html b/templates/settings.html index a52a85e0..8cc15477 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -13,6 +13,8 @@
  • Users & Groups
  • +
  • Templates +
  • Settings
  • API Documentation diff --git a/templates/templates.html b/templates/templates.html new file mode 100644 index 00000000..8bc73e56 --- /dev/null +++ b/templates/templates.html @@ -0,0 +1,100 @@ +{{% define "content" %}} {{% template "nav" .User %}} +
    +
    +

    + Templates +

    +
    +
    +
    + +
    +
    + +
    +   +
    + + + + + + + +
    {{template.modified_date | date:'medium'}}{{template.name}} +
    + + +
    +
    +
    +
    + + +
    +{{%end%}} diff --git a/templates/users.html b/templates/users.html index 614e535b..9bacd1e8 100644 --- a/templates/users.html +++ b/templates/users.html @@ -13,6 +13,8 @@
  • Users & Groups
  • +
  • Templates +
  • Settings
  • API Documentation @@ -53,7 +55,7 @@ - +