mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-05-09 20:46:16 +02:00
ACL Manager
This commit is contained in:
@@ -7,33 +7,37 @@ from django.http import HttpResponse
|
||||
import json
|
||||
import plogical.CyberCPLogFileWriter as logging
|
||||
from plogical.installUtilities import installUtilities
|
||||
from loginSystem.models import Administrator
|
||||
import subprocess
|
||||
import shlex
|
||||
from plogical.virtualHostUtilities import virtualHostUtilities
|
||||
from plogical.acl import ACLManager
|
||||
# Create your views here.
|
||||
|
||||
|
||||
def logsHome(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
if admin.type == 3:
|
||||
return HttpResponse("You don't have enough privileges to access this page.")
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadError()
|
||||
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
return render(request,'serverLogs/index.html')
|
||||
|
||||
|
||||
def accessLogs(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
if admin.type == 3:
|
||||
return HttpResponse("You don't have enough privileges to access this page.")
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadError()
|
||||
|
||||
return render(request,'serverLogs/accessLogs.html')
|
||||
|
||||
@@ -41,15 +45,15 @@ def accessLogs(request):
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[accessLogs]")
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def errorLogs(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
|
||||
if admin.type == 3:
|
||||
return HttpResponse("You don't have enough privileges to access this page.")
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadError()
|
||||
|
||||
|
||||
return render(request,'serverLogs/errorLogs.html')
|
||||
@@ -60,13 +64,13 @@ def errorLogs(request):
|
||||
|
||||
def ftplogs(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
|
||||
if admin.type == 3:
|
||||
return HttpResponse("You don't have enough privileges to access this page.")
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadError()
|
||||
|
||||
return render(request,'serverLogs/ftplogs.html')
|
||||
|
||||
@@ -76,12 +80,13 @@ def ftplogs(request):
|
||||
|
||||
def emailLogs(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
|
||||
if admin.type == 3:
|
||||
return HttpResponse("You don't have enough privileges to access this page.")
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadError()
|
||||
|
||||
|
||||
return render(request,'serverLogs/emailLogs.html')
|
||||
@@ -92,13 +97,13 @@ def emailLogs(request):
|
||||
|
||||
def modSecAuditLogs(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
|
||||
admin = Administrator.objects.get(pk=val)
|
||||
|
||||
if admin.type == 3:
|
||||
return HttpResponse("You don't have enough privileges to access this page.")
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
return ACLManager.loadError()
|
||||
|
||||
return render(request,'serverLogs/modSecAuditLog.html')
|
||||
|
||||
@@ -106,41 +111,37 @@ def modSecAuditLogs(request):
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[accessLogs]")
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def getLogsFromFile(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
|
||||
admin = Administrator.objects.get(id=val)
|
||||
|
||||
if admin.type == 1:
|
||||
data = json.loads(request.body)
|
||||
type = data['type']
|
||||
|
||||
if type=="access":
|
||||
fileName = installUtilities.Server_root_path+"/logs/access.log"
|
||||
elif type=="error":
|
||||
fileName = installUtilities.Server_root_path + "/logs/error.log"
|
||||
elif type=="email":
|
||||
fileName="/var/log/maillog"
|
||||
elif type=="ftp":
|
||||
fileName="/var/log/messages"
|
||||
elif type == "modSec":
|
||||
fileName = "/usr/local/lsws/logs/auditmodsec.log"
|
||||
|
||||
|
||||
command = "sudo tail -50 " + fileName
|
||||
|
||||
fewLinesOfLogFile = subprocess.check_output(shlex.split(command))
|
||||
|
||||
status = {"logstatus":1,"logsdata":fewLinesOfLogFile}
|
||||
final_json = json.dumps(status)
|
||||
return HttpResponse(final_json)
|
||||
userID = request.session['userID']
|
||||
currentACL = ACLManager.loadedACL(userID)
|
||||
|
||||
if currentACL['admin'] == 1:
|
||||
pass
|
||||
else:
|
||||
status = {"logstatus": 0, 'error': "You don't have enough privileges to access this page."}
|
||||
final_json = json.dumps(status)
|
||||
return HttpResponse(final_json)
|
||||
return ACLManager.loadErrorJson('logstatus', 0)
|
||||
|
||||
data = json.loads(request.body)
|
||||
type = data['type']
|
||||
|
||||
if type == "access":
|
||||
fileName = installUtilities.Server_root_path + "/logs/access.log"
|
||||
elif type == "error":
|
||||
fileName = installUtilities.Server_root_path + "/logs/error.log"
|
||||
elif type == "email":
|
||||
fileName = "/var/log/maillog"
|
||||
elif type == "ftp":
|
||||
fileName = "/var/log/messages"
|
||||
elif type == "modSec":
|
||||
fileName = "/usr/local/lsws/logs/auditmodsec.log"
|
||||
|
||||
command = "sudo tail -50 " + fileName
|
||||
|
||||
fewLinesOfLogFile = subprocess.check_output(shlex.split(command))
|
||||
|
||||
status = {"logstatus": 1, "logsdata": fewLinesOfLogFile}
|
||||
final_json = json.dumps(status)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
|
||||
except KeyError, msg:
|
||||
@@ -150,34 +151,35 @@ def getLogsFromFile(request):
|
||||
|
||||
def clearLogFile(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('cleanStatus', 0)
|
||||
|
||||
try:
|
||||
if admin.type == 1:
|
||||
if request.method == 'POST':
|
||||
if request.method == 'POST':
|
||||
|
||||
data = json.loads(request.body)
|
||||
data = json.loads(request.body)
|
||||
|
||||
fileName = data['fileName']
|
||||
fileName = data['fileName']
|
||||
|
||||
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/serverLogs.py"
|
||||
execPath = "sudo python " + virtualHostUtilities.cyberPanel + "/plogical/serverLogs.py"
|
||||
|
||||
execPath = execPath + " cleanLogFile --fileName " + fileName
|
||||
execPath = execPath + " cleanLogFile --fileName " + fileName
|
||||
|
||||
output = subprocess.check_output(shlex.split(execPath))
|
||||
output = subprocess.check_output(shlex.split(execPath))
|
||||
|
||||
if output.find("1,None") > -1:
|
||||
data_ret = {'cleanStatus': 1, 'error_message': "None"}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
else:
|
||||
data_ret = {'cleanStatus': 0, 'error_message': output}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
else:
|
||||
data_ret = {'cleanStatus': 0, 'error_message': 'Not enough privileges.'}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
if output.find("1,None") > -1:
|
||||
data_ret = {'cleanStatus': 1, 'error_message': "None"}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
else:
|
||||
data_ret = {'cleanStatus': 0, 'error_message': output}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
except BaseException,msg:
|
||||
data_ret = {'cleanStatus': 0, 'error_message': str(msg)}
|
||||
|
||||
Reference in New Issue
Block a user