Email App

This commit is contained in:
Zarak Khan
2024-01-22 16:42:47 +05:00
parent 102a9a1c36
commit a3efc18f28
6 changed files with 528 additions and 4 deletions

View File

@@ -653,7 +653,7 @@
Create Email</a>
</li>
<li>
<a href="#"
<a href="{% url 'listEmailsV2' %}"
class="flex items-center w-full text-base font-normal text-white transition duration-75 rounded-lg group hover:bg-cyan-400 dark:text-white dark:hover:bg-gray-700 pl-11">
List Emails</a>
</li>

View File

@@ -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:

View File

@@ -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'
});
}
};
});

View File

@@ -0,0 +1,256 @@
{% extends "baseTemplate/newBase.html" %}
{% load i18n %}
{% block titleNew %}{% trans "Home - CyberPanel" %}{% endblock %}
{% block newContent %}
{% load static %}
<div ng-controller="listEmailsV2" class="p-8">
<div>
<div class="flex justify-between items-center">
<div>
<p class="text-4xl font-bold">List Email Accounts
- </p>
</div>
<div>
<a target="_blank" href="https://go.cyberpanel.net/DebugEmail" style="height: 23px;line-height: 21px;"
class="btn btn-border btn-alt border-red btn-link font-red"
title=""><span>{% trans "Debug Email Issues" %}</span></a>
</div>
<div>
<a class="bg-orange-500 text-white font-semibold px-2 py-1"
href="{% url "createEmailAccount" %}">{% trans "Create Email" %}</a>
</div>
</div>
<p class="text-xs text-gray-600 py-2 font-semibold">List Emails Accounts. Change their passwords or delete
them.</p>
</div>
<div>
<div class="py-4">
<p class="text-xl font-bold">List Email Accounts</p>
<img ng-hide="cyberpanelLoading"
src="{% static 'images/loading.gif' %}">
</div>
<hr>
{% if not status %}
<div class="col-md-12 text-center" style="margin-bottom: 2%;">
<h3>{% trans "Postfix is disabled." %}
<a href="{% url 'managePostfix' %}">
<button class="btn btn-alt btn-hover btn-blue-alt">
<span>{% trans "Enable Now" %}</span>
<i class="glyph-icon icon-arrow-right"></i>
</button>
</a></h3>
</div>
{% else %}
<div>
<div class="flex mt-4 py-2 px-6">
<div>
<p class="font-semibold w-60">Select Domain</p>
</div>
<div>
<select ng-change="populateCurrentRecords()" ng-model="selectedDomain"
class="w-80 bg-gray-100 rounded px-2 py-1">
{% for items in websiteList %}
<option>{{ items }}</option>
{% endfor %}
</select>
</div>
</div>
<div ng-hide="emailsAccounts" class="form-group">
<div ng-hide="mailConfigured==1" class="col-sm-12">
<div class="alert alert-danger">
<p>{% trans "SSL for email is not configured properly, you may get Self-Signed error on mail clients such as Outlook and Thunderbird. More details " %}<a
href="https://cyberpanel.net/docs/6-self-signed-ssl-error-on-outlook-thunderbird/">here</a>.
</p>
</div>
<a target="_blank" href="">
<button style="margin-bottom: 2%" ng-click='fixMailSSL()' class="btn btn-primary">Fix Now</button>
</a>
</div>
<div class="col-sm-4">
<h4>{% trans "Details To Configure Mail Clients" %}</h4>
<table class="table">
<thead>
<tr>
<th>{% trans "POP3" %}</th>
<th>{% trans "Details" %}</th>
</tr>
</thead>
<tbody>
<tr>
<td>{% trans "Server Hostname" %}</td>
<td>{$ serverHostname $}</td>
</tr>
<tr>
<td>{% trans "Port" %}</td>
<td>110</td>
</tr>
<tr>
<td>{% trans "Port" %}</td>
<td>995 (SSL)</td>
</tr>
<tr>
<td>{% trans "SSL" %}</td>
<td>STARTTLS</td>
</tr>
</tbody>
</table>
<table class="table">
<thead>
<tr>
<th>{% trans "IMAP" %}</th>
<th>{% trans "Details" %}</th>
</tr>
</thead>
<tbody>
<tr>
<td>{% trans "Server Hostname" %}</td>
<td>{$ serverHostname $}</td>
</tr>
<tr>
<td>{% trans "Port" %}</td>
<td>143</td>
</tr>
<tr>
<td>{% trans "Port" %}</td>
<td>993 (SSL)</td>
</tr>
<tr>
<td>{% trans "SSL" %}</td>
<td>STARTTLS</td>
</tr>
</tbody>
</table>
<table class="table">
<thead>
<tr>
<th>{% trans "SMTP" %}</th>
<th>{% trans "Details" %}</th>
</tr>
</thead>
<tbody>
<tr>
<td>{% trans "Server Hostname" %}</td>
<td>{$ serverHostname $}</td>
</tr>
<tr>
<td>{% trans "Port" %}</td>
<td>25</td>
</tr>
<tr>
<td>{% trans "Port" %}</td>
<td>587 (SSL)</td>
</tr>
<tr>
<td>{% trans "Port" %}</td>
<td>465 (SSL)</td>
</tr>
<tr>
<td>{% trans "SSL" %}</td>
<td>STARTTLS</td>
</tr>
</tbody>
</table>
</div>
<div class="col-sm-8">
<table class="table">
<thead>
<tr>
<th>{% trans "Emails" %}</th>
<th>{% trans "Disk Usage" %}</th>
<th>{% trans "Actions" %}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="record in records track by $index">
<td ng-bind="record.email"></td>
<td ng-bind="record.DiskUsage"></td>
<td>
<a data-toggle="modal" data-target="#settings"
ng-click="changePasswordInitial(record.email)"
class="btn btn-border btn-alt border-purple btn-link font-purple"
href="#"
title=""><span>{% trans 'Change Password' %}</span></a>
<a ng-click="deleteEmailAccountFinal(record.email)"
class="btn btn-border btn-alt border-red btn-link font-red" href="#"
title=""><span>{% trans 'Delete' %}</span></a>
<!--- Modal --->
<div id="settings" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close"
data-dismiss="modal">&times;
</button>
<h4 class="modal-title">Change Password
<img ng-hide="cyberpanelLoading"
src="{% static 'images/loading.gif' %}">
</h4>
</div>
<div class="modal-body">
<form name="containerSettingsForm" action="/"
class="form-horizontal">
<div ng-hide="installationDetailsForm"
class="form-group">
<label class="col-sm-3 control-label">{% trans "Email" %}</label>
<div class="col-sm-6">
<input name="name" type="text"
class="form-control"
ng-model="email" readonly>
</div>
</div>
<hr>
<div ng-hide="installationDetailsForm"
class="form-group">
<label class="col-sm-3 control-label">{% trans "Password" %}</label>
<div class="col-sm-6">
<input type="password"
class="form-control"
ng-model="$parent.password">
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" ng-disabled="savingSettings"
class="btn btn-primary"
ng-click="changePassword()"
data-dismiss="modal">
Save
</button>
<button type="button" ng-disabled="savingSettings"
class="btn btn-default" data-dismiss="modal">
Close
</button>
</div>
</div>
</div>
</div>
<!--- Modal End--->
</td>
</tr>
</tbody>
</table>
</div>
{% endif %}
</div>
{% endblock %}

View File

@@ -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'),

View File

@@ -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)