mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-07 13:56:01 +01:00
use new CloudLinux API
This commit is contained in:
16
CLScript/CLMain.py
Normal file
16
CLScript/CLMain.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import json
|
||||
class CLMain():
|
||||
def __init__(self):
|
||||
self.path = '/usr/local/CyberCP/version.txt'
|
||||
versionInfo = json.loads(open(self.path, 'r').read())
|
||||
self.version = versionInfo['version']
|
||||
self.build = versionInfo['build']
|
||||
|
||||
ipFile = "/etc/cyberpanel/machineIP"
|
||||
f = open(ipFile)
|
||||
ipData = f.read()
|
||||
self.ipAddress = ipData.split('\n', 1)[0]
|
||||
|
||||
self.initialMeta = {
|
||||
"result": "ok"
|
||||
}
|
||||
39
CLScript/CloudLinuxPackages.py
Executable file
39
CLScript/CloudLinuxPackages.py
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/usr/local/CyberCP/bin/python
|
||||
import sys
|
||||
import os.path
|
||||
import django
|
||||
sys.path.append('/usr/local/CyberCP')
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
|
||||
try:
|
||||
django.setup()
|
||||
except:
|
||||
pass
|
||||
from websiteFunctions.models import Websites
|
||||
from CLManager.CLPackages import CLPackages
|
||||
import argparse
|
||||
import pwd
|
||||
import json
|
||||
from CLScript.CLMain import CLMain
|
||||
|
||||
|
||||
class CloudLinuxPackages(CLMain):
|
||||
def __init__(self):
|
||||
CLMain.__init__(self)
|
||||
|
||||
def listAll(self):
|
||||
packages = []
|
||||
for items in Websites.objects.all():
|
||||
itemPackage = items.package
|
||||
try:
|
||||
clPackage = CLPackages.objects.get(owner=itemPackage)
|
||||
packages.append({'name': clPackage.name, 'owner': items.externalApp})
|
||||
except:
|
||||
pass
|
||||
|
||||
final = {'data': packages, 'metadata': self.initialMeta}
|
||||
print(json.dumps(final))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
pi = CloudLinuxPackages()
|
||||
pi.listAll()
|
||||
0
CLScript/__init__.py
Normal file
0
CLScript/__init__.py
Normal file
27
CLScript/panel_info.py
Executable file
27
CLScript/panel_info.py
Executable file
@@ -0,0 +1,27 @@
|
||||
#!/usr/local/CyberCP/bin/python
|
||||
import sys
|
||||
sys.path.append('/usr/local/CyberCP')
|
||||
import json
|
||||
from CLScript.CLMain import CLMain
|
||||
|
||||
|
||||
class PanelInfo(CLMain):
|
||||
def __init__(self):
|
||||
CLMain.__init__(self)
|
||||
|
||||
def emit(self):
|
||||
|
||||
initial = {
|
||||
"name": "CyberPanel",
|
||||
"version": "%s.%s" % (self.version, self.build),
|
||||
"user_login_url": "https://%s:8090/" % (self.ipAddress)
|
||||
}
|
||||
|
||||
final = {'data': initial, 'metadata': self.initialMeta}
|
||||
|
||||
print(json.dumps(final))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
pi = PanelInfo()
|
||||
pi.emit()
|
||||
@@ -11,6 +11,7 @@ from plogical import hashPassword
|
||||
from plogical.acl import ACLManager
|
||||
from packages.models import Package
|
||||
from baseTemplate.models import version
|
||||
from CLManager.models import CLPackages
|
||||
|
||||
def main():
|
||||
|
||||
@@ -38,9 +39,19 @@ def main():
|
||||
bandwidth=1000, ftpAccounts=1000, dataBases=1000,
|
||||
emailAccounts=1000, allowedDomains=20)
|
||||
package.save()
|
||||
|
||||
print("Admin password successfully changed!")
|
||||
return 1
|
||||
|
||||
## CL Package Creation
|
||||
|
||||
package = Package.objects.get(packageName='Default')
|
||||
|
||||
if CLPackages.objects.count() == 0:
|
||||
clPackage = CLPackages(name='Default', owner=package, speed='100%', vmem='1G', pmem='1G', io='1024',
|
||||
iops='1024', ep='20', nproc='50', inodessoft='20', inodeshard='20')
|
||||
clPackage.save()
|
||||
|
||||
token = hashPassword.generateToken('admin', adminPass)
|
||||
admin = Administrator.objects.get(userName="admin")
|
||||
admin.password = hashPassword.hash_password(adminPass)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#!/usr/local/CyberCP/bin/python
|
||||
import sys
|
||||
sys.path.append('/usr/local/CyberCP')
|
||||
from plogical import CyberCPLogFileWriter as logging
|
||||
import subprocess
|
||||
import shlex
|
||||
|
||||
@@ -226,39 +226,7 @@ class virtualHostUtilities:
|
||||
CLPath = '/etc/sysconfig/cloudlinux'
|
||||
|
||||
if os.path.exists(CLPath):
|
||||
if CLPackages.objects.count() == 0:
|
||||
package = Package.objects.get(packageName='Default')
|
||||
clPackage = CLPackages(name='Default', owner=package, speed='100%', vmem='1G', pmem='1G', io='1024',
|
||||
iops='1024', ep='20', nproc='50', inodessoft='20', inodeshard='20')
|
||||
clPackage.save()
|
||||
|
||||
writeToFile = open(CLPath, 'a')
|
||||
writeToFile.writelines('CUSTOM_GETPACKAGE_SCRIPT=/usr/local/CyberCP/CLManager/CLPackages.py\n')
|
||||
writeToFile.close()
|
||||
|
||||
command = 'chmod +x /usr/local/CyberCP/CLManager/CLPackages.py'
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
virtualHostUtilities.EnableCloudLinux()
|
||||
installUtilities.installUtilities.reStartLiteSpeed()
|
||||
|
||||
command = 'sudo lvectl package-set %s --speed=%s --pmem=%s --io=%s --nproc=%s --iops=%s --vmem=%s --ep=%s' % (
|
||||
'Default', '100%', '1G', '1024', '50', '1024', '1G', '20')
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
command = 'lvectl apply all'
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
else:
|
||||
try:
|
||||
clPackage = CLPackages.objects.get(owner=selectedPackage)
|
||||
command = 'sudo lvectl package-set %s --speed=%s --pmem=%s --io=%s --nproc=%s --iops=%s --vmem=%s --ep=%s' % (
|
||||
clPackage.name, clPackage.speed, clPackage.pmem, clPackage.io, clPackage.np, clPackage.iops,
|
||||
clPackage.vmem, clPackage.ep)
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
command = 'sudo lvectl apply all'
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
except:
|
||||
pass
|
||||
|
||||
return 1, 'None'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user