import threading as multi from plogical.acl import ACLManager import plogical.CyberCPLogFileWriter as logging from plogical.processUtilities import ProcessUtilities from django.shortcuts import render import os from serverStatus.serverStatusUtil import ServerStatusUtil import json from django.shortcuts import HttpResponse from math import ceil from websiteFunctions.models import Websites from .models import CLPackages class CLManagerMain(multi.Thread): def __init__(self, request=None, templateName=None, function=None, data=None): multi.Thread.__init__(self) self.request = request self.templateName = templateName self.function = function self.data = data def run(self): try: if self.function == 'submitCageFSInstall': self.submitCageFSInstall() elif self.function == 'enableOrDisable': self.enableOrDisable() except BaseException, msg: logging.CyberCPLogFileWriter.writeToFile(str(msg) + ' [ContainerManager.run]') def renderC(self): userID = self.request.session['userID'] currentACL = ACLManager.loadedACL(userID) if currentACL['admin'] == 1: pass else: return ACLManager.loadError() data = {} data['CL'] = 0 data['CAGEFS'] = 0 CLPath = '/etc/sysconfig/cloudlinux' CageFSPath = '/usr/sbin/cagefsctl' if os.path.exists(CLPath): data['CL'] = 1 if os.path.exists(CageFSPath): data['CAGEFS'] = 1 if data['CL'] == 0: return render(self.request, 'CLManager/notAvailable.html', data) elif data['CAGEFS'] == 0: return render(self.request, 'CLManager/notAvailable.html', data) else: return render(self.request, self.templateName, self.data) def submitCageFSInstall(self): try: userID = self.request.session['userID'] currentACL = ACLManager.loadedACL(userID) if currentACL['admin'] == 1: pass else: logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, 'Not authorized to install container packages. [404].', 1) return 0 execPath = "/usr/local/CyberCP/bin/python2 /usr/local/CyberCP/CLManager/CageFS.py" execPath = execPath + " --function submitCageFSInstall" ProcessUtilities.outputExecutioner(execPath) except BaseException, msg: logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, str(msg) + ' [404].', 1) def findWebsitesJson(self, currentACL, userID, pageNumber): finalPageNumber = ((pageNumber * 10)) - 10 endPageNumber = finalPageNumber + 10 websites = ACLManager.findWebsiteObjects(currentACL, userID)[finalPageNumber:endPageNumber] json_data = "[" checker = 0 command = '/usr/sbin/cagefsctl --list-enabled' Enabled = ProcessUtilities.outputExecutioner(command) for items in websites: if Enabled.find(items.externalApp) > -1: status = 1 else: status = 0 dic = {'domain': items.domain, 'externalApp': items.externalApp, 'status': status} if checker == 0: json_data = json_data + json.dumps(dic) checker = 1 else: json_data = json_data + ',' + json.dumps(dic) json_data = json_data + ']' return json_data def websitePagination(self, currentACL, userID): websites = ACLManager.findAllSites(currentACL, userID) pages = float(len(websites)) / float(10) pagination = [] if pages <= 1.0: pages = 1 pagination.append('