mirror of
				https://github.com/usmannasir/cyberpanel.git
				synced 2025-11-03 20:05:58 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			184 lines
		
	
	
		
			7.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			184 lines
		
	
	
		
			7.1 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
import CyberCPLogFileWriter as logging
 | 
						|
import subprocess
 | 
						|
import shlex
 | 
						|
import thread
 | 
						|
import installUtilities
 | 
						|
import argparse
 | 
						|
import os
 | 
						|
from mailUtilities import mailUtilities
 | 
						|
 | 
						|
class phpUtilities:
 | 
						|
 | 
						|
    installLogPath = "/home/cyberpanel/phpExtensionRequestLog"
 | 
						|
 | 
						|
    @staticmethod
 | 
						|
    def installPHPExtension(extension,extensions):
 | 
						|
        try:
 | 
						|
 | 
						|
            mailUtilities.checkHome()
 | 
						|
 | 
						|
            command = 'sudo yum install '+extension +' -y'
 | 
						|
 | 
						|
            cmd = shlex.split(command)
 | 
						|
 | 
						|
            with open(phpUtilities.installLogPath, 'w') as f:
 | 
						|
                res = subprocess.call(cmd, stdout=f)
 | 
						|
 | 
						|
            if res == 1:
 | 
						|
                writeToFile = open(phpUtilities.installLogPath, 'a')
 | 
						|
                writeToFile.writelines("Can not be installed.\n")
 | 
						|
                writeToFile.close()
 | 
						|
                logging.CyberCPLogFileWriter.writeToFile("[Could not Install]")
 | 
						|
                return 0
 | 
						|
            else:
 | 
						|
                writeToFile = open(phpUtilities.installLogPath, 'a')
 | 
						|
                writeToFile.writelines("PHP Extension Installed.\n")
 | 
						|
                writeToFile.close()
 | 
						|
 | 
						|
            return 1
 | 
						|
        except BaseException, msg:
 | 
						|
            logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[installPHPExtension]")
 | 
						|
 | 
						|
    @staticmethod
 | 
						|
    def unInstallPHPExtension(extension,extensions):
 | 
						|
        try:
 | 
						|
 | 
						|
            mailUtilities.checkHome()
 | 
						|
 | 
						|
            command = 'sudo rpm --nodeps -e  ' + extension + ' -v'
 | 
						|
 | 
						|
            cmd = shlex.split(command)
 | 
						|
 | 
						|
            with open(phpUtilities.installLogPath, 'w') as f:
 | 
						|
                res = subprocess.call(cmd, stdout=f)
 | 
						|
 | 
						|
            if res == 1:
 | 
						|
                writeToFile = open(phpUtilities.installLogPath, 'a')
 | 
						|
                writeToFile.writelines("Can not un-install Extension.\n")
 | 
						|
                writeToFile.close()
 | 
						|
                logging.CyberCPLogFileWriter.writeToFile("[Could not Install]")
 | 
						|
                return 0
 | 
						|
            else:
 | 
						|
                writeToFile = open(phpUtilities.installLogPath, 'a')
 | 
						|
                writeToFile.writelines("PHP Extension Removed.\n")
 | 
						|
                writeToFile.close()
 | 
						|
 | 
						|
            return 1
 | 
						|
        except BaseException, msg:
 | 
						|
            logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[unInstallPHPExtension]")
 | 
						|
 | 
						|
    @staticmethod
 | 
						|
    def initiateInstall(extension):
 | 
						|
        try:
 | 
						|
            thread.start_new_thread(phpUtilities.installPHPExtension, (extension, extension))
 | 
						|
        except BaseException, msg:
 | 
						|
            logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [initiateInstall]")
 | 
						|
 | 
						|
 | 
						|
    @staticmethod
 | 
						|
    def initiateRemoval(extension):
 | 
						|
        try:
 | 
						|
            thread.start_new_thread(phpUtilities.unInstallPHPExtension, (extension, extension))
 | 
						|
        except BaseException, msg:
 | 
						|
            logging.CyberCPLogFileWriter.writeToFile(str(msg) + " [initiateRestore]")
 | 
						|
 | 
						|
    @staticmethod
 | 
						|
    def savePHPConfigBasic(phpVers,allow_url_fopen,display_errors,file_uploads,allow_url_include,memory_limit,max_execution_time,upload_max_filesize,max_input_time,post_max_size):
 | 
						|
        try:
 | 
						|
 | 
						|
            path = "/usr/local/lsws/ls" + phpVers + "/etc/php.ini"
 | 
						|
 | 
						|
            data = open(path, 'r').readlines()
 | 
						|
 | 
						|
            writeToFile = open(path, 'w')
 | 
						|
 | 
						|
            for items in data:
 | 
						|
                if items.find("allow_url_fopen") > -1 and items.find("=") > -1:
 | 
						|
                    writeToFile.writelines(allow_url_fopen + "\n")
 | 
						|
                elif items.find("display_errors") > -1 and items.find("=") > -1:
 | 
						|
                    writeToFile.writelines(display_errors + "\n")
 | 
						|
                elif items.find("file_uploads") > -1 and items.find("=") > -1 and not items.find(
 | 
						|
                        "max_file_uploads") > -1:
 | 
						|
                    writeToFile.writelines(file_uploads + "\n")
 | 
						|
                elif items.find("allow_url_include") > -1 and items.find("=") > -1:
 | 
						|
                    writeToFile.writelines(allow_url_include + "\n")
 | 
						|
 | 
						|
                elif items.find("memory_limit") > -1 and items.find("=") > -1:
 | 
						|
                    writeToFile.writelines("memory_limit = " + memory_limit + "\n")
 | 
						|
 | 
						|
                elif items.find("max_execution_time") > -1 and items.find("=") > -1:
 | 
						|
                    writeToFile.writelines("max_execution_time = " + max_execution_time + "\n")
 | 
						|
 | 
						|
                elif items.find("upload_max_filesize") > -1 and items.find("=") > -1:
 | 
						|
                    writeToFile.writelines("upload_max_filesize = " + upload_max_filesize + "\n")
 | 
						|
 | 
						|
                elif items.find("max_input_time") > -1 and items.find("=") > -1:
 | 
						|
                    writeToFile.writelines("max_input_time = " + max_input_time + "\n")
 | 
						|
                elif items.find("post_max_size") > -1 and items.find("=") > -1:
 | 
						|
                    writeToFile.writelines("post_max_size = " + post_max_size + "\n")
 | 
						|
                else:
 | 
						|
                    writeToFile.writelines(items)
 | 
						|
 | 
						|
            writeToFile.close()
 | 
						|
 | 
						|
            installUtilities.installUtilities.reStartLiteSpeed()
 | 
						|
 | 
						|
            print "1,None"
 | 
						|
 | 
						|
        except BaseException, msg:
 | 
						|
            logging.CyberCPLogFileWriter.writeToFile(
 | 
						|
                str(msg) + " [savePHPConfigBasic]")
 | 
						|
            print "0,"+str(msg)
 | 
						|
 | 
						|
    @staticmethod
 | 
						|
    def savePHPConfigAdvance(phpVers,tempPath):
 | 
						|
        try:
 | 
						|
            phpINI = open(phpVers, 'w')
 | 
						|
            phpINI.write(open(tempPath, "r").read())
 | 
						|
            phpINI.close()
 | 
						|
            installUtilities.installUtilities.reStartLiteSpeed()
 | 
						|
 | 
						|
            if os.path.exists(tempPath):
 | 
						|
                os.remove(tempPath)
 | 
						|
 | 
						|
            print "1,None"
 | 
						|
        except BaseException, msg:
 | 
						|
            logging.CyberCPLogFileWriter.writeToFile(
 | 
						|
                str(msg) + " [savePHPConfigAdvance]")
 | 
						|
            print "0,"+str(msg)
 | 
						|
 | 
						|
 | 
						|
 | 
						|
