Skip to content

Commit f28402c

Browse files
committed
bug fix: alias domains, php fetch and domain with sudo
1 parent 24b10a3 commit f28402c

12 files changed

Lines changed: 954 additions & 146 deletions

File tree

CLScript/CloudLinuxDomains.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def listAll(self):
5151
parser = argparse.ArgumentParser(description='CyberPanel CloudLinux Manager')
5252
parser.add_argument('-o', '--owner', help='Owner')
5353
parser.add_argument('-n', '--name', help='Owner')
54+
parser.add_argument('-p', '--with-php', help='False (X-Ray support only)')
5455

5556
args = parser.parse_args()
5657

plogical/IncScheduler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,6 @@ def startNormalBackups(type):
533533
if result.find(pid) > -1 and result.find('IncScheduler.py') > -1:
534534
quit(1)
535535

536-
537536
except:
538537
### Save some important info in backup config
539538
oldJobContinue = 0

plogical/childDomain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ def __init__(self, masterDomain = None, childDomain = None):
1515
self.masterDomain = masterDomain
1616
self.childDomain = childDomain
1717

18-
def findChildDomainsJson(self):
18+
def findChildDomainsJson(self, alias=0):
1919
master = Websites.objects.get(domain=self.masterDomain)
20-
childDomains = master.childdomains_set.all()
20+
childDomains = master.childdomains_set.filter(alais=alias)
2121

2222
json_data = "["
2323
checker = 0

plogical/phpUtilities.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def WrapGetPHPVersionFromFileToGetVersionWithPHP(vhFile):
266266
if os.path.exists(ProcessUtilities.debugPath):
267267
logging.CyberCPLogFileWriter.writeToFile(result)
268268

269-
command = result + " -v | awk '/^PHP/ {print $2}'"
269+
command = result + " -v 2>/dev/null | awk '/^PHP/ {print $2}'"
270270
php_version = ProcessUtilities.outputExecutioner(command, None, True).rstrip('\n')
271271
return f"PHP {php_version}"
272272

@@ -291,8 +291,6 @@ def FindIfSaidPHPIsAvaiableOtherwiseMaketheNextOneAvailableToUse(vhFile, phpVers
291291
return PHPManager.findPHPVersions()[-2]
292292

293293

294-
295-
296294
@staticmethod
297295
def InstallSaidPHP(php):
298296
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu or ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu20:
@@ -305,10 +303,6 @@ def InstallSaidPHP(php):
305303

306304

307305

308-
309-
310-
311-
312306
def main():
313307

314308
parser = argparse.ArgumentParser(description='CyberPanel Installer')

plogical/processUtilities.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,9 @@ def sendCommand(command, user=None, dir=None):
245245
command = '%s-u %s %s' % (ProcessUtilities.token, user, command)
246246
else:
247247
command = '%s-u %s -d %s %s' % (ProcessUtilities.token, user, dir, command)
248-
command = command.replace('sudo', '')
249248

249+
if command.startswith('sudo'):
250+
command = command.replace('sudo', '', 1) # Replace 'sudo' with an empty string, only once
250251

251252
if os.path.exists(ProcessUtilities.debugPath):
252253
if command.find('cat') == -1:

plogical/sslUtilities.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def getDomainsCovered(cert_path):
3737
if san_extension:
3838
# Extract and print the domains from SAN
3939
san_domains = san_extension.value.get_values_for_type(x509.DNSName)
40+
try:
41+
logging.CyberCPLogFileWriter.writeToFile(f'Covered domains: {str(san_domains)}')
42+
except:
43+
pass
4044
return 1, san_domains
4145
else:
4246
# If SAN is not present, return the Common Name as a fallback
@@ -54,20 +58,52 @@ def CheckIfSSLNeedsToBeIssued(virtualHostName):
5458
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, open(filePath, 'r').read())
5559
SSLProvider = x509.get_issuer().get_components()[1][1].decode('utf-8')
5660

57-
if SSLProvider != 'Denial':
58-
return sslUtilities.ISSUE_SSL
59-
else:
60-
status, domains = sslUtilities.getDomainsCovered(filePath)
6161

