Skip to content

Commit 44983fa

Browse files
committed
CloudLinux, CageFS and security improvements
1 parent 5c8e25e commit 44983fa

File tree

85 files changed

+7512
-3248
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+7512
-3248
lines changed

CLManager/CLManagerMain.py

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
import threading as multi
2+
from plogical.acl import ACLManager
3+
import plogical.CyberCPLogFileWriter as logging
4+
from plogical.processUtilities import ProcessUtilities
5+
from django.shortcuts import render
6+
import os
7+
from serverStatus.serverStatusUtil import ServerStatusUtil
8+
import json
9+
from django.shortcuts import HttpResponse
10+
from math import ceil
11+
from websiteFunctions.models import Websites
12+
from .models import CLPackages
13+
14+
15+
class CLManagerMain(multi.Thread):
16+
17+
def __init__(self, request=None, templateName=None, function=None, data=None):
18+
multi.Thread.__init__(self)
19+
self.request = request
20+
self.templateName = templateName
21+
self.function = function
22+
self.data = data
23+
24+
def run(self):
25+
try:
26+
if self.function == 'submitCageFSInstall':
27+
self.submitCageFSInstall()
28+
elif self.function == 'enableOrDisable':
29+
self.enableOrDisable()
30+
31+
except BaseException, msg:
32+
logging.CyberCPLogFileWriter.writeToFile(str(msg) + ' [ContainerManager.run]')
33+
34+
def renderC(self):
35+
36+
userID = self.request.session['userID']
37+
currentACL = ACLManager.loadedACL(userID)
38+
39+
if currentACL['admin'] == 1:
40+
pass
41+
else:
42+
return ACLManager.loadError()
43+
44+
data = {}
45+
data['CL'] = 0
46+
data['CAGEFS'] = 0
47+
CLPath = '/etc/sysconfig/cloudlinux'
48+
CageFSPath = '/usr/sbin/cagefsctl'
49+
50+
if os.path.exists(CLPath):
51+
data['CL'] = 1
52+
53+
if os.path.exists(CageFSPath):
54+
data['CAGEFS'] = 1
55+
56+
if data['CL'] == 0:
57+
return render(self.request, 'CLManager/notAvailable.html', data)
58+
elif data['CAGEFS'] == 0:
59+
return render(self.request, 'CLManager/notAvailable.html', data)
60+
else:
61+
return render(self.request, self.templateName, self.data)
62+
63+
def submitCageFSInstall(self):
64+
try:
65+
userID = self.request.session['userID']
66+
currentACL = ACLManager.loadedACL(userID)
67+
68+
if currentACL['admin'] == 1:
69+
pass
70+
else:
71+
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath,
72+
'Not authorized to install container packages. [404].',
73+
1)
74+
return 0
75+
76+
execPath = "sudo python /usr/local/CyberCP/CLManager/CageFS.py"
77+
execPath = execPath + " --function submitCageFSInstall"
78+
ProcessUtilities.outputExecutioner(execPath)
79+
80+
except BaseException, msg:
81+
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, str(msg) + ' [404].', 1)
82+
83+
def findWebsitesJson(self, currentACL, userID, pageNumber):
84+
finalPageNumber = ((pageNumber * 10)) - 10
85+
endPageNumber = finalPageNumber + 10
86+
websites = ACLManager.findWebsiteObjects(currentACL, userID)[finalPageNumber:endPageNumber]
87+
88+
json_data = "["
89+
checker = 0
90+
91+
command = '/usr/sbin/cagefsctl --list-enabled'
92+
Enabled = ProcessUtilities.outputExecutioner(command)
93+
94+
for items in websites:
95+
if Enabled.find(items.externalApp) > -1:
96+
status = 1
97+
else:
98+
status = 0
99+
dic = {'domain': items.domain, 'externalApp': items.externalApp, 'status': status}
100+
101+
if checker == 0:
102+
json_data = json_data + json.dumps(dic)
103+
checker = 1
104+
else:
105+
json_data = json_data + ',' + json.dumps(dic)
106+
107+
json_data = json_data + ']'
108+
109+
return json_data
110+
111+
def websitePagination(self, currentACL, userID):
112+
websites = ACLManager.findAllSites(currentACL, userID)
113+
114+
pages = float(len(websites)) / float(10)
115+
pagination = []
116+
117+
if pages <= 1.0:
118+
pages = 1
119+
pagination.append('<li><a href="\#"></a></li>')
120+
else:
121+
pages = ceil(pages)
122+
finalPages = int(pages) + 1
123+
124+
for i in range(1, finalPages):
125+
pagination.append('<li><a href="\#">' + str(i) + '</a></li>')
126+
127+
return pagination
128+
129+
def getFurtherAccounts(self, userID=None, data=None):
130+
try:
131+
currentACL = ACLManager.loadedACL(userID)
132+
pageNumber = int(data['page'])
133+
json_data = self.findWebsitesJson(currentACL, userID, pageNumber)
134+
pagination = self.websitePagination(currentACL, userID)
135+
136+
cageFSPath = '/home/cyberpanel/cagefs'
137+
138+
if os.path.exists(cageFSPath):
139+
default = 'On'
140+
else:
141+
default = 'Off'
142+
143+
final_dic = {'status': 1, 'listWebSiteStatus': 1, 'error_message': "None", "data": json_data,
144+
'pagination': pagination, 'default': default}
145+
final_json = json.dumps(final_dic)
146+
return HttpResponse(final_json)
147+
except BaseException, msg:
148+
dic = {'status': 1, 'listWebSiteStatus': 0, 'error_message': str(msg)}
149+
json_data = json.dumps(dic)
150+
return HttpResponse(json_data)
151+
152+
def enableOrDisable(self):
153+
try:
154+
websites = Websites.objects.all()
155+
if self.data['mode'] == 1:
156+
for items in websites:
157+
command = '/usr/sbin/cagefsctl --enable %s' % (items.externalApp)
158+
ProcessUtilities.executioner(command)
159+
else:
160+
for items in websites:
161+
command = '/usr/sbin/cagefsctl --disable %s' % (items.externalApp)
162+
ProcessUtilities.executioner(command)
163+
except BaseException, msg:
164+
logging.CyberCPLogFileWriter.writeToFile(str(msg))
165+
166+
def fetchPackages(self, currentACL):
167+
168+
if currentACL['admin'] == 1:
169+
pass
170+
else:
171+
return ACLManager.loadErrorJson()
172+
173+
json_data = "["
174+
checker = 0
175+
176+
for items in CLPackages.objects.all():
177+
dic = {'name': items.name, 'SPEED': items.speed, 'VMEM': items.vmem, 'PMEM': items.pmem, 'IO': items.io, 'IOPS': items.iops, 'EP': items.ep,
178+
'NPROC': items.nproc, 'inodessoft': items.inodessoft, 'inodeshard': items.inodeshard}
179+
180+
if checker == 0:
181+
json_data = json_data + json.dumps(dic)
182+
checker = 1
183+
else:
184+
json_data = json_data + ',' + json.dumps(dic)
185+
186+
json_data = json_data + ']'
187+
188+
final_dic = {'status': 1, 'error_message': "None", "data": json_data}
189+
final_json = json.dumps(final_dic)
190+
return HttpResponse(final_json)
191+

