Browse Source

Finished implementing PUT /templates/:id

Now deleting events on campaign deletion
Added some minor UI fixes and changes
pull/24/head
Jordan 7 years ago
parent
commit
86dca67a5a
10 changed files with 122 additions and 61 deletions
  1. +6
    -3
      controllers/api.go
  2. +5
    -2
      gophish.go
  3. +2
    -1
      models/attachment.go
  4. +5
    -0
      models/campaign.go
  5. +30
    -2
      models/template.go
  6. +7
    -3
      static/js/app/controllers.js
  7. +0
    -1
      static/js/app/partials/campaign_results.html
  8. +8
    -1
      static/js/app/partials/campaigns.html
  9. +46
    -42
      static/js/app/partials/dashboard.html
  10. +13
    -6
      static/js/app/partials/modals/templateModal.html

+ 6
- 3
controllers/api.go View File

@ -234,14 +234,17 @@ func API_Templates_Id(w http.ResponseWriter, r *http.Request) {
case r.Method == "PUT":
t = models.Template{}
err = json.NewDecoder(r.Body).Decode(&t)
if err != nil {
Logger.Println(err)
}
if t.Id != id {
http.Error(w, "Error: /:id and template_id mismatch", http.StatusBadRequest)
return
}
err = t.Validate()
/* if checkError(err, w, http.StatusBadRequest) {
return
}*/
/* if checkError(err, w, http.StatusBadRequest) {
return
}*/
t.ModifiedDate = time.Now()
t.UserId = ctx.Get(r, "user_id").(int64)
err = models.PutTemplate(&t)

+ 5
- 2
gophish.go View File

@ -27,6 +27,7 @@ THE SOFTWARE.
*/
import (
"fmt"
"log"
"net/http"
"os"
@ -36,6 +37,8 @@ import (
"github.com/jordan-wright/gophish/models"
)
var Logger = log.New(os.Stdout, " ", log.Ldate|log.Ltime|log.Lshortfile)
func main() {
// Setup the global variables and settings
err := models.Setup()
@ -43,8 +46,8 @@ func main() {
fmt.Println(err)
}
// Start the web servers
fmt.Printf("Admin server started at http://%s\n", config.Conf.AdminURL)
Logger.Printf("Admin server started at http://%s\n", config.Conf.AdminURL)
go http.ListenAndServe(config.Conf.AdminURL, handlers.CombinedLoggingHandler(os.Stdout, controllers.CreateAdminRouter()))
fmt.Printf("Phishing server started at http://%s\n", config.Conf.PhishURL)
Logger.Printf("Phishing server started at http://%s\n", config.Conf.PhishURL)
http.ListenAndServe(config.Conf.PhishURL, handlers.CombinedLoggingHandler(os.Stdout, controllers.CreatePhishingRouter()))
}

+ 2
- 1
models/attachment.go View File

@ -1,7 +1,8 @@
package models
type Attachment struct {
TemplateId string `json:"-"`
Id int64 `json:"-"`
TemplateId int64 `json:"-"`
Content string `json:"content"`
Type string `json:"type"`
Name string `json:"name"`

+ 5
- 0
models/campaign.go View File

@ -162,6 +162,11 @@ func DeleteCampaign(id int64) error {
Logger.Println(err)
return err
}
err = db.Where("campaign_id=?", id).Delete(&Event{}).Error
if err != nil {
Logger.Println(err)
return err
}
// Delete the campaign
err = db.Delete(&Campaign{Id: id}).Error
if err != nil {

+ 30
- 2
models/template.go View File

@ -82,13 +82,36 @@ func PostTemplate(t *Template) error {
Logger.Println(err)
return err
}
for i, _ := range t.Attachments {
Logger.Println(t.Attachments[i].Name)
t.Attachments[i].TemplateId = t.Id
err := db.Save(&t.Attachments[i]).Error
if err != nil {
Logger.Println(err)
return err
}
}
return nil
}
// PutTemplate edits an existing template in the database.
// Per the PUT Method RFC, it presumes all data for a template is provided.
func PutTemplate(t *Template) error {
err := db.Where("id=?", t.Id).Save(t).Error
// Delete all attachments, and replace with new ones
err := db.Where("template_id=?", t.Id).Delete(&Attachment{}).Error
if err != nil {
Logger.Println(err)
return err
}
for i, _ := range t.Attachments {
t.Attachments[i].TemplateId = t.Id
err := db.Save(&t.Attachments[i]).Error
if err != nil {
Logger.Println(err)
return err
}
}
err = db.Where("id=?", t.Id).Save(t).Error
if err != nil {
Logger.Println(err)
return err
@ -99,7 +122,12 @@ func PutTemplate(t *Template) error {
// DeleteTemplate deletes an existing template in the database.
// An error is returned if a template with the given user id and template id is not found.
func DeleteTemplate(id int64, uid int64) error {
err := db.Where("user_id=?", uid).Delete(Template{Id: id}).Error
err := db.Where("template_id=?", id).Delete(&Attachment{}).Error
if err != nil {
Logger.Println(err)
return err
}
err = db.Where("user_id=?", uid).Delete(Template{Id: id}).Error
if err != nil {
Logger.Println(err)
return err

+ 7
- 3
static/js/app/controllers.js View File

@ -600,7 +600,7 @@ app.controller('TemplateCtrl', function($scope, $modal, TemplateService, ngTable
name: '',
html: '',
text: '',
files: []
attachments: []
};
} else {
@ -654,11 +654,12 @@ app.controller('TemplateCtrl', function($scope, $modal, TemplateService, ngTable
})
var TemplateModalCtrl = function($scope, $upload, $modalInstance) {
var reader = new FileReader();
$scope.onFileSelect = function($files) {
console.log($files)
angular.forEach($files, function(file, key) {
var reader = new FileReader();
reader.onload = function(e) {
$scope.template.files.push({
$scope.template.attachments.push({
name : file.name,
content : reader.result.split(",")[1],
type : file.type || "application/octet-stream"
@ -678,6 +679,9 @@ var TemplateModalCtrl = function($scope, $upload, $modalInstance) {
$modalInstance.dismiss('')
$scope.saveTemplate(template)
};
$scope.removeFile = function(file) {
$scope.template.attachments.splice($scope.template.attachments.indexOf(file), 1);
}
};
app.controller('SettingsCtrl', function($scope, $http, $window) {

+ 0
- 1
static/js/app/partials/campaign_results.html View File

@ -52,7 +52,6 @@
</div>
</div>
</tab>
<tab heading="Timeline">Timeline here</tab>
<tab heading="Plugins">Plugins here</tab>
<tab heading="Demographics">Demographics here</tab>
</tabset>

+ 8
- 1
static/js/app/partials/campaigns.html View File

@ -31,7 +31,14 @@
<button type="button" class="btn btn-primary" ng-click="newCampaign()"><i class="fa fa-plus"></i> New Campaign</button>
</div>
&nbsp;
<div class="row">
<div ng-show="!campaigns.length">
<div class="row">
<div class="alert alert-info">
No campaigns yet.
</div>
</div>
</div>
<div ng-show="campaigns.length" class="row">
<table ng-table="mainTableParams" class="table table-hover table-striped table-bordered">
<tbody>
<tr ng-repeat="campaign in $data" class="editable-row">

+ 46
- 42
static/js/app/partials/dashboard.html View File

@ -22,51 +22,55 @@
<h1 class="page-header">
Dashboard
</h1>
<div class="row">
<div ng-repeat="flash in flashes" style="text-align:center" class="alert alert-{{flash.type}}">
<i class="fa {{flash.icon}}"></i> {{flash.message}}
<div ng-show="!campaigns.length">
<div class="row">
<div class="alert alert-info">
No campaigns yet.
</div>
</div>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<highchart config="overview_chart"></highchart>
<div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<highchart config="overview_chart"></highchart>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<highchart config="average_chart"></highchart>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<highchart config="average_chart"></highchart>
<div class="row">
<h2>Recent Campaigns</h2>
</div>
<div class="row">
<a href="#/campaigns"><button type="button" class="btn btn-primary">View All</button></a>
</div>
&nbsp;&nbsp;
<div class="row">
<table ng-table="mainTableParams" class="table table-hover table-striped table-bordered">
<tbody>
<tr ng-repeat="campaign in $data" class="editable-row">
<td data-title="'Created Date'" class="col-sm-1">{{campaign.created_date | date:'medium'}}</td>
<td data-title="'Name'" class="col-sm-2">{{campaign.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-href="#/campaigns/{{campaign.id}}">View</a>
</li>
<li><a href="/campaigns/{{campaign.id}}/relaunch">Relaunch</a>
</li>
<li class="divider"></li>
<li><a ng-click="deleteCampaign(campaign)" ng-href="#">Delete</a>
</li>
</ul>
</div>
</td>
<td data-title="'Status'" class="col-sm-1">{{campaign.status}}</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row">
<h2>Recent Campaigns</h2>
</div>
<div class="row">
<a href="#/campaigns"><button type="button" class="btn btn-primary">View All</button></a>
</div>
&nbsp;&nbsp;
<div class="row">
<table ng-table="mainTableParams" class="table table-hover table-striped table-bordered">
<tbody>
<tr ng-repeat="campaign in $data" class="editable-row">
<td data-title="'Created Date'" class="col-sm-1">{{campaign.created_date | date:'medium'}}</td>
<td data-title="'Name'" class="col-sm-2">{{campaign.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-href="#/campaigns/{{campaign.id}}">View</a>
</li>
<li><a href="/campaigns/{{campaign.id}}/relaunch">Relaunch</a>
</li>
<li class="divider"></li>
<li><a ng-click="deleteCampaign(campaign)" ng-href="#">Delete</a>
</li>
</ul>
</div>
</td>
<td data-title="'Status'" class="col-sm-1">{{campaign.status}}</td>
</tr>
</tbody>
</table>
</div>
</div>

+ 13
- 6
static/js/app/partials/modals/templateModal.html View File

@ -31,17 +31,24 @@
</tab>
</tabset>
<br />
<span class="btn btn-danger btn-file"><i class="fa fa-plus"></i> Add Files (Coming Soon!)
<input type="file" ng-file-select="onFileSelect($files)">
</span>
<div ng-repeat="file in template.files" ng-model="template.files">
<label class="control-label" ng-hide="template.attachments.length == 0">Files:</label>
<div ng-repeat="file in template.attachments" ng-model="template.attachments">
<i class="fa fa-file-excel-o" ng-show="file.type == 'application/vnd.ms-excel'"></i>
<i class="fa fa-file-text-o" ng-show="file.type == 'text/plain'"></i>
<i class="fa fa-file-image-o" ng-show="file.type == 'image/gif'"></i>
<i class="fa fa-file" ng-show="file.type == 'application/octet-stream'"></i>
<i class="fa fa-file-pdf-o" ng-show="file.type == 'application/pdf'"></i>
<i class="fa fa-file-archive-o" ng-show="file.type == 'application/x-zip-compressed' || file.type == 'application/x-gzip'"></i>
<i class="fa fa-file-powerpoint-o" ng-show="file.type == 'application/vnd.openxmlformats-officedocument.presentationml.presentation'"></i>
<i class="fa fa-file-word-o" ng-show="file.type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'"></i>
<i class="fa fa-file-o" ng-show="file.type == 'application/octet-stream' || file.type == 'application/x-msdownload'"></i>
&nbsp;{{file.name}}
{{file.type}}
<span ng-click="removeFile(file)" class="remove-row"><i class="fa fa-trash-o"></i>
</span>
</div>
<br/>
<span class="btn btn-danger btn-file"><i class="fa fa-plus"></i> Add Files
<input type="file" ng-file-select="onFileSelect($files)" multiple>
</span>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="cancel()">Cancel</button>

Loading…
Cancel
Save