diff --git a/baseTemplate/templates/baseTemplate/index.html b/baseTemplate/templates/baseTemplate/index.html index b5c4726d2..0b3236ded 100755 --- a/baseTemplate/templates/baseTemplate/index.html +++ b/baseTemplate/templates/baseTemplate/index.html @@ -60,6 +60,7 @@ } + {% block title %}Page Title{% endblock %} @@ -72,7 +73,20 @@ - + + + + + + + + + + + + + diff --git a/emailPremium/static/emailPremium/emailPremium.js b/emailPremium/static/emailPremium/emailPremium.js index 48f7109fc..9f580ac0b 100755 --- a/emailPremium/static/emailPremium/emailPremium.js +++ b/emailPremium/static/emailPremium/emailPremium.js @@ -1287,4 +1287,287 @@ app.controller('mailQueue', function($scope,$http) { }; }); -/* Java script code to manage mail queue ends here */ \ No newline at end of file +/* Java script code to manage mail queue ends here */ + +app.controller('MailScanner', 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/installMailScanner"; + + 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/MailScanner.html b/emailPremium/templates/emailPremium/MailScanner.html index 5812b68e9..831b710e7 100755 --- a/emailPremium/templates/emailPremium/MailScanner.html +++ b/emailPremium/templates/emailPremium/MailScanner.html @@ -17,7 +17,7 @@

- {% trans "SpamAssassin" %} + {% trans "MailScanner" %}

@@ -66,7 +66,7 @@

{% trans "Winter is coming, but so is SpamAssassin." %} + src="{% static 'firewall/icons/firewall.png' %}"> {% trans "Winter is coming, but so is MailScanner." %}

@@ -83,12 +83,13 @@ {% else %}
-

{% trans "MailScanner is not installed " %} +

{% trans "MailScanner is installed. " %}

- +
{% endif %} diff --git a/emailPremium/urls.py b/emailPremium/urls.py index f7d511b59..f4ebb2960 100755 --- a/emailPremium/urls.py +++ b/emailPremium/urls.py @@ -39,6 +39,7 @@ urlpatterns = [ url(r'^flushQueue$', views.flushQueue, name='flushQueue'), url(r'^delete$', views.delete, name='delete'), url(r'^MailScanner$', views.MailScanner, name='MailScanner'), + url(r'^installMailScanner$', views.installMailScanner, name='installMailScanner'), url(r'^(?P(.*))$', views.emailLimits, name='emailLimits'), diff --git a/emailPremium/views.py b/emailPremium/views.py index 8a05c968c..1bfdc9445 100755 --- a/emailPremium/views.py +++ b/emailPremium/views.py @@ -1182,10 +1182,42 @@ def MailScanner(request): checkIfMailScannerInstalled = 0 + ipFile = "/etc/cyberpanel/machineIP" + f = open(ipFile) + ipData = f.read() + ipAddress = ipData.split('\n', 1)[0] + if mailUtilities.checkIfMailScannerInstalled() == 1: checkIfMailScannerInstalled = 1 - return render(request, 'emailPremium/MailScanner.html',{'checkIfMailScannerInstalled': checkIfMailScannerInstalled}) + + return render(request, 'emailPremium/MailScanner.html',{'checkIfMailScannerInstalled': checkIfMailScannerInstalled, 'ipAddress': ipAddress}) except KeyError: - return redirect(loadLoginPage) \ No newline at end of file + return redirect(loadLoginPage) + +def installMailScanner(request): + try: + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadErrorJson() + try: + + execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py" + execPath = execPath + " installMailScanner" + ProcessUtilities.popenExecutioner(execPath) + + final_json = json.dumps({'status': 1, 'error_message': "None"}) + return HttpResponse(final_json) + except BaseException as msg: + final_dic = {'status': 0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + except KeyError: + final_dic = {'status': 0, 'error_message': "Not Logged In, please refresh the page or login again."} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) \ No newline at end of file diff --git a/plogical/mailUtilities.py b/plogical/mailUtilities.py index a635c71ba..3424eccef 100755 --- a/plogical/mailUtilities.py +++ b/plogical/mailUtilities.py @@ -449,6 +449,9 @@ milter_default_action = accept def installSpamAssassin(install, SpamAssassin): try: + if os.path.exists(mailUtilities.spamassassinInstallLogPath): + os.remove(mailUtilities.spamassassinInstallLogPath) + if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: command = 'sudo yum install spamassassin -y' else: @@ -477,6 +480,51 @@ milter_default_action = accept writeToFile.close() logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installSpamAssassin]") + @staticmethod + def installMailScanner(install, SpamAssassin): + try: + + if os.path.exists(mailUtilities.spamassassinInstallLogPath): + os.remove(mailUtilities.spamassassinInstallLogPath) + + if mailUtilities.checkIfSpamAssassinInstalled(): + + command = 'chmod +x /usr/local/CyberCP/CPScripts/mailscannerinstaller.sh' + ProcessUtilities.executioner(command) + + + command = '/usr/local/CyberCP/CPScripts/mailscannerinstaller.sh' + + cmd = shlex.split(command) + + with open(mailUtilities.spamassassinInstallLogPath, 'w') as f: + res = subprocess.call(cmd, stdout=f) + + if res == 1: + writeToFile = open(mailUtilities.spamassassinInstallLogPath, 'a') + writeToFile.writelines("Can not be installed.[404]\n") + writeToFile.close() + logging.CyberCPLogFileWriter.writeToFile("[Could not Install MailScanner.]") + return 0 + else: + writeToFile = open(mailUtilities.spamassassinInstallLogPath, 'a') + writeToFile.writelines("MailScanner Installed.[200]\n") + writeToFile.close() + + return 1 + else: + writeToFile = open(mailUtilities.spamassassinInstallLogPath, 'a') + writeToFile.writelines("Please install SpamAssassin from CyberPanel before installing MailScanner.[404]\n") + writeToFile.close() + + + + except BaseException as msg: + writeToFile = open(mailUtilities.spamassassinInstallLogPath, 'a') + writeToFile.writelines("Can not be installed.[404]\n") + writeToFile.close() + logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installSpamAssassin]") + @staticmethod def checkIfSpamAssassinInstalled(): try: @@ -670,7 +718,7 @@ milter_default_action = accept def checkIfMailScannerInstalled(): try: - path = "/usr/local/CyberCP/public/mailscanner" + path = "/usr/local/CyberCP/public/mailwatch" if os .path.exists(path): return 1 @@ -711,6 +759,8 @@ def main(): mailUtilities.savePolicyServerStatus(args.install) elif args.function == 'installSpamAssassin': mailUtilities.installSpamAssassin("install", "SpamAssassin") + elif args.function == 'installMailScanner': + mailUtilities.installMailScanner("install", "installMailScanner") elif args.function == 'AfterEffects': mailUtilities.AfterEffects(args.domain) diff --git a/static/emailPremium/emailPremium.js b/static/emailPremium/emailPremium.js index 48f7109fc..9f580ac0b 100644 --- a/static/emailPremium/emailPremium.js +++ b/static/emailPremium/emailPremium.js @@ -1287,4 +1287,287 @@ app.controller('mailQueue', function($scope,$http) { }; }); -/* Java script code to manage mail queue ends here */ \ No newline at end of file +/* Java script code to manage mail queue ends here */ + +app.controller('MailScanner', 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/installMailScanner"; + + 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