mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-06-27 16:08:59 +02:00
ACL Manager
This commit is contained in:
@@ -19,22 +19,23 @@ import subprocess
|
||||
import shlex
|
||||
from plogical.virtualHostUtilities import virtualHostUtilities
|
||||
from random import randint
|
||||
|
||||
from plogical.acl import ACLManager
|
||||
|
||||
|
||||
# Create your views here.
|
||||
|
||||
def listDomains(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadError()
|
||||
|
||||
try:
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
|
||||
if admin.type == 1:
|
||||
websites = DomainLimits.objects.all()
|
||||
else:
|
||||
return HttpResponse("Only administrator can view this page.")
|
||||
websites = DomainLimits.objects.all()
|
||||
|
||||
## Check if Policy Server is installed.
|
||||
|
||||
@@ -53,8 +54,6 @@ def listDomains(request):
|
||||
|
||||
###
|
||||
|
||||
|
||||
|
||||
pages = float(len(websites)) / float(10)
|
||||
pagination = []
|
||||
|
||||
@@ -80,10 +79,16 @@ def listDomains(request):
|
||||
|
||||
def getFurtherDomains(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
|
||||
try:
|
||||
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
|
||||
if request.method == 'POST':
|
||||
try:
|
||||
@@ -94,16 +99,9 @@ def getFurtherDomains(request):
|
||||
except BaseException, msg:
|
||||
status = str(msg)
|
||||
|
||||
|
||||
if admin.type == 1:
|
||||
finalPageNumber = ((pageNumber * 10))-10
|
||||
endPageNumber = finalPageNumber + 10
|
||||
websites = Websites.objects.all()[finalPageNumber:endPageNumber]
|
||||
|
||||
else:
|
||||
final_dic = {'listWebSiteStatus': 0, 'error_message': "Only administrator can view this page."}
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
finalPageNumber = ((pageNumber * 10)) - 10
|
||||
endPageNumber = finalPageNumber + 10
|
||||
websites = Websites.objects.all()[finalPageNumber:endPageNumber]
|
||||
|
||||
json_data = "["
|
||||
checker = 0
|
||||
@@ -143,18 +141,18 @@ def getFurtherDomains(request):
|
||||
|
||||
def enableDisableEmailLimits(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
|
||||
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
|
||||
if admin.type != 1:
|
||||
dic = {'status': 0, 'error_message': "Only administrator can view this page."}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
|
||||
data = json.loads(request.body)
|
||||
operationVal = data['operationVal']
|
||||
domainName = data['domainName']
|
||||
@@ -186,58 +184,52 @@ def enableDisableEmailLimits(request):
|
||||
|
||||
def emailLimits(request,domain):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
|
||||
if admin.type != 1:
|
||||
return HttpResponse("Only administrator can view this page.")
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadError()
|
||||
|
||||
|
||||
if Websites.objects.filter(domain=domain).exists():
|
||||
if admin.type == 1:
|
||||
website = Websites.objects.get(domain=domain)
|
||||
domainEmail = Domains.objects.get(domainOwner=website)
|
||||
domainLimits = DomainLimits.objects.get(domain=domainEmail)
|
||||
website = Websites.objects.get(domain=domain)
|
||||
domainEmail = Domains.objects.get(domainOwner=website)
|
||||
domainLimits = DomainLimits.objects.get(domain=domainEmail)
|
||||
|
||||
Data = {}
|
||||
Data['domain'] = domain
|
||||
Data['monthlyLimit'] = domainLimits.monthlyLimit
|
||||
Data['monthlyUsed'] = domainLimits.monthlyUsed
|
||||
Data['emailAccounts'] = domainEmail.eusers_set.count()
|
||||
Data = {}
|
||||
Data['domain'] = domain
|
||||
Data['monthlyLimit'] = domainLimits.monthlyLimit
|
||||
Data['monthlyUsed'] = domainLimits.monthlyUsed
|
||||
Data['emailAccounts'] = domainEmail.eusers_set.count()
|
||||
|
||||
if domainLimits.limitStatus == 1:
|
||||
Data['limitsOn'] = 1
|
||||
Data['limitsOff'] = 0
|
||||
else:
|
||||
Data['limitsOn'] = 0
|
||||
Data['limitsOff'] = 1
|
||||
|
||||
## Pagination for emails
|
||||
|
||||
|
||||
pages = float(Data['emailAccounts']) / float(10)
|
||||
pagination = []
|
||||
|
||||
if pages <= 1.0:
|
||||
pages = 1
|
||||
pagination.append('<li><a href="\#"></a></li>')
|
||||
else:
|
||||
pages = ceil(pages)
|
||||
finalPages = int(pages) + 1
|
||||
|
||||
for i in range(1, finalPages):
|
||||
pagination.append('<li><a href="\#">' + str(i) + '</a></li>')
|
||||
|
||||
Data['pagination'] = pagination
|
||||
|
||||
|
||||
return render(request, 'emailPremium/emailLimits.html', Data)
|
||||
if domainLimits.limitStatus == 1:
|
||||
Data['limitsOn'] = 1
|
||||
Data['limitsOff'] = 0
|
||||
else:
|
||||
return render(request, 'emailPremium/emailLimits.html',
|
||||
{"error": 1, "domain": "You do not own this domain."})
|
||||
Data['limitsOn'] = 0
|
||||
Data['limitsOff'] = 1
|
||||
|
||||
## Pagination for emails
|
||||
|
||||
|
||||
pages = float(Data['emailAccounts']) / float(10)
|
||||
pagination = []
|
||||
|
||||
if pages <= 1.0:
|
||||
pages = 1
|
||||
pagination.append('<li><a href="\#"></a></li>')
|
||||
else:
|
||||
pages = ceil(pages)
|
||||
finalPages = int(pages) + 1
|
||||
|
||||
for i in range(1, finalPages):
|
||||
pagination.append('<li><a href="\#">' + str(i) + '</a></li>')
|
||||
|
||||
Data['pagination'] = pagination
|
||||
|
||||
return render(request, 'emailPremium/emailLimits.html', Data)
|
||||
else:
|
||||
return render(request, 'emailPremium/emailLimits.html', {"error":1,"domain": "This domain does not exists"})
|
||||
except KeyError:
|
||||
@@ -245,17 +237,16 @@ def emailLimits(request,domain):
|
||||
|
||||
def changeDomainLimit(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
|
||||
if admin.type != 1:
|
||||
dic = {'status': 0, 'error_message': "Only administrator can view this page."}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
data = json.loads(request.body)
|
||||
newLimit = data['newLimit']
|
||||
domainName = data['domainName']
|
||||
@@ -286,15 +277,15 @@ def changeDomainLimit(request):
|
||||
|
||||
def getFurtherEmail(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
|
||||
if admin.type != 1:
|
||||
dic = {'status': 0, 'error_message': "Only administrator can view this page."}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
data = json.loads(request.body)
|
||||
status = data['page']
|
||||
@@ -346,17 +337,16 @@ def getFurtherEmail(request):
|
||||
|
||||
def enableDisableIndividualEmailLimits(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
|
||||
if admin.type != 1:
|
||||
dic = {'status': 0, 'error_message': "Only administrator can view this page."}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
data = json.loads(request.body)
|
||||
operationVal = data['operationVal']
|
||||
emailAddress = data['emailAddress']
|
||||
@@ -385,11 +375,13 @@ def enableDisableIndividualEmailLimits(request):
|
||||
|
||||
def emailPage(request, emailAddress):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if admin.type != 1:
|
||||
return HttpResponse("Only administrator can view this page.")
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadError()
|
||||
|
||||
Data = {}
|
||||
Data['emailAddress'] = emailAddress
|
||||
@@ -418,17 +410,16 @@ def emailPage(request, emailAddress):
|
||||
|
||||
def getEmailStats(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
|
||||
if admin.type != 1:
|
||||
dic = {'status': 0, 'error_message': "Only administrator can view this page."}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
data = json.loads(request.body)
|
||||
emailAddress = data['emailAddress']
|
||||
|
||||
@@ -459,17 +450,16 @@ def getEmailStats(request):
|
||||
|
||||
def enableDisableIndividualEmailLogs(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
|
||||
if admin.type != 1:
|
||||
dic = {'status': 0, 'error_message': "Only administrator can view this page."}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
data = json.loads(request.body)
|
||||
operationVal = data['operationVal']
|
||||
emailAddress = data['emailAddress']
|
||||
@@ -498,17 +488,16 @@ def enableDisableIndividualEmailLogs(request):
|
||||
|
||||
def changeDomainEmailLimitsIndividual(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
|
||||
if admin.type != 1:
|
||||
dic = {'status': 0, 'error_message': "Only administrator can view this page."}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
data = json.loads(request.body)
|
||||
emailAddress = data['emailAddress']
|
||||
monthlyLimit = data['monthlyLimit']
|
||||
@@ -571,17 +560,16 @@ def changeDomainEmailLimitsIndividual(request):
|
||||
|
||||
def getEmailLogs(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
|
||||
if admin.type != 1:
|
||||
dic = {'status': 0, 'error_message': "Only administrator can view this page."}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
data = json.loads(request.body)
|
||||
status = data['page']
|
||||
emailAddress = data['emailAddress']
|
||||
@@ -626,17 +614,16 @@ def getEmailLogs(request):
|
||||
|
||||
def flushEmailLogs(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
|
||||
if admin.type != 1:
|
||||
dic = {'status': 0, 'error_message': "Only administrator can view this page."}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
data = json.loads(request.body)
|
||||
emailAddress = data['emailAddress']
|
||||
|
||||
@@ -664,11 +651,13 @@ def flushEmailLogs(request):
|
||||
|
||||
def spamAssassinHome(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if admin.type != 1:
|
||||
return HttpResponse("Only administrator can view this page.")
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadError()
|
||||
|
||||
checkIfSpamAssassinInstalled = 0
|
||||
|
||||
@@ -682,16 +671,14 @@ def spamAssassinHome(request):
|
||||
|
||||
def installSpamAssassin(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
try:
|
||||
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
|
||||
if admin.type != 1:
|
||||
dic = {'status': 0, 'error_message': "Only administrator can view this page."}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
thread.start_new_thread(mailUtilities.installSpamAssassin, ('Install','SpamAssassin'))
|
||||
final_json = json.dumps({'status': 1, 'error_message': "None"})
|
||||
return HttpResponse(final_json)
|
||||
@@ -706,17 +693,10 @@ def installSpamAssassin(request):
|
||||
|
||||
def installStatusSpamAssassin(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
userID = request.session['userID']
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
|
||||
if admin.type != 1:
|
||||
dic = {'status': 0, 'error_message': "Only administrator can view this page."}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
command = "sudo cat " + mailUtilities.spamassassinInstallLogPath
|
||||
installStatus = subprocess.check_output(shlex.split(command))
|
||||
|
||||
@@ -763,8 +743,6 @@ def installStatusSpamAssassin(request):
|
||||
'requestStatus': installStatus,
|
||||
})
|
||||
return HttpResponse(final_json)
|
||||
|
||||
|
||||
except BaseException,msg:
|
||||
final_dic = {'abort':1,'installed':0, 'error_message': str(msg)}
|
||||
final_json = json.dumps(final_dic)
|
||||
@@ -774,19 +752,19 @@ def installStatusSpamAssassin(request):
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
|
||||
def fetchSpamAssassinSettings(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson('fetchStatus', 0)
|
||||
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
if admin.type != 1:
|
||||
final_dic = {'fetchStatus': 0, 'error_message': 'Not enough privileges.'}
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
report_safe = 0
|
||||
required_hits = '5.0'
|
||||
rewrite_header = 'Subject [SPAM]'
|
||||
@@ -848,16 +826,16 @@ def fetchSpamAssassinSettings(request):
|
||||
|
||||
def saveSpamAssassinConfigurations(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson('saveStatus', 0)
|
||||
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
if admin.type != 1:
|
||||
dic = {'status': 0, 'error_message': "Only administrator can view this page."}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
data = json.loads(request.body)
|
||||
|
||||
report_safe = data['report_safe']
|
||||
@@ -922,11 +900,13 @@ def saveSpamAssassinConfigurations(request):
|
||||
|
||||
def emailPolicyServer(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if admin.type != 1:
|
||||
return HttpResponse("Only administrator can view this page.")
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadError()
|
||||
|
||||
return render(request, 'emailPremium/policyServer.html')
|
||||
|
||||
@@ -935,16 +915,16 @@ def emailPolicyServer(request):
|
||||
|
||||
def fetchPolicyServerStatus(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
if admin.type != 1:
|
||||
dic = {'status': 0, 'error_message': "Only administrator can view this page."}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
command = 'sudo cat /etc/postfix/main.cf'
|
||||
output = subprocess.check_output(shlex.split(command)).split('\n')
|
||||
|
||||
@@ -974,16 +954,16 @@ def fetchPolicyServerStatus(request):
|
||||
|
||||
def savePolicyServerStatus(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadErrorJson()
|
||||
try:
|
||||
if request.method == 'POST':
|
||||
|
||||
if admin.type != 1:
|
||||
dic = {'status': 0, 'error_message': "Only administrator can view this page."}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
data = json.loads(request.body)
|
||||
|
||||
policServerStatus = data['policServerStatus']
|
||||
|
||||
Reference in New Issue
Block a user