mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-10-26 07:46:35 +01:00
136 lines
4.8 KiB
Python
136 lines
4.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from django.shortcuts import render, HttpResponse
|
|
import json
|
|
from plogical.processUtilities import ProcessUtilities
|
|
|
|
|
|
class httpProc:
|
|
def __init__(self, request, templateName, data = None, function = None):
|
|
self.request = request
|
|
self.templateName = templateName
|
|
self.data = data
|
|
self.function = function
|
|
|
|
|
|
def render(self):
|
|
try:
|
|
userID = self.request.session['userID']
|
|
try:
|
|
from loginSystem.models import Administrator
|
|
from plogical.acl import ACLManager
|
|
|
|
currentACL = ACLManager.loadedACL(userID)
|
|
admin = Administrator.objects.get(pk=userID)
|
|
|
|
### Permissions Check
|
|
|
|
if self.function != None:
|
|
if not currentACL['admin']:
|
|
if not currentACL[self.function]:
|
|
templateName = 'baseTemplate/error.html'
|
|
return render(self.request, templateName, {'error_message': 'You are not authorized to access %s' % (self.function)})
|
|
|
|
###
|
|
|
|
if self.data == None:
|
|
self.data = {}
|
|
|
|
from IncBackups.models import OneClickBackups
|
|
if OneClickBackups.objects.filter(owner=admin).count() == 0:
|
|
self.data['backupDisplay'] = 1
|
|
else:
|
|
self.data['backupDisplay'] = 0
|
|
|
|
### Onboarding checks
|
|
|
|
if currentACL['admin']:
|
|
try:
|
|
admin = Administrator.objects.get(userName='admin')
|
|
config = json.loads(admin.config)
|
|
self.data['onboarding'] = config['onboarding']
|
|
except:
|
|
self.data['onboarding'] = 0
|
|
self.data['onboardingError'] = """
|
|
Please launch the <a href="/base/onboarding">set-up wizard</a> to get maximum out of your CyberPanel installation.
|
|
"""
|
|
else:
|
|
|
|
self.data['onboarding'] = 2
|
|
|
|
ipFile = "/etc/cyberpanel/machineIP"
|
|
f = open(ipFile)
|
|
ipData = f.read()
|
|
ipAddress = ipData.split('\n', 1)[0]
|
|
self.data['ipAddress'] = ipAddress
|
|
self.data['fullName'] = '%s %s' % (admin.firstName, admin.lastName)
|
|
# self.data['serverCheck'] = 1
|
|
|
|
if ProcessUtilities.decideServer() == ProcessUtilities.ent:
|
|
self.data['serverCheck'] = 1
|
|
|
|
### Load Custom CSS
|
|
try:
|
|
from baseTemplate.models import CyberPanelCosmetic
|
|
cosmetic = CyberPanelCosmetic.objects.get(pk=1)
|
|
self.data['cosmetic'] = cosmetic
|
|
except:
|
|
try:
|
|
from baseTemplate.models import CyberPanelCosmetic
|
|
cosmetic = CyberPanelCosmetic()
|
|
cosmetic.save()
|
|
self.data['cosmetic'] = cosmetic
|
|
except:
|
|
pass
|
|
|
|
|
|
ACLManager.GetServiceStatus(self.data)
|
|
|
|
self.data.update(currentACL)
|
|
|
|
return render(self.request, self.templateName, self.data)
|
|
except BaseException as msg:
|
|
templateName = 'baseTemplate/error.html'
|
|
return render(self.request, templateName, {'error_message': str(msg)})
|
|
except:
|
|
from loginSystem.views import loadLoginPage
|
|
from django.shortcuts import redirect
|
|
return redirect(loadLoginPage)
|
|
|
|
def renderPre(self):
|
|
if self.data == None:
|
|
return render(self.request, self.templateName)
|
|
else:
|
|
return render(self.request, self.templateName, self.data)
|
|
|
|
def ajaxPre(self, status, errorMessage, success = None):
|
|
final_dic = {'status': status, 'error_message': errorMessage, 'success': success}
|
|
final_json = json.dumps(final_dic)
|
|
return HttpResponse(final_json)
|
|
|
|
def ajax(self, status, errorMessage, data = None):
|
|
if data == None:
|
|
finalDic = {'status': status, 'error_message': errorMessage}
|
|
finalJson = json.dumps(finalDic)
|
|
return HttpResponse(finalJson)
|
|
else:
|
|
finalDic = {}
|
|
finalDic['status'] = status
|
|
finalDic['error_message'] = errorMessage
|
|
|
|
for key, value in data.items():
|
|
finalDic[key] = value
|
|
|
|
finalJson = json.dumps(finalDic)
|
|
return HttpResponse(finalJson)
|
|
|
|
@staticmethod
|
|
def AJAX(status, errorMessage, success = None):
|
|
final_dic = {'status': status, 'error_message': errorMessage, 'success': success}
|
|
final_json = json.dumps(final_dic)
|
|
return HttpResponse(final_json)
|
|
|
|
|
|
|
|
|