diff --git a/CLManager/CageFS.py b/CLManager/CageFS.py index 9baaa8bc6..2e4729b84 100644 --- a/CLManager/CageFS.py +++ b/CLManager/CageFS.py @@ -108,6 +108,26 @@ def submitCageFSInstall(): writeToFile.write('CLInstalled') writeToFile.close() + + + #### mount session save paths + + if os.path.exists('/etc/cagefs/cagefs.mp'): + + from managePHP.phpManager import PHPManager + php_versions = PHPManager.findPHPVersions() + + for php in php_versions: + PHPVers = PHPManager.getPHPString(php) + line = f'@/var/lib/lsphp/session/lsphp{PHPVers},700\n' + + WriteToFile = open('/etc/cagefs/cagefs.mp', 'a') + WriteToFile.write(line) + WriteToFile.close() + + command = 'cagefsctl --remount-all' + ServerStatusUtil.executioner(command, statusFile) + logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, "Packages successfully installed.[200]\n", 1) diff --git a/baseTemplate/static/baseTemplate/assets/finalBase/favicon.png b/baseTemplate/static/baseTemplate/assets/finalBase/favicon.png index f72790ed5..8834c6716 100644 Binary files a/baseTemplate/static/baseTemplate/assets/finalBase/favicon.png and b/baseTemplate/static/baseTemplate/assets/finalBase/favicon.png differ diff --git a/baseTemplate/templates/baseTemplate/index.html b/baseTemplate/templates/baseTemplate/index.html index fbd3bc549..8498b96a2 100755 --- a/baseTemplate/templates/baseTemplate/index.html +++ b/baseTemplate/templates/baseTemplate/index.html @@ -217,65 +217,6 @@ title="{% trans 'CPU Load Average' %}" data-placement="bottom"> {$ three $} {% endcomment %} - - {# #} @@ -430,6 +371,35 @@ + + + +
  • {% trans "Server" %}
  • + +
  • + + + {% trans "MySQL Manager" %} + {% trans "NEW" %} + +
  • +
  • #} - {# #} - {# #} - {# {% trans "Web Terminal" %}#} - {# {% trans "NEW" %}#} - {# #} - {# #} - {#
  • #}
  • ') + else: + pages = ceil(pages) + finalPages = int(pages) + 1 + + for i in range(1, finalPages): + pagination.append('
  • ' + str(i) + '
  • ') + + return pagination + def getSwitchStatus(self, userID=None, data=None): try: @@ -4670,7 +4777,7 @@ def tuneSettings(self, userID=None, data=None): else: phpVersion = f'PHP {phpPath[2]}' - #php = PHPManager.getPHPString(phpVersion) + # php = PHPManager.getPHPString(phpVersion) if os.path.exists(ProcessUtilities.debugPath): logging.CyberCPLogFileWriter.writeToFile(f'PHP Version in tune settings {phpVersion}') @@ -4690,7 +4797,7 @@ def tuneSettings(self, userID=None, data=None): json_data = json.dumps(data_ret) return HttpResponse(json_data) except BaseException as msg: - data_ret = {'status': 0, 'error_message': str(msg)} + data_ret = {'status': 0, 'error_message': str(msg)} json_data = json.dumps(data_ret) return HttpResponse(json_data) @@ -6450,7 +6557,6 @@ def addSSHKey(self, userID=None, data=None): final_json = json.dumps(final_dic) return HttpResponse(final_json) - def ApacheManager(self, request=None, userID=None, data=None): currentACL = ACLManager.loadedACL(userID) admin = Administrator.objects.get(pk=userID) @@ -6467,7 +6573,8 @@ def ApacheManager(self, request=None, userID=None, data=None): else: apachemanager = 0 - proc = httpProc(request, 'websiteFunctions/ApacheManager.html', {'domainName': self.domain, 'phps': phps, 'apachemanager':apachemanager}) + proc = httpProc(request, 'websiteFunctions/ApacheManager.html', + {'domainName': self.domain, 'phps': phps, 'apachemanager': apachemanager}) return proc.render() def saveApacheConfigsToFile(self, userID=None, data=None): @@ -6509,3 +6616,380 @@ def saveApacheConfigsToFile(self, userID=None, data=None): final_dic = {'status': 0, 'error_message': output} final_json = json.dumps(final_dic) return HttpResponse(final_json) + + def CreateDockerPackage(self, request=None, userID=None, data=None, DeleteID=None): + Data = {} + + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadError() + + try: + if DeleteID != None: + DockerPackagesDelete = DockerPackages.objects.get(pk=DeleteID) + DockerPackagesDelete.delete() + except: + pass + + Data['packages'] = DockerPackages.objects.all() + + proc = httpProc(request, 'websiteFunctions/CreateDockerPackage.html', + Data, 'createWebsite') + return proc.render() + + def AssignPackage(self, request=None, userID=None, data=None, DeleteID=None): + + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadError() + + try: + if DeleteID != None: + DockerPackagesDelete = PackageAssignment.objects.get(pk=DeleteID) + DockerPackagesDelete.delete() + except: + pass + + adminNames = ACLManager.loadAllUsers(userID) + dockerpackages = DockerPackages.objects.all() + assignpackage = PackageAssignment.objects.all() + Data = {'adminNames': adminNames, 'DockerPackages': dockerpackages, 'assignpackage': assignpackage} + proc = httpProc(request, 'websiteFunctions/assignPackage.html', + Data, 'createWebsite') + return proc.render() + + def CreateDockersite(self, request=None, userID=None, data=None): + adminNames = ACLManager.loadAllUsers(userID) + Data = {'adminNames': adminNames} + + + if PackageAssignment.objects.all().count() == 0: + + name = 'Default' + cpu = 2 + Memory = 1024 + Bandwidth = '100' + disk = '100' + + saveobj = DockerPackages(Name=name, CPUs=cpu, Ram=Memory, Bandwidth=Bandwidth, DiskSpace=disk, config='') + saveobj.save() + + userobj = Administrator.objects.get(pk=1) + + sv = PackageAssignment(user=userobj, package=saveobj) + sv.save() + + proc = httpProc(request, 'websiteFunctions/CreateDockerSite.html', + Data, 'createWebsite') + return proc.render() + + def AddDockerpackage(self, userID=None, data=None): + try: + + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadError() + + admin = Administrator.objects.get(pk=userID) + + name = data['name'] + cpu = data['cpu'] + Memory = data['Memory'] + Bandwidth = data['Bandwidth'] + disk = data['disk'] + + saveobj = DockerPackages(Name=name, CPUs=cpu, Ram=Memory, Bandwidth=Bandwidth, DiskSpace=disk, config='') + saveobj.save() + + status = {"status": 1, 'error_message': None} + final_json = json.dumps(status) + return HttpResponse(final_json) + except BaseException as msg: + final_dic = {'status': 0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + def Getpackage(self, userID=None, data=None): + try: + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadError() + + admin = Administrator.objects.get(pk=userID) + id = data['id'] + + docker_package = DockerPackages.objects.get(pk=id) + + # Convert DockerPackages object to dictionary + package_data = { + 'Name': docker_package.Name, + 'CPU': docker_package.CPUs, + 'Memory': docker_package.Ram, + 'Bandwidth': docker_package.Bandwidth, + 'DiskSpace': docker_package.DiskSpace, + } + + rdata = {'obj': package_data} + + status = {"status": 1, 'error_message': rdata} + final_json = json.dumps(status) + return HttpResponse(final_json) + except BaseException as msg: + final_dic = {'status': 0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + def Updatepackage(self, userID=None, data=None): + try: + + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadError() + + admin = Administrator.objects.get(pk=userID) + id = data['id'] + CPU = data['CPU'] + RAM = data['RAM'] + Bandwidth = data['Bandwidth'] + DiskSpace = data['DiskSpace'] + + docker_package = DockerPackages.objects.get(pk=id) + + docker_package.CPUs = CPU + docker_package.Ram = RAM + docker_package.Bandwidth = Bandwidth + docker_package.DiskSpace = DiskSpace + docker_package.save() + + status = {"status": 1, 'error_message': None} + final_json = json.dumps(status) + return HttpResponse(final_json) + + except BaseException as msg: + final_dic = {'status': 0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + def AddAssignment(self, userID=None, data=None): + try: + + currentACL = ACLManager.loadedACL(userID) + + if currentACL['admin'] == 1: + pass + else: + return ACLManager.loadError() + + + admin = Administrator.objects.get(pk=userID) + + package = data['package'] + user = data['user'] + + userobj = Administrator.objects.get(userName=user) + + delasg = PackageAssignment.objects.get(user=userobj) + delasg.delete() + + docker_package = DockerPackages.objects.get(pk=int(package)) + + sv = PackageAssignment(user=userobj, package=docker_package) + sv.save() + + status = {"status": 1, 'error_message': None} + final_json = json.dumps(status) + return HttpResponse(final_json) + + except BaseException as msg: + final_dic = {'status': 0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + def submitDockerSiteCreation(self, userID=None, data=None): + try: + admin = Administrator.objects.get(pk=userID) + currentACL = ACLManager.loadedACL(userID) + + sitename = data['sitename'] + Owner = data['Owner'] + Domain = data['Domain'] + MysqlCPU = int(data['MysqlCPU']) + MYsqlRam = int(data['MYsqlRam']) + SiteCPU = int(data['SiteCPU']) + SiteRam = int(data['SiteRam']) + App = data['App'] + WPusername = data['WPusername'] + WPemal = data['WPemal'] + WPpasswd = data['WPpasswd'] + + pattern = r"^[a-z0-9][a-z0-9]*$" + + if re.match(pattern, sitename): + pass + else: + final_dic = {'status': 0, 'error_message': f'invalid site name "{sitename}": must consist only of lowercase alphanumeric characters, as well as start with a letter or number.'} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + loggedUser = Administrator.objects.get(pk=userID) + newOwner = Administrator.objects.get(userName=Owner) + + try: + pkaobj = PackageAssignment.objects.get(user=newOwner) + except: + final_dic = {'status': 0, 'error_message': str('Please assign package to selected user')} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + Dpkgobj = DockerPackages.objects.get(pk=pkaobj.package.id) + + pkg_cpu = Dpkgobj.CPUs + pkg_Ram = Dpkgobj.Ram + + totalcup = SiteCPU + MysqlCPU + totalRam = SiteRam + MYsqlRam + + if (totalcup > pkg_cpu): + final_dic = {'status': 0, 'error_message': str(f'You can add {pkg_cpu} or less then {pkg_cpu} CPUs.')} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + if (totalRam > pkg_Ram): + final_dic = {'status': 0, 'error_message': str(f'You can add {pkg_Ram} or less then {pkg_Ram} Ram.')} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + if ACLManager.currentContextPermission(currentACL, 'createWebsite') == 0: + return ACLManager.loadErrorJson('createWebSiteStatus', 0) + + if ACLManager.checkOwnerProtection(currentACL, loggedUser, newOwner) == 0: + return ACLManager.loadErrorJson('createWebSiteStatus', 0) + + if ACLManager.CheckDomainBlackList(Domain) == 0: + data_ret = {'status': 0, 'createWebSiteStatus': 0, 'error_message': "Blacklisted domain."} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + tempStatusPath = "/home/cyberpanel/" + str(randint(1000, 9999)) + data = {} + + data['JobID'] = tempStatusPath + data['Domain'] = Domain + data['WPemal'] = WPemal + data['Owner'] = Owner + data['userID'] = userID + data['MysqlCPU'] = MysqlCPU + data['MYsqlRam'] = MYsqlRam + data['SiteCPU'] = SiteCPU + data['SiteRam'] = SiteRam + data['sitename'] = sitename + data['WPusername'] = WPusername + data['WPpasswd'] = WPpasswd + data['externalApp'] = "".join(re.findall("[a-zA-Z]+", Domain))[:5] + str(randint(1000, 9999)) + data['App'] = App + + background = Docker_Sites('SubmitDockersiteCreation', data) + background.start() + + time.sleep(2) + + data_ret = {'status': 1, 'installStatus': 1, 'error_message': 'None', + 'tempStatusPath': tempStatusPath} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) + + except BaseException as msg: + final_dic = {'status': 0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + def ListDockerSites(self, request=None, userID=None, data=None, DeleteID=None): + admin = Administrator.objects.get(pk=userID) + currentACL = ACLManager.loadedACL(userID) + fdata={} + + try: + if DeleteID != None: + + DockerSitesDelete = DockerSites.objects.get(pk=DeleteID) + if ACLManager.checkOwnership(DockerSitesDelete.admin.domain, admin, currentACL) == 1: + pass + else: + return ACLManager.loadError() + + passdata={} + passdata["domain"] = DockerSitesDelete.admin.domain + passdata["JobID"] = None + passdata['name'] = DockerSitesDelete.SiteName + da = Docker_Sites(None, passdata) + da.DeleteDockerApp() + DockerSitesDelete.delete() + fdata['Deleted'] = 1 + except BaseException as msg: + fdata['LPError'] = 1 + fdata['LPMessage'] = str(msg) + + + fdata['pagination'] = self.DockersitePagination(currentACL, userID) + + proc = httpProc(request, 'websiteFunctions/ListDockersite.html', + fdata) + return proc.render() + + def fetchDockersite(self, userID=None, data=None): + try: + currentACL = ACLManager.loadedACL(userID) + pageNumber = int(data['page']) + recordsToShow = int(data['recordsToShow']) + + + endPageNumber, finalPageNumber = self.recordsPointer(pageNumber, recordsToShow) + + dockersites = ACLManager.findDockersiteObjects(currentACL, userID) + pagination = self.getPagination(len(dockersites), recordsToShow) + logging.CyberCPLogFileWriter.writeToFile("Our dockersite" + str(dockersites)) + + + json_data = self.findDockersitesListJson(dockersites[finalPageNumber:endPageNumber]) + + + final_dic = {'status': 1, 'listWebSiteStatus': 1, 'error_message': "None", "data": json_data, + 'pagination': pagination} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + except BaseException as msg: + final_dic = {'status': 0, 'listWebSiteStatus': 1, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) + + def Dockersitehome(self, request=None, userID=None, data=None, DeleteID=None): + + currentACL = ACLManager.loadedACL(userID) + admin = Administrator.objects.get(pk=userID) + + ds = DockerSites.objects.get(pk=self.domain) + + if ACLManager.checkOwnership(ds.admin.domain, admin, currentACL) == 1: + pass + else: + return ACLManager.loadError() + + proc = httpProc(request, 'websiteFunctions/DockerSiteHome.html', + {'dockerSite': ds}) + return proc.render()