From b6cc274b93c994f7644d9a29cfbc4b7e35039872 Mon Sep 17 00:00:00 2001 From: usmannasir <01-134132-158@student.bahria.edu.pk> Date: Mon, 25 Jun 2018 05:45:38 +0500 Subject: [PATCH] SpamAssassin --- .../templates/baseTemplate/index.html | 1 + .../static/emailPremium/emailPremium.js | 290 +++++++++++++++++- .../templates/emailPremium/SpamAssassin.html | 157 ++++++++++ emailPremium/urls.py | 8 + emailPremium/views.py | 241 ++++++++++++++- firewall/urls.py | 5 - firewall/views.py | 14 - plogical/mailUtilities.py | 159 ++++++++++ postfixSenderPolicy/accept_traffic.py | 2 +- 9 files changed, 853 insertions(+), 24 deletions(-) create mode 100644 emailPremium/templates/emailPremium/SpamAssassin.html diff --git a/baseTemplate/templates/baseTemplate/index.html b/baseTemplate/templates/baseTemplate/index.html index 057203e17..065e30264 100755 --- a/baseTemplate/templates/baseTemplate/index.html +++ b/baseTemplate/templates/baseTemplate/index.html @@ -558,6 +558,7 @@
diff --git a/emailPremium/static/emailPremium/emailPremium.js b/emailPremium/static/emailPremium/emailPremium.js index 356fb1fca..e2a7f3e09 100644 --- a/emailPremium/static/emailPremium/emailPremium.js +++ b/emailPremium/static/emailPremium/emailPremium.js @@ -666,8 +666,292 @@ app.controller('emailPage', function($scope,$http, $timeout, $window) { }; - - }); -/* Java script code for Email Page */ \ No newline at end of file +/* 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; + } + + + }; + +}); \ No newline at end of file diff --git a/emailPremium/templates/emailPremium/SpamAssassin.html b/emailPremium/templates/emailPremium/SpamAssassin.html new file mode 100644 index 000000000..274fbd24c --- /dev/null +++ b/emailPremium/templates/emailPremium/SpamAssassin.html @@ -0,0 +1,157 @@ +{% extends "baseTemplate/index.html" %} +{% load i18n %} +{% block title %}{% trans "SpamAssassin - CyberPanel" %}{% endblock %} +{% block content %} + +{% load static %} +{% get_current_language as LANGUAGE_CODE %} + + + +{% trans "On this page you can configure SpamAssassin settings." %}
+
+ {% trans "Failed to start installation, Error message: " %} {$ errorMessage $}
+{% trans "Could not connect. Please refresh this page." %}
+{% trans "Installation failed." %} {$ errorMessage $}
+{% trans "SpamAssassin successfully installed, refreshing page in 3 seconds.." %}
+