mirror of https://github.com/gophish/gophish
Can now use Position in CSV import.
Added Position attribute to Target model. Fixes #17pull/24/head
parent
2948ea490a
commit
0b73d5f6ee
|
@ -31,6 +31,7 @@ type Target struct {
|
||||||
FirstName string `json:"first_name"`
|
FirstName string `json:"first_name"`
|
||||||
LastName string `json:"last_name"`
|
LastName string `json:"last_name"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
|
Position string `json:"position"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrGroupNameNotSpecified is thrown when a group name is not specified
|
// ErrGroupNameNotSpecified is thrown when a group name is not specified
|
||||||
|
@ -218,6 +219,6 @@ func insertTargetIntoGroup(t Target, gid int64) error {
|
||||||
// GetTargets performs a many-to-many select to get all the Targets for a Group
|
// GetTargets performs a many-to-many select to get all the Targets for a Group
|
||||||
func GetTargets(gid int64) ([]Target, error) {
|
func GetTargets(gid int64) ([]Target, error) {
|
||||||
ts := []Target{}
|
ts := []Target{}
|
||||||
err := db.Table("targets").Select("targets.id, targets.email, targets.first_name, targets.last_name").Joins("left join group_targets gt ON targets.id = gt.target_id").Where("gt.group_id=?", gid).Scan(&ts).Error
|
err := db.Table("targets").Select("targets.id, targets.email, targets.first_name, targets.last_name, targets.position").Joins("left join group_targets gt ON targets.id = gt.target_id").Where("gt.group_id=?", gid).Scan(&ts).Error
|
||||||
return ts, err
|
return ts, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -571,7 +571,8 @@ var GroupModalCtrl = function($scope, GroupService, $modalInstance, $upload) {
|
||||||
$scope.group.targets.push({
|
$scope.group.targets.push({
|
||||||
first_name : record.first_name,
|
first_name : record.first_name,
|
||||||
last_name : record.last_name,
|
last_name : record.last_name,
|
||||||
email: record.email
|
email: record.email,
|
||||||
|
position: record.position
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$scope.editGroupTableParams.reload();
|
$scope.editGroupTableParams.reload();
|
||||||
|
|
10
util/util.go
10
util/util.go
|
@ -25,6 +25,7 @@ func ParseMail(r *http.Request) (email.Email, error) {
|
||||||
return e, err
|
return e, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ParseCSV contains the logic to parse the user provided csv file containing Target entries
|
||||||
func ParseCSV(r *http.Request) ([]models.Target, error) {
|
func ParseCSV(r *http.Request) ([]models.Target, error) {
|
||||||
mr, err := r.MultipartReader()
|
mr, err := r.MultipartReader()
|
||||||
ts := []models.Target{}
|
ts := []models.Target{}
|
||||||
|
@ -50,11 +51,12 @@ func ParseCSV(r *http.Request) ([]models.Target, error) {
|
||||||
fi := -1
|
fi := -1
|
||||||
li := -1
|
li := -1
|
||||||
ei := -1
|
ei := -1
|
||||||
|
pi := -1
|
||||||
fn := ""
|
fn := ""
|
||||||
ln := ""
|
ln := ""
|
||||||
ea := ""
|
ea := ""
|
||||||
|
ps := ""
|
||||||
for i, v := range record {
|
for i, v := range record {
|
||||||
fmt.Println(v)
|
|
||||||
switch {
|
switch {
|
||||||
case v == "First Name":
|
case v == "First Name":
|
||||||
fi = i
|
fi = i
|
||||||
|
@ -62,6 +64,8 @@ func ParseCSV(r *http.Request) ([]models.Target, error) {
|
||||||
li = i
|
li = i
|
||||||
case v == "Email":
|
case v == "Email":
|
||||||
ei = i
|
ei = i
|
||||||
|
case v == "Position":
|
||||||
|
pi = i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
|
@ -78,10 +82,14 @@ func ParseCSV(r *http.Request) ([]models.Target, error) {
|
||||||
if ei != -1 {
|
if ei != -1 {
|
||||||
ea = record[ei]
|
ea = record[ei]
|
||||||
}
|
}
|
||||||
|
if pi != -1 {
|
||||||
|
ps = record[pi]
|
||||||
|
}
|
||||||
t := models.Target{
|
t := models.Target{
|
||||||
FirstName: fn,
|
FirstName: fn,
|
||||||
LastName: ln,
|
LastName: ln,
|
||||||
Email: ea,
|
Email: ea,
|
||||||
|
Position: ps,
|
||||||
}
|
}
|
||||||
ts = append(ts, t)
|
ts = append(ts, t)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue