diff --git a/controllers/api.go b/controllers/api.go
index fe7be5ea..57c06b38 100644
--- a/controllers/api.go
+++ b/controllers/api.go
@@ -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)
diff --git a/gophish.go b/gophish.go
index 3e83147f..90d520fc 100644
--- a/gophish.go
+++ b/gophish.go
@@ -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()))
}
diff --git a/models/attachment.go b/models/attachment.go
index 49366eb8..996c3ea6 100644
--- a/models/attachment.go
+++ b/models/attachment.go
@@ -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"`
diff --git a/models/campaign.go b/models/campaign.go
index 81287a06..1720e529 100644
--- a/models/campaign.go
+++ b/models/campaign.go
@@ -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 {
diff --git a/models/template.go b/models/template.go
index 8017ed7c..d4e78dac 100644
--- a/models/template.go
+++ b/models/template.go
@@ -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
diff --git a/static/js/app/controllers.js b/static/js/app/controllers.js
index 5ff20f3b..9097615d 100644
--- a/static/js/app/controllers.js
+++ b/static/js/app/controllers.js
@@ -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) {
diff --git a/static/js/app/partials/campaign_results.html b/static/js/app/partials/campaign_results.html
index 316ecf24..aa31a503 100644
--- a/static/js/app/partials/campaign_results.html
+++ b/static/js/app/partials/campaign_results.html
@@ -52,7 +52,6 @@
-
{{campaign.created_date | date:'medium'}} | +{{campaign.name}}
+
+
+
+
+ |
+ {{campaign.status}} | +
{{campaign.created_date | date:'medium'}} | -{{campaign.name}}
-
-
-
-
- |
- {{campaign.status}} | -