add lsws conversion to cli

This commit is contained in:
Usman Nasir
2022-06-17 12:21:06 +05:00
parent 12ccf2491f
commit 9c0f4927ae
3 changed files with 56 additions and 1 deletions

View File

@@ -63,6 +63,7 @@ class cliParser:
parser.add_argument('--selectedACL', help='Select ACL while creating user.') parser.add_argument('--selectedACL', help='Select ACL while creating user.')
parser.add_argument('--securityLevel', help='Set security level while creating user.') parser.add_argument('--securityLevel', help='Set security level while creating user.')
parser.add_argument('--state', help='State value used in user suspension.') parser.add_argument('--state', help='State value used in user suspension.')
parser.add_argument('--licenseKey', help='LSWS License Key')
### WP Install ### WP Install

View File

@@ -1582,6 +1582,18 @@ def main():
wm = WebsiteManager() wm = WebsiteManager()
wm.installJoomla(1, data) wm.installJoomla(1, data)
elif args.function == "switchTOLSWS":
completeCommandExample = 'cyberpanel switchTOLSWS --licenseKey <Your lsws key here or you can enter TRIAL)'
if not args.licenseKey:
print("\n\nPlease enter LiteSpeed License key. For example:\n\n" + completeCommandExample + "\n\n")
return
from serverStatus.serverStatusUtil import ServerStatusUtil
ServerStatusUtil.switchTOLSWSCLI(args.licenseKey)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@@ -1,5 +1,6 @@
#!/usr/local/CyberCP/bin/python #!/usr/local/CyberCP/bin/python
import os,sys import os,sys
import time
sys.path.append('/usr/local/CyberCP') sys.path.append('/usr/local/CyberCP')
import django import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings")
@@ -15,12 +16,21 @@ from plogical.virtualHostUtilities import virtualHostUtilities
from plogical.sslUtilities import sslUtilities from plogical.sslUtilities import sslUtilities
from plogical.vhost import vhost from plogical.vhost import vhost
from shutil import ignore_patterns from shutil import ignore_patterns
import threading as multi
class ServerStatusUtil: class ServerStatusUtil(multi.Thread):
lswsInstallStatusPath = '/home/cyberpanel/switchLSWSStatus' lswsInstallStatusPath = '/home/cyberpanel/switchLSWSStatus'
serverRootPath = '/usr/local/lsws/' serverRootPath = '/usr/local/lsws/'
def __init__(self, key):
multi.Thread.__init__(self)
self.key = key
def run(self):
self.switchTOLSWS(self.key)
@staticmethod @staticmethod
def executioner(command, statusFile): def executioner(command, statusFile):
try: try:
@@ -379,6 +389,38 @@ class ServerStatusUtil:
logging.CyberCPLogFileWriter.writeToFile(str(msg)) logging.CyberCPLogFileWriter.writeToFile(str(msg))
ServerStatusUtil.recover() ServerStatusUtil.recover()
@staticmethod
def switchTOLSWSCLI(licenseKey):
try:
ssu = ServerStatusUtil(licenseKey)
ssu.start()
while(True):
command = 'sudo cat ' + ServerStatusUtil.lswsInstallStatusPath
output = ProcessUtilities.outputExecutioner(command)
if output.find('[404]') > -1:
command = "sudo rm -f " + ServerStatusUtil.lswsInstallStatusPath
ProcessUtilities.popenExecutioner(command)
data_ret = {'status': 1, 'abort': 1, 'requestStatus': output, 'installed': 0}
print(str(data_ret))
return 0
elif output.find('[200]') > -1:
command = "sudo rm -f " + ServerStatusUtil.lswsInstallStatusPath
ProcessUtilities.popenExecutioner(command)
data_ret = {'status': 1, 'abort': 1, 'requestStatus': 'Successfully converted.', 'installed': 1}
print(str(data_ret))
return 1
else:
data_ret = {'status': 1, 'abort': 0, 'requestStatus': output, 'installed': 0}
#print(output)
time.sleep(2)
except BaseException as msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg))
def main(): def main():
parser = argparse.ArgumentParser(description='Server Status Util.') parser = argparse.ArgumentParser(description='Server Status Util.')