62+
63+
#### totally seprate check to see if both non-www and www are covered
64+
65+
if SSLProvider == "Let's Encrypt":
66+
status, domains = sslUtilities.getDomainsCovered(filePath)
6267
if status:
6368
if len(domains) > 1:
64-
return sslUtilities.DONT_ISSUE
69+
### need further checks here to see if ssl is valid for less then 15 days etc
70+
logging.CyberCPLogFileWriter.writeToFile(
71+
'[CheckIfSSLNeedsToBeIssued] SSL exists for %s and both versions are covered, just need to ensure if SSL is valid for less then 15 days.' % (virtualHostName), 0)
72+
pass
6573
else:
6674
return sslUtilities.ISSUE_SSL
75+
76+
#####
77+
78+
expireData = x509.get_notAfter().decode('ascii')
79+
from datetime import datetime
80+
finalDate = datetime.strptime(expireData, '%Y%m%d%H%M%SZ')
81+
now = datetime.now()
82+
diff = finalDate - now
83+
84+
if int(diff.days) >= 15 and SSLProvider!='Denial':
85+
logging.CyberCPLogFileWriter.writeToFile(
86+
'[CheckIfSSLNeedsToBeIssued] SSL exists for %s and is not ready to fetch new SSL., skipping..' % (
87+
virtualHostName), 0)
88+
89+
return sslUtilities.DONT_ISSUE
90+
elif SSLProvider == 'Denial':
91+
logging.CyberCPLogFileWriter.writeToFile(
92+
f'[CheckIfSSLNeedsToBeIssued] Self-signed SSL found, lets issue new SSL for {virtualHostName}', 0)
93+
return sslUtilities.ISSUE_SSL
94+
elif SSLProvider != "Let's Encrypt":
95+
logging.CyberCPLogFileWriter.writeToFile(
96+
f'[CheckIfSSLNeedsToBeIssued] Custom SSL found for {virtualHostName}', 0)
97+
return sslUtilities.DONT_ISSUE
98+
else:
99+
logging.CyberCPLogFileWriter.writeToFile(
100+
f'[CheckIfSSLNeedsToBeIssued] We will issue SSL for {virtualHostName}', 0)
101+
return sslUtilities.ISSUE_SSL
67102
else:
103+
logging.CyberCPLogFileWriter.writeToFile(
104+
f'[CheckIfSSLNeedsToBeIssued] We will issue SSL for {virtualHostName}', 0)
68105
return sslUtilities.ISSUE_SSL
69106

70-
71107
@staticmethod
72108
def checkIfSSLMap(virtualHostName):
73109
try:
@@ -435,6 +471,7 @@ def installSSLForDomain(virtualHostName, adminEmail='example@example.org'):
435471

436472
@staticmethod
437473
def obtainSSLForADomain(virtualHostName, adminEmail, sslpath, aliasDomain=None):
474+
438475
from plogical.acl import ACLManager
439476
from plogical.sslv2 import sslUtilities as sslv2
440477
import json

plogical/upgrade.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,13 @@ def IncBackupMigrations():
20472047
except:
20482048
pass
20492049

2050+
query = "ALTER TABLE `websiteFunctions_childdomains` ADD `alais` INT NOT NULL DEFAULT '0' AFTER `master_id`; "
2051+
try:
2052+
cursor.execute(query)
2053+
except:
2054+
pass
2055+
2056+
20502057
try:
20512058
connection.close()
20522059
except:

plogical/virtualHostUtilities.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ def saveSSL(virtualHost, keyPath, certPath):
12431243

12441244
@staticmethod
12451245
def createDomain(masterDomain, virtualHostName, phpVersion, path, ssl, dkimCheck, openBasedir, owner, apache,
1246-
tempStatusPath='/home/cyberpanel/fakePath', LimitsCheck=1):
1246+
tempStatusPath='/home/cyberpanel/fakePath', LimitsCheck=1, alias = 0):
12471247
try:
12481248

12491249
logging.CyberCPLogFileWriter.statusWriter(tempStatusPath, 'Running some checks..,0')
@@ -1336,7 +1336,7 @@ def createDomain(masterDomain, virtualHostName, phpVersion, path, ssl, dkimCheck
13361336

13371337
if LimitsCheck:
13381338
website = ChildDomains(master=master, domain=virtualHostName, path=path, phpSelection=phpVersion,
1339-
ssl=ssl)
1339+
ssl=ssl, alais=alias)
13401340
website.save()
13411341

13421342
if ssl == 1:
@@ -1852,9 +1852,14 @@ def main():
18521852
except:
18531853
tempStatusPath = '/home/cyberpanel/fakePath'
18541854

1855+
try:
1856+
aliasDomain = int(args.aliasDomain)
1857+
except:
1858+
aliasDomain = 0
1859+
18551860
virtualHostUtilities.createDomain(args.masterDomain, args.virtualHostName, args.phpVersion, args.path,
18561861
int(args.ssl), dkimCheck, openBasedir, args.websiteOwner, apache,
1857-
tempStatusPath)
1862+
tempStatusPath, 1, aliasDomain)
18581863
elif args.function == "issueSSL":
18591864
virtualHostUtilities.issueSSL(args.virtualHostName, args.path, args.administratorEmail)
18601865
elif args.function == "issueSSLv2":

websiteFunctions/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class ChildDomains(models.Model):
2727
path = models.CharField(max_length=200,default=None)
2828
ssl = models.IntegerField()
2929
phpSelection = models.CharField(max_length=10,default=None)
30+
alais = models.IntegerField(default=0)
31+
3032

3133
class Backups(models.Model):
3234
website = models.ForeignKey(Websites,on_delete=models.CASCADE)

0 commit comments

Comments
 (0)