Added "templates" Template, View, and Route

Added "unsafe" filter per stackoverflow
Updated side nav to include links to "/templates"
pull/24/head
Jordan 2014-03-18 15:20:34 -05:00
parent a3882cbf02
commit b3e3dd8ff1
7 changed files with 197 additions and 2 deletions

View File

@ -27,6 +27,7 @@ func CreateRouter() *nosurf.CSRFHandler {
router.HandleFunc("/campaigns/{id:[0-9]+}", Use(Campaigns_Id, mid.RequireLogin)) router.HandleFunc("/campaigns/{id:[0-9]+}", Use(Campaigns_Id, mid.RequireLogin))
router.HandleFunc("/users", Use(Users, mid.RequireLogin)) router.HandleFunc("/users", Use(Users, mid.RequireLogin))
router.HandleFunc("/settings", Use(Settings, mid.RequireLogin)) router.HandleFunc("/settings", Use(Settings, mid.RequireLogin))
router.HandleFunc("/templates", Use(Templates, mid.RequireLogin))
// Create the API routes // Create the API routes
api := router.PathPrefix("/api").Subrouter() api := router.PathPrefix("/api").Subrouter()
@ -137,6 +138,15 @@ func Users(w http.ResponseWriter, r *http.Request) {
getTemplate(w, "users").ExecuteTemplate(w, "base", params) 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) { func Settings(w http.ResponseWriter, r *http.Request) {
params := struct { params := struct {
User models.User User models.User

View File

@ -1,5 +1,11 @@
var app = angular.module('gophish', ['ngTable', 'ngResource', 'ui.bootstrap']); 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) { app.factory('CampaignService', function($resource) {
return $resource('/api/campaigns/:id?api_key=' + API_KEY, { return $resource('/api/campaigns/:id?api_key=' + API_KEY, {
id: "@id" 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) { app.controller('CampaignCtrl', function($scope, CampaignService, GroupService, ngTableParams, $http) {
$scope.flashes = [] $scope.flashes = []
$scope.mainTableParams = new ngTableParams({ $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();
});
}
})

View File

@ -13,6 +13,8 @@
</li> </li>
<li><a href="/users">Users &amp; Groups</a> <li><a href="/users">Users &amp; Groups</a>
</li> </li>
<li><a href="/templates">Templates</a>
</li>
<li><a href="/settings">Settings</a> <li><a href="/settings">Settings</a>
</li> </li>
<li><a href="/api/">API Documentation</a> <li><a href="/api/">API Documentation</a>

View File

@ -13,6 +13,8 @@
</li> </li>
<li><a href="/users">Users &amp; Groups</a> <li><a href="/users">Users &amp; Groups</a>
</li> </li>
<li><a href="/templates">Templates</a>
</li>
<li><a href="/settings">Settings</a> <li><a href="/settings">Settings</a>
</li> </li>
<li><a href="/api/">API Documentation</a> <li><a href="/api/">API Documentation</a>
@ -91,7 +93,7 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" ng-click="saveCampaign(campaign)" type="submit">Launch Campaign</button> <button type="button" class="btn btn-primary" data-dismiss="modal" ng-click="saveCampaign(campaign)" type="submit">Launch Campaign</button>
</div> </div>
</div> </div>
</div> </div>

View File

@ -13,6 +13,8 @@
</li> </li>
<li><a href="/users">Users &amp; Groups</a> <li><a href="/users">Users &amp; Groups</a>
</li> </li>
<li><a href="/templates">Templates</a>
</li>
<li class="active"><a href="/settings">Settings</a> <li class="active"><a href="/settings">Settings</a>
</li> </li>
<li><a href="/api/">API Documentation</a> <li><a href="/api/">API Documentation</a>

100
templates/templates.html Normal file
View File

@ -0,0 +1,100 @@
{{% define "content" %}} {{% template "nav" .User %}}
<div class="jumbotron">
<div class="container" style="text-align:center;">
<h1 class="sans header">
Templates
</h1>
</div>
</div>
<div class="container" ng-controller="TemplateCtrl">
<div class="col-md-3 sidebar">
<ul class="nav nav-pills nav-stacked">
<li><a href="/">Dashboard</a>
</li>
<li><a href="/users">Users &amp; Groups</a>
</li>
<li class="active"><a href="/templates">Templates</a>
</li>
<li><a href="/settings">Settings</a>
</li>
<li><a href="/api/">API Documentation</a>
</li>
</ul>
</div>
<div class="col-md-9">
<div class="row">
<button type="button" class="btn btn-primary" ng-click="editTemplate('new')" data-toggle="modal" data-target="#newTemplateModal"><i class="fa fa-plus"></i> New Template</button>
</div>
&nbsp;
<div class="row">
<table ng-table="mainTableParams" class="table table-hover table-striped table-bordered">
<tbody>
<tr ng-repeat="template in $data" class="editable-row">
<td data-title="'Modified Date'" class="col-sm-1">{{template.modified_date | date:'medium'}}</td>
<td data-title="'Name'" sortable="'name'" class="col-sm-2">{{template.name}}
<div class="btn-group" style="float: right;">
<button type="button" class="btn btn-primary dropdown-toggle edit-button" data-toggle="dropdown">
<span class="caret" style="border-top-color:#FFFFFF"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" style="left:auto; right:0;" role="menu">
<li><a ng-click="editTemplate(template)" data-toggle="modal" ng-href="#" data-target="#newTemplateModal">Edit</a>
</li>
<li class="divider"></li>
<li><a ng-click="deleteTemplate(template)" ng-href="#">Delete</a>
</li>
</ul>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- New Template Modal -->
<div class="modal" id="newTemplateModal" tabindex="-1" role="dialog" aria-labelledby="templateModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" ng-hide="newTemplate" id="groupModalLabel">Edit Template: {{template.name}}</h4>
<h4 class="modal-title" ng-show="newTemplate" id="groupModalLabel">New Template</h4>
</div>
<div class="modal-body">
<label class="control-label" for="name">Name:</label>
<div class="form-group">
<input type="text" class="form-control" ng-model="template.name" placeholder="Template name" id="name" />
</div>
<!-- Nav tabs -->
<ul class="nav nav-tabs">
<li class="active"><a href="#template_text" data-toggle="tab">Text</a>
</li>
<li><a href="#template_html" data-toggle="tab">HTML</a>
</li>
<li><a href="#template_preview" data-toggle="tab">Preview</a>
</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane active" id="template_text">
<textarea class="form-control" ng-model="template.text" placeholder="Plaintext"></textarea>
</div>
<div class="tab-pane" id="template_html">
<textarea class="form-control" ng-model="template.html" placeholder="HTML"></textarea>
</div>
<div class="tab-pane" id="template_preview" ng-bind-html="template.html | unsafe"></div>
</div>
<div class="form-group" style="margin-top:15px">
<button class="btn btn-danger"><i class="fa fa-plus"></i> Add Files</button>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" ng-click="saveTemplate(template)" data-dismiss="modal">Save Template</button>
</div>
</div>
</div>
</div>
</div>
{{%end%}}

View File

@ -13,6 +13,8 @@
</li> </li>
<li class="active"><a href="/users">Users &amp; Groups</a> <li class="active"><a href="/users">Users &amp; Groups</a>
</li> </li>
<li><a href="/templates">Templates</a>
</li>
<li><a href="/settings">Settings</a> <li><a href="/settings">Settings</a>
</li> </li>
<li><a href="/api/">API Documentation</a> <li><a href="/api/">API Documentation</a>
@ -53,7 +55,7 @@
</table> </table>
</div> </div>
</div> </div>
<!-- New Campaign Modal --> <!-- New Group Modal -->
<div class="modal" id="newGroupModal" tabindex="-1" role="dialog" aria-labelledby="groupModalLabel" aria-hidden="true"> <div class="modal" id="newGroupModal" tabindex="-1" role="dialog" aria-labelledby="groupModalLabel" aria-hidden="true">
<div class="modal-dialog"> <div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">