2025-08-01 14:56:30 +05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								#!/usr/local/CyberCP/bin/python  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  os  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  os . path  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  sys  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  time  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  django  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# PACKAGE_PARENT = '..'  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# SCRIPT_DIR = os.path.dirname(os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))))  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								sys . path . append ( ' /usr/local/CyberCP ' )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								os . environ . setdefault ( " DJANGO_SETTINGS_MODULE " ,  " CyberCP.settings " )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								from  random  import  randint  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								django . setup ( )  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  argparse  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								from  plogical  import  installUtilities  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								from  plogical  import  sslUtilities  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								from  multiprocessing  import  Process  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  subprocess  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  shlex  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								from  plogical . mailUtilities  import  mailUtilities  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								from  plogical  import  CyberCPLogFileWriter  as  logging  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								from  plogical . dnsUtilities  import  DNS  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								from  plogical . vhost  import  vhost  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								from  plogical . acl  import  ACLManager  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								from  plogical . processUtilities  import  ProcessUtilities  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								from  ApachController . ApacheController  import  ApacheController  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								from  ApachController . ApacheVhosts  import  ApacheVhost  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								from  managePHP . phpManager  import  PHPManager  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								try :  
						 
					
						
							
								
									
										
										
										
											2025-09-22 13:31:20 +05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    from  websiteFunctions . models  import  Websites ,  ChildDomains ,  aliasDomains ,  WPSites ,  WPStaging 
							 
						 
					
						
							
								
									
										
										
										
											2025-08-01 14:56:30 +05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    from  loginSystem . models  import  Administrator 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    from  packages . models  import  Package 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    from  CLManager . models  import  CLPackages 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								except :  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    pass 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## If you want justice, you have come to the wrong place.  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								class  virtualHostUtilities :  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    apache  =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ols  =  2 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    lsws  =  3 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Server_root  =  " /usr/local/lsws " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    cyberPanel  =  " /usr/local/CyberCP " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    redisConf  =  ' /usr/local/lsws/conf/dvhost_redis.conf ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    vhostConfPath  =  ' /usr/local/lsws/conf ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  OnBoardingHostName ( Domain ,  tempStatusPath ,  skipRDNSCheck ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        import  json 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        import  OpenSSL 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Setting up hostname,10 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        admin  =  Administrator . objects . get ( pk = 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        # Validate admin email exists 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  not  hasattr ( admin ,  ' email ' )  or  not  admin . email : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            message  =  ' Administrator email is not configured. Please set admin email first. [404] ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            config  =  json . loads ( admin . config ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            config  =  { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ### probably need to add temporary dns resolver nameserver here - pending 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            CurrentHostName  =  config [ ' hostname ' ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            CurrentHostName  =  ' ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  skipRDNSCheck : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            pass 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( ' /home/cyberpanel/postfix ' ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                pass 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                message  =  ' This server does not come with postfix installed. [404] ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print ( message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . writeToFile ( message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        #### 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        # Get postfix hostname with error handling 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            PostFixHostname  =  mailUtilities . FetchPostfixHostname ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  Exception  as  e : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            message  =  f ' Failed to fetch postfix hostname:  { str ( e ) }  [404] ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        # Get server IP with error handling 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            serverIP  =  ACLManager . fetchIP ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  Exception  as  e : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            message  =  f ' Failed to fetch server IP:  { str ( e ) }  [404] ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ### if skipRDNSCheck == 1, it means we need to skip checking for rDNS 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  skipRDNSCheck : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ### When skipping rDNS check, include both current hostname and the domain being set up 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ### This ensures both code paths work correctly 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            rDNS  =  [ CurrentHostName ,  Domain ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                rDNS  =  mailUtilities . reverse_dns_lookup ( serverIP ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            except  Exception  as  e : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                message  =  f ' Failed to perform reverse DNS lookup:  { str ( e ) }  [404] ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . writeToFile ( message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        time . sleep ( 3 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  os . path . exists ( ProcessUtilities . debugPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( f ' Postfix Hostname:  { PostFixHostname } . Server IP  { serverIP } . rDNS:  { str ( rDNS ) } ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( f ' Postfix Hostname:  { PostFixHostname } . Server IP  { serverIP } . rDNS:  { str ( rDNS ) } , rDNS check  { skipRDNSCheck } ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ### Case 1 if hostname already exists check if same hostname in postfix and rdns 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        filePath  =  ' /etc/letsencrypt/live/ %s /fullchain.pem '  %  ( PostFixHostname ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( CurrentHostName  ==  PostFixHostname  and  CurrentHostName  in  rDNS )  and  os . path . exists ( filePath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            # expireData = x509.get_notAfter().decode('ascii') 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            # finalDate = datetime.strptime(expireData, '%Y%m%d%H%M%SZ') 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            # now = datetime.now() 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            # diff = finalDate - now 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            message  =  ' Hostname is already set, the same hostname is also used with mail service and rDNS. Let see if valid SSL also exists for this hostname..,10 ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                with  open ( filePath ,  ' r ' )  as  f : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    x509  =  OpenSSL . crypto . load_certificate ( OpenSSL . crypto . FILETYPE_PEM ,  f . read ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                # Safely extract SSL provider from issuer components 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                issuer_components  =  x509 . get_issuer ( ) . get_components ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                SSLProvider  =  ' Denial '   # Default to Denial if we can't find the provider 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                # Look for the Organization (O) field in the issuer 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                for  component  in  issuer_components : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  component [ 0 ]  ==  b ' O ' :   # Organization field 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        SSLProvider  =  component [ 1 ] . decode ( ' utf-8 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        break 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    elif  component [ 0 ]  ==  b ' CN '  and  SSLProvider  ==  ' Denial ' :   # Fallback to CN if O not found 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        SSLProvider  =  component [ 1 ] . decode ( ' utf-8 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            except  ( FileNotFoundError ,  IndexError ,  OpenSSL . crypto . Error )  as  e : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                SSLProvider  =  ' Denial ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . writeToFile ( f " SSL certificate check error:  { str ( e ) } " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            # Get website object and admin email 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            adminEmail  =  None 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                child  =  ChildDomains . objects . get ( domain = CurrentHostName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                website  =  child . master 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                path  =  child . path 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                adminEmail  =  website . adminEmail 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    website  =  Websites . objects . get ( domain = CurrentHostName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    path  =  f ' /home/ { CurrentHostName } /public_html ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    adminEmail  =  website . adminEmail 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    # If neither child domain nor website exists, use admin email 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    adminEmail  =  admin . email 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    path  =  f ' /home/ { CurrentHostName } /public_html ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  SSLProvider  ==  ' Denial ' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                message  =  ' It seems that the hostname used with mail service and rDNS does not have a valid SSL certificate, CyberPanel will try to issue valid SSL and restart related services,20 ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . writeToFile ( message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                virtualHostUtilities . issueSSL ( CurrentHostName ,  path ,  adminEmail ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ### once SSL is issued, re-read the SSL file and check if valid ssl got issued. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    with  open ( filePath ,  ' r ' )  as  f : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        x509  =  OpenSSL . crypto . load_certificate ( OpenSSL . crypto . FILETYPE_PEM ,  f . read ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    # Safely extract SSL provider from issuer components 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    issuer_components  =  x509 . get_issuer ( ) . get_components ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    SSLProvider  =  ' Denial '   # Default to Denial if we can't find the provider 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    # Look for the Organization (O) field in the issuer 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    for  component  in  issuer_components : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        if  component [ 0 ]  ==  b ' O ' :   # Organization field 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            SSLProvider  =  component [ 1 ] . decode ( ' utf-8 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            break 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        elif  component [ 0 ]  ==  b ' CN '  and  SSLProvider  ==  ' Denial ' :   # Fallback to CN if O not found 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            SSLProvider  =  component [ 1 ] . decode ( ' utf-8 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                except  ( FileNotFoundError ,  IndexError ,  OpenSSL . crypto . Error )  as  e : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    SSLProvider  =  ' Denial ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    logging . CyberCPLogFileWriter . writeToFile ( f " SSL re-check error:  { str ( e ) } " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  SSLProvider  ==  ' Denial ' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    message  =  ' Hostname SSL was already issued, and same hostname was used in mail server SSL, rDNS was also configured but we found invalid SSL. However, we tried to issue SSL and it failed. [404] ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    logging . CyberCPLogFileWriter . writeToFile ( message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    config [ ' hostname ' ]  =  Domain 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    config [ ' onboarding ' ]  =  3 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    config [ ' skipRDNSCheck ' ]  =  skipRDNSCheck 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    admin . config  =  json . dumps ( config ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    admin . save ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    return  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                message  =  " It looks like your current hostname is already the mail server hostname and rDNS is also set and there is a valid SSL, nothing needed to do. " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print ( message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                config [ ' hostname ' ]  =  Domain 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                config [ ' onboarding ' ]  =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                config [ ' skipRDNSCheck ' ]  =  skipRDNSCheck 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                admin . config  =  json . dumps ( config ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                admin . save ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . writeToFile ( message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' postmap -F hash:/etc/postfix/vmail_ssl.map && systemctl restart postfix && systemctl restart dovecot ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . executioner ( command ,  ' root ' ,  True ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Completed. [200] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ### create site if not there 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                website  =  Websites . objects . get ( domain = Domain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    child  =  ChildDomains . objects . get ( domain = Domain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    DataToPass  =  { } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    currentTemp  =  tempStatusPath 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    DataToPass [ ' domainName ' ]  =  Domain 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    DataToPass [ ' adminEmail ' ]  =  admin . email 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    DataToPass [ ' phpSelection ' ]  =  " PHP 8.0 " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    DataToPass [ ' websiteOwner ' ]  =  " admin " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    DataToPass [ ' package ' ]  =  " Default " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    DataToPass [ ' ssl ' ]  =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    DataToPass [ ' dkimCheck ' ]  =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    DataToPass [ ' openBasedir ' ]  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    DataToPass [ ' mailDomain ' ]  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    DataToPass [ ' apacheBackend ' ]  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    UserID  =  admin . pk 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    from  websiteFunctions . website  import  WebsiteManager 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ab  =  WebsiteManager ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    coreResult  =  ab . submitWebsiteCreation ( admin . id ,  DataToPass ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    coreResult1  =  json . loads ( ( coreResult ) . content ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    logging . CyberCPLogFileWriter . writeToFile ( " Creating website result.... %s "  %  coreResult1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    returnTempPath  =  coreResult1 . get ( ' tempStatusPath ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  not  returnTempPath : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        with  open ( currentTemp ,  ' w ' )  as  statusFile : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            statusFile . write ( ' Failed to get status path from website creation. [404] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        return  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    # Wait for website creation with timeout 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    timeout  =  120   # 2 minutes timeout 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    poll_interval  =  2   # Check every 2 seconds 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    start_time  =  time . time ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    while  ( time . time ( )  -  start_time )  <  timeout : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            # Check if file exists before trying to read 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            if  not  os . path . exists ( returnTempPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                time . sleep ( poll_interval ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            # Read file content safely 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            with  open ( returnTempPath ,  ' r ' )  as  f : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                lastLine  =  f . read ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            if  os . path . exists ( ProcessUtilities . debugPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                logging . CyberCPLogFileWriter . writeToFile ( " Info web creating lastline .......  %s "  %  lastLine ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            # Check for completion 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            if  lastLine . find ( ' [200] ' )  >  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                break 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            elif  lastLine . find ( ' [404] ' )  >  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                with  open ( currentTemp ,  ' w ' )  as  statusFile : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                    statusFile . write ( ' Failed to Create Website: error:  %s . [404] '  %  lastLine ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                return  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                with  open ( currentTemp ,  ' w ' )  as  statusFile : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                    statusFile . write ( ' Creating Website....,20 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                    
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        except  Exception  as  e : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            logging . CyberCPLogFileWriter . writeToFile ( f " Error reading status file:  { str ( e ) } " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        time . sleep ( poll_interval ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        # Timeout reached 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        with  open ( currentTemp ,  ' w ' )  as  statusFile : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            statusFile . write ( ' Website creation timed out after  %d  seconds. [404] '  %  timeout ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        return  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ### Case 2 where postfix hostname either does not exist or does not match with server hostname or 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ### hostname does not exists at all 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            # Note: rDNS is already set at the beginning of the function, no need to set it again here 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( ProcessUtilities . debugPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . writeToFile ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    f ' Second if: Postfix Hostname:  { PostFixHostname } . Server IP  { serverIP } . rDNS:  { str ( rDNS ) } , rDNS check  { skipRDNSCheck } ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            #first check if hostname is already configured as rDNS, if not return error 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  Domain  not  in  rDNS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                message  =  ' Domain that you have provided is not configured as rDNS for your server IP. [404] ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print ( message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . writeToFile ( message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                config [ ' hostname ' ]  =  Domain 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                config [ ' onboarding ' ]  =  3 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                config [ ' skipRDNSCheck ' ]  =  skipRDNSCheck 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                admin . config  =  json . dumps ( config ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                admin . save ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ### now issue hostname ssl 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            # Get website path - we don't need the website object itself here 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                website  =  Websites . objects . get ( domain = Domain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                path  =  " /home/ "  +  Domain  +  " /public_html " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    child  =  ChildDomains . objects . get ( domain = Domain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    path  =  child . path 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    # If neither exists, use default path 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    path  =  " /home/ "  +  Domain  +  " /public_html " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            filePath  =  ' /etc/letsencrypt/live/ %s /fullchain.pem '  %  ( Domain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            virtualHostUtilities . issueSSLForHostName ( Domain ,  path ,  1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                with  open ( filePath ,  ' r ' )  as  f : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    x509  =  OpenSSL . crypto . load_certificate ( OpenSSL . crypto . FILETYPE_PEM ,  f . read ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                # Safely extract SSL provider from issuer components 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                issuer_components  =  x509 . get_issuer ( ) . get_components ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                SSLProvider  =  ' Denial '   # Default to Denial if we can't find the provider 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                # Look for the Organization (O) field in the issuer 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                for  component  in  issuer_components : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  component [ 0 ]  ==  b ' O ' :   # Organization field 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        SSLProvider  =  component [ 1 ] . decode ( ' utf-8 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        break 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    elif  component [ 0 ]  ==  b ' CN '  and  SSLProvider  ==  ' Denial ' :   # Fallback to CN if O not found 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        SSLProvider  =  component [ 1 ] . decode ( ' utf-8 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            except  ( FileNotFoundError ,  IndexError ,  OpenSSL . crypto . Error )  as  e : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                SSLProvider  =  ' Denial ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . writeToFile ( f " Hostname SSL check error:  { str ( e ) } " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  SSLProvider  ==  ' Denial ' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                message  =  ' Failed to issue Hostname SSL, either its DNS record is not propagated or the domain is behind Cloudflare. If DNS is already propagated you might have reached Lets Encrypt limit, please wait before trying again.. [404] ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . writeToFile ( message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                config [ ' hostname ' ]  =  Domain 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                config [ ' onboarding ' ]  =  3 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                config [ ' skipRDNSCheck ' ]  =  skipRDNSCheck 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                admin . config  =  json . dumps ( config ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                admin . save ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Hostname SSL issued,50 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            virtualHostUtilities . issueSSLForMailServer ( Domain ,  path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                with  open ( filePath ,  ' r ' )  as  f : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    x509  =  OpenSSL . crypto . load_certificate ( OpenSSL . crypto . FILETYPE_PEM ,  f . read ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                # Safely extract SSL provider from issuer components 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                issuer_components  =  x509 . get_issuer ( ) . get_components ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                SSLProvider  =  ' Denial '   # Default to Denial if we can't find the provider 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                # Look for the Organization (O) field in the issuer 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                for  component  in  issuer_components : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  component [ 0 ]  ==  b ' O ' :   # Organization field 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        SSLProvider  =  component [ 1 ] . decode ( ' utf-8 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        break 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    elif  component [ 0 ]  ==  b ' CN '  and  SSLProvider  ==  ' Denial ' :   # Fallback to CN if O not found 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        SSLProvider  =  component [ 1 ] . decode ( ' utf-8 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            except  ( FileNotFoundError ,  IndexError ,  OpenSSL . crypto . Error )  as  e : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                SSLProvider  =  ' Denial ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . writeToFile ( f " Mail server SSL check error:  { str ( e ) } " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  SSLProvider  ==  ' Denial ' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                message  =  ' Failed to issue Mail server SSL, either its DNS record is not propagated or the domain is behind Cloudflare. [404] ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . writeToFile ( message ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                config [ ' hostname ' ]  =  Domain 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                config [ ' onboarding ' ]  =  3 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                config [ ' skipRDNSCheck ' ]  =  skipRDNSCheck 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                admin . config  =  json . dumps ( config ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                admin . save ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                config [ ' hostname ' ]  =  Domain 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                config [ ' onboarding ' ]  =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                config [ ' skipRDNSCheck ' ]  =  skipRDNSCheck 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                admin . config  =  json . dumps ( config ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                admin . save ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                # First update the postfix hash database, then restart services 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                command  =  ' postmap -F hash:/etc/postfix/vmail_ssl.map && systemctl restart postfix && systemctl restart dovecot ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ProcessUtilities . executioner ( command ,  ' root ' ,  True ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Completed. [200] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  setupAutoDiscover ( mailDomain ,  tempStatusPath ,  virtualHostName ,  admin ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  mailDomain : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Creating mail child domain..,80 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            childDomain  =  ' mail. %s '  %  ( virtualHostName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            childPath  =  ' /home/ %s / %s '  %  ( virtualHostName ,  childDomain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            result  =  virtualHostUtilities . createDomain ( virtualHostName ,  childDomain ,  ' PHP 7.3 ' ,  childPath ,  1 ,  0 ,  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                       admin . userName ,  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                       " /home/cyberpanel/ "  +  str ( randint ( 1000 ,  9999 ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  result [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                sslUtilities . issueSSLForDomain ( childDomain ,  admin . email ,  childPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## update dovecot conf to enable auto-discover 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            dovecotPath  =  ' /etc/dovecot/dovecot.conf ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( dovecotPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                dovecotContent  =  open ( dovecotPath ,  ' r ' ) . read ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  dovecotContent . find ( ' /live/ %s / '  %  ( childDomain ) )  ==  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    content  =  """ \n local_name  %s   { 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ssl_cert  =  < / etc / letsencrypt / live / % s / fullchain . pem 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ssl_key  =  < / etc / letsencrypt / live / % s / privkey . pem 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								local_name  % s  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ssl_cert  =  < / etc / letsencrypt / live / % s / fullchain . pem 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ssl_key  =  < / etc / letsencrypt / live / % s / privkey . pem 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								\n """   %  (childDomain, childDomain, childDomain, virtualHostName, virtualHostName, virtualHostName) 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile  =  open ( dovecotPath ,  ' a ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile . write ( content ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                command  =  ' systemctl restart dovecot ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ### Update postfix configurations 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                postFixPath  =  ' /etc/postfix/main.cf ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                postFixContent  =  open ( postFixPath ,  ' r ' ) . read ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  postFixContent . find ( ' tls_server_sni_maps ' )  ==  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile  =  open ( postFixPath ,  ' a ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile . write ( ' \n tls_server_sni_maps = hash:/etc/postfix/vmail_ssl.map \n ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                postfixMapFile  =  ' /etc/postfix/vmail_ssl.map ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    postfixMapFileContent  =  open ( postfixMapFile ,  ' r ' ) . read ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    postfixMapFileContent  =  ' ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  postfixMapFileContent . find ( ' /live/ %s / '  %  ( childDomain ) )  ==  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    mapContent  =  f ' %s /etc/letsencrypt/live/%s/privkey.pem /etc/letsencrypt/live/%s/fullchain.pem \n { virtualHostName }  /etc/letsencrypt/live/ { virtualHostName } /privkey.pem /etc/letsencrypt/live/ { virtualHostName } /fullchain.pem \n '  %  ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        childDomain ,  childDomain ,  childDomain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile  =  open ( postfixMapFile ,  ' a ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile . write ( mapContent ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                command  =  ' postmap -F hash:/etc/postfix/vmail_ssl.map ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                command  =  ' systemctl restart postfix ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ### even if mail domain creation is not set, we will have to set up auto discover for main domain 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        dovecotPath  =  ' /etc/dovecot/dovecot.conf ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  os . path . exists ( dovecotPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            dovecotContent  =  open ( dovecotPath ,  ' r ' ) . read ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  dovecotContent . find ( ' /live/ %s / '  %  ( virtualHostName ) )  ==  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                content  =  """ 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								local_name  % s  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ssl_cert  =  < / etc / letsencrypt / live / % s / fullchain . pem 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        ssl_key  =  < / etc / letsencrypt / live / % s / privkey . pem 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								"""   %  (virtualHostName, virtualHostName, virtualHostName) 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                writeToFile  =  open ( dovecotPath ,  ' a ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                writeToFile . write ( content ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                writeToFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' systemctl restart dovecot ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ### Update postfix configurations 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            postFixPath  =  ' /etc/postfix/main.cf ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            postFixContent  =  open ( postFixPath ,  ' r ' ) . read ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  postFixContent . find ( ' tls_server_sni_maps ' )  ==  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                writeToFile  =  open ( postFixPath ,  ' a ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                writeToFile . write ( ' \n tls_server_sni_maps = hash:/etc/postfix/vmail_ssl.map \n ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                writeToFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            postfixMapFile  =  ' /etc/postfix/vmail_ssl.map ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                postfixMapFileContent  =  open ( postfixMapFile ,  ' r ' ) . read ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                postfixMapFileContent  =  ' ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  postfixMapFileContent . find ( ' /live/ %s / '  %  ( virtualHostName ) )  ==  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                mapContent  =  f ' { virtualHostName }  /etc/letsencrypt/live/ { virtualHostName } /privkey.pem /etc/letsencrypt/live/ { virtualHostName } /fullchain.pem \n ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                writeToFile  =  open ( postfixMapFile ,  ' a ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                writeToFile . write ( mapContent ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                writeToFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' postmap -F hash:/etc/postfix/vmail_ssl.map ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' systemctl restart postfix ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  createVirtualHost ( virtualHostName ,  administratorEmail ,  phpVersion ,  virtualHostUser ,  ssl , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                          dkimCheck ,  openBasedir ,  websiteOwner ,  packageName ,  apache , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                          tempStatusPath = ' /home/cyberpanel/fakePath ' ,  mailDomain = None ,  LimitsCheck = 1 ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Running some checks..,0 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ####### Limitations check 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            admin  =  Administrator . objects . get ( userName = websiteOwner ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  LimitsCheck : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ACLManager . websitesLimitCheck ( admin ,  1 )  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                              ' You \' ve reached maximum websites limit as a reseller. [404] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    return  0 ,  ' You \' ve reached maximum websites limit as a reseller. ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ####### Limitations Check End 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  Websites . objects . filter ( domain = virtualHostName ) . count ( )  >  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' This website already exists. [404] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    return  0 ,  " This website already exists. " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  Websites . objects . filter ( domain = virtualHostName . lstrip ( ' www. ' ) ) . count ( )  >  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' This website already exists. [404] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    return  0 ,  " This website already exists. " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ChildDomains . objects . filter ( domain = virtualHostName ) . count ( )  >  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                              ' This website already exists as child domain. [404] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    return  0 ,  " This website already exists as child domain. " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ChildDomains . objects . filter ( domain = virtualHostName . lstrip ( ' www. ' ) ) . count ( )  >  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                              ' This website already exists as child domain. [404] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    return  0 ,  " This website already exists as child domain. " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-09-22 13:31:20 +05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                # Check for orphaned staging site domain conflicts 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    # Check if there are any WP sites with FinalURL matching this domain 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    conflicting_wp_sites  =  WPSites . objects . filter ( FinalURL__icontains = virtualHostName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    for  wp_site  in  conflicting_wp_sites : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        # Check if the WP site's owner website still exists 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            owner_website  =  wp_site . owner 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            if  not  Websites . objects . filter ( id = owner_website . id ) . exists ( ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                # Orphaned WP site found, clean it up 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                wp_site . delete ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                logging . CyberCPLogFileWriter . writeToFile ( f " Cleaned up orphaned WP site:  { wp_site . id }  with URL:  { wp_site . FinalURL } " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            # WP site owner is missing, delete it 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            wp_site . delete ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            logging . CyberCPLogFileWriter . writeToFile ( f " Cleaned up orphaned WP site:  { wp_site . id }  (missing owner) " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    # Check for orphaned staging sites 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    orphaned_staging  =  WPStaging . objects . filter ( wpsite__FinalURL__icontains = virtualHostName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    for  staging  in  orphaned_staging : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            # Check if the staging site's wpsite still exists and has valid owner 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            wpsite  =  staging . wpsite 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            owner_website  =  wpsite . owner 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            if  not  Websites . objects . filter ( id = owner_website . id ) . exists ( ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                # Owner website doesn't exist, clean up staging 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                staging . delete ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                logging . CyberCPLogFileWriter . writeToFile ( f " Cleaned up orphaned staging site:  { staging . id } " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            # Staging site has invalid references, delete it 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            staging . delete ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            logging . CyberCPLogFileWriter . writeToFile ( f " Cleaned up orphaned staging site:  { staging . id }  (invalid references) " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                except  Exception  as  e : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    logging . CyberCPLogFileWriter . writeToFile ( f " Error during staging site cleanup:  { str ( e ) } " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-08-01 14:56:30 +05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								                ####### Limitations Check End 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Creating DNS records..,10 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ##### Zone creation 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                DNS . dnsTemplate ( virtualHostName ,  admin ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ## Zone creation 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Setting up directories..,25 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  vhost . checkIfVirtualHostExists ( virtualHostName )  ==  1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                              ' Virtual Host Directory already exists. [404] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    return  0 ,  " Virtual Host Directory already exists! " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  vhost . checkIfAliasExists ( virtualHostName )  ==  1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' This domain exists as Alias. [404] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    return  0 ,  " This domain exists as Alias. " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            postfixPath  =  ' /home/cyberpanel/postfix ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( postfixPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                retValues  =  mailUtilities . setupDKIM ( virtualHostName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  retValues [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    raise  BaseException ( retValues [ 1 ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            retValues  =  vhost . createDirectoryForVirtualHost ( virtualHostName ,  administratorEmail , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                            virtualHostUser ,  phpVersion ,  openBasedir ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  retValues [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                raise  BaseException ( retValues [ 1 ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Creating configurations..,50 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  not  os . path . exists ( virtualHostUtilities . redisConf ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                retValues  =  vhost . createConfigInMainVirtualHostFile ( virtualHostName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  retValues [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    raise  BaseException ( retValues [ 1 ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            selectedPackage  =  Package . objects . get ( packageName = packageName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  LimitsCheck : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                website  =  Websites ( admin = admin ,  package = selectedPackage ,  domain = virtualHostName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                   adminEmail = administratorEmail , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                   phpSelection = phpVersion ,  ssl = ssl ,  externalApp = virtualHostUser ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                website . save ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  admin . defaultSite  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    admin . defaultSite  =  website . id 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    admin . save ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ssl  ==  1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                sslPath  =  " /home/ "  +  virtualHostName  +  " /public_html " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Setting up SSL..,70 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  not  os . path . exists ( virtualHostUtilities . redisConf ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                retValues  =  sslUtilities . issueSSLForDomain ( virtualHostName ,  administratorEmail ,  sslPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  retValues [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    raise  BaseException ( retValues [ 1 ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  not  os . path . exists ( virtualHostUtilities . redisConf ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' SSL set up done..,70 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ssl  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  not  os . path . exists ( virtualHostUtilities . redisConf ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            vhost . finalizeVhostCreation ( virtualHostName ,  virtualHostUser ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' vHost finalized..,70 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## Check If Apache is requested 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            confPath  =  vhost . Server_root  +  " /conf/vhosts/ "  +  virtualHostName 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            completePathToConfigFile  =  confPath  +  " /vhost.conf " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  apache : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ProcessUtilities . decideServer ( )  ==  ProcessUtilities . OLS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  ApacheController . checkIfApacheInstalled ( )  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        result  =  ApacheController . setupApache ( tempStatusPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        if  result [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            raise  BaseException ( result [ 1 ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    result  =  ApacheVhost . setupApacheVhost ( administratorEmail ,  virtualHostUser ,  virtualHostUser , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                          phpVersion ,  virtualHostName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  result [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        raise  BaseException ( result [ 1 ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        ApacheVhost . perHostVirtualConfOLS ( completePathToConfigFile ,  administratorEmail ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        php  =  PHPManager . getPHPString ( phpVersion ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        phpService  =  ApacheVhost . DecideFPMServiceName ( phpVersion ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        command  =  f " systemctl restart  { phpService } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        ProcessUtilities . normalExecutioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## Create Configurations ends here 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' DKIM Setup..,70 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## DKIM Check 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            postFixPath  =  ' /home/cyberpanel/postfix ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( postFixPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  dkimCheck  ==  1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    DNS . createDKIMRecords ( virtualHostName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            CLPath  =  ' /etc/sysconfig/cloudlinux ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( CLPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                command  =  ' /usr/share/cloudlinux/hooks/post_modify_user.py create --username  %s  --owner  %s '  %  ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    virtualHostUser ,  admin . userName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ### For autodiscover of mail clients. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            virtualHostUtilities . setupAutoDiscover ( mailDomain ,  tempStatusPath ,  virtualHostName ,  admin ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ### 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            spaceString  =  f ' { selectedPackage . diskSpace } M  { selectedPackage . diskSpace } M ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  selectedPackage . enforceDiskLimits : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                command  =  f ' setquota -u  { virtualHostUser }   { spaceString }  0 0 / ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Website successfully created. [200] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  1 ,  ' None ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ACLManager . FindIfChild ( )  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                vhost . deleteVirtualHostConfigurations ( virtualHostName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( str ( msg )  +  "   [createVirtualHost] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  str ( msg )  +  "  [404] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  0 ,  str ( msg ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  issueSSL ( virtualHost ,  path ,  adminEmail ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            retValues  =  sslUtilities . issueSSLForDomain ( virtualHost ,  adminEmail ,  path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  retValues [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
									
										
										
										
											2025-08-06 14:56:58 +05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                # Enhanced error reporting 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                error_msg  =  str ( retValues [ 1 ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . writeToFile ( f " SSL issuance failed for  { virtualHost } :  { error_msg } " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                # Parse and format the error message for better readability 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                from  plogical . sslUtilities  import  sslUtilities  as  sslUtil 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                parsed_error  =  sslUtil . parseACMEError ( error_msg ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print ( " 0, "  +  parsed_error ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  0 ,  parsed_error 
							 
						 
					
						
							
								
									
										
										
										
											2025-08-01 14:56:30 +05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' systemctl restart postfix ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' systemctl restart dovecot ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 1,None " ) 
							 
						 
					
						
							
								
									
										
										
										
											2025-08-06 14:56:58 +05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( f " SSL successfully issued for  { virtualHost } " ) 
							 
						 
					
						
							
								
									
										
										
										
											2025-08-01 14:56:30 +05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            return  1 ,  None 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException  as  msg : 
							 
						 
					
						
							
								
									
										
										
										
											2025-08-06 14:56:58 +05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            error_detail  =  f " Exception in issueSSL for  { virtualHost } :  { str ( msg ) } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( error_detail  +  "  [issueSSL] " ) 
							 
						 
					
						
							
								
									
										
										
										
											2025-08-01 14:56:30 +05:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								            print ( " 0, "  +  str ( msg ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  0 ,  str ( msg ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  issueSSLv2 ( virtualHost ,  path ,  adminEmail ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            import  plogical . sslv2  as  sslv2 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            retValues  =  sslv2 . issueSSLForDomain ( virtualHost ,  adminEmail ,  path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  retValues [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print ( " 0, "  +  str ( retValues [ 1 ] ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . writeToFile ( str ( retValues [ 1 ] ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  0 ,  str ( retValues [ 1 ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' systemctl restart postfix ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' systemctl restart dovecot ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( f " 1, { str ( retValues [ 1 ] ) } " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  1 ,  str ( retValues [ 1 ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( str ( msg )  +  "  [issueSSL] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 0, "  +  str ( msg ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  0 ,  str ( msg ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  getAccessLogs ( fileName ,  page ,  externalApp ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . islink ( fileName ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print ( " 0,  %s  file is symlinked. "  %  ( fileName ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            groupName  =  ' nobody ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            numberOfTotalLines  =  int ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ProcessUtilities . outputExecutioner ( ' wc -l  %s '  %  ( fileName ) ,  groupName ) . split ( "   " ) [ 0 ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  numberOfTotalLines  <  25 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                data  =  ProcessUtilities . outputExecutioner ( ' cat  %s '  %  ( fileName ) ,  groupName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  page  ==  1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    end  =  numberOfTotalLines 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    start  =  end  -  24 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  start  < =  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        start  =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    startingAndEnding  =  " ' "  +  str ( start )  +  " , "  +  str ( end )  +  " p ' " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    command  =  " sed -n  "  +  startingAndEnding  +  "   "  +  fileName 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    data  =  ProcessUtilities . outputExecutioner ( command ,  groupName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    end  =  numberOfTotalLines  -  ( ( page  -  1 )  *  25 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    start  =  end  -  24 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  start  < =  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        start  =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    startingAndEnding  =  " ' "  +  str ( start )  +  " , "  +  str ( end )  +  " p ' " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    command  =  " sed -n  "  +  startingAndEnding  +  "   "  +  fileName 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    data  =  ProcessUtilities . outputExecutioner ( command ,  groupName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( data ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  data 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                str ( msg )  +  "   [getAccessLogs] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 1,None " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  " 1,None " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  getErrorLogs ( fileName ,  page ,  externalApp ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . islink ( fileName ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print ( " 0,  %s  file is symlinked. "  %  ( fileName ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            numberOfTotalLines  =  int ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ProcessUtilities . outputExecutioner ( ' wc -l  %s '  %  ( fileName ) ,  externalApp ) . split ( "   " ) [ 0 ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  numberOfTotalLines  <  25 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                data  =  ProcessUtilities . outputExecutioner ( ' cat  %s '  %  ( fileName ) ,  externalApp ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  page  ==  1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    end  =  numberOfTotalLines 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    start  =  end  -  24 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  start  < =  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        start  =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    startingAndEnding  =  " ' "  +  str ( start )  +  " , "  +  str ( end )  +  " p ' " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    command  =  " sed -n  "  +  startingAndEnding  +  "   "  +  fileName 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    data  =  ProcessUtilities . outputExecutioner ( command ,  externalApp ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    end  =  numberOfTotalLines  -  ( ( page  -  1 )  *  25 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    start  =  end  -  24 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  start  < =  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        start  =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    startingAndEnding  =  " ' "  +  str ( start )  +  " , "  +  str ( end )  +  " p ' " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    command  =  " sed -n  "  +  startingAndEnding  +  "   "  +  fileName 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    data  =  ProcessUtilities . outputExecutioner ( command ,  externalApp ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( data ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  data 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                str ( msg )  +  "   [getErrorLogs] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 1,None " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  " 1,None " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  saveVHostConfigs ( fileName ,  tempPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            vhost  =  open ( fileName ,  " w " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            vhost . write ( open ( tempPath ,  " r " ) . read ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            vhost . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( tempPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                os . remove ( tempPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 1,None " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                str ( msg )  +  "   [saveVHostConfigs] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 0, "  +  str ( msg ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  saveApacheConfigsToFile ( fileName ,  tempPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            vhost  =  open ( fileName ,  " w " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            vhost . write ( open ( tempPath ,  " r " ) . read ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            vhost . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( tempPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                os . remove ( tempPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  f " systemctl restart  { ApacheVhost . serviceName } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . normalExecutioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 1,None " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                str ( msg )  +  "   [saveApacheConfigsToFile] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 0, "  +  str ( msg ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  saveRewriteRules ( virtualHost ,  fileName ,  tempPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . islink ( fileName ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print ( " 0, .htaccess file is symlinked. " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            vhost . addRewriteRules ( virtualHost ,  fileName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            vhostFile  =  open ( fileName ,  " w " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            vhostFile . write ( open ( tempPath ,  " r " ) . read ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            vhostFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  os . path . exists ( tempPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    os . remove ( tempPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                pass 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 1,None " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                str ( msg )  +  "   [saveRewriteRules] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 0, "  +  str ( msg ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  issueSSLForHostName ( virtualHost ,  path ,  skipLSCPDRestart = 0 ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            destPrivKey  =  " /usr/local/lscp/conf/key.pem " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            destCert  =  " /usr/local/lscp/conf/cert.pem " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            lswsAdminPrivKey  =  " /usr/local/lsws/admin/conf/cert/admin.key " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            lswsAdminCert  =  " /usr/local/lsws/admin/conf/cert/admin.crt " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            olsAdminPrivKey  =  " /usr/local/lsws/admin/conf/webadmin.key " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            olsAdminCert  =  " /usr/local/lsws/admin/conf/webadmin.crt " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            pathToStoreSSLFullChain  =  ' /etc/letsencrypt/live/ '  +  virtualHost  +  ' /fullchain.pem ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            pathToStoreSSLPrivKey  =  ' /etc/letsencrypt/live/ '  +  virtualHost  +  ' /privkey.pem ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            adminEmail  =  " email@ "  +  virtualHost 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            retValues  =  sslUtilities . issueSSLForDomain ( virtualHost ,  adminEmail ,  path ,  None ,  isHostname = True ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  retValues [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print ( " 0, "  +  str ( retValues [ 1 ] ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  0 ,  retValues [ 1 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' chmod 600  %s '  %  ( destPrivKey ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . normalExecutioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## removing old certs for lscpd 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( destPrivKey ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                os . remove ( destPrivKey ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( destCert ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                os . remove ( destCert ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## removing self signed certs for lsws webadmin 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( lswsAdminCert ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                os . remove ( lswsAdminCert ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( lswsAdminPrivKey ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                os . remove ( lswsAdminPrivKey ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## create symlink for hostname SSL for lsws webadmin SSL 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' ln -s  %s  /usr/local/lsws/admin/conf/cert/admin.crt '  %  ( pathToStoreSSLFullChain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . normalExecutioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' ln -s  %s  /usr/local/lsws/admin/conf/cert/admin.key '  %  ( pathToStoreSSLPrivKey ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . normalExecutioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## removing self signed certs for ols webadmin 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( olsAdminCert ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                os . remove ( olsAdminCert ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( olsAdminPrivKey ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                os . remove ( olsAdminPrivKey ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## create symlink for hostname SSL for lsws webadmin SSL 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' ln -s  %s  /usr/local/lsws/admin/conf/webadmin.crt '  %  ( pathToStoreSSLFullChain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . normalExecutioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' ln -s  %s  /usr/local/lsws/admin/conf/webadmin.key '  %  ( pathToStoreSSLPrivKey ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . normalExecutioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' ln -s  %s   %s '  %  ( pathToStoreSSLFullChain ,  destCert ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' ln -s  %s   %s '  %  ( pathToStoreSSLPrivKey ,  destPrivKey ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  skipLSCPDRestart : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                pass 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                command  =  ' systemctl restart lscpd ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                cmd  =  shlex . split ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                subprocess . call ( cmd ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' systemctl restart fastapi_ssh_server.service ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            cmd  =  shlex . split ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            subprocess . call ( cmd ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 1,None " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  1 ,  ' None ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( str ( msg )  +  "   [issueSSLForHostName] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 0, "  +  str ( msg ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  0 ,  str ( msg ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  issueSSLForMailServer ( virtualHost ,  path ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            srcFullChain  =  ' /etc/letsencrypt/live/ '  +  virtualHost  +  ' /fullchain.pem ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            srcPrivKey  =  ' /etc/letsencrypt/live/ '  +  virtualHost  +  ' /privkey.pem ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            adminEmail  =  " email@ "  +  virtualHost 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            retValues  =  sslUtilities . issueSSLForDomain ( virtualHost ,  adminEmail ,  path ,  None ,  isHostname = True ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  retValues [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print ( " 0, "  +  str ( retValues [ 1 ] ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  0 ,  retValues [ 1 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## MailServer specific functions 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( " /etc/postfix/cert.pem " ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                os . remove ( " /etc/postfix/cert.pem " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( " /etc/postfix/key.pem " ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                os . remove ( " /etc/postfix/key.pem " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( " /etc/pki/dovecot/private/dovecot.pem " ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                os . remove ( " /etc/pki/dovecot/private/dovecot.pem " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( " /etc/pki/dovecot/certs/dovecot.pem " ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                os . remove ( " /etc/pki/dovecot/certs/dovecot.pem " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( " /etc/dovecot/key.pem " ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                os . remove ( " /etc/dovecot/key.pem " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( " /etc/dovecot/cert.pem " ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                os . remove ( " /etc/dovecot/cert.pem " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## Postfix 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' ln -s  %s  /etc/postfix/key.pem '  %  ( srcPrivKey ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' ln -s  %s  /etc/postfix/cert.pem '  %  ( srcFullChain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## Dovecot 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' ln -s  %s  /etc/pki/dovecot/private/dovecot.pem '  %  ( srcPrivKey ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' ln -s  %s  /etc/pki/dovecot/certs/dovecot.pem '  %  ( srcFullChain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## Dovecot 2ND 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' ln -s  %s  /etc/dovecot/key.pem '  %  ( srcPrivKey ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' ln -s  %s  /etc/dovecot/cert.pem '  %  ( srcFullChain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## Update postmaster address dovecot 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            filePath  =  " /etc/dovecot/dovecot.conf " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            data  =  open ( filePath ,  ' r ' ) . readlines ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            writeFile  =  open ( filePath ,  ' w ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            for  items  in  data : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  items . find ( ' postmaster_address ' )  >  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeFile . writelines ( '     postmaster_address = postmaster@ '  +  virtualHost  +  ' \n ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeFile . writelines ( items ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            writeFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## Update myhostname address postfix 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            filePath  =  " /etc/postfix/main.cf " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            data  =  open ( filePath ,  ' r ' ) . readlines ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            writeFile  =  open ( filePath ,  ' w ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            for  items  in  data : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  items . find ( ' myhostname ' )  >  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeFile . writelines ( ' myhostname =  '  +  virtualHost  +  ' \n ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeFile . writelines ( items ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            writeFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            p  =  Process ( target = mailUtilities . restartServices ,  args = ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            p . start ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 1,None " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  1 ,  ' None ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                str ( msg )  +  "   [issueSSLForHostName] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 0, "  +  str ( msg ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  0 ,  str ( msg ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  createAlias ( masterDomain ,  aliasDomain ,  ssl ,  sslPath ,  administratorEmail ,  owner = None ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            admin  =  Administrator . objects . get ( userName = owner ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            DNS . dnsTemplate ( aliasDomain ,  admin ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  vhost . checkIfAliasExists ( aliasDomain )  ==  1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print ( " 0, This domain already exists as vHost or Alias. " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ProcessUtilities . decideServer ( )  ==  ProcessUtilities . OLS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                confPath  =  os . path . join ( virtualHostUtilities . Server_root ,  " conf/httpd_config.conf " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                data  =  open ( confPath ,  ' r ' ) . readlines ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                writeToFile  =  open ( confPath ,  ' w ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                listenerTrueCheck  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                for  items  in  data : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  items . find ( " listener " )  >  - 1  and  items . find ( " Default " )  >  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        listenerTrueCheck  =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  items . find ( '   '  +  masterDomain )  >  - 1  and  items . find ( ' map ' )  >  - 1  and  listenerTrueCheck  ==  1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        data  =  [ _f  for  _f  in  items . split ( "   " )  if  _f ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        if  data [ 1 ]  ==  masterDomain : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            writeToFile . writelines ( items . rstrip ( ' \n ' )  +  " ,  "  +  aliasDomain  +  " \n " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            listenerTrueCheck  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        writeToFile . writelines ( items ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                writeToFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                completePathToConf  =  virtualHostUtilities . Server_root  +  ' /conf/vhosts/ '  +  masterDomain  +  ' /vhost.conf ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                data  =  open ( completePathToConf ,  ' r ' ) . readlines ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                writeToFile  =  open ( completePathToConf ,  ' w ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                for  items  in  data : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  items . find ( ' ServerAlias ' )  >  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        items  =  items . strip ( ' \n ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        writeToFile . writelines ( items  +  "   "  +  aliasDomain  +  " \n " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        writeToFile . writelines ( items ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                writeToFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ssl  ==  1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                retValues  =  sslUtilities . issueSSLForDomain ( masterDomain ,  administratorEmail ,  sslPath ,  aliasDomain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ProcessUtilities . decideServer ( )  ==  ProcessUtilities . OLS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  retValues [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        print ( " 0, "  +  str ( retValues [ 1 ] ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        vhost . createAliasSSLMap ( confPath ,  masterDomain ,  aliasDomain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    retValues  =  sslUtilities . issueSSLForDomain ( masterDomain ,  administratorEmail ,  sslPath ,  aliasDomain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  retValues [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        print ( " 0, "  +  str ( retValues [ 1 ] ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            website  =  Websites . objects . get ( domain = masterDomain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            newAlias  =  aliasDomains ( master = website ,  aliasDomain = aliasDomain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            newAlias . save ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 1,None " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( str ( msg )  +  "   [createAlias] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 0, "  +  str ( msg ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  issueAliasSSL ( masterDomain ,  aliasDomain ,  sslPath ,  administratorEmail ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            retValues  =  sslUtilities . issueSSLForDomain ( masterDomain ,  administratorEmail ,  sslPath ,  aliasDomain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ProcessUtilities . decideServer ( )  ==  ProcessUtilities . OLS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                confPath  =  os . path . join ( virtualHostUtilities . Server_root ,  " conf/httpd_config.conf " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  retValues [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    print ( " 0, "  +  str ( retValues [ 1 ] ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    vhost . createAliasSSLMap ( confPath ,  masterDomain ,  aliasDomain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  retValues [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    print ( " 0, "  +  str ( retValues [ 1 ] ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 1,None " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( str ( msg )  +  "   [issueAliasSSL] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 0, "  +  str ( msg ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  deleteAlias ( masterDomain ,  aliasDomain ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ProcessUtilities . decideServer ( )  ==  ProcessUtilities . OLS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                confPath  =  os . path . join ( virtualHostUtilities . Server_root ,  " conf/httpd_config.conf " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                data  =  open ( confPath ,  ' r ' ) . readlines ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                writeToFile  =  open ( confPath ,  ' w ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                aliases  =  [ ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                for  items  in  data : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  items . find ( masterDomain )  >  - 1  and  items . find ( ' map ' )  >  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        data  =  [ _f  for  _f  in  items . split ( "   " )  if  _f ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        if  data [ 1 ]  ==  masterDomain : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            length  =  len ( data ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            for  i  in  range ( 3 ,  length ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                currentAlias  =  data [ i ] . rstrip ( ' , ' ) . strip ( ' \n ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                if  currentAlias  !=  aliasDomain : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                    aliases . append ( currentAlias ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            aliasString  =  " " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            for  alias  in  aliases : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                aliasString  =  " ,  "  +  alias 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            writeToFile . writelines ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                '   map                      '  +  masterDomain  +  "   "  +  masterDomain  +  aliasString  +  " \n " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            aliases  =  [ ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            aliasString  =  " " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            writeToFile . writelines ( items ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        writeToFile . writelines ( items ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                writeToFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                delAlias  =  aliasDomains . objects . get ( aliasDomain = aliasDomain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                delAlias . delete ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print ( " 1,None " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . writeToFile ( str ( msg )  +  "   [deleteAlias] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print ( " 0, "  +  str ( msg ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                completePathToConf  =  virtualHostUtilities . Server_root  +  ' /conf/vhosts/ '  +  masterDomain  +  ' /vhost.conf ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                data  =  open ( completePathToConf ,  ' r ' ) . readlines ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                writeToFile  =  open ( completePathToConf ,  ' w ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                for  items  in  data : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  items . find ( ' ServerAlias ' )  >  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        writeToFile . writelines ( items . replace ( '   '  +  aliasDomain ,  ' ' ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        writeToFile . writelines ( items ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                writeToFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                alias  =  aliasDomains . objects . get ( aliasDomain = aliasDomain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                alias . delete ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print ( " 1,None " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . writeToFile ( str ( msg )  +  "   [deleteAlias] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print ( " 0, "  +  str ( msg ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  changeOpenBasedir ( domainName ,  openBasedirValue ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ProcessUtilities . decideServer ( )  ==  ProcessUtilities . OLS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                confPath  =  virtualHostUtilities . Server_root  +  " /conf/vhosts/ "  +  domainName 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                completePathToConfigFile  =  confPath  +  " /vhost.conf " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                data  =  open ( completePathToConfigFile ,  ' r ' ) . readlines ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  openBasedirValue  ==  ' Disable ' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile  =  open ( completePathToConfigFile ,  ' w ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    for  items  in  data : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        if  items . find ( ' php_admin_value ' )  >  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        writeToFile . writelines ( items ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ## Check if phpini already active 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    fileManagerCheck  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile  =  open ( completePathToConfigFile ,  ' w ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    for  items  in  data : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        if  items . find ( ' context /.filemanager ' )  >  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            writeToFile . writelines ( items ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            fileManagerCheck  =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        if  items . find ( ' phpIniOverride ' )  >  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            writeToFile . writelines ( items ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            if  fileManagerCheck  ==  1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                writeToFile . writelines ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                    ' php_admin_value open_basedir  " /tmp:/usr/local/lsws/Example/html/FileManager:$VH_ROOT " \n ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                fileManagerCheck  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                writeToFile . writelines ( ' php_admin_value open_basedir  " /tmp:$VH_ROOT " \n ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        writeToFile . writelines ( items ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print ( " 1,None " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . writeToFile ( str ( msg )  +  "   [changeOpenBasedir] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print ( " 0, "  +  str ( msg ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                confPath  =  virtualHostUtilities . Server_root  +  " /conf/vhosts/ "  +  domainName 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                completePathToConfigFile  =  confPath  +  " /vhost.conf " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                data  =  open ( completePathToConfigFile ,  ' r ' ) . readlines ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  openBasedirValue  ==  ' Disable ' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile  =  open ( completePathToConfigFile ,  ' w ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    for  items  in  data : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        if  items . find ( ' open_basedir ' )  >  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        writeToFile . writelines ( items ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ## Check if phpini already active 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    path  =  ' ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        childDomain  =  ChildDomains . objects . get ( domain = domainName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        path  =  childDomain . path 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        path  =  ' /home/ '  +  domainName  +  ' /public_html ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    activate  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile  =  open ( completePathToConfigFile ,  ' w ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    for  items  in  data : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        if  items . find ( ' CustomLog  ' )  >  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            activate  =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            writeToFile . writelines ( items ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        if  activate  ==  1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            activate  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            if  items . find ( ' open_basedir ' )  >  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                writeToFile . writelines ( items ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                writeToFile . writelines ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                    '         php_admin_value open_basedir /usr/local/lsws/FileManager:/tmp: '  +  path  +  ' \n ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                writeToFile . writelines ( items ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            writeToFile . writelines ( items ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print ( " 1,None " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . writeToFile ( str ( msg )  +  "   [changeOpenBasedir] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                print ( " 0, "  +  str ( msg ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  saveSSL ( virtualHost ,  keyPath ,  certPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            pathToStoreSSL  =  ' /etc/letsencrypt/live/ '  +  virtualHost 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' mkdir -p  '  +  pathToStoreSSL 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            subprocess . call ( shlex . split ( command ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            pathToStoreSSLPrivKey  =  pathToStoreSSL  +  " /privkey.pem " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            pathToStoreSSLFullChain  =  pathToStoreSSL  +  " /fullchain.pem " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            privkey  =  open ( pathToStoreSSLPrivKey ,  ' w ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            privkey . write ( open ( keyPath ,  " r " ) . read ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            privkey . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            fullchain  =  open ( pathToStoreSSLFullChain ,  ' w ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            fullchain . write ( open ( certPath ,  " r " ) . read ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            fullchain . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            os . remove ( keyPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            os . remove ( certPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            sslUtilities . sslUtilities . installSSLForDomain ( virtualHost ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            FNULL  =  open ( os . devnull ,  ' w ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  " chown  "  +  " lsadm "  +  " : "  +  " lsadm "  +  "   "  +  pathToStoreSSL 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            cmd  =  shlex . split ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            subprocess . call ( cmd ,  stdout = FNULL ,  stderr = subprocess . STDOUT ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' chmod 600  %s '  %  ( pathToStoreSSLPrivKey ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . normalExecutioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 1,None " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                str ( msg )  +  "   [saveSSL] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 0, "  +  str ( msg ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  createDomain ( masterDomain ,  virtualHostName ,  phpVersion ,  path ,  ssl ,  dkimCheck ,  openBasedir ,  owner ,  apache , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                     tempStatusPath = ' /home/cyberpanel/fakePath ' ,  LimitsCheck = 1 ,  alias  =  0 ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Running some checks..,0 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## Check if this domain either exists as website or child domain 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            admin  =  Administrator . objects . get ( userName = owner ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            master  =  Websites . objects . get ( domain = masterDomain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  LimitsCheck : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                DNS . dnsTemplate ( virtualHostName ,  admin ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  Websites . objects . filter ( domain = virtualHostName ) . count ( )  >  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                              ' This Domain already exists as a website. [404] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    return  0 ,  " This Domain already exists as a website. " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  Websites . objects . filter ( domain = virtualHostName . lstrip ( ' www. ' ) ) . count ( )  >  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                              ' This Domain already exists as a website. [404] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    return  0 ,  " This Domain already exists as a website. " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ChildDomains . objects . filter ( domain = virtualHostName ) . count ( )  >  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                              ' This domain already exists as child domain. [404] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    return  0 ,  " This domain already exists as child domain. " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ChildDomains . objects . filter ( domain = virtualHostName . lstrip ( ' www. ' ) ) . count ( )  >  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                              ' This domain already exists as child domain. [404] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    return  0 ,  " This domain already exists as child domain. " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ####### Limitations check 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                domainsInPackage  =  master . package . allowedDomains 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  master . package . allowFullDomain  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  virtualHostName . find ( masterDomain )  >  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        pass 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                                  ' Fully qualified domain is not allowed in the package. [404] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        return  0 ,  " Fully qualified domain is not allowed in the package. " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  domainsInPackage  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    pass 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                elif  domainsInPackage  >  master . childdomains_set . all ( ) . count ( ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    pass 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                              ' Exceeded maximum number of domains for this package. [404] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    return  0 ,  " Exceeded maximum number of domains for this package " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ####### Limitations Check End 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  vhost . checkIfVirtualHostExists ( virtualHostName )  ==  1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                              ' Virtual Host Directory already exists. [404] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    return  0 ,  " Virtual Host Directory already exists! " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  vhost . checkIfAliasExists ( virtualHostName )  ==  1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' This domain exists as Alias. [404] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    #return 0, "This domain exists as Alias." 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' DKIM Setup..,30 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            postFixPath  =  ' /home/cyberpanel/postfix ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( postFixPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                retValues  =  mailUtilities . setupDKIM ( virtualHostName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  retValues [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    raise  BaseException ( retValues [ 1 ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            FNULL  =  open ( os . devnull ,  ' w ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Creating configurations..,50 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            retValues  =  vhost . createDirectoryForDomain ( masterDomain ,  virtualHostName ,  phpVersion ,  path , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                       master . adminEmail ,  master . externalApp ,  openBasedir ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  retValues [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                raise  BaseException ( retValues [ 1 ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  not  os . path . exists ( virtualHostUtilities . redisConf ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                retValues  =  vhost . createConfigInMainDomainHostFile ( virtualHostName ,  masterDomain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  retValues [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    raise  BaseException ( retValues [ 1 ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## Now restart litespeed after initial configurations are done 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  LimitsCheck : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                website  =  ChildDomains ( master = master ,  domain = virtualHostName ,  path = path ,  phpSelection = phpVersion , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                       ssl = ssl ,  alais = alias ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                website . save ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ssl  ==  1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Creating SSL..,50 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  not  os . path . exists ( virtualHostUtilities . redisConf ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                retValues  =  sslUtilities . issueSSLForDomain ( virtualHostName ,  master . adminEmail ,  path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  not  os . path . exists ( virtualHostUtilities . redisConf ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  retValues [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    raise  BaseException ( retValues [ 1 ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## Final Restart 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ssl  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  not  os . path . exists ( virtualHostUtilities . redisConf ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            vhost . finalizeDomainCreation ( master . externalApp ,  path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## Apache Settings 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            confPath  =  vhost . Server_root  +  " /conf/vhosts/ "  +  virtualHostName 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            completePathToConfigFile  =  confPath  +  " /vhost.conf " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  apache : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ProcessUtilities . decideServer ( )  ==  ProcessUtilities . OLS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  ApacheController . checkIfApacheInstalled ( )  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        result  =  ApacheController . setupApache ( tempStatusPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        if  result [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            raise  BaseException ( result [ 1 ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    result  =  ApacheVhost . setupApacheVhostChild ( master . adminEmail ,  master . externalApp , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                               master . externalApp ,  phpVersion ,  virtualHostName ,  path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  result [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        raise  BaseException ( result [ 1 ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        ApacheVhost . perHostVirtualConfOLS ( completePathToConfigFile ,  master . adminEmail ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        php  =  PHPManager . getPHPString ( phpVersion ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        phpService  =  ApacheVhost . DecideFPMServiceName ( phpVersion ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        command  =  f " systemctl restart  { phpService } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        ProcessUtilities . normalExecutioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ## DKIM Check 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            postFixPath  =  ' /home/cyberpanel/postfix ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( postFixPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  dkimCheck  ==  1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    DNS . createDKIMRecords ( virtualHostName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Domain successfully created. [200] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  1 ,  " None " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ACLManager . FindIfChild ( )  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                numberOfWebsites  =  Websites . objects . count ( )  +  ChildDomains . objects . count ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                vhost . deleteCoreConf ( virtualHostName ,  numberOfWebsites ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  str ( msg )  +  " . [404] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                str ( msg )  +  "   [createDomain] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  0 ,  str ( msg ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  deleteDomain ( virtualHostName ,  DeleteDocRoot = 0 ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            numberOfWebsites  =  Websites . objects . count ( )  +  ChildDomains . objects . count ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            vhost . deleteCoreConf ( virtualHostName ,  numberOfWebsites ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            delWebsite  =  ChildDomains . objects . get ( domain = virtualHostName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  DeleteDocRoot : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                command  =  ' rm -rf  %s '  %  ( delWebsite . path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            delWebsite . delete ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 1,None " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  1 ,  ' None ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                str ( msg )  +  "   [deleteDomain] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( " 0, "  +  str ( msg ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  0 ,  str ( msg ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  switchServer ( virtualHostName ,  phpVersion ,  server ,  tempStatusPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Starting Conversion..,0 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            child  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                website  =  Websites . objects . get ( domain = virtualHostName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                website  =  ChildDomains . objects . get ( domain = virtualHostName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                child  =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            confPath  =  vhost . Server_root  +  " /conf/vhosts/ "  +  virtualHostName 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            completePathToConfigFile  =  confPath  +  " /vhost.conf " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  server  ==  virtualHostUtilities . apache : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  os . path . exists ( completePathToConfigFile ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    os . remove ( completePathToConfigFile ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  ApacheController . checkIfApacheInstalled ( )  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    result  =  ApacheController . setupApache ( tempStatusPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  result [ 0 ]  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        raise  BaseException ( result [ 1 ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Creating apache configurations..,90 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  child : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ApacheVhost . perHostVirtualConfOLS ( completePathToConfigFile ,  website . master . adminEmail ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ApacheVhost . perHostVirtualConfOLS ( completePathToConfigFile ,  website . adminEmail ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  child : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ApacheVhost . setupApacheVhostChild ( website . master . adminEmail ,  website . master . externalApp , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                      website . master . externalApp , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                      phpVersion ,  virtualHostName ,  website . path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ApacheVhost . setupApacheVhost ( website . adminEmail ,  website . externalApp ,  website . externalApp , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                                 phpVersion ,  virtualHostName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Restarting servers and phps..,90 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                php  =  PHPManager . getPHPString ( phpVersion ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ## 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                phpService  =  ApacheVhost . DecideFPMServiceName ( phpVersion ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                # if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                #     phpService = f'php{php}-php-fpm' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                # else: 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                #     phpService = f"{phpVersion.replace(' ', '').lower()}-fpm" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                command  =  f " systemctl stop  { phpService } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ProcessUtilities . normalExecutioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                command  =  f " systemctl restart  { phpService } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ProcessUtilities . normalExecutioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                command  =  f " systemctl restart  { ApacheVhost . serviceName } " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ProcessUtilities . normalExecutioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ### 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Successfully converted.[200] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Starting Conversion..,0 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                ApacheVhost . DeleteApacheVhost ( virtualHostName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  child : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    vhost . perHostDomainConf ( website . path ,  website . master . domain ,  virtualHostName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                            completePathToConfigFile , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                            website . master . adminEmail ,  phpVersion ,  website . master . externalApp ,  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    vhost . perHostVirtualConf ( completePathToConfigFile ,  website . adminEmail ,  website . externalApp , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                             phpVersion ,  virtualHostName ,  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    sslFCPath  =  f ' /etc/letsencrypt/live/ { virtualHostName } /fullchain.pem ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  os . path . exists ( sslFCPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        sslUtilities . sslUtilities . installSSLForDomain ( virtualHostName ,  website . adminEmail ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Restarting server..,90 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' Successfully converted. [200] ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,  ' %s [404] '  %  str ( msg ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( str ( msg )  +  "   [switchServer] " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  getDiskUsage ( path ,  totalAllowed ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            totalUsageInMB  =  \
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                subprocess . check_output ( ' du -hs  %s  --block-size=1M '  %  ( path ) ,  shell = True ) . decode ( " utf-8 " ) . split ( ) [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            percentage  =  float ( 100 )  /  float ( totalAllowed ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            percentage  =  float ( percentage )  *  float ( totalUsageInMB ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            data  =  [ int ( totalUsageInMB ) ,  int ( percentage ) ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  data 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  [ int ( totalUsageInMB ) ,  int ( 0 ) ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                return  [ int ( 0 ) ,  int ( 0 ) ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  getDiskUsageofPath ( path ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  subprocess . check_output ( ' du -hs  %s  --block-size=1M '  %  ( path ) ,  shell = True ) . decode ( " utf-8 " ) . split ( ) [ 0 ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  ' 0MB ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  permissionControl ( path ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' sudo chown -R  cyberpanel:cyberpanel  '  +  path 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            cmd  =  shlex . split ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            res  =  subprocess . call ( cmd ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( str ( msg ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  leaveControl ( path ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  ' sudo chown -R  root:root  '  +  path 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            cmd  =  shlex . split ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            res  =  subprocess . call ( cmd ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            logging . CyberCPLogFileWriter . writeToFile ( str ( msg ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  FindStats ( website ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        import  json 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            config  =  json . loads ( website . config ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            DiskUsage  =  config [ ' DiskUsage ' ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            DiskUsagePercentage  =  config [ ' DiskUsagePercentage ' ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            bwInMB  =  config [ ' bwInMB ' ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            bwUsage  =  config [ ' bwUsage ' ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            DiskUsage  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            DiskUsagePercentage  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            bwInMB  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            bwUsage  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  DiskUsage ,  DiskUsagePercentage ,  bwInMB ,  bwUsage 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    @staticmethod 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    def  EnableDisablePP ( vhostName ,  username = None ,  password = None ,  path = None ,  wpid = None ,  externalApp = None ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            vhostPassDir  =  f ' /home/ { vhostName } ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            uBuntuPath  =  ' /etc/lsb-release ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  os . path . exists ( uBuntuPath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                group  =  ' nogroup ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                group  =  ' nobody ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            confPath  =  f ' { virtualHostUtilities . vhostConfPath } /vhosts/ { vhostName } /vhost.conf ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            htpassword  =  f ' { vhostPassDir } / { wpid } ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            htpasstemp  =  f ' /usr/local/CyberCP/ { wpid } ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  f ' touch  { htpasstemp } ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            command  =  f ' chown   { externalApp } : { group }   { htpasstemp } ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            FindLine  =  f ' PASSWORD PROTECTION CONF STARTS  { path } ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            FindLineEnd  =  f ' PASSWORD PROTECTION CONF ENDS  { path } ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            if  ProcessUtilities . decideServer ( )  ==  ProcessUtilities . OLS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  os . path . exists ( htpassword ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    command  =  f ' rm -f  { htpassword } ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ProcessUtilities . executioner ( command ,  externalApp ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    # os.remove(htpassword) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    removeCheck  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    data  =  open ( confPath ,  ' r ' ) . readlines ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile  =  open ( confPath ,  ' w ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    for  line  in  data : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        if  line . find ( FindLine )  >  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            removeCheck  =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        if  line . find ( FindLineEnd )  >  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            removeCheck  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        if  removeCheck  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            writeToFile . writelines ( line ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile  =  open ( confPath ,  ' a ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    from  vhostConfs  import  vhostConfs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    OLSPPConf  =  vhostConfs . OLSPPConf 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    OLSPPConf  =  OLSPPConf . replace ( ' {{ RealM_Name}} ' ,  str ( randint ( 1000 ,  9999 ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    OLSPPConf  =  OLSPPConf . replace ( ' {{ path}} ' ,  path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    OLSPPConf  =  OLSPPConf . replace ( ' {{ wpid}} ' ,  wpid ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    OLSPPConf  =  OLSPPConf . replace ( ' {{ PassFile}} ' ,  htpassword ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile . write ( OLSPPConf ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ### 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    import  bcrypt 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    password  =  password . encode ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    hashed  =  bcrypt . hashpw ( password ,  bcrypt . gensalt ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    UserPass  =  f ' { username } : { hashed . decode ( ) } : { username } ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile  =  open ( htpasstemp ,  ' w ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile . write ( UserPass ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    command  =  f ' cp  { htpasstemp }   { htpassword } ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ProcessUtilities . executioner ( command ,  externalApp ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    os . remove ( htpasstemp ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    command  =  f ' chmod 640  { htpassword } ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ProcessUtilities . executioner ( command ,  externalApp ,  True ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    command  =  f ' sudo -u  { externalApp }  -g  { group }  chown  { externalApp } : { group }   { htpassword } ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                RealmName  =  str ( randint ( 1000 ,  9999 ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                htaccesspath  =  f ' { path } /.htaccess ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                if  os . path . exists ( htpassword ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    command  =  f ' rm -f  { htpassword } ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ProcessUtilities . executioner ( command ,  externalApp ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    # os.remove(htpassword) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    removeCheck  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    if  os . path . exists ( htaccesspath ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        data  =  open ( htaccesspath ,  ' r ' ) . readlines ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        writeToFile  =  open ( htaccesspath ,  ' w ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        for  line  in  data : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            if  line . find ( FindLine )  >  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                removeCheck  =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            if  line . find ( FindLineEnd )  >  - 1 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                removeCheck  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                continue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                            if  removeCheck  ==  0 : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                writeToFile . writelines ( line ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                        writeToFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                else : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile  =  open ( htaccesspath ,  ' a ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    from  vhostConfs  import  vhostConfs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    LSWSPPProtection  =  vhostConfs . LSWSPPProtection 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    LSWSPPProtection  =  LSWSPPProtection . replace ( ' {{ RealM_Name}} ' ,  RealmName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    LSWSPPProtection  =  LSWSPPProtection . replace ( ' {{ path}} ' ,  path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    LSWSPPProtection  =  LSWSPPProtection . replace ( ' {{ PassFile}} ' ,  htpassword ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile . write ( LSWSPPProtection ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ### 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    import  bcrypt 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    password  =  password . encode ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    hashed  =  bcrypt . hashpw ( password ,  bcrypt . gensalt ( ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    UserPass  =  f ' { username } : { hashed . decode ( ) } : { username } ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile  =  open ( htpasstemp ,  ' w ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile . write ( UserPass ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    writeToFile . close ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    command  =  f ' cp  { htpasstemp }   { htpassword } ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ProcessUtilities . executioner ( command ,  externalApp ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    os . remove ( htpasstemp ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    command  =  f ' chmod 640  { htpassword } ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ProcessUtilities . executioner ( command ,  externalApp ,  True ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    command  =  f ' sudo -u  { externalApp }  -g  { group }  chown  { externalApp } : { group }   { htpassword } ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                    ProcessUtilities . executioner ( command ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            installUtilities . installUtilities . reStartLiteSpeed ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( ' 1,None ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except  BaseException  as  msg : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            print ( f ' 0, { str ( msg ) } ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  0 ,  str ( msg ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								def  main ( ) :  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser  =  argparse . ArgumentParser ( description = ' CyberPanel Installer ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' function ' ,  help = ' Specific a function to call! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --virtualHostName ' ,  help = ' Domain name! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --administratorEmail ' ,  help = ' Administration Email! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --phpVersion ' ,  help = ' PHP Version ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( " --virtualHostUser " ,  help = " Virtual Host Directory Owner and Group! " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( " --numberOfSites " ,  help = " Number of sites! " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( " --ssl " ,  help = " Weather to activate SSL " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( " --sslPath " ,  help = " Path to website document root! " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --dkimCheck ' ,  help = ' To enable or disable DKIM support for domain. ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --openBasedir ' ,  help = ' To enable or disable open_basedir protection for domain. ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --websiteOwner ' ,  help = ' Website Owner Name ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --package ' ,  help = ' Website package ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --restore ' ,  help = ' Restore Check. ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --apache ' ,  help = ' Enable/Disable Apache as backend ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ## arguments for creation child domains 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --masterDomain ' ,  help = ' Master Domain Needed While Creating Child Domains! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --path ' ,  help = ' Path Needed for Child domains Creation! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --restart ' ,  help = ' OLS Restart Frequency while child domain creation! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ## arguments for logs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --page ' ,  help = ' Page number to fetch logs! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ## arguments for configuration files 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --tempPath ' ,  help = ' Temporary path where configuration data is placed! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ## save ssl arguments 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --tempKeyPath ' ,  help = ' Temporary path to store key! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --tempCertPath ' ,  help = ' Temporary path to store cert! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --sslCheck ' ,  help = ' Weather SSL is already activated or not! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ## install wordpress arguments 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --dbName ' ,  help = ' Database Name! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --dbUser ' ,  help = ' Database User! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --dbPassword ' ,  help = ' Database Password! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ## calculate bw arguments 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --bandwidth ' ,  help = ' Pack Bandwidth! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ## extras 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --username ' ,  help = ' Admin Username! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --password ' ,  help = ' Admin Password! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --prefix ' ,  help = ' Database Prefix! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --sitename ' ,  help = ' Site Name! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ## Arguments for alias domain 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --aliasDomain ' ,  help = ' Alias Domain! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ## Arguments for OpenBasedir 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --openBasedirValue ' ,  help = ' open_base dir protection value! ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --tempStatusPath ' ,  help = ' Temporary Status file path. ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --mailDomain ' ,  help = ' To create or not to create mail domain. ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ## Switch Server 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --server ' ,  help = ' Switch server parameter. ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --wpid ' ,  help = ' WordPress ID ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ## Doc root deletion for child domain 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --DeleteDocRoot ' ,  help = ' Doc root deletion for child domain. ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ### for onboarding 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    parser . add_argument ( ' --rdns ' ,  help = ' Doc root deletion for child domain. ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    args  =  parser . parse_args ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  args . function  ==  " createVirtualHost " : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            dkimCheck  =  int ( args . dkimCheck ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            dkimCheck  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            openBasedir  =  int ( args . openBasedir ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            openBasedir  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            apache  =  int ( args . apache ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            apache  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            tempStatusPath  =  args . tempStatusPath 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            tempStatusPath  =  ' /home/cyberpanel/fakePath ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . createVirtualHost ( args . virtualHostName ,  args . administratorEmail ,  args . phpVersion , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                               args . virtualHostUser ,  int ( args . ssl ) ,  dkimCheck ,  openBasedir , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                               args . websiteOwner ,  args . package ,  apache ,  tempStatusPath , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                               int ( args . mailDomain ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  " setupAutoDiscover " : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        admin  =  Administrator . objects . get ( userName = args . websiteOwner ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . setupAutoDiscover ( 1 ,  ' /home/cyberpanel/templogs ' ,  args . virtualHostName ,  admin ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  " deleteVirtualHostConfigurations " : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        vhost . deleteVirtualHostConfigurations ( args . virtualHostName ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  " createDomain " : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            dkimCheck  =  int ( args . dkimCheck ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            dkimCheck  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            openBasedir  =  int ( args . openBasedir ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            openBasedir  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            apache  =  int ( args . apache ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            apache  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            tempStatusPath  =  args . tempStatusPath 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            tempStatusPath  =  ' /home/cyberpanel/fakePath ' 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            aliasDomain  =  int ( args . aliasDomain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        except : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            aliasDomain  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . createDomain ( args . masterDomain ,  args . virtualHostName ,  args . phpVersion ,  args . path , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                          int ( args . ssl ) ,  dkimCheck ,  openBasedir ,  args . websiteOwner ,  apache , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                          tempStatusPath ,  1 ,  aliasDomain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  " issueSSL " : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . issueSSL ( args . virtualHostName ,  args . path ,  args . administratorEmail ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  " issueSSLv2 " : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . issueSSLv2 ( args . virtualHostName ,  args . path ,  args . administratorEmail ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  " changePHP " : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        vhost . changePHP ( args . path ,  args . phpVersion ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  " getAccessLogs " : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . getAccessLogs ( args . path ,  int ( args . page ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  " getErrorLogs " : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . getErrorLogs ( args . path ,  int ( args . page ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  " saveVHostConfigs " : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . saveVHostConfigs ( args . path ,  args . tempPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  " saveApacheConfigsToFile " : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . saveApacheConfigsToFile ( args . path ,  args . tempPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  " saveRewriteRules " : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . saveRewriteRules ( args . virtualHostName ,  args . path ,  args . tempPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  " saveSSL " : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . saveSSL ( args . virtualHostName ,  args . tempKeyPath ,  args . tempCertPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  " installWordPress " : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . installWordPress ( args . virtualHostName ,  args . path ,  args . virtualHostUser ,  args . dbName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                              args . dbUser ,  args . dbPassword ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  " installJoomla " : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . installJoomla ( args . virtualHostName ,  args . path ,  args . virtualHostUser ,  args . dbName , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                           args . dbUser ,  args . dbPassword ,  args . username ,  args . password ,  args . prefix , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                           args . sitename ,  args . tempStatusPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  " issueSSLForHostName " : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . issueSSLForHostName ( args . virtualHostName ,  args . path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  " issueSSLForMailServer " : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . issueSSLForMailServer ( args . virtualHostName ,  args . path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  " findDomainBW " : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        vhost . findDomainBW ( args . virtualHostName ,  int ( args . bandwidth ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  ' createAlias ' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . createAlias ( args . masterDomain ,  args . aliasDomain ,  int ( args . ssl ) ,  args . sslPath , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                         args . administratorEmail ,  args . websiteOwner ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  ' issueAliasSSL ' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . issueAliasSSL ( args . masterDomain ,  args . aliasDomain ,  args . sslPath ,  args . administratorEmail ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  ' deleteAlias ' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . deleteAlias ( args . masterDomain ,  args . aliasDomain ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  ' changeOpenBasedir ' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . changeOpenBasedir ( args . virtualHostName ,  args . openBasedirValue ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  ' deleteDomain ' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . deleteDomain ( args . virtualHostName ,  int ( args . DeleteDocRoot ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  ' switchServer ' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . switchServer ( args . virtualHostName ,  args . phpVersion ,  int ( args . server ) ,  args . tempStatusPath ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  ' EnableDisablePP ' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . EnableDisablePP ( args . virtualHostName ,  args . username ,  args . password ,  args . path ,  args . wpid , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                                             args . virtualHostUser ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    elif  args . function  ==  ' OnBoardingHostName ' : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        # in virtualHostName pass domain for which hostname should be set up 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        # in path pass temporary path where status of the function will be stored 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        virtualHostUtilities . OnBoardingHostName ( args . virtualHostName ,  args . path ,  int ( args . rdns ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if  __name__  ==  " __main__ " :  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    main ( )