From c97791b3df2abb5f6b287301538ade40793c2340 Mon Sep 17 00:00:00 2001 From: usmannasir Date: Fri, 2 May 2025 12:40:09 +0500 Subject: [PATCH] bug fix: with website search and wpsites --- plogical/acl.py | 32 +++++++++++++--- .../websiteFunctions/listWebsites.html | 2 +- websiteFunctions/website.py | 38 +++++++++++++------ 3 files changed, 53 insertions(+), 19 deletions(-) diff --git a/plogical/acl.py b/plogical/acl.py index f0aee9150..a9788791b 100644 --- a/plogical/acl.py +++ b/plogical/acl.py @@ -14,7 +14,7 @@ django.setup() from loginSystem.models import Administrator, ACL from django.shortcuts import HttpResponse from packages.models import Package -from websiteFunctions.models import Websites, ChildDomains, aliasDomains, DockerSites +from websiteFunctions.models import Websites, ChildDomains, aliasDomains, DockerSites, WPSites import json from subprocess import call, CalledProcessError from shlex import split @@ -582,24 +582,44 @@ class ACLManager: @staticmethod def searchWebsiteObjects(currentACL, userID, searchTerm): - if currentACL['admin'] == 1: - return Websites.objects.filter(domain__istartswith=searchTerm) + # Get websites that match the search term + websites = Websites.objects.filter(domain__istartswith=searchTerm) + # Get WordPress sites that match the search term + wp_sites = WPSites.objects.filter(title__icontains=searchTerm) + # Add WordPress sites' parent websites to the results + for wp in wp_sites: + if wp.owner not in websites: + websites = websites | Websites.objects.filter(pk=wp.owner.pk) + return websites else: websiteList = [] admin = Administrator.objects.get(pk=userID) + # Get websites that match the search term websites = admin.websites_set.filter(domain__istartswith=searchTerm) - for items in websites: websiteList.append(items) - admins = Administrator.objects.filter(owner=admin.pk) + # Get WordPress sites that match the search term + wp_sites = WPSites.objects.filter(title__icontains=searchTerm) + for wp in wp_sites: + if wp.owner.admin == admin and wp.owner not in websiteList: + websiteList.append(wp.owner) + admins = Administrator.objects.filter(owner=admin.pk) for items in admins: + # Get websites that match the search term webs = items.websites_set.filter(domain__istartswith=searchTerm) for web in webs: - websiteList.append(web) + if web not in websiteList: + websiteList.append(web) + + # Get WordPress sites that match the search term + wp_sites = WPSites.objects.filter(title__icontains=searchTerm) + for wp in wp_sites: + if wp.owner.admin == items and wp.owner not in websiteList: + websiteList.append(wp.owner) return websiteList diff --git a/websiteFunctions/templates/websiteFunctions/listWebsites.html b/websiteFunctions/templates/websiteFunctions/listWebsites.html index 44fbaf468..4e09feade 100755 --- a/websiteFunctions/templates/websiteFunctions/listWebsites.html +++ b/websiteFunctions/templates/websiteFunctions/listWebsites.html @@ -66,7 +66,7 @@
-
diff --git a/websiteFunctions/website.py b/websiteFunctions/website.py index ab607dac1..a57cff62b 100755 --- a/websiteFunctions/website.py +++ b/websiteFunctions/website.py @@ -4566,8 +4566,7 @@ StrictHostKeyChecking no websites = ACLManager.searchWebsiteObjects(currentlACL, userID, searchTerm) - json_data = "[" - checker = 0 + json_data = [] try: ipFile = "/etc/cyberpanel/machineIP" @@ -4598,19 +4597,34 @@ StrictHostKeyChecking no PHPVersionActual = 'PHP 8.1' diskUsed = "%sMB" % str(DiskUsage) - dic = {'domain': items.domain, 'adminEmail': items.adminEmail, 'ipAddress': ipAddress, - 'admin': items.admin.userName, 'package': items.package.packageName, 'state': state, - 'diskUsed': diskUsed, 'phpVersion': PHPVersionActual} - if checker == 0: - json_data = json_data + json.dumps(dic) - checker = 1 - else: - json_data = json_data + ',' + json.dumps(dic) + # Get WordPress sites for this website + wp_sites = [] + try: + wp_sites = WPSites.objects.filter(owner=items) + wp_sites = [{ + 'id': wp.id, + 'title': wp.title, + 'url': wp.FinalURL, + 'version': wp.version if hasattr(wp, 'version') else 'Unknown', + 'phpVersion': wp.phpVersion if hasattr(wp, 'phpVersion') else 'Unknown' + } for wp in wp_sites] + except: + pass - json_data = json_data + ']' + json_data.append({ + 'domain': items.domain, + 'adminEmail': items.adminEmail, + 'ipAddress': ipAddress, + 'admin': items.admin.userName, + 'package': items.package.packageName, + 'state': state, + 'diskUsed': diskUsed, + 'phpVersion': PHPVersionActual, + 'wp_sites': wp_sites + }) - return json_data + return json.dumps(json_data) def findWebsitesJson(self, currentACL, userID, pageNumber): finalPageNumber = ((pageNumber * 10)) - 10