diff --git a/mailServer/templates/mailServer/changeEmailPassword.html b/mailServer/templates/mailServer/changeEmailPassword.html index 6047d301d..f0dbaa2e9 100644 --- a/mailServer/templates/mailServer/changeEmailPassword.html +++ b/mailServer/templates/mailServer/changeEmailPassword.html @@ -20,6 +20,19 @@
+ {% if not status %} + +
+

{% trans "Postfix is disabled." %} +

+
+ + + {% else %} +
@@ -93,6 +106,8 @@
+ {% endif %} + diff --git a/mailServer/templates/mailServer/createEmailAccount.html b/mailServer/templates/mailServer/createEmailAccount.html index ff1b38ffc..dcfea33db 100644 --- a/mailServer/templates/mailServer/createEmailAccount.html +++ b/mailServer/templates/mailServer/createEmailAccount.html @@ -20,6 +20,19 @@
+ {% if not status %} + +
+

{% trans "Postfix is disabled." %} +

+
+ + + {% else %} +
@@ -88,6 +101,8 @@
+ {% endif %} + diff --git a/mailServer/templates/mailServer/deleteEmailAccount.html b/mailServer/templates/mailServer/deleteEmailAccount.html index 1d451b2f0..dd5dad0e8 100644 --- a/mailServer/templates/mailServer/deleteEmailAccount.html +++ b/mailServer/templates/mailServer/deleteEmailAccount.html @@ -20,6 +20,19 @@
+ {% if not status %} + +
+

{% trans "Postfix is disabled." %} +

+
+ + + {% else %} +
@@ -92,6 +105,8 @@
+ {% endif %} + diff --git a/mailServer/templates/mailServer/emailForwarding.html b/mailServer/templates/mailServer/emailForwarding.html index cb0c1bceb..82c76ec1d 100644 --- a/mailServer/templates/mailServer/emailForwarding.html +++ b/mailServer/templates/mailServer/emailForwarding.html @@ -20,6 +20,19 @@
+ {% if not status %} + +
+

{% trans "Postfix is disabled." %} +