CLManager/CLPackages.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/local/CyberCP/bin/python2
2+
import os
3+
import os.path
4+
import sys
5+
import django
6+
sys.path.append('/usr/local/CyberCP')
7+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
8+
django.setup()
9+
import argparse
10+
from websiteFunctions.models import Websites
11+
from CLManager.models import CLPackages
12+
import pwd
13+
14+
class CLinuxPackages:
15+
16+
@staticmethod
17+
def listAll():
18+
for items in Websites.objects.all():
19+
itemPackage = items.package
20+
try:
21+
clPackage = CLPackages.objects.get(owner=itemPackage)
22+
statement = '%s %s' % (pwd.getpwnam(items.externalApp).pw_uid, clPackage.name)
23+
print statement
24+
except:
25+
pass
26+
27+
28+
@staticmethod
29+
def listPackages():
30+
for items in CLPackages.objects.all():
31+
print items.name
32+
33+
@staticmethod
34+
def userIDPackage(user):
35+
website = Websites.objects.get(externalApp=user)
36+
itemPackage = website.package
37+
try:
38+
clPackage = CLPackages.objects.get(owner=itemPackage)
39+
print clPackage
40+
except:
41+
pass
42+
43+
44+
@staticmethod
45+
def packageForUser(package):
46+
for items in Websites.objects.all():
47+
itemPackage = items.package
48+
try:
49+
clPackage = CLPackages.objects.get(owner=itemPackage)
50+
if clPackage.name == package:
51+
print pwd.getpwnam(items.externalApp).pw_uid
52+
except:
53+
pass
54+
55+
def main():
56+
57+
parser = argparse.ArgumentParser(description='CyberPanel Container Manager')
58+
parser.add_argument('--userid', help='User ID')
59+
parser.add_argument('--package', help='Package')
60+
parser.add_argument('--function', help='Function')
61+
parser.add_argument('--list-all', help='List all users/packages.', action='store_true')
62+
parser.add_argument('--list-packages', help='List all packages.', action='store_true')
63+
64+
65+
args = vars(parser.parse_args())
66+
67+
if args['userid']:
68+
CLinuxPackages.userIDPackage(args['userid'])
69+
elif args['package']:
70+
CLinuxPackages.packageForUser(args['package'])
71+
elif args['list_all']:
72+
CLinuxPackages.listAll()
73+
elif args['list_packages']:
74+
CLinuxPackages.listPackages()
75+
76+
77+
78+
79+
80+
if __name__ == "__main__":
81+
main()
82+

