From 97f87b4e50d2e0a8044237f9af8bf989a9a6ad7a Mon Sep 17 00:00:00 2001
From: Hassan Hashmi <75794688+hassanhashmey@users.noreply.github.com>
Date: Thu, 22 Feb 2024 15:30:35 +0500
Subject: [PATCH] fix manage child domain in v2
---
.../websiteFunctions/launchChildv2.html | 9 ++
websiteFunctions/views.py | 8 ++
websiteFunctions/website.py | 84 +++++++++++++++++++
websitesv2/urls.py | 2 +-
4 files changed, 102 insertions(+), 1 deletion(-)
create mode 100644 websiteFunctions/templates/websiteFunctions/launchChildv2.html
diff --git a/websiteFunctions/templates/websiteFunctions/launchChildv2.html b/websiteFunctions/templates/websiteFunctions/launchChildv2.html
new file mode 100644
index 000000000..8304c1da7
--- /dev/null
+++ b/websiteFunctions/templates/websiteFunctions/launchChildv2.html
@@ -0,0 +1,9 @@
+{% extends "baseTemplate/newBase.html" %}
+{% load i18n %}
+{% block titleNew %}{% trans "Home - CyberPanel" %}{% endblock %}
+{% block newContent %}
+
+ {% load static %}
+
test
+
+{% endblock %}
\ No newline at end of file
diff --git a/websiteFunctions/views.py b/websiteFunctions/views.py
index 5e9ea895e..55e21ef59 100755
--- a/websiteFunctions/views.py
+++ b/websiteFunctions/views.py
@@ -1324,6 +1324,14 @@ def launchChild(request, domain, childDomain):
except KeyError:
return redirect(loadLoginPage)
+def launchChildv2(request, domain, childDomain):
+ try:
+ userID = request.session['userID']
+ wm = WebsiteManager(domain, childDomain)
+ return wm.launchChildv2(request, userID)
+ except KeyError:
+ return redirect(loadLoginPage)
+
def getDataFromLogFile(request):
try:
diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py
index dca8fdb14..30c5e9ed0 100755
--- a/websiteFunctions/website.py
+++ b/websiteFunctions/website.py
@@ -3572,6 +3572,90 @@ class WebsiteManager:
else:
proc = httpProc(request, 'websiteFunctions/launchChild.html',
{"error": 1, "domain": "This child domain does not exists"})
+
+ def launchChildv2(self, request=None, userID=None, data=None):
+
+ if ChildDomains.objects.filter(domain=self.childDomain).exists():
+ currentACL = ACLManager.loadedACL(userID)
+ admin = Administrator.objects.get(pk=userID)
+
+ if ACLManager.checkOwnership(self.domain, admin, currentACL) == 1:
+ pass
+ else:
+ return ACLManager.loadError()
+
+ website = Websites.objects.get(domain=self.domain)
+
+ Data = {}
+
+ Data['ftpTotal'] = website.package.ftpAccounts
+ Data['ftpUsed'] = website.users_set.all().count()
+
+ Data['databasesUsed'] = website.databases_set.all().count()
+ Data['databasesTotal'] = website.package.dataBases
+
+ Data['domain'] = self.domain
+ Data['childDomain'] = self.childDomain
+
+ DiskUsage, DiskUsagePercentage, bwInMB, bwUsage = virtualHostUtilities.FindStats(website)
+
+ ## bw usage calculations
+
+ Data['bwInMBTotal'] = website.package.bandwidth
+ Data['bwInMB'] = bwInMB
+ Data['bwUsage'] = bwUsage
+
+ if DiskUsagePercentage > 100:
+ DiskUsagePercentage = 100
+
+ Data['diskUsage'] = DiskUsagePercentage
+ Data['diskInMB'] = DiskUsage
+ Data['diskInMBTotal'] = website.package.diskSpace
+
+ Data['phps'] = PHPManager.findPHPVersions()
+
+ servicePath = '/home/cyberpanel/postfix'
+ if os.path.exists(servicePath):
+ Data['email'] = 1
+ else:
+ Data['email'] = 0
+
+ servicePath = '/home/cyberpanel/pureftpd'
+ if os.path.exists(servicePath):
+ Data['ftp'] = 1
+ else:
+ Data['ftp'] = 0
+
+ ## Getting SSL Information
+ try:
+ import OpenSSL
+ from datetime import datetime
+ filePath = '/etc/letsencrypt/live/%s/fullchain.pem' % (self.childDomain)
+ x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM,
+ open(filePath, 'r').read())
+ expireData = x509.get_notAfter().decode('ascii')
+ finalDate = datetime.strptime(expireData, '%Y%m%d%H%M%SZ')
+
+ now = datetime.now()
+ diff = finalDate - now
+ Data['viewSSL'] = 1
+ Data['days'] = str(diff.days)
+ Data['authority'] = x509.get_issuer().get_components()[1][1].decode('utf-8')
+
+ if Data['authority'] == 'Denial':
+ Data['authority'] = '%s has SELF-SIGNED SSL.' % (self.childDomain)
+ else:
+ Data['authority'] = '%s has SSL from %s.' % (self.childDomain, Data['authority'])
+
+ except BaseException as msg:
+ Data['viewSSL'] = 0
+ logging.CyberCPLogFileWriter.writeToFile(str(msg))
+
+ proc = httpProc(request, 'websiteFunctions/launchChildv2.html', Data)
+ return proc.render()
+ else:
+ proc = httpProc(request, 'websiteFunctions/launchChildv2.html',
+ {"error": 1, "domain": "This child domain does not exists"})
return proc.render()
def getDataFromLogFile(self, userID=None, data=None):
diff --git a/websitesv2/urls.py b/websitesv2/urls.py
index 94d358d73..8388e6cb7 100755
--- a/websitesv2/urls.py
+++ b/websitesv2/urls.py
@@ -215,7 +215,7 @@ urlpatterns = [
url(r'^saveApacheConfigsToFile$', views.saveApacheConfigsToFile, name='saveApacheConfigsToFile'),
## Catch all for domains
- url(r'^(?P(.*))/(?P(.*))$', views.launchChild, name='launchChild'),
+ url(r'^(?P(.*))/(?P(.*))$', views.launchChildv2, name='launchChildv2'),
url(r'^(?P(.*))$', views.domainV2, name='domainv2'),
]