mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-09 14:56:10 +01:00
CloudLinux, CageFS and security improvements
This commit is contained in:
@@ -24,6 +24,7 @@ import os
|
||||
from plogical.dnsUtilities import DNS
|
||||
from loginSystem.models import Administrator
|
||||
from plogical.processUtilities import ProcessUtilities
|
||||
import bcrypt
|
||||
|
||||
class MailServerManager:
|
||||
|
||||
@@ -69,24 +70,25 @@ class MailServerManager:
|
||||
data = json.loads(self.request.body)
|
||||
domainName = data['domain']
|
||||
userName = data['username']
|
||||
password = data['password']
|
||||
password = data['passwordByPass']
|
||||
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if ACLManager.checkOwnership(domainName, admin, currentACL) == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
|
||||
## Create email entry
|
||||
|
||||
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py"
|
||||
result = mailUtilities.createEmailAccount(domainName, userName, password)
|
||||
|
||||
execPath = execPath + " createEmailAccount --domain " + domainName + " --userName " \
|
||||
+ userName + " --password '" + password + "'"
|
||||
|
||||
output = ProcessUtilities.outputExecutioner(execPath)
|
||||
|
||||
if output.find("1,None") > -1:
|
||||
if result[0] == 1:
|
||||
data_ret = {'status': 1, 'createEmailStatus': 1, 'error_message': "None"}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
else:
|
||||
data_ret = {'status': 0, 'createEmailStatus': 0, 'error_message': output}
|
||||
data_ret = {'status': 0, 'createEmailStatus': 0, 'error_message': result[1]}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
@@ -127,6 +129,12 @@ class MailServerManager:
|
||||
data = json.loads(self.request.body)
|
||||
domain = data['domain']
|
||||
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if ACLManager.checkOwnership(domain, admin, currentACL) == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
|
||||
try:
|
||||
domain = Domains.objects.get(domain=domain)
|
||||
except:
|
||||
@@ -174,9 +182,18 @@ class MailServerManager:
|
||||
if ACLManager.currentContextPermission(currentACL, 'deleteEmail') == 0:
|
||||
return ACLManager.loadErrorJson('deleteEmailStatus', 0)
|
||||
|
||||
|
||||
data = json.loads(self.request.body)
|
||||
email = data['email']
|
||||
|
||||
eUser = EUsers.objects.get(email=email)
|
||||
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if ACLManager.checkOwnership(eUser.emailOwner.domainOwner.domain, admin, currentACL) == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
|
||||
mailUtilities.deleteEmailAccount(email)
|
||||
data_ret = {'status': 1, 'deleteEmailStatus': 1, 'error_message': "None"}
|
||||
json_data = json.dumps(data_ret)
|
||||
@@ -217,6 +234,14 @@ class MailServerManager:
|
||||
data = json.loads(self.request.body)
|
||||
emailAddress = data['emailAddress']
|
||||
|
||||
eUser = EUsers.objects.get(email=emailAddress)
|
||||
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if ACLManager.checkOwnership(eUser.emailOwner.domainOwner.domain, admin, currentACL) == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
|
||||
currentForwardings = Forwardings.objects.filter(source=emailAddress)
|
||||
|
||||
json_data = "["
|
||||
@@ -260,6 +285,14 @@ class MailServerManager:
|
||||
destination = data['destination']
|
||||
source = data['source']
|
||||
|
||||
eUser = EUsers.objects.get(email=source)
|
||||
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if ACLManager.checkOwnership(eUser.emailOwner.domainOwner.domain, admin, currentACL) == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
|
||||
for items in Forwardings.objects.filter(destination=destination, source=source):
|
||||
items.delete()
|
||||
|
||||
@@ -284,6 +317,14 @@ class MailServerManager:
|
||||
source = data['source']
|
||||
destination = data['destination']
|
||||
|
||||
eUser = EUsers.objects.get(email=source)
|
||||
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if ACLManager.checkOwnership(eUser.emailOwner.domainOwner.domain, admin, currentACL) == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
|
||||
if Forwardings.objects.filter(source=source, destination=destination).count() > 0:
|
||||
data_ret = {'status': 0, 'createStatus': 0,
|
||||
'error_message': "You have already forwared to this destination."}
|
||||
@@ -340,10 +381,16 @@ class MailServerManager:
|
||||
|
||||
emailDB = EUsers.objects.get(email=email)
|
||||
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if ACLManager.checkOwnership(emailDB.emailOwner.domainOwner.domain, admin, currentACL) == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
|
||||
CentOSPath = '/etc/redhat-release'
|
||||
if os.path.exists(CentOSPath):
|
||||
command = 'doveadm pw -p %s' % (password)
|
||||
password = ProcessUtilities.outputExecutioner(command).strip('\n')
|
||||
password = bcrypt.hashpw(str(password), bcrypt.gensalt())
|
||||
password = '{CRYPT}%s' % (password)
|
||||
emailDB.password = password
|
||||
else:
|
||||
emailDB.password = password
|
||||
@@ -392,16 +439,22 @@ class MailServerManager:
|
||||
data = json.loads(self.request.body)
|
||||
domainName = data['domainName']
|
||||
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if ACLManager.checkOwnership(domainName, admin, currentACL) == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadError()
|
||||
|
||||
try:
|
||||
path = "/etc/opendkim/keys/" + domainName + "/default.txt"
|
||||
command = "sudo cat " + path
|
||||
output = ProcessUtilities.outputExecutioner(command)
|
||||
output = ProcessUtilities.outputExecutioner(command, 'opendkim')
|
||||
leftIndex = output.index('(') + 2
|
||||
rightIndex = output.rindex(')') - 1
|
||||
|
||||
path = "/etc/opendkim/keys/" + domainName + "/default.private"
|
||||
command = "sudo cat " + path
|
||||
privateKey = ProcessUtilities.outputExecutioner(command)
|
||||
privateKey = ProcessUtilities.outputExecutioner(command, 'opendkim')
|
||||
|
||||
data_ret = {'status': 1, 'fetchStatus': 1, 'keysAvailable': 1, 'publicKey': output[leftIndex:rightIndex],
|
||||
'privateKey': privateKey, 'dkimSuccessMessage': 'Keys successfully fetched!',
|
||||
@@ -430,6 +483,12 @@ class MailServerManager:
|
||||
data = json.loads(self.request.body)
|
||||
domainName = data['domainName']
|
||||
|
||||
admin = Administrator.objects.get(pk=userID)
|
||||
if ACLManager.checkOwnership(domainName, admin, currentACL) == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
|
||||
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/mailUtilities.py"
|
||||
execPath = execPath + " generateKeys --domain " + domainName
|
||||
output = ProcessUtilities.outputExecutioner(execPath)
|
||||
|
||||
Reference in New Issue
Block a user