CLManager/CageFS.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/local/CyberCP/bin/python2
2+
import sys
3+
sys.path.append('/usr/local/CyberCP')
4+
import plogical.CyberCPLogFileWriter as logging
5+
import argparse
6+
from plogical.mailUtilities import mailUtilities
7+
from serverStatus.serverStatusUtil import ServerStatusUtil
8+
9+
10+
class CageFS:
11+
packages = ['talksho']
12+
users = ['5001']
13+
14+
@staticmethod
15+
def submitCageFSInstall():
16+
try:
17+
18+
mailUtilities.checkHome()
19+
20+
statusFile = open(ServerStatusUtil.lswsInstallStatusPath, 'w')
21+
22+
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath,
23+
"Starting Packages Installation..\n", 1)
24+
25+
command = 'sudo yum install cagefs -y'
26+
ServerStatusUtil.executioner(command, statusFile)
27+
28+
command = 'sudo /usr/sbin/cagefsctl --init'
29+
ServerStatusUtil.executioner(command, statusFile)
30+
31+
command = 'sudo /usr/sbin/cagefsctl --update-etc'
32+
ServerStatusUtil.executioner(command, statusFile)
33+
34+
command = 'sudo /usr/sbin/cagefsctl --force-update'
35+
ServerStatusUtil.executioner(command, statusFile)
36+
37+
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath,
38+
"Packages successfully installed.[200]\n", 1)
39+
40+
except BaseException, msg:
41+
logging.CyberCPLogFileWriter.statusWriter(ServerStatusUtil.lswsInstallStatusPath, str(msg) + ' [404].', 1)
42+
43+
def main():
44+
45+
parser = argparse.ArgumentParser(description='CyberPanel CageFS Manager')
46+
parser.add_argument('--function', help='Function')
47+
48+
49+
args = vars(parser.parse_args())
50+
51+
if args["function"] == "submitCageFSInstall":
52+
CageFS.submitCageFSInstall()
53+
54+
55+
56+
57+
58+
if __name__ == "__main__":
59+
main()
60+

CLManager/__init__.py

Whitespace-only changes.

CLManager/admin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.contrib import admin
5+
6+
# Register your models here.

CLManager/apps.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.apps import AppConfig
5+
6+
7+
class ClmanagerConfig(AppConfig):
8+
name = 'CLManager'

CLManager/migrations/__init__.py

Whitespace-only changes.

CLManager/models.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import models
5+
from packages.models import Package
6+
7+
# Create your models here.
8+
9+
class CLPackages(models.Model):
10+
owner = models.ForeignKey(Package)
11+
name = models.CharField(max_length=50,unique=True)
12+
speed = models.CharField(max_length=50)
13+
vmem = models.CharField(max_length=50)
14+
pmem = models.CharField(max_length=50)
15+
io = models.CharField(max_length=50)
16+
iops = models.CharField(max_length=50)
17+
ep = models.CharField(max_length=50)
18+
nproc = models.CharField(max_length=50)
19+
inodessoft = models.CharField(max_length=50)
20+
inodeshard = models.CharField(max_length=50)

0 commit comments

Comments
 (0)