From a3efc18f284e051cdc98abf69ee9a890f0c7f932 Mon Sep 17 00:00:00 2001 From: Zarak Khan Date: Mon, 22 Jan 2024 16:42:47 +0500 Subject: [PATCH] Email App --- .../templates/baseTemplate/newBase.html | 2 +- mailServer/mailserverManager.py | 16 ++ mailServer/static/mailServer/mailServerV2.js | 223 +++++++++++++++ .../templates/mailServer/listEmailsV2.html | 256 ++++++++++++++++++ mailServer/urls.py | 1 + mailServer/views.py | 34 ++- 6 files changed, 528 insertions(+), 4 deletions(-) create mode 100644 mailServer/templates/mailServer/listEmailsV2.html diff --git a/baseTemplate/templates/baseTemplate/newBase.html b/baseTemplate/templates/baseTemplate/newBase.html index d01692bbe..fa470ab18 100644 --- a/baseTemplate/templates/baseTemplate/newBase.html +++ b/baseTemplate/templates/baseTemplate/newBase.html @@ -653,7 +653,7 @@ Create Email
  • - • List Emails
  • diff --git a/mailServer/mailserverManager.py b/mailServer/mailserverManager.py index c7c892468..26e65f00d 100755 --- a/mailServer/mailserverManager.py +++ b/mailServer/mailserverManager.py @@ -112,6 +112,22 @@ class MailServerManager(multi.Thread): {'websiteList': websitesName, "status": 1}, 'listEmails') return proc.render() + def listEmailsV2(self): + userID = self.request.session['userID'] + currentACL = ACLManager.loadedACL(userID) + + if not os.path.exists('/home/cyberpanel/postfix'): + proc = httpProc(self.request, 'mailServer/listEmails.html', + {"status": 0}, 'listEmails') + return proc.render() + + websitesName = ACLManager.findAllSites(currentACL, userID) + websitesName = websitesName + ACLManager.findChildDomains(websitesName) + + proc = httpProc(self.request, 'mailServer/listEmailsV2.html', + {'websiteList': websitesName, "status": 1}, 'listEmails') + return proc.render() + def submitEmailCreation(self): try: diff --git a/mailServer/static/mailServer/mailServerV2.js b/mailServer/static/mailServer/mailServerV2.js index 9d9c5cdcb..d76af33a9 100644 --- a/mailServer/static/mailServer/mailServerV2.js +++ b/mailServer/static/mailServer/mailServerV2.js @@ -111,4 +111,227 @@ newapp.controller('createEmailAccountV2', function ($scope, $http) { $scope.generatedPasswordView = true; }; +}); + +newapp.controller('listEmailsV2', function ($scope, $http) { + + $scope.cyberpanelLoading = true; + $scope.emailsAccounts = true; + $scope.mailConfigured = 1; + + $scope.populateCurrentRecords = function () { + $scope.cyberpanelLoading = false; + $scope.emailsAccounts = true; + + url = "/email/fetchEmails"; + + var data = { + selectedDomain: $scope.selectedDomain, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.cyberpanelLoading = true; + + if (response.data.status === 1) { + $scope.emailsAccounts = false; + $scope.records = JSON.parse(response.data.data); + $scope.mailConfigured = response.data.mailConfigured; + $scope.serverHostname = response.data.serverHostname; + + new PNotify({ + title: 'Success!', + text: 'Emails Successfully Fetched.', + type: 'success' + }); + + + } else { + $scope.emailsAccounts = true; + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + $scope.errorMessage = response.data.error_message; + } + + } + + function cantLoadInitialDatas(response) { + $scope.cyberpanelLoading = true; + $scope.emailsAccounts = true; + new PNotify({ + title: 'Error!', + text: 'Could not connect to server, please refresh this page.', + type: 'error' + }); + } + + }; + + $scope.deleteEmailAccountFinal = function (email) { + + $scope.cyberpanelLoading = false; + + var url = "/email/submitEmailDeletion"; + + var data = { + email: email, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + function ListInitialDatas(response) { + if (response.data.deleteEmailStatus === 1) { + $scope.populateCurrentRecords(); + new PNotify({ + title: 'Success!', + text: 'Email Successfully deleted.', + 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.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) { + $scope.email = email; + }; + + $scope.changePassword = function () { + + $scope.cyberpanelLoading = false; + + + var url = "/email/submitPasswordChange"; + + var data = { + domain: $scope.selectedDomain, + email: $scope.email, + passwordByPass: $scope.password, + }; + + var config = { + headers: { + 'X-CSRFToken': getCookie('csrftoken') + } + }; + + $http.post(url, data, config).then(ListInitialDatas, cantLoadInitialDatas); + + + function ListInitialDatas(response) { + $scope.cyberpanelLoading = true; + if (response.data.status === 1) { + new PNotify({ + title: 'Success!', + text: 'Password Successfully changed.', + type: 'success' + }); + + } else { + new PNotify({ + title: 'Error!', + text: response.data.error_message, + type: 'error' + }); + + } + + } + + function cantLoadInitialDatas(response) { + $scope.cyberpanelLoading = true; + new PNotify({ + title: 'Error!', + text: 'Could not connect to server, please refresh this page.', + type: 'error' + }); + } + + + }; }); \ No newline at end of file diff --git a/mailServer/templates/mailServer/listEmailsV2.html b/mailServer/templates/mailServer/listEmailsV2.html new file mode 100644 index 000000000..59d488000 --- /dev/null +++ b/mailServer/templates/mailServer/listEmailsV2.html @@ -0,0 +1,256 @@ +{% extends "baseTemplate/newBase.html" %} +{% load i18n %} +{% block titleNew %}{% trans "Home - CyberPanel" %}{% endblock %} +{% block newContent %} + + {% load static %} + +
    +
    +
    +
    +

    List Email Accounts + -

    +
    +
    + {% trans "Debug Email Issues" %} +
    +
    + {% trans "Create Email" %} +
    +
    +

    List Emails Accounts. Change their passwords or delete + them.

    +
    +
    +
    +

    List Email Accounts

    + +
    +
    + {% if not status %} + +
    +

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

    +
    + {% else %} +
    +
    +
    +

    Select Domain

    +
    +
    + +
    +
    +
    + +
    +
    +

    {% 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. +

    +
    + + + +
    + +
    + +

    {% trans "Details To Configure Mail Clients" %}

    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    {% trans "POP3" %}{% trans "Details" %}
    {% trans "Server Hostname" %}{$ serverHostname $}
    {% trans "Port" %}110
    {% trans "Port" %}995 (SSL)
    {% trans "SSL" %}STARTTLS
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    {% trans "IMAP" %}{% trans "Details" %}
    {% trans "Server Hostname" %}{$ serverHostname $}
    {% trans "Port" %}143
    {% trans "Port" %}993 (SSL)
    {% trans "SSL" %}STARTTLS
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    {% trans "SMTP" %}{% trans "Details" %}
    {% trans "Server Hostname" %}{$ serverHostname $}
    {% trans "Port" %}25
    {% trans "Port" %}587 (SSL)
    {% trans "Port" %}465 (SSL)
    {% trans "SSL" %}STARTTLS
    +
    + +
    + + + + + + + + + + + + + + + + +
    {% trans "Emails" %}{% trans "Disk Usage" %}{% trans "Actions" %}
    + {% trans 'Change Password' %} + {% trans 'Delete' %} + + + + +
    +
    + {% endif %} +
    +{% endblock %} diff --git a/mailServer/urls.py b/mailServer/urls.py index 78c0835bc..0f10fb752 100755 --- a/mailServer/urls.py +++ b/mailServer/urls.py @@ -6,6 +6,7 @@ urlpatterns = [ url(r'^createEmailAccount', views.createEmailAccount, name='createEmailAccount'), url(r'^V2/createEmailAccountV2', views.createEmailAccountV2, name='createEmailAccountV2'), url(r'^listEmails$', views.listEmails, name='listEmails'), + url(r'^V2/listEmailsV2$', views.listEmailsV2, name='listEmailsV2'), url(r'^submitEmailCreation', views.submitEmailCreation, name='submitEmailCreation'), url(r'^fetchEmails$', views.fetchEmails, name='fetchEmails'), diff --git a/mailServer/views.py b/mailServer/views.py index 42ae8c74c..31fe7670e 100755 --- a/mailServer/views.py +++ b/mailServer/views.py @@ -8,6 +8,7 @@ import json from .mailserverManager import MailServerManager from .pluginManager import pluginManager + def loadEmailHome(request): try: msM = MailServerManager(request) @@ -15,6 +16,7 @@ def loadEmailHome(request): except KeyError: return redirect(loadLoginPage) + def createEmailAccount(request): try: msM = MailServerManager(request) @@ -22,12 +24,15 @@ def createEmailAccount(request): except KeyError: return redirect(loadLoginPage) + def createEmailAccountV2(request): try: msM = MailServerManager(request) return msM.createEmailAccountV2() except KeyError: return redirect(loadLoginPage) + + def listEmails(request): try: msM = MailServerManager(request) @@ -36,6 +41,14 @@ def listEmails(request): return redirect(loadLoginPage) +def listEmailsV2(request): + try: + msM = MailServerManager(request) + return msM.listEmailsV2() + except KeyError: + return redirect(loadLoginPage) + + def fetchEmails(request): try: msM = MailServerManager(request) @@ -43,6 +56,7 @@ def fetchEmails(request): except KeyError: return redirect(loadLoginPage) + def submitEmailCreation(request): try: @@ -61,6 +75,7 @@ def submitEmailCreation(request): except KeyError: return redirect(loadLoginPage) + def deleteEmailAccount(request): try: msM = MailServerManager(request) @@ -68,6 +83,7 @@ def deleteEmailAccount(request): except KeyError: return redirect(loadLoginPage) + def getEmailsForDomain(request): try: msM = MailServerManager(request) @@ -77,6 +93,7 @@ def getEmailsForDomain(request): json_data = json.dumps(data_ret) return HttpResponse(json_data) + def submitEmailDeletion(request): try: @@ -97,6 +114,7 @@ def submitEmailDeletion(request): json_data = json.dumps(data_ret) return HttpResponse(json_data) + def fixMailSSL(request): try: @@ -109,6 +127,7 @@ def fixMailSSL(request): json_data = json.dumps(data_ret) return HttpResponse(json_data) + def emailForwarding(request): try: msM = MailServerManager(request) @@ -116,6 +135,7 @@ def emailForwarding(request): except KeyError: return redirect(loadLoginPage) + def fetchCurrentForwardings(request): try: msM = MailServerManager(request) @@ -125,6 +145,7 @@ def fetchCurrentForwardings(request): json_data = json.dumps(data_ret) return HttpResponse(json_data) + def submitForwardDeletion(request): try: @@ -145,6 +166,7 @@ def submitForwardDeletion(request): json_data = json.dumps(data_ret) return HttpResponse(json_data) + def submitEmailForwardingCreation(request): try: @@ -165,6 +187,7 @@ def submitEmailForwardingCreation(request): json_data = json.dumps(data_ret) return HttpResponse(json_data) + ####### def changeEmailAccountPassword(request): @@ -174,6 +197,7 @@ def changeEmailAccountPassword(request): except KeyError: return redirect(loadLoginPage) + def submitPasswordChange(request): try: @@ -194,6 +218,7 @@ def submitPasswordChange(request): json_data = json.dumps(data_ret) return HttpResponse(json_data) + ####### def dkimManager(request): @@ -203,6 +228,7 @@ def dkimManager(request): except KeyError: return redirect(loadLoginPage) + def fetchDKIMKeys(request): try: msM = MailServerManager(request) @@ -212,6 +238,7 @@ def fetchDKIMKeys(request): json_data = json.dumps(data_ret) return HttpResponse(json_data) + def generateDKIMKeys(request): try: @@ -232,6 +259,7 @@ def generateDKIMKeys(request): json_data = json.dumps(data_ret) return HttpResponse(json_data) + def installOpenDKIM(request): try: msM = MailServerManager(request) @@ -241,13 +269,13 @@ def installOpenDKIM(request): final_json = json.dumps(final_dic) return HttpResponse(final_json) + def installStatusOpenDKIM(request): try: msM = MailServerManager() return msM.installStatusOpenDKIM() except KeyError: - final_dic = {'abort':1,'installed':0, 'error_message': "Not Logged In, please refresh the page or login again."} + final_dic = {'abort': 1, 'installed': 0, + 'error_message': "Not Logged In, please refresh the page or login again."} final_json = json.dumps(final_dic) return HttpResponse(final_json) - -