2014-02-18 02:46:57 +00:00
|
|
|
var app = angular.module('gophish', ['ngTable', 'ngResource', 'ui.bootstrap']);
|
2014-02-08 01:40:16 +00:00
|
|
|
|
|
|
|
app.factory('CampaignService', function($resource) {
|
2014-02-18 02:46:57 +00:00
|
|
|
return $resource('/api/campaigns/:id?api_key=' + API_KEY, {
|
|
|
|
id: "@id"
|
|
|
|
}, {
|
2014-02-08 21:16:36 +00:00
|
|
|
update: {
|
|
|
|
method: 'PUT'
|
|
|
|
}
|
|
|
|
});
|
2014-02-08 01:40:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
app.factory('GroupService', function($resource) {
|
2014-02-18 02:46:57 +00:00
|
|
|
return $resource('/api/groups/:id?api_key=' + API_KEY, {
|
|
|
|
id: "@id"
|
|
|
|
}, {
|
2014-02-08 21:16:36 +00:00
|
|
|
update: {
|
|
|
|
method: 'PUT'
|
|
|
|
}
|
|
|
|
});
|
2014-02-08 01:40:16 +00:00
|
|
|
});
|
|
|
|
|
2014-03-13 02:49:10 +00:00
|
|
|
app.controller('CampaignCtrl', function($scope, CampaignService, GroupService, ngTableParams, $http) {
|
2014-02-20 01:40:23 +00:00
|
|
|
$scope.flashes = []
|
2014-02-18 20:22:16 +00:00
|
|
|
$scope.mainTableParams = new ngTableParams({
|
2014-02-10 15:44:15 +00:00
|
|
|
page: 1, // show first page
|
|
|
|
count: 10, // count per page
|
|
|
|
sorting: {
|
|
|
|
name: 'asc' // initial sorting
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
total: 0, // length of data
|
|
|
|
getData: function($defer, params) {
|
|
|
|
CampaignService.query(function(campaigns) {
|
|
|
|
$scope.campaigns = campaigns
|
|
|
|
params.total(campaigns.length)
|
|
|
|
$defer.resolve(campaigns.slice((params.page() - 1) * params.count(), params.page() * params.count()));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
2014-02-18 02:46:57 +00:00
|
|
|
|
2014-03-13 02:49:10 +00:00
|
|
|
GroupService.query(function(groups) {
|
|
|
|
$scope.groups = groups;
|
|
|
|
})
|
|
|
|
|
2014-02-18 02:46:57 +00:00
|
|
|
$scope.addGroup = function() {
|
|
|
|
if ($scope.group.name != "") {
|
|
|
|
$scope.campaign.groups.push({
|
|
|
|
name: $scope.group.name
|
|
|
|
});
|
|
|
|
$scope.group.name = ""
|
|
|
|
$scope.editGroupTableParams.reload()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.removeGroup = function(group) {
|
|
|
|
$scope.campaign.groups.splice($scope.campaign.groups.indexOf(group), 1);
|
|
|
|
$scope.editGroupTableParams.reload()
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.newCampaign = function() {
|
|
|
|
$scope.campaign = {
|
|
|
|
name: '',
|
|
|
|
groups: []
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.editGroupTableParams = 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) {
|
|
|
|
params.total($scope.campaign.groups.length)
|
|
|
|
$defer.resolve($scope.campaign.groups.slice((params.page() - 1) * params.count(), params.page() * params.count()));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.saveCampaign = function(campaign) {
|
2014-02-20 01:40:23 +00:00
|
|
|
$scope.flashes = []
|
2014-02-18 02:46:57 +00:00
|
|
|
var newCampaign = new CampaignService(campaign);
|
|
|
|
newCampaign.$save({}, function() {
|
|
|
|
$scope.campaigns.push(newCampaign);
|
|
|
|
$scope.mainTableParams.reload()
|
2014-02-20 01:40:23 +00:00
|
|
|
}, function(response){
|
|
|
|
$scope.errorFlash(response.data)
|
2014-02-18 02:46:57 +00:00
|
|
|
});
|
2014-02-20 01:40:23 +00:00
|
|
|
$scope.campaign = {
|
|
|
|
groups: [],
|
2014-02-18 02:46:57 +00:00
|
|
|
};
|
|
|
|
$scope.editGroupTableParams.reload()
|
|
|
|
}
|
2014-02-18 20:22:16 +00:00
|
|
|
|
|
|
|
$scope.deleteCampaign = function(campaign) {
|
|
|
|
var deleteCampaign = new CampaignService(campaign);
|
|
|
|
deleteCampaign.$delete({
|
|
|
|
id: deleteCampaign.id
|
|
|
|
}, function() {
|
|
|
|
$scope.mainTableParams.reload();
|
|
|
|
});
|
|
|
|
}
|
2014-02-20 01:40:23 +00:00
|
|
|
|
|
|
|
$scope.errorFlash = function(message) {
|
|
|
|
$scope.flashes.push({"type" : "danger", "message" : message, "icon" : "fa-exclamation-circle"})
|
|
|
|
}
|
2014-02-08 01:40:16 +00:00
|
|
|
});
|
|
|
|
|
2014-02-10 07:15:36 +00:00
|
|
|
app.controller('GroupCtrl', function($scope, GroupService, ngTableParams) {
|
2014-02-10 15:44:15 +00:00
|
|
|
$scope.mainTableParams = new ngTableParams({
|
2014-02-10 07:15:36 +00:00
|
|
|
page: 1, // show first page
|
|
|
|
count: 10, // count per page
|
|
|
|
sorting: {
|
2014-02-10 15:44:15 +00:00
|
|
|
name: 'asc' // initial sorting
|
2014-02-10 07:15:36 +00:00
|
|
|
}
|
|
|
|
}, {
|
|
|
|
total: 0, // length of data
|
|
|
|
getData: function($defer, params) {
|
|
|
|
GroupService.query(function(groups) {
|
|
|
|
$scope.groups = groups
|
|
|
|
params.total(groups.length)
|
|
|
|
$defer.resolve(groups.slice((params.page() - 1) * params.count(), params.page() * params.count()));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
});
|
2014-02-08 01:40:16 +00:00
|
|
|
|
2014-02-10 15:44:15 +00:00
|
|
|
$scope.editGroupTableParams = 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) {
|
|
|
|
params.total($scope.group.targets.length)
|
|
|
|
$defer.resolve($scope.group.targets.slice((params.page() - 1) * params.count(), params.page() * params.count()));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-02-08 01:40:16 +00:00
|
|
|
$scope.editGroup = function(group) {
|
|
|
|
if (group === 'new') {
|
|
|
|
$scope.newGroup = true;
|
|
|
|
$scope.group = {
|
|
|
|
name: '',
|
2014-02-08 21:16:36 +00:00
|
|
|
targets: [],
|
2014-02-08 01:40:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$scope.newGroup = false;
|
|
|
|
$scope.group = group;
|
2014-02-10 15:44:15 +00:00
|
|
|
$scope.editGroupTableParams.reload()
|
2014-02-08 01:40:16 +00:00
|
|
|
}
|
|
|
|
};
|
2014-02-08 21:16:36 +00:00
|
|
|
|
|
|
|
$scope.addTarget = function() {
|
|
|
|
if ($scope.newTarget.email != "") {
|
|
|
|
$scope.group.targets.push({
|
|
|
|
email: $scope.newTarget.email
|
|
|
|
});
|
|
|
|
$scope.newTarget.email = ""
|
2014-02-10 15:44:15 +00:00
|
|
|
$scope.editGroupTableParams.reload()
|
2014-02-08 21:16:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
$scope.removeTarget = function(target) {
|
|
|
|
$scope.group.targets.splice($scope.group.targets.indexOf(target), 1);
|
2014-02-10 15:44:15 +00:00
|
|
|
$scope.editGroupTableParams.reload()
|
2014-02-08 21:16:36 +00:00
|
|
|
};
|
2014-02-10 01:34:47 +00:00
|
|
|
$scope.saveGroup = function(group) {
|
2014-02-13 18:05:22 +00:00
|
|
|
var newGroup = new GroupService(group);
|
2014-02-10 01:34:47 +00:00
|
|
|
if ($scope.newGroup) {
|
2014-02-18 02:46:57 +00:00
|
|
|
newGroup.$save({}, function() {
|
2014-02-10 01:34:47 +00:00
|
|
|
$scope.groups.push(newGroup);
|
2014-02-10 19:02:44 +00:00
|
|
|
$scope.mainTableParams.reload()
|
2014-02-10 01:34:47 +00:00
|
|
|
});
|
2014-02-10 07:15:36 +00:00
|
|
|
} else {
|
2014-02-18 02:46:57 +00:00
|
|
|
newGroup.$update({
|
|
|
|
id: newGroup.id
|
|
|
|
})
|
2014-02-10 01:34:47 +00:00
|
|
|
}
|
2014-02-10 19:02:44 +00:00
|
|
|
$scope.group = {
|
2014-02-18 02:46:57 +00:00
|
|
|
name: '',
|
|
|
|
targets: [],
|
|
|
|
};
|
2014-02-10 19:02:44 +00:00
|
|
|
$scope.editGroupTableParams.reload()
|
2014-02-10 01:34:47 +00:00
|
|
|
}
|
2014-02-13 18:05:22 +00:00
|
|
|
$scope.deleteGroup = function(group) {
|
|
|
|
var deleteGroup = new GroupService(group);
|
2014-02-18 02:46:57 +00:00
|
|
|
deleteGroup.$delete({
|
|
|
|
id: deleteGroup.id
|
|
|
|
}, function() {
|
2014-02-13 18:05:22 +00:00
|
|
|
$scope.mainTableParams.reload();
|
|
|
|
});
|
|
|
|
}
|
2014-02-08 01:40:16 +00:00
|
|
|
})
|