mirror of https://github.com/gophish/gophish
Finished implementing PUT /templates/:id
Now deleting events on campaign deletion Added some minor UI fixes and changespull/24/head
parent
533742d833
commit
86dca67a5a
|
@ -234,6 +234,9 @@ 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
|
||||
|
|
|
@ -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()))
|
||||
}
|
||||
|
|
|
@ -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"`
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -31,7 +31,14 @@
|
|||
<button type="button" class="btn btn-primary" ng-click="newCampaign()"><i class="fa fa-plus"></i> New Campaign</button>
|
||||
</div>
|
||||
|
||||
<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">
|
||||
|
|
|
@ -22,11 +22,14 @@
|
|||
<h1 class="page-header">
|
||||
Dashboard
|
||||
</h1>
|
||||
<div ng-show="!campaigns.length">
|
||||
<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 class="alert alert-info">
|
||||
No campaigns yet.
|
||||
</div>
|
||||
</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>
|
||||
|
@ -70,3 +73,4 @@
|
|||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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>
|
||||
{{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…
Reference in New Issue