diff --git a/baseTemplate/templates/baseTemplate/index.html b/baseTemplate/templates/baseTemplate/index.html index 7b1c21a37..0b3236ded 100755 --- a/baseTemplate/templates/baseTemplate/index.html +++ b/baseTemplate/templates/baseTemplate/index.html @@ -877,6 +877,9 @@
  • {% trans "Email Marketing" %}
  • +
  • {% trans "MailScanner" %} +
  • diff --git a/baseTemplate/urls.py b/baseTemplate/urls.py index 31a0ed8c5..b904ed09b 100755 --- a/baseTemplate/urls.py +++ b/baseTemplate/urls.py @@ -13,6 +13,4 @@ urlpatterns = [ url(r'^UpgradeStatus',views.upgradeStatus, name='UpgradeStatus'), url(r'^upgradeVersion',views.upgradeVersion, name='upgradeVersion'), - - ] \ No newline at end of file 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 new file mode 100755 index 000000000..831b710e7 --- /dev/null +++ b/emailPremium/templates/emailPremium/MailScanner.html @@ -0,0 +1,107 @@ +{% extends "baseTemplate/index.html" %} +{% load i18n %} +{% block title %}{% trans "MailScanner - CyberPanel" %}{% endblock %} +{% block content %} + + {% load static %} + {% get_current_language as LANGUAGE_CODE %} + + + +
    +
    +

    {% trans "MailScanner" %}

    +

    {% trans "Install/Access MailScanner" %}

    +
    + +
    +
    +

    + {% trans "MailScanner" %} +

    + +
    +
    + + {% if checkIfMailScannerInstalled == 0 %} + +
    +

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

    + +
    + + + +
    + +
    + +
    +

    {% 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.." %}

    +
    +
    +
    + + +
    + +
    +
    +
    +

    {% trans "Winter is coming, but so is MailScanner." %} + +

    +
    +
    + +
    +
    +
    +
    + + + + {% else %} + +
    +

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

    + + +
    + + {% endif %} + + +
    +
    +
    +
    + + +
    + + +{% endblock %} diff --git a/emailPremium/urls.py b/emailPremium/urls.py index 50bff1050..f4ebb2960 100755 --- a/emailPremium/urls.py +++ b/emailPremium/urls.py @@ -38,6 +38,8 @@ urlpatterns = [ url(r'^fetchMessage$', views.fetchMessage, name='fetchMessage'), 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 54478c894..1bfdc9445 100755 --- a/emailPremium/views.py +++ b/emailPremium/views.py @@ -1166,4 +1166,58 @@ def delete(request): except KeyError as msg: dic = {'status': 0, 'error_message': str(msg)} json_data = json.dumps(dic) - return HttpResponse(json_data) \ No newline at end of file + return HttpResponse(json_data) + +## MailScanner + +def MailScanner(request): + try: + userID = request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadError() + + 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, 'ipAddress': ipAddress}) + + except KeyError: + 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 812b5317a..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: @@ -666,6 +714,22 @@ milter_default_action = accept str(msg) + " [savePolicyServerStatus]") print("0," + str(msg)) + @staticmethod + def checkIfMailScannerInstalled(): + try: + + path = "/usr/local/CyberCP/public/mailwatch" + + if os .path.exists(path): + return 1 + else: + return 0 + + except BaseException as msg: + logging.CyberCPLogFileWriter.writeToFile( + str(msg) + " [checkIfMailScannerInstalled]") + return 0 + def main(): @@ -695,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