2019-12-10 23:04:24 +05:00
#!/usr/local/CyberCP/bin/python
2018-06-01 02:08:21 +05:00
import os
2017-10-24 19:16:36 +05:00
import os . path
2018-06-01 02:08:21 +05:00
import sys
2024-01-25 10:44:06 +05:00
import time
2018-06-01 02:08:21 +05:00
import django
2024-01-18 13:04:47 +05:00
# 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)))
2019-12-15 11:34:09 +05:00
2018-06-01 02:08:21 +05:00
sys . path . append ( ' /usr/local/CyberCP ' )
os . environ . setdefault ( " DJANGO_SETTINGS_MODULE " , " CyberCP.settings " )
2020-01-27 20:11:23 +05:00
from random import randint
2019-11-24 12:14:18 +05:00
2019-12-15 11:34:09 +05:00
django . setup ( )
2017-12-09 22:30:10 +05:00
import argparse
2019-12-15 11:34:09 +05:00
from plogical import installUtilities
from plogical import sslUtilities
2018-05-24 23:37:10 +05:00
from multiprocessing import Process
2018-06-01 02:08:21 +05:00
import subprocess
import shlex
from plogical . mailUtilities import mailUtilities
2019-12-15 11:34:09 +05:00
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
2019-06-08 21:41:43 +00:00
from ApachController . ApacheController import ApacheController
from ApachController . ApacheVhosts import ApacheVhost
from managePHP . phpManager import PHPManager
2019-07-18 14:08:00 +05:00
try :
from websiteFunctions . models import Websites , ChildDomains , aliasDomains
from loginSystem . models import Administrator
from packages . models import Package
from CLManager . models import CLPackages
except :
pass
2017-10-24 19:16:36 +05:00
2019-10-27 18:08:10 +05:00
2018-05-08 21:25:37 +05:00
## If you want justice, you have come to the wrong place.
2017-10-24 19:16:36 +05:00
class virtualHostUtilities :
2019-06-08 21:41:43 +00:00
apache = 1
ols = 2
lsws = 3
2017-10-24 19:16:36 +05:00
Server_root = " /usr/local/lsws "
2017-12-09 22:30:10 +05:00
cyberPanel = " /usr/local/CyberCP "
2020-01-11 19:27:49 +05:00
redisConf = ' /usr/local/lsws/conf/dvhost_redis.conf '
2021-04-02 01:14:30 +05:00
vhostConfPath = ' /usr/local/lsws/conf '
2019-10-27 18:08:10 +05:00
2024-01-24 10:50:52 +05:00
2024-01-18 13:04:47 +05:00
@staticmethod
2024-01-25 10:44:06 +05:00
def OnBoardingHostName ( Domain , tempStatusPath , skipRDNSCheck ) :
2024-01-18 13:04:47 +05:00
import json
import OpenSSL
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' Setting up hostname,10 ' )
admin = Administrator . objects . get ( pk = 1 )
2024-02-06 18:25:19 +05:00
try :
config = json . loads ( admin . config )
except :
config = { }
2024-01-18 13:04:47 +05:00
### probably need to add temporary dns resolver nameserver here - pending
try :
CurrentHostName = config [ ' hostname ' ]
except :
CurrentHostName = ' '
2024-02-07 14:54:49 +05:00
if not skipRDNSCheck :
if not os . path . exists ( ' /home/cyberpanel/postfix ' ) :
message = ' This server does not come with postfix installed. [404] '
print ( message )
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , message )
logging . CyberCPLogFileWriter . writeToFile ( message )
2024-01-18 13:04:47 +05:00
####
PostFixHostname = mailUtilities . FetchPostfixHostname ( )
serverIP = ACLManager . fetchIP ( )
2024-01-25 10:44:06 +05:00
### if skipRDNSCheck == 1, it means we need to skip checking for rDNS
if skipRDNSCheck :
### so if skipRDNSCheck is 1 means we need to skip checking for rDNS so lets set current as rDNS because no checking is required
rDNS = CurrentHostName
else :
rDNS = mailUtilities . reverse_dns_lookup ( serverIP )
2024-01-18 13:04:47 +05:00
2024-01-25 10:44:06 +05:00
time . sleep ( 3 )
if os . path . exists ( ProcessUtilities . debugPath ) :
print ( f ' Postfix Hostname: { PostFixHostname } . Server IP { serverIP } . rDNS: { rDNS } ' )
logging . CyberCPLogFileWriter . writeToFile ( f ' Postfix Hostname: { PostFixHostname } . Server IP { serverIP } . rDNS: { rDNS } , rDNS check { skipRDNSCheck } ' )
2024-01-18 13:04:47 +05:00
### 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 == 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 )
x509 = OpenSSL . crypto . load_certificate ( OpenSSL . crypto . FILETYPE_PEM , open ( filePath , ' r ' ) . read ( ) )
SSLProvider = x509 . get_issuer ( ) . get_components ( ) [ 1 ] [ 1 ] . decode ( ' utf-8 ' )
try :
child = ChildDomains . objects . get ( domain = CurrentHostName )
website = child . master
path = child . path
except :
website = Websites . objects . get ( domain = CurrentHostName )
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 , website . adminEmail )
### once SSL is issued, re-read the SSL file and check if valid ssl got issued.
x509 = OpenSSL . crypto . load_certificate ( OpenSSL . crypto . FILETYPE_PEM , open ( filePath , ' r ' ) . read ( ) )
SSLProvider = x509 . get_issuer ( ) . get_components ( ) [ 1 ] [ 1 ] . decode ( ' utf-8 ' )
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 )
2024-01-25 10:44:06 +05:00
config [ ' hostname ' ] = Domain
config [ ' onboarding ' ] = 3
config [ ' skipRDNSCheck ' ] = skipRDNSCheck
admin . config = json . dumps ( config )
admin . save ( )
2024-01-18 13:04:47 +05:00
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 )
2024-01-25 10:44:06 +05:00
config [ ' hostname ' ] = Domain
config [ ' onboarding ' ] = 1
config [ ' skipRDNSCheck ' ] = skipRDNSCheck
admin . config = json . dumps ( config )
admin . save ( )
2024-01-18 13:04:47 +05:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , message )
logging . CyberCPLogFileWriter . writeToFile ( message )
command = ' systemctl restart postfix && systemctl restart dovecot && postmap -F hash:/etc/postfix/vmail_ssl.map '
ProcessUtilities . executioner ( command , ' root ' , True )
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' Completed. [200] ' )
else :
2024-01-25 11:37:26 +05:00
### create site if not there
try :
2024-01-27 12:02:50 +05:00
2024-01-25 11:37:26 +05:00
website = Websites . objects . get ( domain = Domain )
except :
2024-01-27 12:02:50 +05:00
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 )
reutrntempath = coreResult1 [ ' tempStatusPath ' ]
while ( 1 ) :
lastLine = open ( reutrntempath , ' r ' ) . read ( )
if os . path . exists ( ProcessUtilities . debugPath ) :
logging . CyberCPLogFileWriter . writeToFile ( " Info web creating lastline ....... %s " % lastLine )
if lastLine . find ( ' [200] ' ) > - 1 :
break
elif lastLine . find ( ' [404] ' ) > - 1 :
statusFile = open ( currentTemp , ' w ' )
statusFile . writelines ( ' Failed to Create Website: error: %s . [404] ' % lastLine )
statusFile . close ( )
return 0
else :
statusFile = open ( currentTemp , ' w ' )
statusFile . writelines ( ' Creating Website....,20 ' )
statusFile . close ( )
time . sleep ( 2 )
2024-01-25 11:37:26 +05:00
2024-01-18 13:04:47 +05:00
### Case 2 where postfix hostname either does not exist or does not match with server hostname or
### hostname does not exists at all
2024-01-25 10:44:06 +05:00
### if skipRDNSCheck == 1, it means we need to skip checking for rDNS
if skipRDNSCheck :
### so if skipRDNSCheck is 1 means we need to skip checking for rDNS so lets set current domain as rDNS because no checking is required
rDNS = Domain
if os . path . exists ( ProcessUtilities . debugPath ) :
logging . CyberCPLogFileWriter . writeToFile (
f ' Second if: Postfix Hostname: { PostFixHostname } . Server IP { serverIP } . rDNS: { rDNS } , rDNS check { skipRDNSCheck } ' )
2024-01-18 13:04:47 +05:00
#first check if hostname is already configured as rDNS, if not return error
2024-01-25 10:44:06 +05:00
2024-01-18 13:04:47 +05:00
if Domain != rDNS :
message = ' Domain that you have provided is not configured as rDNS for your server IP. [404] '
2024-01-19 11:54:23 +05:00
print ( message )
2024-01-18 13:04:47 +05:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , message )
logging . CyberCPLogFileWriter . writeToFile ( message )
2024-01-25 10:44:06 +05:00
config [ ' hostname ' ] = Domain
config [ ' onboarding ' ] = 3
config [ ' skipRDNSCheck ' ] = skipRDNSCheck
admin . config = json . dumps ( config )
admin . save ( )
2024-01-18 13:04:47 +05:00
return 0
### now issue hostname ssl
try :
website = Websites . objects . get ( domain = Domain )
path = " /home/ " + Domain + " /public_html "
except :
website = ChildDomains . objects . get ( domain = Domain )
path = website . path
filePath = ' /etc/letsencrypt/live/ %s /fullchain.pem ' % ( Domain )
2024-01-25 10:44:06 +05:00
virtualHostUtilities . issueSSLForHostName ( Domain , path , 1 )
2024-01-19 11:55:55 +05:00
2024-01-18 13:04:47 +05:00
x509 = OpenSSL . crypto . load_certificate ( OpenSSL . crypto . FILETYPE_PEM , open ( filePath , ' r ' ) . read ( ) )
SSLProvider = x509 . get_issuer ( ) . get_components ( ) [ 1 ] [ 1 ] . decode ( ' utf-8 ' )
if SSLProvider == ' Denial ' :
2024-01-31 14:42:28 +05:00
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] '
2024-01-18 13:04:47 +05:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , message )
logging . CyberCPLogFileWriter . writeToFile ( message )
2024-01-25 10:44:06 +05:00
config [ ' hostname ' ] = Domain
config [ ' onboarding ' ] = 3
config [ ' skipRDNSCheck ' ] = skipRDNSCheck
admin . config = json . dumps ( config )
admin . save ( )
2024-01-18 13:04:47 +05:00
return 0
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' Hostname SSL issued,50 ' )
2024-01-19 11:55:55 +05:00
virtualHostUtilities . issueSSLForMailServer ( Domain , path )
2024-01-18 13:04:47 +05:00
2024-01-19 11:54:23 +05:00
x509 = OpenSSL . crypto . load_certificate ( OpenSSL . crypto . FILETYPE_PEM , open ( filePath , ' r ' ) . read ( ) )
SSLProvider = x509 . get_issuer ( ) . get_components ( ) [ 1 ] [ 1 ] . decode ( ' utf-8 ' )
2024-01-18 13:04:47 +05:00
if SSLProvider == ' Denial ' :
2024-01-26 09:39:05 +05:00
message = ' Failed to issue Mail server SSL, either its DNS record is not propagated or the domain is behind Cloudflare. [404] '
2024-01-18 13:04:47 +05:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , message )
logging . CyberCPLogFileWriter . writeToFile ( message )
2024-01-25 10:44:06 +05:00
config [ ' hostname ' ] = Domain
config [ ' onboarding ' ] = 3
config [ ' skipRDNSCheck ' ] = skipRDNSCheck
admin . config = json . dumps ( config )
admin . save ( )
2024-01-18 13:04:47 +05:00
return 0
else :
config [ ' hostname ' ] = Domain
2024-01-25 10:44:06 +05:00
config [ ' onboarding ' ] = 1
config [ ' skipRDNSCheck ' ] = skipRDNSCheck
2024-01-18 13:04:47 +05:00
admin . config = json . dumps ( config )
admin . save ( )
command = ' systemctl restart postfix && systemctl restart dovecot && postmap -F hash:/etc/postfix/vmail_ssl.map '
ProcessUtilities . executioner ( command , ' root ' , True )
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' Completed. [200] ' )
2020-05-10 03:15:33 +05:00
@staticmethod
def setupAutoDiscover ( mailDomain , tempStatusPath , virtualHostName , admin ) :
if mailDomain :
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' Creating mail child domain..,80 ' )
childDomain = ' mail. %s ' % ( virtualHostName )
2021-09-29 00:29:19 +06:00
childPath = ' /home/ %s / %s ' % ( virtualHostName , childDomain )
2020-05-10 03:15:33 +05:00
2021-10-07 16:27:13 +06:00
result = virtualHostUtilities . createDomain ( virtualHostName , childDomain , ' PHP 7.3 ' , childPath , 1 , 0 , 0 ,
2024-01-18 13:04:47 +05:00
admin . userName , 0 ,
" /home/cyberpanel/ " + str ( randint ( 1000 , 9999 ) ) )
2020-05-10 03:15:33 +05:00
2020-11-06 12:07:39 +05:00
if result [ 0 ] == 0 :
2023-05-08 15:42:39 +05:00
sslUtilities . issueSSLForDomain ( childDomain , admin . email , childPath )
2020-11-06 12:07:39 +05:00
2020-05-10 03:15:33 +05:00
## update dovecot conf to enable auto-discover
dovecotPath = ' /etc/dovecot/dovecot.conf '
if os . path . exists ( dovecotPath ) :
dovecotContent = open ( dovecotPath , ' r ' ) . read ( )
2020-11-06 12:07:39 +05:00
if dovecotContent . find ( ' /live/ %s / ' % ( childDomain ) ) == - 1 :
2020-05-10 03:15:33 +05:00
content = """ \n local_name %s {
2020-11-06 12:07:39 +05:00
ssl_cert = < / etc / letsencrypt / live / % s / fullchain . pem
ssl_key = < / etc / letsencrypt / live / % s / privkey . pem
2020-05-10 03:15:33 +05:00
} \n """ % (childDomain, childDomain, childDomain)
writeToFile = open ( dovecotPath , ' a ' )
writeToFile . write ( content )
writeToFile . close ( )
2020-11-06 12:07:39 +05:00
command = ' systemctl restart dovecot '
ProcessUtilities . executioner ( command )
2020-05-10 03:15:33 +05:00
### 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 '
2020-11-12 15:12:35 +05:00
try :
postfixMapFileContent = open ( postfixMapFile , ' r ' ) . read ( )
except :
postfixMapFileContent = ' '
2020-05-10 03:15:33 +05:00
2020-11-06 12:07:39 +05:00
if postfixMapFileContent . find ( ' /live/ %s / ' % ( childDomain ) ) == - 1 :
mapContent = ' %s /etc/letsencrypt/live/ %s /privkey.pem /etc/letsencrypt/live/ %s /fullchain.pem \n ' % (
childDomain , childDomain , childDomain )
writeToFile = open ( postfixMapFile , ' a ' )
writeToFile . write ( mapContent )
writeToFile . close ( )
2020-05-10 03:15:33 +05:00
2020-05-11 00:56:38 +05:00
command = ' postmap -F hash:/etc/postfix/vmail_ssl.map '
2020-05-10 23:41:09 +05:00
2020-05-10 03:15:33 +05:00
ProcessUtilities . executioner ( command )
command = ' systemctl restart postfix '
ProcessUtilities . executioner ( command )
2017-10-24 19:16:36 +05:00
@staticmethod
2018-08-22 00:37:43 +05:00
def createVirtualHost ( virtualHostName , administratorEmail , phpVersion , virtualHostUser , ssl ,
2019-10-27 18:08:10 +05:00
dkimCheck , openBasedir , websiteOwner , packageName , apache ,
2021-10-07 16:27:13 +06:00
tempStatusPath = ' /home/cyberpanel/fakePath ' , mailDomain = None , LimitsCheck = 1 ) :
2018-08-22 00:37:43 +05:00
try :
2018-07-30 17:33:28 +05:00
2018-08-22 00:37:43 +05:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' Running some checks..,0 ' )
2018-07-30 17:33:28 +05:00
2018-08-22 00:37:43 +05:00
####### Limitations check
admin = Administrator . objects . get ( userName = websiteOwner )
2021-04-02 01:14:30 +05:00
if LimitsCheck :
2018-08-22 00:37:43 +05:00
2021-04-02 01:14:30 +05:00
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
2017-10-24 19:16:36 +05:00
2021-04-02 01:14:30 +05:00
if Websites . objects . filter ( domain = virtualHostName ) . count ( ) > 0 :
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' This website already exists. [404] ' )
return 0 , " This website already exists. "
2017-10-24 19:16:36 +05:00
2021-04-02 01:14:30 +05:00
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. "
2019-11-11 20:04:17 +05:00
2021-04-02 01:14:30 +05:00
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. "
2017-12-09 22:30:10 +05:00
2021-04-02 01:14:30 +05:00
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. "
2019-11-11 20:04:17 +05:00
2021-04-02 01:14:30 +05:00
####### Limitations Check End
2017-12-09 22:30:10 +05:00
2021-04-02 01:14:30 +05:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' Creating DNS records..,10 ' )
2018-07-30 17:33:28 +05:00
2021-04-02 01:14:30 +05:00
##### Zone creation
2017-12-09 22:30:10 +05:00
2021-04-02 01:14:30 +05:00
DNS . dnsTemplate ( virtualHostName , admin )
2017-12-09 22:30:10 +05:00
2021-04-02 01:14:30 +05:00
## Zone creation
2017-12-09 22:30:10 +05:00
2021-04-02 01:14:30 +05:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' Setting up directories..,25 ' )
2018-07-30 17:33:28 +05:00
2021-04-02 01:14:30 +05:00
if vhost . checkIfVirtualHostExists ( virtualHostName ) == 1 :
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,
' Virtual Host Directory already exists. [404] ' )
return 0 , " Virtual Host Directory already exists! "
2017-12-09 22:30:10 +05:00
2021-04-02 01:14:30 +05:00
if vhost . checkIfAliasExists ( virtualHostName ) == 1 :
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' This domain exists as Alias. [404] ' )
return 0 , " This domain exists as Alias. "
2017-12-09 22:30:10 +05:00
2021-04-02 12:45:42 +05:00
postfixPath = ' /home/cyberpanel/postfix '
if os . path . exists ( postfixPath ) :
retValues = mailUtilities . setupDKIM ( virtualHostName )
if retValues [ 0 ] == 0 :
raise BaseException ( retValues [ 1 ] )
2017-12-09 22:30:10 +05:00
2018-06-01 02:08:21 +05:00
retValues = vhost . createDirectoryForVirtualHost ( virtualHostName , administratorEmail ,
2019-10-27 18:08:10 +05:00
virtualHostUser , phpVersion , openBasedir )
2018-06-01 02:08:21 +05:00
if retValues [ 0 ] == 0 :
raise BaseException ( retValues [ 1 ] )
2017-12-09 22:30:10 +05:00
2018-08-22 00:37:43 +05:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' Creating configurations..,50 ' )
2018-07-30 17:33:28 +05:00
2020-01-11 19:27:49 +05:00
if not os . path . exists ( virtualHostUtilities . redisConf ) :
retValues = vhost . createConfigInMainVirtualHostFile ( virtualHostName )
if retValues [ 0 ] == 0 :
raise BaseException ( retValues [ 1 ] )
2017-12-09 22:30:10 +05:00
2018-11-10 02:37:45 +05:00
selectedPackage = Package . objects . get ( packageName = packageName )
2021-04-02 01:14:30 +05:00
if LimitsCheck :
website = Websites ( admin = admin , package = selectedPackage , domain = virtualHostName ,
adminEmail = administratorEmail ,
phpSelection = phpVersion , ssl = ssl , externalApp = virtualHostUser )
2018-11-10 02:37:45 +05:00
2021-04-02 01:14:30 +05:00
website . save ( )
2018-11-10 02:37:45 +05:00
2024-01-19 15:39:38 +05:00
if admin . defaultSite == 0 :
admin . defaultSite = website . id
admin . save ( )
2018-06-01 02:08:21 +05:00
if ssl == 1 :
2018-08-22 00:37:43 +05:00
sslPath = " /home/ " + virtualHostName + " /public_html "
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' Setting up SSL..,70 ' )
2020-01-11 19:27:49 +05:00
if not os . path . exists ( virtualHostUtilities . redisConf ) :
installUtilities . installUtilities . reStartLiteSpeed ( )
2018-06-01 02:08:21 +05:00
retValues = sslUtilities . issueSSLForDomain ( virtualHostName , administratorEmail , sslPath )
if retValues [ 0 ] == 0 :
raise BaseException ( retValues [ 1 ] )
else :
2020-01-11 19:27:49 +05:00
if not os . path . exists ( virtualHostUtilities . redisConf ) :
installUtilities . installUtilities . reStartLiteSpeed ( )
2017-11-05 03:02:51 +05:00
2024-01-24 20:11:15 +05:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' SSL set up done..,70 ' )
2018-06-01 02:08:21 +05:00
if ssl == 0 :
2020-01-11 19:27:49 +05:00
if not os . path . exists ( virtualHostUtilities . redisConf ) :
installUtilities . installUtilities . reStartLiteSpeed ( )
2017-12-09 22:30:10 +05:00
2018-06-05 00:53:45 +05:00
vhost . finalizeVhostCreation ( virtualHostName , virtualHostUser )
2017-12-09 22:30:10 +05:00
2024-01-24 20:11:15 +05:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' vHost finalized..,70 ' )
2019-06-08 21:41:43 +00:00
## 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 ,
2019-10-27 18:08:10 +05:00
phpVersion , virtualHostName )
2019-06-08 21:41:43 +00:00
if result [ 0 ] == 0 :
raise BaseException ( result [ 1 ] )
else :
ApacheVhost . perHostVirtualConfOLS ( completePathToConfigFile , administratorEmail )
installUtilities . installUtilities . reStartLiteSpeed ( )
php = PHPManager . getPHPString ( phpVersion )
2023-05-15 21:16:10 +05:00
2023-05-17 16:05:58 +05:00
phpService = ApacheVhost . DecideFPMServiceName ( phpVersion )
2023-05-15 21:16:10 +05:00
command = f " systemctl restart { phpService } "
2019-06-08 21:41:43 +00:00
ProcessUtilities . normalExecutioner ( command )
2018-06-01 02:08:21 +05:00
## Create Configurations ends here
2017-11-05 03:02:51 +05:00
2020-01-27 20:11:23 +05:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' DKIM Setup..,70 ' )
2018-08-22 00:37:43 +05:00
2018-06-01 02:08:21 +05:00
## DKIM Check
2017-12-09 22:30:10 +05:00
2019-07-16 23:23:16 +05:00
postFixPath = ' /home/cyberpanel/postfix '
if os . path . exists ( postFixPath ) :
if dkimCheck == 1 :
DNS . createDKIMRecords ( virtualHostName )
2018-05-12 02:21:42 +05:00
2019-07-16 23:23:16 +05:00
CLPath = ' /etc/sysconfig/cloudlinux '
if os . path . exists ( CLPath ) :
2024-01-18 13:04:47 +05:00
command = ' /usr/share/cloudlinux/hooks/post_modify_user.py create --username %s --owner %s ' % (
virtualHostUser , admin . userName )
2019-12-31 19:55:29 +05:00
ProcessUtilities . executioner ( command )
2020-01-27 20:29:14 +05:00
### For autodiscover of mail clients.
2020-05-10 03:15:33 +05:00
virtualHostUtilities . setupAutoDiscover ( mailDomain , tempStatusPath , virtualHostName , admin )
2020-02-02 16:27:04 +05:00
###
2019-12-31 19:55:29 +05:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' Website successfully created. [200] ' )
2019-07-16 23:23:16 +05:00
2018-06-01 02:08:21 +05:00
return 1 , ' None '
2017-12-09 22:30:10 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg :
2021-04-02 12:45:42 +05:00
if ACLManager . FindIfChild ( ) == 0 :
vhost . deleteVirtualHostConfigurations ( virtualHostName )
2018-06-01 02:08:21 +05:00
logging . CyberCPLogFileWriter . writeToFile ( str ( msg ) + " [createVirtualHost] " )
2018-08-22 00:37:43 +05:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , str ( msg ) + " [404] " )
2018-06-01 02:08:21 +05:00
return 0 , str ( msg )
2017-11-05 03:02:51 +05:00
2018-05-12 02:21:42 +05:00
@staticmethod
2018-06-01 02:08:21 +05:00
def issueSSL ( virtualHost , path , adminEmail ) :
2017-11-05 03:02:51 +05:00
try :
2017-12-09 22:30:10 +05:00
2018-06-01 02:08:21 +05:00
retValues = sslUtilities . issueSSLForDomain ( virtualHost , adminEmail , path )
2018-05-12 02:21:42 +05:00
2018-06-01 02:08:21 +05:00
if retValues [ 0 ] == 0 :
2019-12-10 15:09:10 +05:00
print ( " 0, " + str ( retValues [ 1 ] ) )
2019-09-11 15:07:10 +05:00
logging . CyberCPLogFileWriter . writeToFile ( str ( retValues [ 1 ] ) )
2018-08-23 15:39:28 +05:00
return 0 , str ( retValues [ 1 ] )
2018-05-12 02:21:42 +05:00
2018-06-01 02:08:21 +05:00
installUtilities . installUtilities . reStartLiteSpeed ( )
2018-05-12 02:21:42 +05:00
2020-09-01 13:02:05 +05:00
command = ' systemctl restart postfix '
ProcessUtilities . executioner ( command )
command = ' systemctl restart dovecot '
ProcessUtilities . executioner ( command )
2019-12-10 15:09:10 +05:00
print ( " 1,None " )
2018-06-05 00:53:45 +05:00
return 1 , None
2017-12-09 22:30:10 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg :
2018-08-23 15:39:28 +05:00
logging . CyberCPLogFileWriter . writeToFile ( str ( msg ) + " [issueSSL] " )
2019-12-10 15:09:10 +05:00
print ( " 0, " + str ( msg ) )
2018-06-05 00:53:45 +05:00
return 0 , str ( msg )
2017-10-24 19:16:36 +05:00
2023-04-01 05:39:18 +05:00
@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 )
2017-10-24 19:16:36 +05:00
@staticmethod
2019-11-26 13:36:17 +05:00
def getAccessLogs ( fileName , page , externalApp ) :
2017-10-24 19:16:36 +05:00
try :
2019-07-16 23:23:16 +05:00
if os . path . islink ( fileName ) :
2019-12-10 15:09:10 +05:00
print ( " 0, %s file is symlinked. " % ( fileName ) )
2019-07-16 23:23:16 +05:00
return 0
2020-05-15 01:47:48 +05:00
groupName = ' nobody '
2020-04-03 11:28:27 +05:00
2024-01-18 13:04:47 +05:00
numberOfTotalLines = int (
ProcessUtilities . outputExecutioner ( ' wc -l %s ' % ( fileName ) , groupName ) . split ( " " ) [ 0 ] )
2017-12-09 22:30:10 +05:00
2018-06-01 02:08:21 +05:00
if numberOfTotalLines < 25 :
2020-04-03 11:28:27 +05:00
data = ProcessUtilities . outputExecutioner ( ' cat %s ' % ( fileName ) , groupName )
2018-06-01 02:08:21 +05:00
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
2020-04-03 11:28:27 +05:00
data = ProcessUtilities . outputExecutioner ( command , groupName )
2017-10-24 19:16:36 +05:00
else :
2018-06-01 02:08:21 +05:00
end = numberOfTotalLines - ( ( page - 1 ) * 25 )
start = end - 24
if start < = 0 :
start = 1
startingAndEnding = " ' " + str ( start ) + " , " + str ( end ) + " p ' "
command = " sed -n " + startingAndEnding + " " + fileName
2020-04-03 11:28:27 +05:00
data = ProcessUtilities . outputExecutioner ( command , groupName )
2019-12-10 15:09:10 +05:00
print ( data )
2019-11-26 13:36:17 +05:00
return data
2019-12-10 15:09:10 +05:00
except BaseException as msg :
2017-10-24 19:16:36 +05:00
logging . CyberCPLogFileWriter . writeToFile (
2018-06-01 02:08:21 +05:00
str ( msg ) + " [getAccessLogs] " )
2019-12-10 15:09:10 +05:00
print ( " 1,None " )
2019-11-26 13:36:17 +05:00
return " 1,None "
2017-10-24 19:16:36 +05:00
@staticmethod
2019-11-26 13:36:17 +05:00
def getErrorLogs ( fileName , page , externalApp ) :
2017-10-24 19:16:36 +05:00
try :
2019-07-16 23:23:16 +05:00
if os . path . islink ( fileName ) :
2019-12-10 15:09:10 +05:00
print ( " 0, %s file is symlinked. " % ( fileName ) )
2019-07-16 23:23:16 +05:00
return 0
2019-11-26 13:36:17 +05:00
numberOfTotalLines = int (
ProcessUtilities . outputExecutioner ( ' wc -l %s ' % ( fileName ) , externalApp ) . split ( " " ) [ 0 ] )
2017-10-24 19:16:36 +05:00
2018-06-01 02:08:21 +05:00
if numberOfTotalLines < 25 :
2019-11-26 13:36:17 +05:00
data = ProcessUtilities . outputExecutioner ( ' cat %s ' % ( fileName ) , externalApp )
2018-05-24 23:37:10 +05:00
else :
2018-06-01 02:08:21 +05:00
if page == 1 :
end = numberOfTotalLines
start = end - 24
if start < = 0 :
start = 1
startingAndEnding = " ' " + str ( start ) + " , " + str ( end ) + " p ' "
command = " sed -n " + startingAndEnding + " " + fileName
2019-11-26 13:36:17 +05:00
data = ProcessUtilities . outputExecutioner ( command , externalApp )
2018-06-01 02:08:21 +05:00
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
2019-11-26 13:36:17 +05:00
data = ProcessUtilities . outputExecutioner ( command , externalApp )
2019-12-10 15:09:10 +05:00
print ( data )
2019-11-26 13:36:17 +05:00
return data
2019-12-10 15:09:10 +05:00
except BaseException as msg :
2017-10-24 19:16:36 +05:00
logging . CyberCPLogFileWriter . writeToFile (
2018-06-01 02:08:21 +05:00
str ( msg ) + " [getErrorLogs] " )
2019-12-10 15:09:10 +05:00
print ( " 1,None " )
2019-11-26 13:36:17 +05:00
return " 1,None "
2017-10-24 19:16:36 +05:00
@staticmethod
2018-06-01 02:08:21 +05:00
def saveVHostConfigs ( fileName , tempPath ) :
2017-10-24 19:16:36 +05:00
try :
2018-06-01 02:08:21 +05:00
vhost = open ( fileName , " w " )
2017-10-24 19:16:36 +05:00
2018-06-01 02:08:21 +05:00
vhost . write ( open ( tempPath , " r " ) . read ( ) )
2017-10-24 19:16:36 +05:00
2018-06-01 02:08:21 +05:00
vhost . close ( )
2017-10-24 19:16:36 +05:00
2018-06-01 02:08:21 +05:00
if os . path . exists ( tempPath ) :
os . remove ( tempPath )
2017-10-24 19:16:36 +05:00
2018-06-01 02:08:21 +05:00
installUtilities . installUtilities . reStartLiteSpeed ( )
2017-12-22 12:36:24 +05:00
2019-12-10 15:09:10 +05:00
print ( " 1,None " )
2017-10-24 19:16:36 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg :
2017-10-24 19:16:36 +05:00
logging . CyberCPLogFileWriter . writeToFile (
2018-06-01 02:08:21 +05:00
str ( msg ) + " [saveVHostConfigs] " )
2019-12-10 15:09:10 +05:00
print ( " 0, " + str ( msg ) )
2018-01-02 11:49:03 +05:00
2023-05-15 21:16:10 +05:00
@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 ) )
2018-01-02 11:49:03 +05:00
@staticmethod
2018-06-01 02:08:21 +05:00
def saveRewriteRules ( virtualHost , fileName , tempPath ) :
2018-01-02 11:49:03 +05:00
try :
2019-07-16 23:23:16 +05:00
if os . path . islink ( fileName ) :
2019-12-10 15:09:10 +05:00
print ( " 0, .htaccess file is symlinked. " )
2019-07-16 23:23:16 +05:00
return 0
2018-06-01 02:08:21 +05:00
vhost . addRewriteRules ( virtualHost , fileName )
2018-01-02 11:49:03 +05:00
2018-06-01 02:08:21 +05:00
vhostFile = open ( fileName , " w " )
vhostFile . write ( open ( tempPath , " r " ) . read ( ) )
vhostFile . close ( )
2018-05-08 21:25:37 +05:00
2019-07-16 23:23:16 +05:00
try :
if os . path . exists ( tempPath ) :
os . remove ( tempPath )
except :
pass
2018-05-08 21:25:37 +05:00
2019-12-10 15:09:10 +05:00
print ( " 1,None " )
2017-12-09 22:30:10 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg :
2018-06-01 02:08:21 +05:00
logging . CyberCPLogFileWriter . writeToFile (
str ( msg ) + " [saveRewriteRules] " )
2019-12-10 15:09:10 +05:00
print ( " 0, " + str ( msg ) )
2018-05-01 00:49:47 +05:00
2018-06-01 02:08:21 +05:00
@staticmethod
2024-01-25 10:44:06 +05:00
def issueSSLForHostName ( virtualHost , path , skipLSCPDRestart = 0 ) :
2018-06-01 02:08:21 +05:00
try :
2017-12-09 22:30:10 +05:00
2019-04-15 15:54:23 +05:00
destPrivKey = " /usr/local/lscp/conf/key.pem "
destCert = " /usr/local/lscp/conf/cert.pem "
2019-10-27 18:08:10 +05:00
2019-10-21 22:27:39 -04:00
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 "
2017-12-14 06:56:27 -05:00
2018-11-10 16:05:40 +05:00
pathToStoreSSLFullChain = ' /etc/letsencrypt/live/ ' + virtualHost + ' /fullchain.pem '
pathToStoreSSLPrivKey = ' /etc/letsencrypt/live/ ' + virtualHost + ' /privkey.pem '
2019-11-18 11:51:31 +05:00
adminEmail = " email@ " + virtualHost
2020-11-12 15:23:01 +05:00
retValues = sslUtilities . issueSSLForDomain ( virtualHost , adminEmail , path )
if retValues [ 0 ] == 0 :
print ( " 0, " + str ( retValues [ 1 ] ) )
return 0 , retValues [ 1 ]
2019-11-18 11:51:31 +05:00
2021-12-28 19:17:25 +05:00
command = ' chmod 600 %s ' % ( destPrivKey )
ProcessUtilities . normalExecutioner ( command )
2018-06-01 02:08:21 +05:00
## removing old certs for lscpd
if os . path . exists ( destPrivKey ) :
os . remove ( destPrivKey )
if os . path . exists ( destCert ) :
os . remove ( destCert )
2019-10-27 18:08:10 +05:00
2019-10-21 22:27:39 -04:00
## removing self signed certs for lsws webadmin
if os . path . exists ( lswsAdminCert ) :
os . remove ( lswsAdminCert )
if os . path . exists ( lswsAdminPrivKey ) :
os . remove ( lswsAdminPrivKey )
2019-11-18 11:51:31 +05:00
2019-10-21 22:27:39 -04:00
## create symlink for hostname SSL for lsws webadmin SSL
2019-11-18 11:51:31 +05:00
command = ' ln -s %s /usr/local/lsws/admin/conf/cert/admin.crt ' % ( pathToStoreSSLFullChain )
2019-10-21 22:27:39 -04:00
ProcessUtilities . normalExecutioner ( command )
2019-11-18 11:51:31 +05:00
command = ' ln -s %s /usr/local/lsws/admin/conf/cert/admin.key ' % ( pathToStoreSSLPrivKey )
2019-10-21 22:27:39 -04:00
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 )
2019-11-18 11:51:31 +05:00
2019-10-21 22:27:39 -04:00
## create symlink for hostname SSL for lsws webadmin SSL
2019-11-18 11:51:31 +05:00
command = ' ln -s %s /usr/local/lsws/admin/conf/webadmin.crt ' % ( pathToStoreSSLFullChain )
2019-10-21 22:27:39 -04:00
ProcessUtilities . normalExecutioner ( command )
2019-11-18 11:51:31 +05:00
command = ' ln -s %s /usr/local/lsws/admin/conf/webadmin.key ' % ( pathToStoreSSLPrivKey )
2019-10-21 22:27:39 -04:00
ProcessUtilities . normalExecutioner ( command )
2018-02-05 01:22:37 +05:00
2019-11-18 11:51:31 +05:00
##
2017-12-14 06:56:27 -05:00
2019-11-18 11:51:31 +05:00
command = ' ln -s %s %s ' % ( pathToStoreSSLFullChain , destCert )
ProcessUtilities . executioner ( command )
2018-02-14 10:39:05 +05:00
2019-11-18 11:51:31 +05:00
command = ' ln -s %s %s ' % ( pathToStoreSSLPrivKey , destPrivKey )
ProcessUtilities . executioner ( command )
2018-02-14 10:39:05 +05:00
2024-01-25 10:44:06 +05:00
if skipLSCPDRestart :
pass
else :
command = ' systemctl restart lscpd '
cmd = shlex . split ( command )
subprocess . call ( cmd )
2017-12-14 06:56:27 -05:00
2019-12-10 15:09:10 +05:00
print ( " 1,None " )
2019-10-27 18:08:10 +05:00
return 1 , ' None '
2017-12-14 06:56:27 -05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg :
2018-08-23 15:39:28 +05:00
logging . CyberCPLogFileWriter . writeToFile ( str ( msg ) + " [issueSSLForHostName] " )
2019-12-10 15:09:10 +05:00
print ( " 0, " + str ( msg ) )
2018-06-05 00:53:45 +05:00
return 0 , str ( msg )
2017-12-14 06:56:27 -05:00
2018-06-01 02:08:21 +05:00
@staticmethod
def issueSSLForMailServer ( virtualHost , path ) :
try :
2017-12-14 06:56:27 -05:00
2018-08-22 00:37:43 +05:00
srcFullChain = ' /etc/letsencrypt/live/ ' + virtualHost + ' /fullchain.pem '
srcPrivKey = ' /etc/letsencrypt/live/ ' + virtualHost + ' /privkey.pem '
2017-12-14 06:56:27 -05:00
2020-11-12 15:23:01 +05:00
adminEmail = " email@ " + virtualHost
retValues = sslUtilities . issueSSLForDomain ( virtualHost , adminEmail , path )
2017-12-14 06:56:27 -05:00
2020-11-12 15:23:01 +05:00
if retValues [ 0 ] == 0 :
print ( " 0, " + str ( retValues [ 1 ] ) )
return 0 , retValues [ 1 ]
2017-12-14 06:56:27 -05:00
2018-06-01 02:08:21 +05:00
## MailServer specific functions
2017-12-14 06:56:27 -05:00
2018-06-01 02:08:21 +05:00
if os . path . exists ( " /etc/postfix/cert.pem " ) :
os . remove ( " /etc/postfix/cert.pem " )
2017-12-14 06:56:27 -05:00
2018-06-01 02:08:21 +05:00
if os . path . exists ( " /etc/postfix/key.pem " ) :
os . remove ( " /etc/postfix/key.pem " )
2017-12-14 06:56:27 -05:00
2018-06-01 02:08:21 +05:00
if os . path . exists ( " /etc/pki/dovecot/private/dovecot.pem " ) :
os . remove ( " /etc/pki/dovecot/private/dovecot.pem " )
2017-12-14 06:56:27 -05:00
2018-06-01 02:08:21 +05:00
if os . path . exists ( " /etc/pki/dovecot/certs/dovecot.pem " ) :
os . remove ( " /etc/pki/dovecot/certs/dovecot.pem " )
2017-12-14 06:56:27 -05:00
2018-06-01 02:08:21 +05:00
if os . path . exists ( " /etc/dovecot/key.pem " ) :
os . remove ( " /etc/dovecot/key.pem " )
2017-12-14 06:56:27 -05:00
2018-06-01 02:08:21 +05:00
if os . path . exists ( " /etc/dovecot/cert.pem " ) :
os . remove ( " /etc/dovecot/cert.pem " )
2017-12-14 06:56:27 -05:00
2018-06-01 02:08:21 +05:00
## Postfix
2017-12-14 06:56:27 -05:00
2019-11-18 14:27:49 +05:00
command = ' ln -s %s /etc/postfix/key.pem ' % ( srcPrivKey )
ProcessUtilities . executioner ( command )
command = ' ln -s %s /etc/postfix/cert.pem ' % ( srcFullChain )
ProcessUtilities . executioner ( command )
2017-12-14 06:56:27 -05:00
2018-06-01 02:08:21 +05:00
## Dovecot
2017-12-14 06:56:27 -05:00
2019-11-18 14:27:49 +05:00
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 )
2017-12-16 11:59:47 +05:00
2018-06-01 02:08:21 +05:00
## Dovecot 2ND
2017-12-14 06:56:27 -05:00
2019-11-18 14:27:49 +05:00
command = ' ln -s %s /etc/dovecot/key.pem ' % ( srcPrivKey )
ProcessUtilities . executioner ( command )
command = ' ln -s %s /etc/dovecot/cert.pem ' % ( srcFullChain )
ProcessUtilities . executioner ( command )
2017-12-14 06:56:27 -05:00
2018-06-01 02:08:21 +05:00
## Update postmaster address dovecot
2017-12-09 22:30:10 +05:00
2018-06-01 02:08:21 +05:00
filePath = " /etc/dovecot/dovecot.conf "
2017-12-09 22:30:10 +05:00
2018-06-01 02:08:21 +05:00
data = open ( filePath , ' r ' ) . readlines ( )
2017-12-09 22:30:10 +05:00
2018-06-01 02:08:21 +05:00
writeFile = open ( filePath , ' w ' )
2017-12-09 22:30:10 +05:00
2018-06-01 02:08:21 +05:00
for items in data :
if items . find ( ' postmaster_address ' ) > - 1 :
writeFile . writelines ( ' postmaster_address = postmaster@ ' + virtualHost + ' \n ' )
else :
writeFile . writelines ( items )
2017-12-09 22:30:10 +05:00
2018-06-01 02:08:21 +05:00
writeFile . close ( )
2017-12-09 22:30:10 +05:00
2018-06-01 02:08:21 +05:00
## Update myhostname address postfix
2017-12-09 22:30:10 +05:00
2018-06-01 02:08:21 +05:00
filePath = " /etc/postfix/main.cf "
2018-05-21 16:51:28 +05:00
2018-06-01 02:08:21 +05:00
data = open ( filePath , ' r ' ) . readlines ( )
2018-05-21 16:51:28 +05:00
2018-06-01 02:08:21 +05:00
writeFile = open ( filePath , ' w ' )
2018-05-21 16:51:28 +05:00
2018-06-01 02:08:21 +05:00
for items in data :
if items . find ( ' myhostname ' ) > - 1 :
writeFile . writelines ( ' myhostname = ' + virtualHost + ' \n ' )
else :
writeFile . writelines ( items )
2018-05-21 16:51:28 +05:00
2018-06-01 02:08:21 +05:00
writeFile . close ( )
2017-12-09 22:30:10 +05:00
2019-01-12 17:52:45 +05:00
p = Process ( target = mailUtilities . restartServices , args = ( ) )
2018-06-01 02:08:21 +05:00
p . start ( )
2017-12-09 22:30:10 +05:00
2019-12-10 15:09:10 +05:00
print ( " 1,None " )
2019-10-27 18:08:10 +05:00
return 1 , ' None '
2017-12-09 22:30:10 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg :
2018-06-01 02:08:21 +05:00
logging . CyberCPLogFileWriter . writeToFile (
str ( msg ) + " [issueSSLForHostName] " )
2019-12-10 15:09:10 +05:00
print ( " 0, " + str ( msg ) )
2019-10-27 18:08:10 +05:00
return 0 , str ( msg )
2018-04-26 17:59:47 +05:00
2018-06-01 02:08:21 +05:00
@staticmethod
def createAlias ( masterDomain , aliasDomain , ssl , sslPath , administratorEmail , owner = None ) :
try :
2018-04-26 17:59:47 +05:00
2018-08-23 15:39:28 +05:00
admin = Administrator . objects . get ( userName = owner )
DNS . dnsTemplate ( aliasDomain , admin )
2018-04-26 17:59:47 +05:00
2018-08-23 15:39:28 +05:00
if vhost . checkIfAliasExists ( aliasDomain ) == 1 :
2019-12-10 15:09:10 +05:00
print ( " 0, This domain already exists as vHost or Alias. " )
2018-06-01 02:08:21 +05:00
return
2018-05-21 16:51:28 +05:00
2018-11-10 16:05:40 +05:00
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
2018-08-23 15:39:28 +05:00
2018-11-10 16:05:40 +05:00
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 :
2019-12-10 15:09:10 +05:00
data = [ _f for _f in items . split ( " " ) if _f ]
2018-11-10 16:05:40 +05:00
if data [ 1 ] == masterDomain :
writeToFile . writelines ( items . rstrip ( ' \n ' ) + " , " + aliasDomain + " \n " )
listenerTrueCheck = 0
else :
writeToFile . writelines ( items )
2018-08-23 15:39:28 +05:00
2018-11-10 16:05:40 +05:00
writeToFile . close ( )
else :
completePathToConf = virtualHostUtilities . Server_root + ' /conf/vhosts/ ' + masterDomain + ' /vhost.conf '
data = open ( completePathToConf , ' r ' ) . readlines ( )
writeToFile = open ( completePathToConf , ' w ' )
2018-08-23 15:39:28 +05:00
2018-11-10 16:05:40 +05:00
for items in data :
if items . find ( ' ServerAlias ' ) > - 1 :
items = items . strip ( ' \n ' )
writeToFile . writelines ( items + " " + aliasDomain + " \n " )
else :
writeToFile . writelines ( items )
writeToFile . close ( )
2018-08-23 15:39:28 +05:00
installUtilities . installUtilities . reStartLiteSpeed ( )
2018-06-01 02:08:21 +05:00
if ssl == 1 :
retValues = sslUtilities . issueSSLForDomain ( masterDomain , administratorEmail , sslPath , aliasDomain )
2018-11-10 16:05:40 +05:00
if ProcessUtilities . decideServer ( ) == ProcessUtilities . OLS :
if retValues [ 0 ] == 0 :
2019-12-10 15:09:10 +05:00
print ( " 0, " + str ( retValues [ 1 ] ) )
2018-11-10 16:05:40 +05:00
return
else :
vhost . createAliasSSLMap ( confPath , masterDomain , aliasDomain )
2018-06-01 02:08:21 +05:00
else :
2018-11-10 16:05:40 +05:00
retValues = sslUtilities . issueSSLForDomain ( masterDomain , administratorEmail , sslPath , aliasDomain )
if retValues [ 0 ] == 0 :
2019-12-10 15:09:10 +05:00
print ( " 0, " + str ( retValues [ 1 ] ) )
2018-11-10 16:05:40 +05:00
return
2018-05-21 16:51:28 +05:00
2018-08-26 04:55:51 +05:00
website = Websites . objects . get ( domain = masterDomain )
2019-10-27 18:08:10 +05:00
newAlias = aliasDomains ( master = website , aliasDomain = aliasDomain )
2018-08-26 04:55:51 +05:00
newAlias . save ( )
2019-12-10 15:09:10 +05:00
print ( " 1,None " )
2018-04-26 17:59:47 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg :
2018-06-01 02:08:21 +05:00
logging . CyberCPLogFileWriter . writeToFile ( str ( msg ) + " [createAlias] " )
2019-12-10 15:09:10 +05:00
print ( " 0, " + str ( msg ) )
2018-04-26 17:59:47 +05:00
2018-06-01 02:08:21 +05:00
@staticmethod
def issueAliasSSL ( masterDomain , aliasDomain , sslPath , administratorEmail ) :
try :
2018-04-26 17:59:47 +05:00
2018-06-01 02:08:21 +05:00
retValues = sslUtilities . issueSSLForDomain ( masterDomain , administratorEmail , sslPath , aliasDomain )
2018-04-26 17:59:47 +05:00
2018-11-10 16:05:40 +05:00
if ProcessUtilities . decideServer ( ) == ProcessUtilities . OLS :
confPath = os . path . join ( virtualHostUtilities . Server_root , " conf/httpd_config.conf " )
if retValues [ 0 ] == 0 :
2019-12-10 15:09:10 +05:00
print ( " 0, " + str ( retValues [ 1 ] ) )
2018-11-10 16:05:40 +05:00
return
else :
vhost . createAliasSSLMap ( confPath , masterDomain , aliasDomain )
2018-06-01 02:08:21 +05:00
else :
2018-11-10 16:05:40 +05:00
if retValues [ 0 ] == 0 :
2019-12-10 15:09:10 +05:00
print ( " 0, " + str ( retValues [ 1 ] ) )
2018-11-10 16:05:40 +05:00
return
2018-04-26 17:59:47 +05:00
2019-12-10 15:09:10 +05:00
print ( " 1,None " )
2018-04-26 17:59:47 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg :
2018-04-26 17:59:47 +05:00
2018-06-01 02:08:21 +05:00
logging . CyberCPLogFileWriter . writeToFile ( str ( msg ) + " [issueAliasSSL] " )
2019-12-10 15:09:10 +05:00
print ( " 0, " + str ( msg ) )
2018-04-26 17:59:47 +05:00
2018-06-01 02:08:21 +05:00
@staticmethod
def deleteAlias ( masterDomain , aliasDomain ) :
2018-11-10 16:05:40 +05:00
if ProcessUtilities . decideServer ( ) == ProcessUtilities . OLS :
try :
2018-04-26 17:59:47 +05:00
2018-11-10 16:05:40 +05:00
confPath = os . path . join ( virtualHostUtilities . Server_root , " conf/httpd_config.conf " )
2018-04-26 17:59:47 +05:00
2018-11-10 16:05:40 +05:00
data = open ( confPath , ' r ' ) . readlines ( )
writeToFile = open ( confPath , ' w ' )
aliases = [ ]
for items in data :
if items . find ( masterDomain ) > - 1 and items . find ( ' map ' ) > - 1 :
2019-12-10 15:09:10 +05:00
data = [ _f for _f in items . split ( " " ) if _f ]
2018-11-10 16:05:40 +05:00
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 )
2018-04-26 17:59:47 +05:00
2018-06-01 02:08:21 +05:00
else :
writeToFile . writelines ( items )
2018-04-26 17:59:47 +05:00
2018-11-10 16:05:40 +05:00
writeToFile . close ( )
installUtilities . installUtilities . reStartLiteSpeed ( )
2018-04-26 17:59:47 +05:00
2018-11-10 16:05:40 +05:00
delAlias = aliasDomains . objects . get ( aliasDomain = aliasDomain )
delAlias . delete ( )
2018-04-26 17:59:47 +05:00
2019-12-10 15:09:10 +05:00
print ( " 1,None " )
except BaseException as msg :
2018-11-10 16:05:40 +05:00
logging . CyberCPLogFileWriter . writeToFile ( str ( msg ) + " [deleteAlias] " )
2019-12-10 15:09:10 +05:00
print ( " 0, " + str ( msg ) )
2018-11-10 16:05:40 +05:00
else :
try :
2018-08-26 04:55:51 +05:00
2018-11-10 16:05:40 +05:00
completePathToConf = virtualHostUtilities . Server_root + ' /conf/vhosts/ ' + masterDomain + ' /vhost.conf '
data = open ( completePathToConf , ' r ' ) . readlines ( )
2018-04-26 17:59:47 +05:00
2018-11-10 16:05:40 +05:00
writeToFile = open ( completePathToConf , ' w ' )
2018-04-26 17:59:47 +05:00
2018-11-10 16:05:40 +05:00
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 ( )
2019-12-10 15:09:10 +05:00
print ( " 1,None " )
except BaseException as msg :
2018-11-10 16:05:40 +05:00
logging . CyberCPLogFileWriter . writeToFile ( str ( msg ) + " [deleteAlias] " )
2019-12-10 15:09:10 +05:00
print ( " 0, " + str ( msg ) )
2018-04-26 17:59:47 +05:00
2018-06-01 02:08:21 +05:00
@staticmethod
def changeOpenBasedir ( domainName , openBasedirValue ) :
2018-11-10 16:05:40 +05:00
if ProcessUtilities . decideServer ( ) == ProcessUtilities . OLS :
try :
confPath = virtualHostUtilities . Server_root + " /conf/vhosts/ " + domainName
completePathToConfigFile = confPath + " /vhost.conf "
2018-04-26 17:59:47 +05:00
2018-11-10 16:05:40 +05:00
data = open ( completePathToConfigFile , ' r ' ) . readlines ( )
2018-04-26 17:59:47 +05:00
2018-11-10 16:05:40 +05:00
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 :
2018-07-05 15:22:48 +05:00
2018-11-10 16:05:40 +05:00
## Check if phpini already active
2018-04-26 17:59:47 +05:00
2018-11-10 16:05:40 +05:00
fileManagerCheck = 0
2018-04-26 17:59:47 +05:00
2018-11-10 16:05:40 +05:00
writeToFile = open ( completePathToConfigFile , ' w ' )
for items in data :
2018-07-05 15:22:48 +05:00
2018-11-10 16:05:40 +05:00
if items . find ( ' context /.filemanager ' ) > - 1 :
writeToFile . writelines ( items )
fileManagerCheck = 1
continue
2018-07-05 15:22:48 +05:00
2018-11-10 16:05:40 +05:00
if items . find ( ' phpIniOverride ' ) > - 1 :
writeToFile . writelines ( items )
if fileManagerCheck == 1 :
2019-10-27 18:08:10 +05:00
writeToFile . writelines (
' php_admin_value open_basedir " /tmp:/usr/local/lsws/Example/html/FileManager:$VH_ROOT " \n ' )
2018-11-10 16:05:40 +05:00
fileManagerCheck = 0
continue
else :
writeToFile . writelines ( ' php_admin_value open_basedir " /tmp:$VH_ROOT " \n ' )
continue
2018-07-05 15:22:48 +05:00
writeToFile . writelines ( items )
2018-04-26 17:59:47 +05:00
2018-11-10 16:05:40 +05:00
writeToFile . close ( )
2018-05-08 21:25:37 +05:00
2018-11-10 16:05:40 +05:00
installUtilities . installUtilities . reStartLiteSpeed ( )
2019-12-10 15:09:10 +05:00
print ( " 1,None " )
except BaseException as msg :
2018-11-10 16:05:40 +05:00
logging . CyberCPLogFileWriter . writeToFile ( str ( msg ) + " [changeOpenBasedir] " )
2019-12-10 15:09:10 +05:00
print ( " 0, " + str ( msg ) )
2018-11-10 16:05:40 +05:00
else :
try :
confPath = virtualHostUtilities . Server_root + " /conf/vhosts/ " + domainName
completePathToConfigFile = confPath + " /vhost.conf "
2018-05-08 21:25:37 +05:00
2018-11-10 16:05:40 +05:00
data = open ( completePathToConfigFile , ' r ' ) . readlines ( )
2018-05-08 21:25:37 +05:00
2018-11-10 16:05:40 +05:00
if openBasedirValue == ' Disable ' :
writeToFile = open ( completePathToConfigFile , ' w ' )
for items in data :
if items . find ( ' open_basedir ' ) > - 1 :
continue
writeToFile . writelines ( items )
writeToFile . close ( )
else :
2018-05-08 21:25:37 +05:00
2018-11-10 16:05:40 +05:00
## 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 ( )
2019-12-10 15:09:10 +05:00
print ( " 1,None " )
except BaseException as msg :
2018-11-10 16:05:40 +05:00
logging . CyberCPLogFileWriter . writeToFile ( str ( msg ) + " [changeOpenBasedir] " )
2019-12-10 15:09:10 +05:00
print ( " 0, " + str ( msg ) )
2018-05-08 21:25:37 +05:00
2018-06-01 02:08:21 +05:00
@staticmethod
2018-08-23 15:39:28 +05:00
def saveSSL ( virtualHost , keyPath , certPath ) :
2018-06-01 02:08:21 +05:00
try :
2018-05-08 21:25:37 +05:00
2018-08-22 00:37:43 +05:00
pathToStoreSSL = ' /etc/letsencrypt/live/ ' + virtualHost
2018-10-03 18:46:44 +05:00
command = ' mkdir -p ' + pathToStoreSSL
2019-03-26 16:19:03 +05:00
subprocess . call ( shlex . split ( command ) )
2018-05-08 21:25:37 +05:00
2018-06-01 02:08:21 +05:00
pathToStoreSSLPrivKey = pathToStoreSSL + " /privkey.pem "
pathToStoreSSLFullChain = pathToStoreSSL + " /fullchain.pem "
2018-05-08 21:25:37 +05:00
2018-06-01 02:08:21 +05:00
privkey = open ( pathToStoreSSLPrivKey , ' w ' )
privkey . write ( open ( keyPath , " r " ) . read ( ) )
privkey . close ( )
2018-05-08 21:25:37 +05:00
2018-06-01 02:08:21 +05:00
fullchain = open ( pathToStoreSSLFullChain , ' w ' )
fullchain . write ( open ( certPath , " r " ) . read ( ) )
fullchain . close ( )
2018-05-08 21:25:37 +05:00
2018-08-22 00:37:43 +05:00
os . remove ( keyPath )
os . remove ( certPath )
2018-08-23 15:39:28 +05:00
sslUtilities . sslUtilities . installSSLForDomain ( virtualHost )
2018-05-08 21:25:37 +05:00
2018-06-01 02:08:21 +05:00
installUtilities . installUtilities . reStartLiteSpeed ( )
2018-05-08 21:25:37 +05:00
2018-06-01 02:08:21 +05:00
FNULL = open ( os . devnull , ' w ' )
2018-05-08 21:25:37 +05:00
2018-06-01 02:08:21 +05:00
command = " chown " + " lsadm " + " : " + " lsadm " + " " + pathToStoreSSL
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
subprocess . call ( cmd , stdout = FNULL , stderr = subprocess . STDOUT )
2018-05-08 21:25:37 +05:00
2021-09-13 14:55:25 +05:00
command = ' chmod 600 %s ' % ( pathToStoreSSLPrivKey )
ProcessUtilities . normalExecutioner ( command )
2019-12-10 15:09:10 +05:00
print ( " 1,None " )
2018-05-08 21:25:37 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg :
2018-06-01 02:08:21 +05:00
logging . CyberCPLogFileWriter . writeToFile (
str ( msg ) + " [saveSSL] " )
2019-12-10 15:09:10 +05:00
print ( " 0, " + str ( msg ) )
2018-05-08 21:25:37 +05:00
2018-06-01 02:08:21 +05:00
@staticmethod
2019-10-27 18:08:10 +05:00
def createDomain ( masterDomain , virtualHostName , phpVersion , path , ssl , dkimCheck , openBasedir , owner , apache ,
2024-02-09 17:58:28 +05:00
tempStatusPath = ' /home/cyberpanel/fakePath ' , LimitsCheck = 1 , alias = 0 ) :
2018-06-01 02:08:21 +05:00
try :
2018-08-22 00:37:43 +05:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' Running some checks..,0 ' )
2018-05-08 21:25:37 +05:00
2018-06-01 02:08:21 +05:00
## Check if this domain either exists as website or child domain
2018-05-08 21:25:37 +05:00
2018-08-22 00:37:43 +05:00
admin = Administrator . objects . get ( userName = owner )
2021-04-02 01:14:30 +05:00
master = Websites . objects . get ( domain = masterDomain )
2018-08-22 00:37:43 +05:00
2021-04-02 01:14:30 +05:00
if LimitsCheck :
DNS . dnsTemplate ( virtualHostName , admin )
2018-05-08 21:25:37 +05:00
2021-04-02 01:14:30 +05:00
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. "
2019-11-11 20:04:17 +05:00
2021-04-02 01:14:30 +05:00
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. "
2019-11-11 20:04:17 +05:00
2021-04-02 01:14:30 +05:00
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. "
2019-11-11 20:04:17 +05:00
2021-04-02 01:14:30 +05:00
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. "
2018-05-08 21:25:37 +05:00
2021-04-02 01:14:30 +05:00
####### Limitations check
domainsInPackage = master . package . allowedDomains
2018-05-08 21:25:37 +05:00
2021-04-02 01:14:30 +05:00
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 ( ) :
2019-08-03 14:53:31 +05:00
pass
else :
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,
2021-04-02 01:14:30 +05:00
' Exceeded maximum number of domains for this package. [404] ' )
return 0 , " Exceeded maximum number of domains for this package "
2019-08-03 14:53:31 +05:00
2021-04-02 01:14:30 +05:00
####### Limitations Check End
2018-07-13 04:26:40 +05:00
2021-04-02 01:14:30 +05:00
if vhost . checkIfVirtualHostExists ( virtualHostName ) == 1 :
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath ,
' Virtual Host Directory already exists. [404] ' )
return 0 , " Virtual Host Directory already exists! "
2018-05-21 21:52:35 +05:00
2021-04-02 01:14:30 +05:00
if vhost . checkIfAliasExists ( virtualHostName ) == 1 :
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' This domain exists as Alias. [404] ' )
return 0 , " This domain exists as Alias. "
2018-05-21 21:52:35 +05:00
2018-08-22 00:37:43 +05:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' DKIM Setup..,30 ' )
2018-07-30 17:33:28 +05:00
2021-04-02 12:45:42 +05:00
postFixPath = ' /home/cyberpanel/postfix '
if os . path . exists ( postFixPath ) :
retValues = mailUtilities . setupDKIM ( virtualHostName )
if retValues [ 0 ] == 0 :
raise BaseException ( retValues [ 1 ] )
2018-05-21 21:52:35 +05:00
2018-06-01 02:08:21 +05:00
FNULL = open ( os . devnull , ' w ' )
2018-05-21 21:52:35 +05:00
2018-08-22 00:37:43 +05:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' Creating configurations..,50 ' )
2018-07-30 17:33:28 +05:00
2018-06-01 02:08:21 +05:00
retValues = vhost . createDirectoryForDomain ( masterDomain , virtualHostName , phpVersion , path ,
2019-10-27 18:08:10 +05:00
master . adminEmail , master . externalApp , openBasedir )
2018-06-01 02:08:21 +05:00
if retValues [ 0 ] == 0 :
raise BaseException ( retValues [ 1 ] )
2021-04-02 12:45:42 +05:00
2020-01-11 19:27:49 +05:00
if not os . path . exists ( virtualHostUtilities . redisConf ) :
retValues = vhost . createConfigInMainDomainHostFile ( virtualHostName , masterDomain )
2018-05-21 21:52:35 +05:00
2021-04-02 12:45:42 +05:00
if retValues [ 0 ] == 0 :
raise BaseException ( retValues [ 1 ] )
2018-05-21 21:52:35 +05:00
2018-06-01 02:08:21 +05:00
## Now restart litespeed after initial configurations are done
2018-05-21 21:52:35 +05:00
2021-04-02 01:14:30 +05:00
if LimitsCheck :
2024-01-18 13:04:47 +05:00
website = ChildDomains ( master = master , domain = virtualHostName , path = path , phpSelection = phpVersion ,
2024-02-09 17:58:28 +05:00
ssl = ssl , alais = alias )
2021-04-02 01:14:30 +05:00
website . save ( )
2018-11-10 02:37:45 +05:00
2018-06-01 02:08:21 +05:00
if ssl == 1 :
2018-08-22 00:37:43 +05:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' Creating SSL..,50 ' )
2020-01-11 19:27:49 +05:00
if not os . path . exists ( virtualHostUtilities . redisConf ) :
installUtilities . installUtilities . reStartLiteSpeed ( )
2018-06-01 02:08:21 +05:00
retValues = sslUtilities . issueSSLForDomain ( virtualHostName , master . adminEmail , path )
2020-01-11 19:27:49 +05:00
if not os . path . exists ( virtualHostUtilities . redisConf ) :
installUtilities . installUtilities . reStartLiteSpeed ( )
2018-06-01 02:08:21 +05:00
if retValues [ 0 ] == 0 :
raise BaseException ( retValues [ 1 ] )
2017-12-09 22:30:10 +05:00
2018-06-01 02:08:21 +05:00
## Final Restart
if ssl == 0 :
2020-01-11 19:27:49 +05:00
if not os . path . exists ( virtualHostUtilities . redisConf ) :
installUtilities . installUtilities . reStartLiteSpeed ( )
2017-12-09 22:30:10 +05:00
2018-06-01 02:08:21 +05:00
vhost . finalizeDomainCreation ( master . externalApp , path )
2017-12-09 22:30:10 +05:00
2019-06-08 21:41:43 +00:00
## 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 ,
2019-10-27 18:08:10 +05:00
master . externalApp , phpVersion , virtualHostName , path )
2019-06-08 21:41:43 +00:00
if result [ 0 ] == 0 :
raise BaseException ( result [ 1 ] )
else :
ApacheVhost . perHostVirtualConfOLS ( completePathToConfigFile , master . adminEmail )
installUtilities . installUtilities . reStartLiteSpeed ( )
php = PHPManager . getPHPString ( phpVersion )
2023-05-15 21:16:10 +05:00
2023-05-17 16:05:58 +05:00
phpService = ApacheVhost . DecideFPMServiceName ( phpVersion )
2023-05-15 21:16:10 +05:00
command = f " systemctl restart { phpService } "
2019-06-08 21:41:43 +00:00
ProcessUtilities . normalExecutioner ( command )
2018-06-01 02:08:21 +05:00
## DKIM Check
2017-12-09 22:30:10 +05:00
2019-07-16 23:23:16 +05:00
postFixPath = ' /home/cyberpanel/postfix '
if os . path . exists ( postFixPath ) :
if dkimCheck == 1 :
DNS . createDKIMRecords ( virtualHostName )
2017-12-09 22:30:10 +05:00
2018-08-22 00:37:43 +05:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' Domain successfully created. [200] ' )
2018-06-01 02:08:21 +05:00
return 1 , " None "
2017-12-09 22:30:10 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg :
2021-04-02 12:45:42 +05:00
if ACLManager . FindIfChild ( ) == 0 :
numberOfWebsites = Websites . objects . count ( ) + ChildDomains . objects . count ( )
vhost . deleteCoreConf ( virtualHostName , numberOfWebsites )
2018-08-22 00:37:43 +05:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , str ( msg ) + " . [404] " )
2018-06-01 02:08:21 +05:00
logging . CyberCPLogFileWriter . writeToFile (
str ( msg ) + " [createDomain] " )
return 0 , str ( msg )
2017-12-09 22:30:10 +05:00
2018-06-01 02:08:21 +05:00
@staticmethod
2021-03-11 13:41:47 +05:00
def deleteDomain ( virtualHostName , DeleteDocRoot = 0 ) :
2018-06-01 02:08:21 +05:00
try :
2017-12-09 22:30:10 +05:00
2018-06-01 02:08:21 +05:00
numberOfWebsites = Websites . objects . count ( ) + ChildDomains . objects . count ( )
vhost . deleteCoreConf ( virtualHostName , numberOfWebsites )
delWebsite = ChildDomains . objects . get ( domain = virtualHostName )
2021-03-11 13:41:47 +05:00
if DeleteDocRoot :
command = ' rm -rf %s ' % ( delWebsite . path )
ProcessUtilities . executioner ( command )
2018-06-01 02:08:21 +05:00
delWebsite . delete ( )
installUtilities . installUtilities . reStartLiteSpeed ( )
2017-12-09 22:30:10 +05:00
2019-12-10 15:09:10 +05:00
print ( " 1,None " )
2019-10-27 18:08:10 +05:00
return 1 , ' None '
2017-12-09 22:30:10 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg :
2018-06-01 02:08:21 +05:00
logging . CyberCPLogFileWriter . writeToFile (
str ( msg ) + " [deleteDomain] " )
2019-12-10 15:09:10 +05:00
print ( " 0, " + str ( msg ) )
2019-10-27 18:08:10 +05:00
return 0 , str ( msg )
2018-06-05 00:53:45 +05:00
2019-06-08 21:41:43 +00:00
@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 :
2019-10-27 18:08:10 +05:00
ApacheVhost . setupApacheVhostChild ( website . master . adminEmail , website . master . externalApp ,
website . master . externalApp ,
2019-06-08 21:41:43 +00:00
phpVersion , virtualHostName , website . path )
else :
2019-10-27 18:08:10 +05:00
ApacheVhost . setupApacheVhost ( website . adminEmail , website . externalApp , website . externalApp ,
phpVersion , virtualHostName )
2019-06-08 21:41:43 +00:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' Restarting servers and phps..,90 ' )
php = PHPManager . getPHPString ( phpVersion )
2023-05-15 21:16:10 +05:00
##
2023-05-17 16:05:58 +05:00
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"
2023-05-15 21:16:10 +05:00
command = f " systemctl stop { phpService } "
ProcessUtilities . normalExecutioner ( command )
command = f " systemctl restart { phpService } "
2019-06-08 21:41:43 +00:00
ProcessUtilities . normalExecutioner ( command )
2023-05-15 21:16:10 +05:00
command = f " systemctl restart { ApacheVhost . serviceName } "
ProcessUtilities . normalExecutioner ( command )
###
2019-06-08 21:41:43 +00:00
installUtilities . installUtilities . reStartLiteSpeed ( )
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' Successfully converted.[200] ' )
else :
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' Starting Conversion..,0 ' )
ApacheVhost . DeleteApacheVhost ( virtualHostName )
if child :
2019-10-27 18:08:10 +05:00
vhost . perHostDomainConf ( website . path , website . master . domain , virtualHostName ,
completePathToConfigFile ,
2019-06-08 21:41:43 +00:00
website . master . adminEmail , phpVersion , website . master . externalApp , 0 )
else :
2019-10-27 18:08:10 +05:00
vhost . perHostVirtualConf ( completePathToConfigFile , website . adminEmail , website . externalApp ,
phpVersion , virtualHostName , 0 )
2019-06-08 21:41:43 +00:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' Restarting server..,90 ' )
installUtilities . installUtilities . reStartLiteSpeed ( )
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' Successfully converted. [200] ' )
2019-12-10 15:09:10 +05:00
except BaseException as msg :
2019-06-08 21:41:43 +00:00
logging . CyberCPLogFileWriter . statusWriter ( tempStatusPath , ' %s [404] ' % str ( msg ) )
logging . CyberCPLogFileWriter . writeToFile ( str ( msg ) + " [switchServer] " )
2018-06-05 00:53:45 +05:00
@staticmethod
def getDiskUsage ( path , totalAllowed ) :
try :
2024-01-18 13:04:47 +05:00
totalUsageInMB = \
subprocess . check_output ( ' du -hs %s --block-size=1M ' % ( path ) , shell = True ) . decode ( " utf-8 " ) . split ( ) [ 0 ]
2018-06-05 00:53:45 +05:00
percentage = float ( 100 ) / float ( totalAllowed )
percentage = float ( percentage ) * float ( totalUsageInMB )
data = [ int ( totalUsageInMB ) , int ( percentage ) ]
return data
2019-04-15 15:54:23 +05:00
except BaseException :
2019-04-22 03:38:40 +05:00
try :
return [ int ( totalUsageInMB ) , int ( 0 ) ]
except :
return [ int ( 0 ) , int ( 0 ) ]
2017-12-09 22:30:10 +05:00
2022-05-22 13:01:04 +05:00
@staticmethod
def getDiskUsageofPath ( path ) :
try :
2024-01-18 13:04:47 +05:00
return subprocess . check_output ( ' du -hs %s --block-size=1M ' % ( path ) , shell = True ) . decode ( " utf-8 " ) . split ( ) [ 0 ]
2022-05-22 13:01:04 +05:00
except BaseException :
return ' 0MB '
2018-06-25 17:53:11 +05:00
@staticmethod
def permissionControl ( path ) :
try :
command = ' sudo chown -R cyberpanel:cyberpanel ' + path
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2018-06-25 17:53:11 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg :
2018-06-25 17:53:11 +05:00
logging . CyberCPLogFileWriter . writeToFile ( str ( msg ) )
@staticmethod
def leaveControl ( path ) :
try :
command = ' sudo chown -R root:root ' + path
cmd = shlex . split ( command )
2019-03-26 16:19:03 +05:00
res = subprocess . call ( cmd )
2018-06-25 17:53:11 +05:00
2019-12-10 15:09:10 +05:00
except BaseException as msg :
2018-06-25 17:53:11 +05:00
logging . CyberCPLogFileWriter . writeToFile ( str ( msg ) )
2021-01-18 14:01:26 +05:00
@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
2022-06-16 00:06:31 +05:00
@staticmethod
2024-01-18 13:04:47 +05:00
def EnableDisablePP ( vhostName , username = None , password = None , path = None , wpid = None , externalApp = None ) :
2022-06-16 00:06:31 +05:00
try :
2022-06-17 20:01:57 +05:00
vhostPassDir = f ' /home/ { vhostName } '
uBuntuPath = ' /etc/lsb-release '
if os . path . exists ( uBuntuPath ) :
group = ' nogroup '
else :
group = ' nobody '
2022-06-16 00:06:31 +05:00
confPath = f ' { virtualHostUtilities . vhostConfPath } /vhosts/ { vhostName } /vhost.conf '
2022-06-17 20:01:57 +05:00
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 )
2022-06-16 14:36:25 +05:00
FindLine = f ' PASSWORD PROTECTION CONF STARTS { path } '
FindLineEnd = f ' PASSWORD PROTECTION CONF ENDS { path } '
2022-06-16 00:06:31 +05:00
if ProcessUtilities . decideServer ( ) == ProcessUtilities . OLS :
if os . path . exists ( htpassword ) :
2022-06-17 20:01:57 +05:00
command = f ' rm -f { htpassword } '
ProcessUtilities . executioner ( command , externalApp )
2024-01-18 13:04:47 +05:00
# os.remove(htpassword)
2022-06-16 00:06:31 +05:00
removeCheck = 0
data = open ( confPath , ' r ' ) . readlines ( )
writeToFile = open ( confPath , ' w ' )
for line in data :
2022-06-16 14:36:25 +05:00
if line . find ( FindLine ) > - 1 :
2022-06-16 00:06:31 +05:00
removeCheck = 1
continue
2022-06-16 14:36:25 +05:00
if line . find ( FindLineEnd ) > - 1 :
2022-06-16 00:06:31 +05:00
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 )
2022-06-16 14:36:25 +05:00
OLSPPConf = OLSPPConf . replace ( ' {{ wpid}} ' , wpid )
2022-06-17 20:01:57 +05:00
OLSPPConf = OLSPPConf . replace ( ' {{ PassFile}} ' , htpassword )
2022-06-16 00:06:31 +05:00
writeToFile . write ( OLSPPConf )
writeToFile . close ( )
###
import bcrypt
password = password . encode ( )
hashed = bcrypt . hashpw ( password , bcrypt . gensalt ( ) )
2022-06-16 14:36:25 +05:00
UserPass = f ' { username } : { hashed . decode ( ) } : { username } '
2022-06-17 20:01:57 +05:00
writeToFile = open ( htpasstemp , ' w ' )
2022-06-16 00:06:31 +05:00
writeToFile . write ( UserPass )
writeToFile . close ( )
2022-06-17 20:01:57 +05:00
command = f ' cp { htpasstemp } { htpassword } '
ProcessUtilities . executioner ( command , externalApp )
2022-06-16 00:06:31 +05:00
2022-06-17 20:01:57 +05:00
os . remove ( htpasstemp )
2022-06-16 00:06:31 +05:00
2022-06-17 20:01:57 +05:00
command = f ' chmod 640 { htpassword } '
ProcessUtilities . executioner ( command , externalApp , True )
2022-06-16 00:06:31 +05:00
2022-06-17 20:01:57 +05:00
command = f ' sudo -u { externalApp } -g { group } chown { externalApp } : { group } { htpassword } '
2022-06-16 00:06:31 +05:00
ProcessUtilities . executioner ( command )
2022-06-16 14:36:25 +05:00
else :
RealmName = str ( randint ( 1000 , 9999 ) )
htaccesspath = f ' { path } /.htaccess '
if os . path . exists ( htpassword ) :
2022-06-17 20:01:57 +05:00
command = f ' rm -f { htpassword } '
ProcessUtilities . executioner ( command , externalApp )
2024-01-18 13:04:47 +05:00
# os.remove(htpassword)
2022-06-16 14:36:25 +05:00
removeCheck = 0
2022-06-16 00:06:31 +05:00
2022-06-16 14:36:25 +05:00
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
2022-06-16 00:06:31 +05:00
2022-06-16 14:36:25 +05:00
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 } '
2022-06-17 20:01:57 +05:00
writeToFile = open ( htpasstemp , ' w ' )
2022-06-16 14:36:25 +05:00
writeToFile . write ( UserPass )
writeToFile . close ( )
2022-06-17 20:01:57 +05:00
command = f ' cp { htpasstemp } { htpassword } '
ProcessUtilities . executioner ( command , externalApp )
2022-06-16 14:36:25 +05:00
2022-06-17 20:01:57 +05:00
os . remove ( htpasstemp )
command = f ' chmod 640 { htpassword } '
ProcessUtilities . executioner ( command , externalApp , True )
2022-06-16 14:36:25 +05:00
2022-06-17 20:01:57 +05:00
command = f ' sudo -u { externalApp } -g { group } chown { externalApp } : { group } { htpassword } '
2022-06-16 14:36:25 +05:00
ProcessUtilities . executioner ( command )
installUtilities . installUtilities . reStartLiteSpeed ( )
print ( ' 1,None ' )
2022-06-16 00:06:31 +05:00
except BaseException as msg :
print ( f ' 0, { str ( msg ) } ' )
2024-01-18 13:04:47 +05:00
return 0 , str ( msg )
2022-06-16 00:06:31 +05:00
2017-12-09 22:30:10 +05:00
2019-10-27 18:08:10 +05:00
def main ( ) :
2017-12-09 22:30:10 +05:00
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! " )
2018-05-01 00:49:47 +05:00
parser . add_argument ( ' --dkimCheck ' , help = ' To enable or disable DKIM support for domain. ' )
2018-05-21 21:52:35 +05:00
parser . add_argument ( ' --openBasedir ' , help = ' To enable or disable open_basedir protection for domain. ' )
2018-06-01 02:08:21 +05:00
parser . add_argument ( ' --websiteOwner ' , help = ' Website Owner Name ' )
parser . add_argument ( ' --package ' , help = ' Website package ' )
parser . add_argument ( ' --restore ' , help = ' Restore Check. ' )
2019-06-08 21:41:43 +00:00
parser . add_argument ( ' --apache ' , help = ' Enable/Disable Apache as backend ' )
2017-12-09 22:30:10 +05:00
## 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! ' )
2017-12-14 06:56:27 -05:00
## 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! ' )
2017-12-09 22:30:10 +05:00
2018-05-08 21:25:37 +05:00
## Arguments for alias domain
parser . add_argument ( ' --aliasDomain ' , help = ' Alias Domain! ' )
2018-05-21 21:52:35 +05:00
## Arguments for OpenBasedir
parser . add_argument ( ' --openBasedirValue ' , help = ' open_base dir protection value! ' )
2018-07-13 21:45:40 +05:00
parser . add_argument ( ' --tempStatusPath ' , help = ' Temporary Status file path. ' )
2020-02-18 20:15:07 +05:00
parser . add_argument ( ' --mailDomain ' , help = ' To create or not to create mail domain. ' )
2018-07-13 21:45:40 +05:00
2019-06-08 21:41:43 +00:00
## Switch Server
parser . add_argument ( ' --server ' , help = ' Switch server parameter. ' )
2022-06-16 14:36:25 +05:00
parser . add_argument ( ' --wpid ' , help = ' WordPress ID ' )
2019-06-08 21:41:43 +00:00
2021-03-11 13:41:47 +05:00
## Doc root deletion for child domain
parser . add_argument ( ' --DeleteDocRoot ' , help = ' Doc root deletion for child domain. ' )
2024-01-25 10:44:06 +05:00
### for onboarding
parser . add_argument ( ' --rdns ' , help = ' Doc root deletion for child domain. ' )
2017-12-09 22:30:10 +05:00
args = parser . parse_args ( )
if args . function == " createVirtualHost " :
2018-05-01 00:49:47 +05:00
try :
dkimCheck = int ( args . dkimCheck )
except :
dkimCheck = 0
2018-05-21 21:52:35 +05:00
try :
openBasedir = int ( args . openBasedir )
except :
openBasedir = 0
2019-06-08 21:41:43 +00:00
try :
apache = int ( args . apache )
except :
apache = 0
2018-07-30 17:33:28 +05:00
try :
tempStatusPath = args . tempStatusPath
except :
tempStatusPath = ' /home/cyberpanel/fakePath '
2019-10-27 18:08:10 +05:00
virtualHostUtilities . createVirtualHost ( args . virtualHostName , args . administratorEmail , args . phpVersion ,
args . virtualHostUser , int ( args . ssl ) , dkimCheck , openBasedir ,
2024-01-18 13:04:47 +05:00
args . websiteOwner , args . package , apache , tempStatusPath ,
int ( args . mailDomain ) )
2020-05-10 03:15:33 +05:00
elif args . function == " setupAutoDiscover " :
admin = Administrator . objects . get ( userName = args . websiteOwner )
virtualHostUtilities . setupAutoDiscover ( 1 , ' /home/cyberpanel/templogs ' , args . virtualHostName , admin )
2017-12-09 22:30:10 +05:00
elif args . function == " deleteVirtualHostConfigurations " :
2018-08-26 04:55:51 +05:00
vhost . deleteVirtualHostConfigurations ( args . virtualHostName )
2017-12-09 22:30:10 +05:00
elif args . function == " createDomain " :
2018-05-03 01:22:28 +05:00
try :
dkimCheck = int ( args . dkimCheck )
except :
dkimCheck = 0
2018-05-21 21:52:35 +05:00
try :
openBasedir = int ( args . openBasedir )
except :
openBasedir = 0
2019-06-08 21:41:43 +00:00
try :
apache = int ( args . apache )
except :
apache = 0
2018-07-30 17:33:28 +05:00
try :
tempStatusPath = args . tempStatusPath
except :
tempStatusPath = ' /home/cyberpanel/fakePath '
2024-02-09 17:58:28 +05:00
try :
aliasDomain = int ( args . aliasDomain )
except :
aliasDomain = 0
2019-10-27 18:08:10 +05:00
virtualHostUtilities . createDomain ( args . masterDomain , args . virtualHostName , args . phpVersion , args . path ,
int ( args . ssl ) , dkimCheck , openBasedir , args . websiteOwner , apache ,
2024-02-09 17:58:28 +05:00
tempStatusPath , 1 , aliasDomain )
2017-12-09 22:30:10 +05:00
elif args . function == " issueSSL " :
2019-10-27 18:08:10 +05:00
virtualHostUtilities . issueSSL ( args . virtualHostName , args . path , args . administratorEmail )
2023-04-01 05:39:18 +05:00
elif args . function == " issueSSLv2 " :
virtualHostUtilities . issueSSLv2 ( args . virtualHostName , args . path , args . administratorEmail )
2017-12-09 22:30:10 +05:00
elif args . function == " changePHP " :
2019-10-27 18:08:10 +05:00
vhost . changePHP ( args . path , args . phpVersion )
2017-12-09 22:30:10 +05:00
elif args . function == " getAccessLogs " :
2019-10-27 18:08:10 +05:00
virtualHostUtilities . getAccessLogs ( args . path , int ( args . page ) )
2017-12-09 22:30:10 +05:00
elif args . function == " getErrorLogs " :
2019-10-27 18:08:10 +05:00
virtualHostUtilities . getErrorLogs ( args . path , int ( args . page ) )
2017-12-09 22:30:10 +05:00
elif args . function == " saveVHostConfigs " :
2019-10-27 18:08:10 +05:00
virtualHostUtilities . saveVHostConfigs ( args . path , args . tempPath )
2023-05-15 21:16:10 +05:00
elif args . function == " saveApacheConfigsToFile " :
virtualHostUtilities . saveApacheConfigsToFile ( args . path , args . tempPath )
2017-12-09 22:30:10 +05:00
elif args . function == " saveRewriteRules " :
2019-10-27 18:08:10 +05:00
virtualHostUtilities . saveRewriteRules ( args . virtualHostName , args . path , args . tempPath )
2017-12-09 22:30:10 +05:00
elif args . function == " saveSSL " :
2019-10-27 18:08:10 +05:00
virtualHostUtilities . saveSSL ( args . virtualHostName , args . tempKeyPath , args . tempCertPath )
2017-12-09 22:30:10 +05:00
elif args . function == " installWordPress " :
2019-10-27 18:08:10 +05:00
virtualHostUtilities . installWordPress ( args . virtualHostName , args . path , args . virtualHostUser , args . dbName ,
args . dbUser , args . dbPassword )
2017-12-14 06:56:27 -05:00
elif args . function == " installJoomla " :
2019-10-27 18:08:10 +05:00
virtualHostUtilities . installJoomla ( args . virtualHostName , args . path , args . virtualHostUser , args . dbName ,
args . dbUser , args . dbPassword , args . username , args . password , args . prefix ,
args . sitename , args . tempStatusPath )
2017-12-09 22:30:10 +05:00
elif args . function == " issueSSLForHostName " :
2019-10-27 18:08:10 +05:00
virtualHostUtilities . issueSSLForHostName ( args . virtualHostName , args . path )
2018-04-26 17:59:47 +05:00
elif args . function == " issueSSLForMailServer " :
2019-10-27 18:08:10 +05:00
virtualHostUtilities . issueSSLForMailServer ( args . virtualHostName , args . path )
2017-12-09 22:30:10 +05:00
elif args . function == " findDomainBW " :
2018-06-01 02:08:21 +05:00
vhost . findDomainBW ( args . virtualHostName , int ( args . bandwidth ) )
2018-05-08 21:25:37 +05:00
elif args . function == ' createAlias ' :
2019-10-27 18:08:10 +05:00
virtualHostUtilities . createAlias ( args . masterDomain , args . aliasDomain , int ( args . ssl ) , args . sslPath ,
args . administratorEmail , args . websiteOwner )
2018-05-08 21:25:37 +05:00
elif args . function == ' issueAliasSSL ' :
2018-06-01 02:08:21 +05:00
virtualHostUtilities . issueAliasSSL ( args . masterDomain , args . aliasDomain , args . sslPath , args . administratorEmail )
2018-05-08 21:25:37 +05:00
elif args . function == ' deleteAlias ' :
2018-06-01 02:08:21 +05:00
virtualHostUtilities . deleteAlias ( args . masterDomain , args . aliasDomain )
2018-05-21 21:52:35 +05:00
elif args . function == ' changeOpenBasedir ' :
2018-06-01 02:08:21 +05:00
virtualHostUtilities . changeOpenBasedir ( args . virtualHostName , args . openBasedirValue )
elif args . function == ' deleteDomain ' :
2021-03-11 13:41:47 +05:00
virtualHostUtilities . deleteDomain ( args . virtualHostName , int ( args . DeleteDocRoot ) )
2019-06-08 21:41:43 +00:00
elif args . function == ' switchServer ' :
virtualHostUtilities . switchServer ( args . virtualHostName , args . phpVersion , int ( args . server ) , args . tempStatusPath )
2022-06-16 00:06:31 +05:00
elif args . function == ' EnableDisablePP ' :
2024-01-18 13:04:47 +05:00
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
2024-01-25 10:44:06 +05:00
virtualHostUtilities . OnBoardingHostName ( args . virtualHostName , args . path , int ( args . rdns ) )
2017-12-09 22:30:10 +05:00
2019-10-27 18:08:10 +05:00
2017-12-09 22:30:10 +05:00
if __name__ == " __main__ " :
2018-10-12 18:18:10 +05:00
main ( )