From 6bc60d7c9eb12433887b1c198ffaab7fae5ad218 Mon Sep 17 00:00:00 2001 From: Usman Nasir Date: Sun, 10 May 2020 03:15:33 +0500 Subject: [PATCH] setup autodiscover at later stage --- mailServer/mailserverManager.py | 47 +++++++- mailServer/static/mailServer/mailServer.js | 52 ++++++++ .../templates/mailServer/listEmails.html | 12 +- mailServer/urls.py | 1 + mailServer/views.py | 12 ++ plogical/virtualHostUtilities.py | 113 ++++++++++-------- static/mailServer/mailServer.js | 52 ++++++++ static/websiteFunctions/websiteFunctions.js | 1 + 8 files changed, 237 insertions(+), 53 deletions(-) diff --git a/mailServer/mailserverManager.py b/mailServer/mailserverManager.py index b5e387627..187fbbe74 100755 --- a/mailServer/mailserverManager.py +++ b/mailServer/mailserverManager.py @@ -226,6 +226,38 @@ class MailServerManager: json_data = json.dumps(data_ret) return HttpResponse(json_data) + def fixMailSSL(self): + try: + + userID = self.request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + data = json.loads(self.request.body) + selectedDomain = data['selectedDomain'] + + admin = Administrator.objects.get(pk=userID) + + if ACLManager.checkOwnership(selectedDomain, admin, currentACL) == 1: + pass + else: + return ACLManager.loadErrorJson('status', 0) + + website = Websites.objects.get(domain=selectedDomain) + + execPath = "/usr/local/CyberCP/bin/python " + virtualHostUtilities.cyberPanel + "/plogical/virtualHostUtilities.py" + execPath = '%s setupAutoDiscover --virtualHostName %s --websiteOwner %s' % (execPath, selectedDomain, website.admin.userName) + + ProcessUtilities.executioner(execPath) + + data_ret = {'status': 1, 'error_message': "None"} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + except BaseException as msg: + data_ret = {'status': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + def emailForwarding(self): try: userID = self.request.session['userID'] @@ -476,6 +508,19 @@ class MailServerManager: except: raise BaseException('No emails exist for this domain.') + postfixMapPath = '/etc/postfix/vmail_ssl.map' + + if os.path.exists(postfixMapPath): + + postfixMapData = open(postfixMapPath, 'r').read() + + if postfixMapData.find(selectedDomain) == -1: + mailConfigured = 0 + else: + mailConfigured = 1 + else: + mailConfigured = 0 + records = emailDomain.eusers_set.all() json_data = "[" @@ -492,7 +537,7 @@ class MailServerManager: json_data = json_data + ',' + json.dumps(dic) json_data = json_data + ']' - final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'error_message': "None", "data": json_data}) + final_json = json.dumps({'status': 1, 'fetchStatus': 1, 'mailConfigured': mailConfigured, 'error_message': "None", "data": json_data}) return HttpResponse(final_json) except BaseException as msg: diff --git a/mailServer/static/mailServer/mailServer.js b/mailServer/static/mailServer/mailServer.js index 3bf1db1c3..c33087815 100755 --- a/mailServer/static/mailServer/mailServer.js +++ b/mailServer/static/mailServer/mailServer.js @@ -1124,6 +1124,7 @@ app.controller('listEmails', function ($scope, $http) { $scope.cyberpanelLoading = true; $scope.emailsAccounts = true; + $scope.mailConfigured = 1; $scope.populateCurrentRecords = function () { $scope.cyberpanelLoading = false; @@ -1151,6 +1152,8 @@ app.controller('listEmails', function ($scope, $http) { if (response.data.status === 1) { $scope.emailsAccounts = false; $scope.records = JSON.parse(response.data.data); + $scope.mailConfigured = response.data.mailConfigured; + new PNotify({ title: 'Success!', text: 'Emails Successfully Fetched.', @@ -1229,6 +1232,55 @@ app.controller('listEmails', function ($scope, $http) { } + }; + + $scope.fixMailSSL = function (email) { + + $scope.cyberpanelLoading = false; + + var url = "/email/fixMailSSL"; + + var data = { + selectedDomain: $scope.selectedDomain, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + if (response.data.status === 1) { + $scope.populateCurrentRecords(); + new PNotify({ + title: 'Success!', + text: 'Configurations applied successfully.', + type: 'success' + }); + + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + new PNotify({ + title: 'Error!', + text: 'Could not connect to server, please refresh this page.', + type: 'error' + }); + } + + }; $scope.changePasswordInitial = function (email) { diff --git a/mailServer/templates/mailServer/listEmails.html b/mailServer/templates/mailServer/listEmails.html index 955cdf4f8..4ed7781ff 100755 --- a/mailServer/templates/mailServer/listEmails.html +++ b/mailServer/templates/mailServer/listEmails.html @@ -56,6 +56,15 @@
+
+
+

{% trans "SSL for email is not configured properly, you may get Self-Signed error on mail clients such as Outlook and Thunderbird. More details " %}here.

+
+ + + +
+
@@ -74,7 +83,8 @@ class="btn btn-border btn-alt border-purple btn-link font-purple" href="#" title="">{% trans 'Change Password' %} - {% trans 'Delete' %} diff --git a/mailServer/urls.py b/mailServer/urls.py index 74d902484..a974c6b64 100755 --- a/mailServer/urls.py +++ b/mailServer/urls.py @@ -20,6 +20,7 @@ urlpatterns = [ url(r'^deleteEmailAccount', views.deleteEmailAccount, name='deleteEmailAccount'), url(r'^getEmailsForDomain$', views.getEmailsForDomain, name='getEmailsForDomain'), url(r'^submitEmailDeletion', views.submitEmailDeletion, name='submitEmailDeletion'), + url(r'^fixMailSSL', views.fixMailSSL, name='fixMailSSL'), ## Change email password diff --git a/mailServer/views.py b/mailServer/views.py index 337567c07..12ce04a91 100755 --- a/mailServer/views.py +++ b/mailServer/views.py @@ -91,6 +91,18 @@ def submitEmailDeletion(request): json_data = json.dumps(data_ret) return HttpResponse(json_data) +def fixMailSSL(request): + try: + + msM = MailServerManager(request) + coreResult = msM.fixMailSSL() + + return coreResult + except KeyError as msg: + data_ret = {'deleteEmailStatus': 0, 'error_message': str(msg)} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + def emailForwarding(request): try: msM = MailServerManager(request) diff --git a/plogical/virtualHostUtilities.py b/plogical/virtualHostUtilities.py index 7bbfcb306..7fae5acb6 100755 --- a/plogical/virtualHostUtilities.py +++ b/plogical/virtualHostUtilities.py @@ -55,6 +55,64 @@ class virtualHostUtilities: cyberPanel = "/usr/local/CyberCP" redisConf = '/usr/local/lsws/conf/dvhost_redis.conf' + @staticmethod + def setupAutoDiscover(mailDomain, tempStatusPath, virtualHostName, admin): + + if mailDomain: + + logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'Creating mail child domain..,80') + childDomain = 'mail.%s' % (virtualHostName) + childPath = '/home/%s/public_html/%s' % (virtualHostName, childDomain) + + virtualHostUtilities.createDomain(virtualHostName, childDomain, 'PHP 7.2', childPath, 1, 0, 0, + admin.userName, 0, "/home/cyberpanel/" + str(randint(1000, 9999))) + + ## update dovecot conf to enable auto-discover + + dovecotPath = '/etc/dovecot/dovecot.conf' + + if os.path.exists(dovecotPath): + dovecotContent = open(dovecotPath, 'r').read() + + if dovecotContent.find(childDomain) == -1: + content = """\nlocal_name %s { + ssl_cert =