+
+ + + {% else %} +
@@ -118,6 +131,8 @@
+ {% endif %} + diff --git a/mailServer/views.py b/mailServer/views.py index 6630ebe71..58d58518a 100644 --- a/mailServer/views.py +++ b/mailServer/views.py @@ -18,6 +18,7 @@ import thread from dns.models import Domains as dnsDomains from dns.models import Records as dnsRecords from mailServer.models import Forwardings +import os def loadEmailHome(request): try: @@ -31,6 +32,10 @@ def createEmailAccount(request): try: val = request.session['userID'] try: + + if not os.path.exists('/home/cyberpanel/postfix'): + return render(request, "mailServer/createEmailAccount.html", {"status": 0}) + admin = Administrator.objects.get(pk=val) if admin.type == 1: @@ -43,7 +48,7 @@ def createEmailAccount(request): for items in websites: websitesName.append(items.domain) - return render(request, 'mailServer/createEmailAccount.html', {'websiteList':websitesName}) + return render(request, 'mailServer/createEmailAccount.html', {'websiteList':websitesName, "status": 1}) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg)) return HttpResponse(str(msg)) @@ -97,6 +102,10 @@ def deleteEmailAccount(request): try: val = request.session['userID'] try: + + if not os.path.exists('/home/cyberpanel/postfix'): + return render(request, "mailServer/deleteEmailAccount.html", {"status": 0}) + admin = Administrator.objects.get(pk=val) if admin.type == 1: @@ -109,7 +118,7 @@ def deleteEmailAccount(request): for items in websites: websitesName.append(items.domain) - return render(request, 'mailServer/deleteEmailAccount.html', {'websiteList':websitesName}) + return render(request, 'mailServer/deleteEmailAccount.html', {'websiteList':websitesName, "status": 1}) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg)) return HttpResponse(str(msg)) @@ -210,6 +219,10 @@ def emailForwarding(request): try: val = request.session['userID'] try: + + if not os.path.exists('/home/cyberpanel/postfix'): + return render(request, "mailServer/emailForwarding.html", {"status": 0}) + admin = Administrator.objects.get(pk=val) if admin.type == 1: @@ -222,7 +235,7 @@ def emailForwarding(request): for items in websites: websitesName.append(items.domain) - return render(request, 'mailServer/emailForwarding.html', {'websiteList':websitesName}) + return render(request, 'mailServer/emailForwarding.html', {'websiteList':websitesName, "status": 1}) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg)) return HttpResponse(str(msg)) @@ -363,7 +376,11 @@ def changeEmailAccountPassword(request): try: val = request.session['userID'] try: - admin = Administrator.objects.get(pk=request.session['userID']) + + if not os.path.exists('/home/cyberpanel/postfix'): + return render(request, "mailServer/changeEmailPassword.html", {"status": 0}) + + admin = Administrator.objects.get(pk=val) if admin.type == 1: websites = Websites.objects.all() @@ -375,7 +392,7 @@ def changeEmailAccountPassword(request): for items in websites: websitesName.append(items.domain) - return render(request, 'mailServer/changeEmailPassword.html', {'websiteList':websitesName}) + return render(request, 'mailServer/changeEmailPassword.html', {'websiteList':websitesName, "status": 1}) except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg)) return HttpResponse(str(msg)) diff --git a/manageServices/static/manageServices/manageServices.js b/manageServices/static/manageServices/manageServices.js index cc0a255fa..b05f712d8 100644 --- a/manageServices/static/manageServices/manageServices.js +++ b/manageServices/static/manageServices/manageServices.js @@ -2,965 +2,8 @@ * Created by usman on 6/22/18. */ -/* Java script code to list accounts */ -app.controller('listDomains', function($scope,$http) { - - $scope.listFail = true; - $scope.emailLimitsLoading = true; - - // Global page number, to be used in later function to refresh the domains - var globalPageNumber; - - - $scope.getFurtherWebsitesFromDB = function(pageNumber) { - - globalPageNumber = pageNumber; - $scope.emailLimitsLoading = false; - - url = "/emailPremium/getFurtherDomains"; - - var data = {page: pageNumber}; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - - $scope.emailLimitsLoading = true; - - if (response.data.listWebSiteStatus === 1) { - - $scope.WebSitesList = JSON.parse(response.data.data); - $scope.listFail = true; - } - else - { - $scope.listFail = false; - $scope.errorMessage = response.data.error_message; - - } - } - function cantLoadInitialData(response) { - $scope.emailLimitsLoading = true; - $scope.listFail = false; - } - - - }; - $scope.getFurtherWebsitesFromDB(1); - - $scope.enableDisableEmailLimits = function (operationVal, domainName) { - - $scope.emailLimitsLoading = false; - - - url = "/emailPremium/enableDisableEmailLimits"; - - var data = { - operationVal: operationVal, - domainName: domainName - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - $scope.emailLimitsLoading = true; - - if (response.data.status === 1) { - - $scope.getFurtherWebsitesFromDB(globalPageNumber); - $scope.listFail = true; - } - else - { - $scope.listFail = false; - $scope.errorMessage = response.data.error_message; - - } - } - function cantLoadInitialData(response) { - $scope.emailLimitsLoading = true; - $scope.listFail = false; - } - } -}); - -/* Java script code to list accounts ends here */ - - - -/* Java script code for email domain page */ - -app.controller('emailDomainPage', function($scope,$http, $timeout, $window) { - - $scope.listFail = true; - $scope.emailLimitsLoading = true; - - var globalDomainName = window.location.pathname.split("/")[2]; - - // Global page number, to be used in later function to refresh the domains - var globalPageNumber; - - - $scope.getFurtherEmailsFromDB = function(pageNumber) { - - globalPageNumber = pageNumber; - $scope.emailLimitsLoading = false; - - url = "/emailPremium/getFurtherEmail"; - - var data = { - page: pageNumber, - domainName: globalDomainName - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - - $scope.emailLimitsLoading = true; - - if (response.data.status === 1) { - - $scope.emailList = JSON.parse(response.data.data); - $scope.listFail = true; - } - else - { - $scope.listFail = false; - $scope.errorMessage = response.data.error_message; - - } - } - function cantLoadInitialData(response) { - $scope.emailLimitsLoading = true; - $scope.listFail = false; - } - - - }; - $scope.getFurtherEmailsFromDB(1); - - $scope.enableDisableEmailLimits = function (operationVal, domainName) { - - $scope.emailLimitsLoading = false; - - - url = "/emailPremium/enableDisableEmailLimits"; - - var data = { - operationVal: operationVal, - domainName: domainName - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - $scope.emailLimitsLoading = true; - - if (response.data.status === 1) { - - $timeout(function() { $window.location.reload(); }, 0); - } - else - { - $timeout(function() { $window.location.reload(); }, 0); - } - } - function cantLoadInitialData(response) { - $timeout(function() { $window.location.reload(); }, 0); - } - }; - - - /// Email limits - - $scope.changeLimitsForm = true; - $scope.changeLimitsFail = true; - $scope.changeLimitsSuccess = true; - $scope.couldNotConnect = true; - - $scope.showLimitsForm = function () { - $scope.changeLimitsForm = false; - }; - - $scope.hideLimitsForm = function () { - $scope.changeLimitsForm = true; - $scope.changeLimitsFail = true; - $scope.changeLimitsSuccess = true; - $scope.couldNotConnect = true; - }; - - $scope.changeDomainEmailLimits = function (domainName) { - $scope.emailLimitsLoading = false; - - url = "/emailPremium/changeDomainLimit"; - - var data = { - domainName: domainName, - newLimit: $scope.monthlyLimit - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - - $scope.emailLimitsLoading = true; - - - if (response.data.status === 1) { - - $scope.changeLimitsForm = false; - $scope.changeLimitsFail = true; - $scope.changeLimitsSuccess = false; - $scope.couldNotConnect = true; - $timeout(function() { $window.location.reload(); }, 3000); - } - else - { - $scope.changeLimitsForm = false; - $scope.changeLimitsFail = false; - $scope.changeLimitsSuccess = true; - $scope.couldNotConnect = true; - $scope.errorMessage = response.data.error_message; - - } - } - function cantLoadInitialData(response) { - $scope.emailLimitsLoading = true; - $scope.changeLimitsForm = false; - $scope.changeLimitsFail = true; - $scope.changeLimitsSuccess = true; - $scope.couldNotConnect = false; - } - } - - - $scope.enableDisableIndividualEmailLimits = function (operationVal, emailAddress) { - - $scope.emailLimitsLoading = false; - - - url = "/emailPremium/enableDisableIndividualEmailLimits"; - - var data = { - operationVal: operationVal, - emailAddress: emailAddress - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - $scope.emailLimitsLoading = true; - - if (response.data.status === 1) { - $scope.getFurtherEmailsFromDB(1); - } - else - { - $scope.getFurtherEmailsFromDB(1); - } - } - function cantLoadInitialData(response) { - $scope.getFurtherEmailsFromDB(1); - } - }; - -}); - -/* Java script code for email domain page */ - - -/* Java script code for Email Page */ - -app.controller('emailPage', function($scope,$http, $timeout, $window) { - - $scope.emailLimitsLoading = true; - - var globalEamilAddress = $("#emailAddress").text(); - - // Global page number, to be used in later function to refresh the domains - var globalPageNumber; - - $scope.getEmailStats = function() { - - $scope.emailLimitsLoading = false; - - //// - - $scope.limitsOn = true; - $scope.limitsOff = true; - - url = "/emailPremium/getEmailStats"; - - var data = { - emailAddress: globalEamilAddress - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - - $scope.emailLimitsLoading = true; - - if (response.data.status === 1) { - - $scope.monthlyLimit = response.data.monthlyLimit; - $scope.monthlyUsed = response.data.monthlyUsed; - $scope.hourlyLimit = response.data.hourlyLimit; - $scope.hourlyUsed = response.data.hourlyUsed; - - if(response.data.limitStatus === 1){ - $scope.limitsOn = false; - $scope.limitsOff = true; - }else{ - $scope.limitsOn = true; - $scope.limitsOff = false; - } - - if(response.data.logsStatus === 1){ - $scope.loggingOn = false; - $scope.loggingOff = true; - }else{ - $scope.loggingOn = true; - $scope.loggingOff = false; - } - - } - else - { - - $scope.errorMessage = response.data.error_message; - - } - } - function cantLoadInitialData(response) { - $scope.emailLimitsLoading = true; - $scope.listFail = false; - } - - - }; - $scope.getEmailStats(); - - $scope.enableDisableIndividualEmailLimits = function (operationVal, emailAddress) { - - $scope.emailLimitsLoading = false; - - - url = "/emailPremium/enableDisableIndividualEmailLimits"; - - var data = { - operationVal: operationVal, - emailAddress: emailAddress - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - $scope.emailLimitsLoading = true; - - if (response.data.status === 1) { - $scope.getEmailStats(); - } - else - { - $scope.getEmailStats(); - } - } - function cantLoadInitialData(response) { - $scope.getEmailStats(); - } - }; - $scope.enableDisableIndividualEmailLogs = function (operationVal, emailAddress) { - - $scope.emailLimitsLoading = false; - - - url = "/emailPremium/enableDisableIndividualEmailLogs"; - - var data = { - operationVal: operationVal, - emailAddress: emailAddress - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - $scope.emailLimitsLoading = true; - - if (response.data.status === 1) { - $scope.getEmailStats(); - } - else - { - $scope.getEmailStats(); - } - } - function cantLoadInitialData(response) { - $scope.getEmailStats(); - } - }; - - - $scope.enableDisableEmailLimits = function (operationVal, domainName) { - - $scope.emailLimitsLoading = false; - - - url = "/emailPremium/enableDisableEmailLimits"; - - var data = { - operationVal: operationVal, - domainName: domainName - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - $scope.emailLimitsLoading = true; - - if (response.data.status === 1) { - - $timeout(function() { $window.location.reload(); }, 0); - } - else - { - $timeout(function() { $window.location.reload(); }, 0); - } - } - function cantLoadInitialData(response) { - $timeout(function() { $window.location.reload(); }, 0); - } - }; - - - /// Email limits - $scope.changeLimitsForm = true; - $scope.changeLimitsFail = true; - $scope.changeLimitsSuccess = true; - $scope.couldNotConnect = true; - - $scope.showLimitsForm = function () { - $scope.changeLimitsForm = false; - }; - - $scope.hideLimitsForm = function () { - $scope.changeLimitsForm = true; - $scope.changeLimitsFail = true; - $scope.changeLimitsSuccess = true; - $scope.couldNotConnect = true; - }; - - $scope.changeDomainEmailLimitsIndividual = function () { - $scope.emailLimitsLoading = false; - - url = "/emailPremium/changeDomainEmailLimitsIndividual"; - - var data = { - emailAddress: globalEamilAddress, - monthlyLimit: $scope.monthlyLimitForm, - hourlyLimit: $scope.hourlyLimitForm - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - - $scope.emailLimitsLoading = true; - - - if (response.data.status === 1) { - - $scope.changeLimitsForm = false; - $scope.changeLimitsFail = true; - $scope.changeLimitsSuccess = false; - $scope.couldNotConnect = true; - $scope.getEmailStats(); - - } - else - { - $scope.changeLimitsForm = false; - $scope.changeLimitsFail = false; - $scope.changeLimitsSuccess = true; - $scope.couldNotConnect = true; - $scope.errorMessage = response.data.error_message; - - } - } - function cantLoadInitialData(response) { - $scope.emailLimitsLoading = true; - $scope.changeLimitsForm = false; - $scope.changeLimitsFail = true; - $scope.changeLimitsSuccess = true; - $scope.couldNotConnect = false; - } - }; - - /// Get email logs - - $scope.getLogEntries = function(pageNumber) { - - globalPageNumber = pageNumber; - $scope.emailLimitsLoading = false; - - url = "/emailPremium/getEmailLogs"; - - var data = { - page: pageNumber, - emailAddress: globalEamilAddress - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - - $scope.emailLimitsLoading = true; - - if (response.data.status === 1) { - - $scope.logs = JSON.parse(response.data.data); - $scope.listFail = true; - } - else - { - $scope.listFail = false; - $scope.errorMessage = response.data.error_message; - - } - } - function cantLoadInitialData(response) { - $scope.emailLimitsLoading = true; - $scope.listFail = false; - } - - - }; - $scope.getLogEntries(1); - - - $scope.flushLogs = function(emailAddress) { - - $scope.emailLimitsLoading = false; - - url = "/emailPremium/flushEmailLogs"; - - var data = { - emailAddress: emailAddress - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - - $scope.emailLimitsLoading = true; - - if (response.data.status === 1) { - $scope.getLogEntries(1); - - } - else - { - $scope.listFail = false; - $scope.errorMessage = response.data.error_message; - - } - } - function cantLoadInitialData(response) { - $scope.emailLimitsLoading = true; - $scope.listFail = false; - } - - - }; - -}); - -/* Java script code for Email Page */ - - -/* Java script code for SpamAssassin */ - -app.controller('SpamAssassin', function($scope, $http, $timeout, $window) { - - $scope.SpamAssassinNotifyBox = true; - $scope.SpamAssassinInstallBox = true; - $scope.SpamAssassinLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.SpamAssassinSuccessfullyInstalled = true; - $scope.installationFailed = true; - - - - $scope.installSpamAssassin = function(){ - - $scope.SpamAssassinNotifyBox = true; - $scope.SpamAssassinInstallBox = true; - $scope.SpamAssassinLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.SpamAssassinSuccessfullyInstalled = true; - $scope.installationFailed = true; - - url = "/emailPremium/installSpamAssassin"; - - var data = {}; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.status === 1){ - - $scope.SpamAssassinNotifyBox = true; - $scope.SpamAssassinInstallBox = false; - $scope.SpamAssassinLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.SpamAssassinSuccessfullyInstalled = true; - $scope.installationFailed = true; - - getRequestStatus(); - - } - else{ - $scope.errorMessage = response.data.error_message; - - $scope.SpamAssassinNotifyBox = false; - $scope.SpamAssassinInstallBox = true; - $scope.SpamAssassinLoading = true; - $scope.failedToStartInallation = false; - $scope.couldNotConnect = true; - $scope.SpamAssassinSuccessfullyInstalled = true; - } - - } - function cantLoadInitialDatas(response) { - - $scope.SpamAssassinNotifyBox = false; - $scope.SpamAssassinInstallBox = false; - $scope.SpamAssassinLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = false; - $scope.SpamAssassinSuccessfullyInstalled = true; - $scope.installationFailed = true; - } - - }; - - function getRequestStatus(){ - - $scope.SpamAssassinNotifyBox = true; - $scope.SpamAssassinInstallBox = false; - $scope.SpamAssassinLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.SpamAssassinSuccessfullyInstalled = true; - $scope.installationFailed = true; - - url = "/emailPremium/installStatusSpamAssassin"; - - var data = {}; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.abort === 0){ - - $scope.SpamAssassinNotifyBox = true; - $scope.SpamAssassinInstallBox = false; - $scope.SpamAssassinLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.SpamAssassinSuccessfullyInstalled = true; - $scope.installationFailed = true; - - $scope.requestData = response.data.requestStatus; - $timeout(getRequestStatus,1000); - } - else{ - // Notifications - $timeout.cancel(); - $scope.SpamAssassinNotifyBox = false; - $scope.SpamAssassinInstallBox = false; - $scope.SpamAssassinLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - - $scope.requestData = response.data.requestStatus; - - if(response.data.installed === 0) { - $scope.installationFailed = false; - $scope.errorMessage = response.data.error_message; - }else{ - $scope.SpamAssassinSuccessfullyInstalled = false; - $timeout(function() { $window.location.reload(); }, 3000); - } - - } - - } - function cantLoadInitialDatas(response) { - - $scope.SpamAssassinNotifyBox = false; - $scope.SpamAssassinInstallBox = false; - $scope.SpamAssassinLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = false; - $scope.SpamAssassinSuccessfullyInstalled = true; - $scope.installationFailed = true; - - - } - - } - - ///// SpamAssassin configs - - var report_safe = false; - - - $('#report_safe').change(function() { - report_safe = $(this).prop('checked'); - }); - - fetchSpamAssassinSettings(); - function fetchSpamAssassinSettings(){ - - $scope.SpamAssassinLoading = false; - - $('#report_safe').bootstrapToggle('off'); - - url = "/emailPremium/fetchSpamAssassinSettings"; - - var data = {}; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - $scope.SpamAssassinLoading = true; - - if(response.data.fetchStatus === 1){ - - if(response.data.installed === 1) { - - if (response.data.report_safe === 1) { - $('#report_safe').bootstrapToggle('on'); - } - - $scope.required_hits = response.data.required_hits; - $scope.rewrite_header = response.data.rewrite_header; - $scope.required_score = response.data.required_score; - - } - - } - - } - function cantLoadInitialDatas(response) { - $scope.SpamAssassinLoading = true; - } - - } - - - ///// - - /// Save SpamAssassin Changes - - $scope.failedToSave = true; - $scope.successfullySaved = true; - - $scope.saveSpamAssassinConfigurations = function () { - - $scope.failedToSave = true; - $scope.successfullySaved = true; - $scope.SpamAssassinLoading = false; - $scope.couldNotConnect = true; - - - url = "/emailPremium/saveSpamAssassinConfigurations"; - - var data = { - report_safe:report_safe, - required_hits:$scope.required_hits, - rewrite_header:$scope.rewrite_header, - required_score:$scope.required_score - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.saveStatus === 1){ - - $scope.failedToSave = true; - $scope.successfullySaved = false; - $scope.SpamAssassinLoading = true; - $scope.couldNotConnect = true; - - } - else{ - $scope.errorMessage = response.data.error_message; - - $scope.failedToSave = false; - $scope.successfullySaved = true; - $scope.SpamAssassinLoading = true; - $scope.couldNotConnect = true; - } - - } - function cantLoadInitialDatas(response) { - $scope.failedToSave = true; - $scope.successfullySaved = false; - $scope.SpamAssassinLoading = true; - $scope.couldNotConnect = true; - } - - - }; - -}); - - -/* Java script code for SpamAssassin */ - - -/* Java script code for Email Policy Server */ +/* Java script code */ app.controller('powerDNS', function($scope, $http, $timeout, $window) { @@ -969,10 +12,7 @@ app.controller('powerDNS', function($scope, $http, $timeout, $window) { $scope.couldNotConnect = true; $scope.changesApplied = true; - - ///// SpamAssassin configs - - var report_safe = false; + var pdnsStatus = false; $('#pdnsStatus').change(function() { @@ -1091,4 +131,137 @@ app.controller('powerDNS', function($scope, $http, $timeout, $window) { }); -/* Java script code for Email Policy Server */ \ No newline at end of file +/* Java script code */ + + + +/* Java script code */ + +app.controller('postfix', function($scope, $http, $timeout, $window) { + + $scope.serviceLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + + + var serviceStatus = false; + + + $('#serviceStatus').change(function() { + serviceStatus = $(this).prop('checked'); + }); + + fetchPDNSStatus('postfix'); + function fetchPDNSStatus(service){ + + $scope.serviceLoading = false; + + $('#serviceStatus').bootstrapToggle('off'); + + url = "/manageservices/fetchStatus"; + + var data = { + 'service' : service + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $scope.serviceLoading = true; + + if(response.data.status === 1){ + + if (response.data.installCheck === 1) { + $('#serviceStatus').bootstrapToggle('on'); + } + + }else{ + $scope.failedToFetch = false; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + + $scope.errorMessage = response.data.error_message; + + } + + } + function cantLoadInitialDatas(response) { + $scope.serviceLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = false; + $scope.changesApplied = true; + } + + } + + + $scope.saveStatus = function (service) { + + $scope.serviceLoading = false; + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + + + + url = "/manageservices/saveStatus"; + + var data = { + status:serviceStatus, + service: service + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.serviceLoading = true; + + if(response.data.status === 1){ + + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = false; + + } + else{ + $scope.errorMessage = response.data.error_message; + + $scope.failedToFetch = false; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + } + + } + function cantLoadInitialDatas(response) { + $scope.serviceLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = false; + $scope.changesApplied = true; + } + + + }; + +}); + + +/* Java script code */ \ No newline at end of file diff --git a/manageServices/templates/manageServices/managePostfix.html b/manageServices/templates/manageServices/managePostfix.html index 3d9fea014..586cfa6da 100644 --- a/manageServices/templates/manageServices/managePostfix.html +++ b/manageServices/templates/manageServices/managePostfix.html @@ -1,6 +1,6 @@ {% extends "baseTemplate/index.html" %} {% load i18n %} -{% block title %}{% trans "Email Policy Server - CyberPanel" %}{% endblock %} +{% block title %}{% trans "Manage Email Server (Postfix) - CyberPanel" %}{% endblock %} {% block content %} {% load static %} @@ -10,14 +10,16 @@
-

{% trans "Email Policy Server Configurations!" %} - {% trans "Emai Limits Docs" %}

-

{% trans "Turn ON Email Policy Server to use Email Limits Feature. " %}

+

{% trans "Manage Email Server (Postfix)!" %} - {% trans "Emai Limits Docs" %}

+

{% trans "Enable or disable Email services. " %}

-
+ {% if status %} + +

- {% trans "Email Policy Server" %} + {% trans "Manage Postfix" %}

@@ -27,9 +29,9 @@
- +
- +
@@ -37,7 +39,7 @@
- +
@@ -74,6 +76,14 @@
+ {% else %} + +
+

{% trans "Only administrator can manage services." %}

+
+ + {% endif %} +
diff --git a/manageServices/urls.py b/manageServices/urls.py index 06276cf19..0f574ca4c 100644 --- a/manageServices/urls.py +++ b/manageServices/urls.py @@ -3,6 +3,7 @@ import views urlpatterns = [ url(r'^managePowerDNS$', views.managePowerDNS, name='managePowerDNS'), + url(r'^managePostfix$', views.managePostfix, name='managePostfix'), url(r'^fetchStatus$', views.fetchStatus, name='fetchStatus'), url(r'^saveStatus$', views.saveStatus, name='saveStatus'), ] \ No newline at end of file diff --git a/manageServices/views.py b/manageServices/views.py index 20608146c..1276dc274 100644 --- a/manageServices/views.py +++ b/manageServices/views.py @@ -33,6 +33,24 @@ def managePowerDNS(request): except KeyError: return redirect(loadLoginPage) +def managePostfix(request): + try: + val = request.session['userID'] + try: + admin = Administrator.objects.get(pk=val) + + if admin.type == 1: + return render(request, 'manageServices/managePostfix.html', {"status": 1}) + else: + return render(request, 'manageServices/managePostfix.html', {"status": 0}) + + except BaseException, msg: + logging.CyberCPLogFileWriter.writeToFile(str(msg)) + return HttpResponse("See CyberCP main log file.") + + except KeyError: + return redirect(loadLoginPage) + def fetchStatus(request): try: @@ -61,6 +79,16 @@ def fetchStatus(request): json_data = json.dumps(data_ret) return HttpResponse(json_data) + elif service == 'postfix': + if os.path.exists('/home/cyberpanel/postfix'): + data_ret = {'status': 1, 'error_message': 'None', 'installCheck': 1} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + else: + data_ret = {'status': 1, 'error_message': 'None', 'installCheck': 0} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + except BaseException,msg: @@ -94,9 +122,10 @@ def saveStatus(request): mailUtilities.checkHome() if service == 'powerdns': - pdnsPath = '/home/cyberpanel/powerdns' + + servicePath = '/home/cyberpanel/powerdns' if status == True: - writeToFile = open(pdnsPath, 'w+') + writeToFile = open(servicePath, 'w+') writeToFile.close() command = 'sudo systemctl start pdns' subprocess.call(shlex.split(command)) @@ -104,13 +133,30 @@ def saveStatus(request): command = 'sudo systemctl stop pdns' subprocess.call(shlex.split(command)) try: - os.remove(pdnsPath) + os.remove(servicePath) except: pass - data_ret = {'status': 1, 'error_message': "None"} - json_data = json.dumps(data_ret) - return HttpResponse(json_data) + + elif service == 'postfix': + + servicePath = '/home/cyberpanel/postfix' + if status == True: + writeToFile = open(servicePath, 'w+') + writeToFile.close() + command = 'sudo systemctl start postfix' + subprocess.call(shlex.split(command)) + else: + command = 'sudo systemctl stop postfix' + subprocess.call(shlex.split(command)) + try: + os.remove(servicePath) + except: + pass + + data_ret = {'status': 1, 'error_message': "None"} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) except BaseException,msg: diff --git a/static/manageServices/manageServices.js b/static/manageServices/manageServices.js index cc0a255fa..b05f712d8 100644 --- a/static/manageServices/manageServices.js +++ b/static/manageServices/manageServices.js @@ -2,965 +2,8 @@ * Created by usman on 6/22/18. */ -/* Java script code to list accounts */ -app.controller('listDomains', function($scope,$http) { - - $scope.listFail = true; - $scope.emailLimitsLoading = true; - - // Global page number, to be used in later function to refresh the domains - var globalPageNumber; - - - $scope.getFurtherWebsitesFromDB = function(pageNumber) { - - globalPageNumber = pageNumber; - $scope.emailLimitsLoading = false; - - url = "/emailPremium/getFurtherDomains"; - - var data = {page: pageNumber}; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - - $scope.emailLimitsLoading = true; - - if (response.data.listWebSiteStatus === 1) { - - $scope.WebSitesList = JSON.parse(response.data.data); - $scope.listFail = true; - } - else - { - $scope.listFail = false; - $scope.errorMessage = response.data.error_message; - - } - } - function cantLoadInitialData(response) { - $scope.emailLimitsLoading = true; - $scope.listFail = false; - } - - - }; - $scope.getFurtherWebsitesFromDB(1); - - $scope.enableDisableEmailLimits = function (operationVal, domainName) { - - $scope.emailLimitsLoading = false; - - - url = "/emailPremium/enableDisableEmailLimits"; - - var data = { - operationVal: operationVal, - domainName: domainName - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - $scope.emailLimitsLoading = true; - - if (response.data.status === 1) { - - $scope.getFurtherWebsitesFromDB(globalPageNumber); - $scope.listFail = true; - } - else - { - $scope.listFail = false; - $scope.errorMessage = response.data.error_message; - - } - } - function cantLoadInitialData(response) { - $scope.emailLimitsLoading = true; - $scope.listFail = false; - } - } -}); - -/* Java script code to list accounts ends here */ - - - -/* Java script code for email domain page */ - -app.controller('emailDomainPage', function($scope,$http, $timeout, $window) { - - $scope.listFail = true; - $scope.emailLimitsLoading = true; - - var globalDomainName = window.location.pathname.split("/")[2]; - - // Global page number, to be used in later function to refresh the domains - var globalPageNumber; - - - $scope.getFurtherEmailsFromDB = function(pageNumber) { - - globalPageNumber = pageNumber; - $scope.emailLimitsLoading = false; - - url = "/emailPremium/getFurtherEmail"; - - var data = { - page: pageNumber, - domainName: globalDomainName - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - - $scope.emailLimitsLoading = true; - - if (response.data.status === 1) { - - $scope.emailList = JSON.parse(response.data.data); - $scope.listFail = true; - } - else - { - $scope.listFail = false; - $scope.errorMessage = response.data.error_message; - - } - } - function cantLoadInitialData(response) { - $scope.emailLimitsLoading = true; - $scope.listFail = false; - } - - - }; - $scope.getFurtherEmailsFromDB(1); - - $scope.enableDisableEmailLimits = function (operationVal, domainName) { - - $scope.emailLimitsLoading = false; - - - url = "/emailPremium/enableDisableEmailLimits"; - - var data = { - operationVal: operationVal, - domainName: domainName - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - $scope.emailLimitsLoading = true; - - if (response.data.status === 1) { - - $timeout(function() { $window.location.reload(); }, 0); - } - else - { - $timeout(function() { $window.location.reload(); }, 0); - } - } - function cantLoadInitialData(response) { - $timeout(function() { $window.location.reload(); }, 0); - } - }; - - - /// Email limits - - $scope.changeLimitsForm = true; - $scope.changeLimitsFail = true; - $scope.changeLimitsSuccess = true; - $scope.couldNotConnect = true; - - $scope.showLimitsForm = function () { - $scope.changeLimitsForm = false; - }; - - $scope.hideLimitsForm = function () { - $scope.changeLimitsForm = true; - $scope.changeLimitsFail = true; - $scope.changeLimitsSuccess = true; - $scope.couldNotConnect = true; - }; - - $scope.changeDomainEmailLimits = function (domainName) { - $scope.emailLimitsLoading = false; - - url = "/emailPremium/changeDomainLimit"; - - var data = { - domainName: domainName, - newLimit: $scope.monthlyLimit - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - - $scope.emailLimitsLoading = true; - - - if (response.data.status === 1) { - - $scope.changeLimitsForm = false; - $scope.changeLimitsFail = true; - $scope.changeLimitsSuccess = false; - $scope.couldNotConnect = true; - $timeout(function() { $window.location.reload(); }, 3000); - } - else - { - $scope.changeLimitsForm = false; - $scope.changeLimitsFail = false; - $scope.changeLimitsSuccess = true; - $scope.couldNotConnect = true; - $scope.errorMessage = response.data.error_message; - - } - } - function cantLoadInitialData(response) { - $scope.emailLimitsLoading = true; - $scope.changeLimitsForm = false; - $scope.changeLimitsFail = true; - $scope.changeLimitsSuccess = true; - $scope.couldNotConnect = false; - } - } - - - $scope.enableDisableIndividualEmailLimits = function (operationVal, emailAddress) { - - $scope.emailLimitsLoading = false; - - - url = "/emailPremium/enableDisableIndividualEmailLimits"; - - var data = { - operationVal: operationVal, - emailAddress: emailAddress - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - $scope.emailLimitsLoading = true; - - if (response.data.status === 1) { - $scope.getFurtherEmailsFromDB(1); - } - else - { - $scope.getFurtherEmailsFromDB(1); - } - } - function cantLoadInitialData(response) { - $scope.getFurtherEmailsFromDB(1); - } - }; - -}); - -/* Java script code for email domain page */ - - -/* Java script code for Email Page */ - -app.controller('emailPage', function($scope,$http, $timeout, $window) { - - $scope.emailLimitsLoading = true; - - var globalEamilAddress = $("#emailAddress").text(); - - // Global page number, to be used in later function to refresh the domains - var globalPageNumber; - - $scope.getEmailStats = function() { - - $scope.emailLimitsLoading = false; - - //// - - $scope.limitsOn = true; - $scope.limitsOff = true; - - url = "/emailPremium/getEmailStats"; - - var data = { - emailAddress: globalEamilAddress - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - - $scope.emailLimitsLoading = true; - - if (response.data.status === 1) { - - $scope.monthlyLimit = response.data.monthlyLimit; - $scope.monthlyUsed = response.data.monthlyUsed; - $scope.hourlyLimit = response.data.hourlyLimit; - $scope.hourlyUsed = response.data.hourlyUsed; - - if(response.data.limitStatus === 1){ - $scope.limitsOn = false; - $scope.limitsOff = true; - }else{ - $scope.limitsOn = true; - $scope.limitsOff = false; - } - - if(response.data.logsStatus === 1){ - $scope.loggingOn = false; - $scope.loggingOff = true; - }else{ - $scope.loggingOn = true; - $scope.loggingOff = false; - } - - } - else - { - - $scope.errorMessage = response.data.error_message; - - } - } - function cantLoadInitialData(response) { - $scope.emailLimitsLoading = true; - $scope.listFail = false; - } - - - }; - $scope.getEmailStats(); - - $scope.enableDisableIndividualEmailLimits = function (operationVal, emailAddress) { - - $scope.emailLimitsLoading = false; - - - url = "/emailPremium/enableDisableIndividualEmailLimits"; - - var data = { - operationVal: operationVal, - emailAddress: emailAddress - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - $scope.emailLimitsLoading = true; - - if (response.data.status === 1) { - $scope.getEmailStats(); - } - else - { - $scope.getEmailStats(); - } - } - function cantLoadInitialData(response) { - $scope.getEmailStats(); - } - }; - $scope.enableDisableIndividualEmailLogs = function (operationVal, emailAddress) { - - $scope.emailLimitsLoading = false; - - - url = "/emailPremium/enableDisableIndividualEmailLogs"; - - var data = { - operationVal: operationVal, - emailAddress: emailAddress - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - $scope.emailLimitsLoading = true; - - if (response.data.status === 1) { - $scope.getEmailStats(); - } - else - { - $scope.getEmailStats(); - } - } - function cantLoadInitialData(response) { - $scope.getEmailStats(); - } - }; - - - $scope.enableDisableEmailLimits = function (operationVal, domainName) { - - $scope.emailLimitsLoading = false; - - - url = "/emailPremium/enableDisableEmailLimits"; - - var data = { - operationVal: operationVal, - domainName: domainName - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - $scope.emailLimitsLoading = true; - - if (response.data.status === 1) { - - $timeout(function() { $window.location.reload(); }, 0); - } - else - { - $timeout(function() { $window.location.reload(); }, 0); - } - } - function cantLoadInitialData(response) { - $timeout(function() { $window.location.reload(); }, 0); - } - }; - - - /// Email limits - $scope.changeLimitsForm = true; - $scope.changeLimitsFail = true; - $scope.changeLimitsSuccess = true; - $scope.couldNotConnect = true; - - $scope.showLimitsForm = function () { - $scope.changeLimitsForm = false; - }; - - $scope.hideLimitsForm = function () { - $scope.changeLimitsForm = true; - $scope.changeLimitsFail = true; - $scope.changeLimitsSuccess = true; - $scope.couldNotConnect = true; - }; - - $scope.changeDomainEmailLimitsIndividual = function () { - $scope.emailLimitsLoading = false; - - url = "/emailPremium/changeDomainEmailLimitsIndividual"; - - var data = { - emailAddress: globalEamilAddress, - monthlyLimit: $scope.monthlyLimitForm, - hourlyLimit: $scope.hourlyLimitForm - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - - $scope.emailLimitsLoading = true; - - - if (response.data.status === 1) { - - $scope.changeLimitsForm = false; - $scope.changeLimitsFail = true; - $scope.changeLimitsSuccess = false; - $scope.couldNotConnect = true; - $scope.getEmailStats(); - - } - else - { - $scope.changeLimitsForm = false; - $scope.changeLimitsFail = false; - $scope.changeLimitsSuccess = true; - $scope.couldNotConnect = true; - $scope.errorMessage = response.data.error_message; - - } - } - function cantLoadInitialData(response) { - $scope.emailLimitsLoading = true; - $scope.changeLimitsForm = false; - $scope.changeLimitsFail = true; - $scope.changeLimitsSuccess = true; - $scope.couldNotConnect = false; - } - }; - - /// Get email logs - - $scope.getLogEntries = function(pageNumber) { - - globalPageNumber = pageNumber; - $scope.emailLimitsLoading = false; - - url = "/emailPremium/getEmailLogs"; - - var data = { - page: pageNumber, - emailAddress: globalEamilAddress - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - - $scope.emailLimitsLoading = true; - - if (response.data.status === 1) { - - $scope.logs = JSON.parse(response.data.data); - $scope.listFail = true; - } - else - { - $scope.listFail = false; - $scope.errorMessage = response.data.error_message; - - } - } - function cantLoadInitialData(response) { - $scope.emailLimitsLoading = true; - $scope.listFail = false; - } - - - }; - $scope.getLogEntries(1); - - - $scope.flushLogs = function(emailAddress) { - - $scope.emailLimitsLoading = false; - - url = "/emailPremium/flushEmailLogs"; - - var data = { - emailAddress: emailAddress - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - $http.post(url, data,config).then(ListInitialData, cantLoadInitialData); - - - function ListInitialData(response) { - - $scope.emailLimitsLoading = true; - - if (response.data.status === 1) { - $scope.getLogEntries(1); - - } - else - { - $scope.listFail = false; - $scope.errorMessage = response.data.error_message; - - } - } - function cantLoadInitialData(response) { - $scope.emailLimitsLoading = true; - $scope.listFail = false; - } - - - }; - -}); - -/* Java script code for Email Page */ - - -/* Java script code for SpamAssassin */ - -app.controller('SpamAssassin', function($scope, $http, $timeout, $window) { - - $scope.SpamAssassinNotifyBox = true; - $scope.SpamAssassinInstallBox = true; - $scope.SpamAssassinLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.SpamAssassinSuccessfullyInstalled = true; - $scope.installationFailed = true; - - - - $scope.installSpamAssassin = function(){ - - $scope.SpamAssassinNotifyBox = true; - $scope.SpamAssassinInstallBox = true; - $scope.SpamAssassinLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.SpamAssassinSuccessfullyInstalled = true; - $scope.installationFailed = true; - - url = "/emailPremium/installSpamAssassin"; - - var data = {}; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.status === 1){ - - $scope.SpamAssassinNotifyBox = true; - $scope.SpamAssassinInstallBox = false; - $scope.SpamAssassinLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.SpamAssassinSuccessfullyInstalled = true; - $scope.installationFailed = true; - - getRequestStatus(); - - } - else{ - $scope.errorMessage = response.data.error_message; - - $scope.SpamAssassinNotifyBox = false; - $scope.SpamAssassinInstallBox = true; - $scope.SpamAssassinLoading = true; - $scope.failedToStartInallation = false; - $scope.couldNotConnect = true; - $scope.SpamAssassinSuccessfullyInstalled = true; - } - - } - function cantLoadInitialDatas(response) { - - $scope.SpamAssassinNotifyBox = false; - $scope.SpamAssassinInstallBox = false; - $scope.SpamAssassinLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = false; - $scope.SpamAssassinSuccessfullyInstalled = true; - $scope.installationFailed = true; - } - - }; - - function getRequestStatus(){ - - $scope.SpamAssassinNotifyBox = true; - $scope.SpamAssassinInstallBox = false; - $scope.SpamAssassinLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.SpamAssassinSuccessfullyInstalled = true; - $scope.installationFailed = true; - - url = "/emailPremium/installStatusSpamAssassin"; - - var data = {}; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.abort === 0){ - - $scope.SpamAssassinNotifyBox = true; - $scope.SpamAssassinInstallBox = false; - $scope.SpamAssassinLoading = false; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - $scope.SpamAssassinSuccessfullyInstalled = true; - $scope.installationFailed = true; - - $scope.requestData = response.data.requestStatus; - $timeout(getRequestStatus,1000); - } - else{ - // Notifications - $timeout.cancel(); - $scope.SpamAssassinNotifyBox = false; - $scope.SpamAssassinInstallBox = false; - $scope.SpamAssassinLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = true; - - $scope.requestData = response.data.requestStatus; - - if(response.data.installed === 0) { - $scope.installationFailed = false; - $scope.errorMessage = response.data.error_message; - }else{ - $scope.SpamAssassinSuccessfullyInstalled = false; - $timeout(function() { $window.location.reload(); }, 3000); - } - - } - - } - function cantLoadInitialDatas(response) { - - $scope.SpamAssassinNotifyBox = false; - $scope.SpamAssassinInstallBox = false; - $scope.SpamAssassinLoading = true; - $scope.failedToStartInallation = true; - $scope.couldNotConnect = false; - $scope.SpamAssassinSuccessfullyInstalled = true; - $scope.installationFailed = true; - - - } - - } - - ///// SpamAssassin configs - - var report_safe = false; - - - $('#report_safe').change(function() { - report_safe = $(this).prop('checked'); - }); - - fetchSpamAssassinSettings(); - function fetchSpamAssassinSettings(){ - - $scope.SpamAssassinLoading = false; - - $('#report_safe').bootstrapToggle('off'); - - url = "/emailPremium/fetchSpamAssassinSettings"; - - var data = {}; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - $scope.SpamAssassinLoading = true; - - if(response.data.fetchStatus === 1){ - - if(response.data.installed === 1) { - - if (response.data.report_safe === 1) { - $('#report_safe').bootstrapToggle('on'); - } - - $scope.required_hits = response.data.required_hits; - $scope.rewrite_header = response.data.rewrite_header; - $scope.required_score = response.data.required_score; - - } - - } - - } - function cantLoadInitialDatas(response) { - $scope.SpamAssassinLoading = true; - } - - } - - - ///// - - /// Save SpamAssassin Changes - - $scope.failedToSave = true; - $scope.successfullySaved = true; - - $scope.saveSpamAssassinConfigurations = function () { - - $scope.failedToSave = true; - $scope.successfullySaved = true; - $scope.SpamAssassinLoading = false; - $scope.couldNotConnect = true; - - - url = "/emailPremium/saveSpamAssassinConfigurations"; - - var data = { - report_safe:report_safe, - required_hits:$scope.required_hits, - rewrite_header:$scope.rewrite_header, - required_score:$scope.required_score - }; - - var config = { - headers : { - 'X-CSRFToken': getCookie('csrftoken') - } - }; - - - - $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); - - - function ListInitialDatas(response) { - - - if(response.data.saveStatus === 1){ - - $scope.failedToSave = true; - $scope.successfullySaved = false; - $scope.SpamAssassinLoading = true; - $scope.couldNotConnect = true; - - } - else{ - $scope.errorMessage = response.data.error_message; - - $scope.failedToSave = false; - $scope.successfullySaved = true; - $scope.SpamAssassinLoading = true; - $scope.couldNotConnect = true; - } - - } - function cantLoadInitialDatas(response) { - $scope.failedToSave = true; - $scope.successfullySaved = false; - $scope.SpamAssassinLoading = true; - $scope.couldNotConnect = true; - } - - - }; - -}); - - -/* Java script code for SpamAssassin */ - - -/* Java script code for Email Policy Server */ +/* Java script code */ app.controller('powerDNS', function($scope, $http, $timeout, $window) { @@ -969,10 +12,7 @@ app.controller('powerDNS', function($scope, $http, $timeout, $window) { $scope.couldNotConnect = true; $scope.changesApplied = true; - - ///// SpamAssassin configs - - var report_safe = false; + var pdnsStatus = false; $('#pdnsStatus').change(function() { @@ -1091,4 +131,137 @@ app.controller('powerDNS', function($scope, $http, $timeout, $window) { }); -/* Java script code for Email Policy Server */ \ No newline at end of file +/* Java script code */ + + + +/* Java script code */ + +app.controller('postfix', function($scope, $http, $timeout, $window) { + + $scope.serviceLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + + + var serviceStatus = false; + + + $('#serviceStatus').change(function() { + serviceStatus = $(this).prop('checked'); + }); + + fetchPDNSStatus('postfix'); + function fetchPDNSStatus(service){ + + $scope.serviceLoading = false; + + $('#serviceStatus').bootstrapToggle('off'); + + url = "/manageservices/fetchStatus"; + + var data = { + 'service' : service + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + + $scope.serviceLoading = true; + + if(response.data.status === 1){ + + if (response.data.installCheck === 1) { + $('#serviceStatus').bootstrapToggle('on'); + } + + }else{ + $scope.failedToFetch = false; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + + $scope.errorMessage = response.data.error_message; + + } + + } + function cantLoadInitialDatas(response) { + $scope.serviceLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = false; + $scope.changesApplied = true; + } + + } + + + $scope.saveStatus = function (service) { + + $scope.serviceLoading = false; + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + + + + url = "/manageservices/saveStatus"; + + var data = { + status:serviceStatus, + service: service + }; + + var config = { + headers : { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + + $http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.serviceLoading = true; + + if(response.data.status === 1){ + + $scope.failedToFetch = true; + $scope.couldNotConnect = true; + $scope.changesApplied = false; + + } + else{ + $scope.errorMessage = response.data.error_message; + + $scope.failedToFetch = false; + $scope.couldNotConnect = true; + $scope.changesApplied = true; + } + + } + function cantLoadInitialDatas(response) { + $scope.serviceLoading = true; + $scope.failedToFetch = true; + $scope.couldNotConnect = false; + $scope.changesApplied = true; + } + + + }; + +}); + + +/* Java script code */ \ No newline at end of file