2020-02-11 21:06:34 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
/* global angular:false */
|
|
|
|
|
/* global $:false */
|
|
|
|
|
|
|
|
|
|
angular.module('Application').controller('EmailsController', ['$scope', '$location', 'Client', function ($scope, $location, Client) {
|
|
|
|
|
Client.onReady(function () { if (!Client.getUserInfo().admin) $location.path('/'); });
|
|
|
|
|
|
|
|
|
|
$scope.ready = false;
|
|
|
|
|
$scope.config = Client.getConfig();
|
2020-02-12 14:51:06 +01:00
|
|
|
$scope.user = Client.getUserInfo();
|
2020-02-11 21:06:34 +01:00
|
|
|
$scope.domains = [];
|
|
|
|
|
|
2020-02-11 22:07:58 -08:00
|
|
|
$scope.activity = {
|
2020-02-12 15:37:05 +01:00
|
|
|
busy: true,
|
|
|
|
|
eventLogs: [],
|
|
|
|
|
activeEventLog: null,
|
2020-02-11 22:07:58 -08:00
|
|
|
currentPage: 1,
|
2020-02-12 15:37:05 +01:00
|
|
|
perPage: 1000,
|
2020-02-11 22:07:58 -08:00
|
|
|
|
|
|
|
|
fetchEventLogs: function () {
|
2020-02-12 15:37:05 +01:00
|
|
|
$scope.activity.busy = true;
|
|
|
|
|
|
2020-02-11 22:07:58 -08:00
|
|
|
Client.getMailEventLogs($scope.activity.currentPage, $scope.activity.perPage, function (error, result) {
|
2020-02-12 15:37:05 +01:00
|
|
|
if (error) return console.error('Failed to fetch mail eventlogs.', error);
|
|
|
|
|
|
|
|
|
|
$scope.activity.busy = false;
|
|
|
|
|
|
|
|
|
|
// FIXME reverse should come from the server
|
|
|
|
|
$scope.activity.eventLogs = result.reverse();
|
2020-02-11 22:07:58 -08:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
showNextPage: function () {
|
|
|
|
|
$scope.activity.currentPage++;
|
|
|
|
|
$scope.activity.fetchEventLogs();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
showPrevPage: function () {
|
|
|
|
|
if ($scope.activity.currentPage > 1) $scope.activity.currentPage--;
|
|
|
|
|
else $scope.activity.currentPage = 1;
|
|
|
|
|
$scope.activity.fetchEventLogs();
|
2020-02-12 15:37:05 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
showEventLogDetails: function (eventLog) {
|
|
|
|
|
if ($scope.activity.activeEventLog === eventLog) $scope.activity.activeEventLog = null;
|
|
|
|
|
else $scope.activity.activeEventLog = eventLog;
|
2020-02-11 22:07:58 -08:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-12 14:51:06 +01:00
|
|
|
$scope.testEmail = {
|
|
|
|
|
busy: false,
|
|
|
|
|
error: {},
|
|
|
|
|
|
|
|
|
|
mailTo: '',
|
|
|
|
|
|
|
|
|
|
domain: null,
|
|
|
|
|
|
|
|
|
|
clearForm: function () {
|
|
|
|
|
$scope.testEmail.mailTo = '';
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
show: function (domain) {
|
|
|
|
|
$scope.testEmail.error = {};
|
|
|
|
|
$scope.testEmail.busy = false;
|
|
|
|
|
|
|
|
|
|
$scope.testEmail.domain = domain;
|
|
|
|
|
$scope.testEmail.mailTo = $scope.user.email;
|
|
|
|
|
|
|
|
|
|
$('#testEmailModal').modal('show');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
submit: function () {
|
|
|
|
|
$scope.testEmail.error = {};
|
|
|
|
|
$scope.testEmail.busy = true;
|
|
|
|
|
|
|
|
|
|
Client.sendTestMail($scope.testEmail.domain.domain, $scope.testEmail.mailTo, function (error) {
|
|
|
|
|
$scope.testEmail.busy = false;
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
$scope.testEmail.error.generic = error.message;
|
|
|
|
|
console.error(error);
|
|
|
|
|
$('#inputTestMailTo').focus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$('#testEmailModal').modal('hide');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-12 14:10:21 +01:00
|
|
|
function refreshDomainStatuses() {
|
|
|
|
|
$scope.domains.forEach(function (domain) {
|
|
|
|
|
Client.getMailStatusForDomain(domain.domain, function (error, result) {
|
|
|
|
|
if (error) return console.error('Failed to fetch mail status for domain', domain.domain, error);
|
|
|
|
|
|
|
|
|
|
domain.status = result;
|
|
|
|
|
domain.statusOk = result.rbl.status && result.relay.status && result.dns.dkim.status && result.dns.dmarc.status && result.dns.mx.status && result.dns.ptr.status && result.dns.spf.status;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
Client.onReady(function () {
|
|
|
|
|
Client.getDomains(function (error, domains) {
|
|
|
|
|
if (error) return console.error('Unable to get domain listing.', error);
|
|
|
|
|
|
|
|
|
|
$scope.domains = domains;
|
|
|
|
|
$scope.ready = true;
|
2020-02-11 22:07:58 -08:00
|
|
|
|
|
|
|
|
$scope.activity.fetchEventLogs();
|
2020-02-12 14:10:21 +01:00
|
|
|
refreshDomainStatuses();
|
2020-02-11 21:06:34 +01:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-02-12 14:51:06 +01:00
|
|
|
// setup all the dialog focus handling
|
|
|
|
|
['testEmailModal'].forEach(function (id) {
|
|
|
|
|
$('#' + id).on('shown.bs.modal', function () {
|
|
|
|
|
$(this).find('[autofocus]:first').focus();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-02-11 21:06:34 +01:00
|
|
|
$('.modal-backdrop').remove();
|
|
|
|
|
}]);
|