mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-12 08:16:11 +01:00
setup autodiscover at later stage
This commit is contained in:
@@ -226,6 +226,38 @@ class MailServerManager:
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
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):
|
def emailForwarding(self):
|
||||||
try:
|
try:
|
||||||
userID = self.request.session['userID']
|
userID = self.request.session['userID']
|
||||||
@@ -476,6 +508,19 @@ class MailServerManager:
|
|||||||
except:
|
except:
|
||||||
raise BaseException('No emails exist for this domain.')
|
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()
|
records = emailDomain.eusers_set.all()
|
||||||
|
|
||||||
json_data = "["
|
json_data = "["
|
||||||
@@ -492,7 +537,7 @@ class MailServerManager:
|
|||||||
json_data = json_data + ',' + json.dumps(dic)
|
json_data = json_data + ',' + json.dumps(dic)
|
||||||
|
|
||||||
json_data = json_data + ']'
|
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)
|
return HttpResponse(final_json)
|
||||||
|
|
||||||
except BaseException as msg:
|
except BaseException as msg:
|
||||||
|
|||||||
@@ -1124,6 +1124,7 @@ app.controller('listEmails', function ($scope, $http) {
|
|||||||
|
|
||||||
$scope.cyberpanelLoading = true;
|
$scope.cyberpanelLoading = true;
|
||||||
$scope.emailsAccounts = true;
|
$scope.emailsAccounts = true;
|
||||||
|
$scope.mailConfigured = 1;
|
||||||
|
|
||||||
$scope.populateCurrentRecords = function () {
|
$scope.populateCurrentRecords = function () {
|
||||||
$scope.cyberpanelLoading = false;
|
$scope.cyberpanelLoading = false;
|
||||||
@@ -1151,6 +1152,8 @@ app.controller('listEmails', function ($scope, $http) {
|
|||||||
if (response.data.status === 1) {
|
if (response.data.status === 1) {
|
||||||
$scope.emailsAccounts = false;
|
$scope.emailsAccounts = false;
|
||||||
$scope.records = JSON.parse(response.data.data);
|
$scope.records = JSON.parse(response.data.data);
|
||||||
|
$scope.mailConfigured = response.data.mailConfigured;
|
||||||
|
|
||||||
new PNotify({
|
new PNotify({
|
||||||
title: 'Success!',
|
title: 'Success!',
|
||||||
text: 'Emails Successfully Fetched.',
|
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) {
|
$scope.changePasswordInitial = function (email) {
|
||||||
|
|||||||
@@ -56,6 +56,15 @@
|
|||||||
|
|
||||||
<div ng-hide="emailsAccounts" class="form-group">
|
<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 ng-click='fixMailSSL()' class="btn btn-primary">Fix Now</button>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
|
|
||||||
<table class="table">
|
<table class="table">
|
||||||
@@ -74,7 +83,8 @@
|
|||||||
class="btn btn-border btn-alt border-purple btn-link font-purple"
|
class="btn btn-border btn-alt border-purple btn-link font-purple"
|
||||||
href="#"
|
href="#"
|
||||||
title=""><span>{% trans 'Change Password' %}</span></a>
|
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="#"
|
<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>
|
title=""><span>{% trans 'Delete' %}</span></a>
|
||||||
|
|
||||||
<!--- Modal --->
|
<!--- Modal --->
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ urlpatterns = [
|
|||||||
url(r'^deleteEmailAccount', views.deleteEmailAccount, name='deleteEmailAccount'),
|
url(r'^deleteEmailAccount', views.deleteEmailAccount, name='deleteEmailAccount'),
|
||||||
url(r'^getEmailsForDomain$', views.getEmailsForDomain, name='getEmailsForDomain'),
|
url(r'^getEmailsForDomain$', views.getEmailsForDomain, name='getEmailsForDomain'),
|
||||||
url(r'^submitEmailDeletion', views.submitEmailDeletion, name='submitEmailDeletion'),
|
url(r'^submitEmailDeletion', views.submitEmailDeletion, name='submitEmailDeletion'),
|
||||||
|
url(r'^fixMailSSL', views.fixMailSSL, name='fixMailSSL'),
|
||||||
|
|
||||||
|
|
||||||
## Change email password
|
## Change email password
|
||||||
|
|||||||
@@ -91,6 +91,18 @@ def submitEmailDeletion(request):
|
|||||||
json_data = json.dumps(data_ret)
|
json_data = json.dumps(data_ret)
|
||||||
return HttpResponse(json_data)
|
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):
|
def emailForwarding(request):
|
||||||
try:
|
try:
|
||||||
msM = MailServerManager(request)
|
msM = MailServerManager(request)
|
||||||
|
|||||||
@@ -55,6 +55,64 @@ class virtualHostUtilities:
|
|||||||
cyberPanel = "/usr/local/CyberCP"
|
cyberPanel = "/usr/local/CyberCP"
|
||||||
redisConf = '/usr/local/lsws/conf/dvhost_redis.conf'
|
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 = </etc/letsencrypt/live/%s/fullchain.pem
|
||||||
|
ssl_key = </etc/letsencrypt/live/%s/privkey.pem
|
||||||
|
}\n""" % (childDomain, childDomain, childDomain)
|
||||||
|
|
||||||
|
writeToFile = open(dovecotPath, 'a')
|
||||||
|
writeToFile.write(content)
|
||||||
|
writeToFile.close()
|
||||||
|
|
||||||
|
command = 'systemctl restart dovecot'
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
### Update postfix configurations
|
||||||
|
|
||||||
|
postFixPath = '/etc/postfix/main.cf'
|
||||||
|
|
||||||
|
postFixContent = open(postFixPath, 'r').read()
|
||||||
|
|
||||||
|
if postFixContent.find('tls_server_sni_maps') == -1:
|
||||||
|
writeToFile = open(postFixPath, 'a')
|
||||||
|
writeToFile.write('\ntls_server_sni_maps = hash:/etc/postfix/vmail_ssl.map\n')
|
||||||
|
writeToFile.close()
|
||||||
|
|
||||||
|
postfixMapFile = '/etc/postfix/vmail_ssl.map'
|
||||||
|
|
||||||
|
mapContent = '%s /etc/letsencrypt/live/%s/privkey.pem /etc/letsencrypt/live/%s/fullchain.pem\n' % (
|
||||||
|
childDomain, childDomain, childDomain)
|
||||||
|
|
||||||
|
writeToFile = open(postfixMapFile, 'a')
|
||||||
|
writeToFile.write(mapContent)
|
||||||
|
writeToFile.close()
|
||||||
|
|
||||||
|
command = 'postmap -F hash:/etc/postfix/vmail_ssl.map'
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
|
command = 'systemctl restart postfix'
|
||||||
|
ProcessUtilities.executioner(command)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def createVirtualHost(virtualHostName, administratorEmail, phpVersion, virtualHostUser, ssl,
|
def createVirtualHost(virtualHostName, administratorEmail, phpVersion, virtualHostUser, ssl,
|
||||||
dkimCheck, openBasedir, websiteOwner, packageName, apache,
|
dkimCheck, openBasedir, websiteOwner, packageName, apache,
|
||||||
@@ -206,57 +264,7 @@ class virtualHostUtilities:
|
|||||||
|
|
||||||
### For autodiscover of mail clients.
|
### For autodiscover of mail clients.
|
||||||
|
|
||||||
if mailDomain:
|
virtualHostUtilities.setupAutoDiscover(mailDomain, tempStatusPath, virtualHostName, admin)
|
||||||
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 = </etc/letsencrypt/live/%s/fullchain.pem
|
|
||||||
ssl_key = </etc/letsencrypt/live/%s/privkey.pem
|
|
||||||
}\n""" % (childDomain, childDomain, childDomain)
|
|
||||||
|
|
||||||
writeToFile = open(dovecotPath, 'a')
|
|
||||||
writeToFile.write(content)
|
|
||||||
writeToFile.close()
|
|
||||||
|
|
||||||
command = 'systemctl restart dovecot'
|
|
||||||
ProcessUtilities.executioner(command)
|
|
||||||
|
|
||||||
### Update postfix configurations
|
|
||||||
|
|
||||||
postFixPath = '/etc/postfix/main.cf'
|
|
||||||
|
|
||||||
postFixContent = open(postFixPath, 'r').read()
|
|
||||||
|
|
||||||
if postFixContent.find('tls_server_sni_maps') == -1:
|
|
||||||
writeToFile = open(postFixPath, 'a')
|
|
||||||
writeToFile.write('\ntls_server_sni_maps = hash:/etc/postfix/vmail_ssl.map\n')
|
|
||||||
writeToFile.close()
|
|
||||||
|
|
||||||
postfixMapFile = '/etc/postfix/vmail_ssl.map'
|
|
||||||
|
|
||||||
mapContent = '%s /etc/letsencrypt/live/%s/privkey.pem /etc/letsencrypt/live/%s/fullchain.pem\n' % (childDomain, childDomain, childDomain)
|
|
||||||
|
|
||||||
writeToFile = open(postfixMapFile, 'a')
|
|
||||||
writeToFile.write(mapContent)
|
|
||||||
writeToFile.close()
|
|
||||||
|
|
||||||
command = 'postmap -F hash:/etc/postfix/vmail_ssl.map'
|
|
||||||
ProcessUtilities.executioner(command)
|
|
||||||
|
|
||||||
command = 'systemctl restart postfix'
|
|
||||||
ProcessUtilities.executioner(command)
|
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
||||||
@@ -1429,6 +1437,9 @@ def main():
|
|||||||
virtualHostUtilities.createVirtualHost(args.virtualHostName, args.administratorEmail, args.phpVersion,
|
virtualHostUtilities.createVirtualHost(args.virtualHostName, args.administratorEmail, args.phpVersion,
|
||||||
args.virtualHostUser, int(args.ssl), dkimCheck, openBasedir,
|
args.virtualHostUser, int(args.ssl), dkimCheck, openBasedir,
|
||||||
args.websiteOwner, args.package, apache, tempStatusPath, int(args.mailDomain))
|
args.websiteOwner, args.package, apache, tempStatusPath, int(args.mailDomain))
|
||||||
|
elif args.function == "setupAutoDiscover":
|
||||||
|
admin = Administrator.objects.get(userName=args.websiteOwner)
|
||||||
|
virtualHostUtilities.setupAutoDiscover(1, '/home/cyberpanel/templogs', args.virtualHostName, admin)
|
||||||
elif args.function == "deleteVirtualHostConfigurations":
|
elif args.function == "deleteVirtualHostConfigurations":
|
||||||
vhost.deleteVirtualHostConfigurations(args.virtualHostName)
|
vhost.deleteVirtualHostConfigurations(args.virtualHostName)
|
||||||
elif args.function == "createDomain":
|
elif args.function == "createDomain":
|
||||||
|
|||||||
@@ -1124,6 +1124,7 @@ app.controller('listEmails', function ($scope, $http) {
|
|||||||
|
|
||||||
$scope.cyberpanelLoading = true;
|
$scope.cyberpanelLoading = true;
|
||||||
$scope.emailsAccounts = true;
|
$scope.emailsAccounts = true;
|
||||||
|
$scope.mailConfigured = 1;
|
||||||
|
|
||||||
$scope.populateCurrentRecords = function () {
|
$scope.populateCurrentRecords = function () {
|
||||||
$scope.cyberpanelLoading = false;
|
$scope.cyberpanelLoading = false;
|
||||||
@@ -1151,6 +1152,8 @@ app.controller('listEmails', function ($scope, $http) {
|
|||||||
if (response.data.status === 1) {
|
if (response.data.status === 1) {
|
||||||
$scope.emailsAccounts = false;
|
$scope.emailsAccounts = false;
|
||||||
$scope.records = JSON.parse(response.data.data);
|
$scope.records = JSON.parse(response.data.data);
|
||||||
|
$scope.mailConfigured = response.data.mailConfigured;
|
||||||
|
|
||||||
new PNotify({
|
new PNotify({
|
||||||
title: 'Success!',
|
title: 'Success!',
|
||||||
text: 'Emails Successfully Fetched.',
|
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) {
|
$scope.changePasswordInitial = function (email) {
|
||||||
|
|||||||
@@ -6805,4 +6805,5 @@ app.controller('manageGIT', function ($scope, $http, $timeout, $window) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Java script code to git tracking ends here */
|
/* Java script code to git tracking ends here */
|
||||||
|
|||||||
Reference in New Issue
Block a user