5LyS d dl Z d dlZd dlZd dlmZ d dlmZmZ d dlm Z d dl
mZmZ d dl
mZ ej e Z ed Zded ee fd
Zdej d ee fdZd ee fd
Zd ee fdZdee d dfdZded ee fdZdeded dfdZ d+dee d ee fdZdeded dfdZ ded dfdZ! d,de"dz de"dz de"d e#e"ee f fdZ$d ee fdZ%d ee d ee fd!Z&d" Z' e ed#d$d%e'& ded e"fd' Z(d ee fd(Z)d ee fd)Z*ded dfd*Z+dS )- N)Path)SqliteDatabaseOperationalError)retry_on)WPSite
WordpressSite)PLUGIN_SLUGzD/var/lib/cloudlinux-app-version-detector/components_versions.sqlite3pathreturnc < t s;t dt t t S t
t d| d }d | D S )a
Get a list of WordPress sites that match the given path.
Args:
path: The path to search for WordPress sites.
Note: The same WordPress site (real_path) can appear in multiple reports
if it was scanned directly and also as part of a parent folder scan.
We use only the entry from the latest report for each real_path.
Returns:
A list of WPSite objects that match the path.
-App detector database '%s' couldn't be found.a
WITH latest_reports AS (
SELECT id, uid, domain, dir
FROM report
WHERE id IN (
SELECT MAX(id)
FROM report
WHERE domain IS NOT NULL
AND domain != ''
GROUP BY dir
)
),
-- Get all WordPress sites with their report IDs
all_wp_sites AS (
SELECT wp.real_path, lr.domain, lr.uid, lr.id as report_id
FROM apps AS wp
INNER JOIN latest_reports AS lr
ON wp.report_id = lr.id
WHERE wp.title = 'wp_core'
AND wp.parent_id IS NULL
AND wp.real_path LIKE 'a %'
AND wp.real_path LIKE RTRIM(lr.dir, '/') || '%'
)
-- For each real_path, keep only the entry from the latest report
SELECT real_path, domain, uid
FROM all_wp_sites
WHERE (real_path, report_id) IN (
SELECT real_path, MAX(report_id)
FROM all_wp_sites
GROUP BY real_path
)
c
p g | ]3}t |d |d t |d 4S r )docrootdomainuidr int.0rows ^/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/wordpress/site_repository.py