def main():
 | 
						|
 | 
						|
    parser = argparse.ArgumentParser(description='CyberPanel Installer')
 | 
						|
    parser.add_argument('function', help='Specific a function to call!')
 | 
						|
    parser.add_argument('--phpVers', help='Domain name!')
 | 
						|
    parser.add_argument('--allow_url_fopen', help='Max Connections for PHP!')
 | 
						|
    parser.add_argument('--display_errors', help='Initial Request Timeout (secs) for PHP!')
 | 
						|
    parser.add_argument("--file_uploads", help="Persistent Connection for PHP!")
 | 
						|
    parser.add_argument("--allow_url_include", help="Memory Soft Limit (bytes) for PHP!")
 | 
						|
    parser.add_argument("--memory_limit", help="Process Hard Limit for PHP!")
 | 
						|
    parser.add_argument("--max_execution_time", help="Memory Hard Limit (bytes) for PHP!")
 | 
						|
    parser.add_argument("--upload_max_filesize", help="Process Soft Limit for PHP!")
 | 
						|
    parser.add_argument("--max_input_time", help="Process Hard Limit for PHP!")
 | 
						|
    parser.add_argument("--post_max_size", help="Process Hard Limit for PHP!")
 | 
						|
 | 
						|
    ## Litespeed Tuning Arguments
 | 
						|
 | 
						|
    parser.add_argument("--tempPath", help="Temporary path to file where PHP is storing data!")
 | 
						|
 | 
						|
 | 
						|
    args = parser.parse_args()
 | 
						|
 | 
						|
    if args.function == "savePHPConfigBasic":
 | 
						|
        phpUtilities.savePHPConfigBasic(args.phpVers, args.allow_url_fopen, args.display_errors, args.file_uploads, args.allow_url_include, args.memory_limit,
 | 
						|
                                        args.max_execution_time, args.upload_max_filesize, args.max_input_time, args.post_max_size)
 | 
						|
    elif args.function == "savePHPConfigAdvance":
 | 
						|
        phpUtilities.savePHPConfigAdvance(args.phpVers, args.tempPath)
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
if __name__ == "__main__":
 | 
						|
    main() |