JezK
Edit File: site_repository.cpython-311.pyc
� X'�q���9� �� � d dl Z d dlZd dlZd dlmZ d dlmZmZmZ d dl m Z d dlmZm Z d dlmZ ej e� � Z ed� � Zded ee fd �Zdej d ee fd�Zd ee fd �Zd ee fd�Zdee d dfd�Zded ee fd�Zdeded dfd�Z d,dee d ee fd�Z deded dfd�Z!ded dfd�Z" d-de#dz de#dz de#d e$e#ee f fd�Z%d e&e#e#f fd�Z'd ee fd �Z(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)�SqliteDatabase�OperationalError�fn)�retry_on)�WPSite� WordpressSite)�PLUGIN_SLUGzD/var/lib/cloudlinux-app-version-detector/components_versions.sqlite3�path�returnc �< � 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 � � )�docroot�domain�uid�r �int��.0�rows �^/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/wordpress/site_repository.py� <listcomp>z%get_sites_by_path.<locals>.<listcomp>I �I � � � � �� �s�1�v�c�!�f�#�c�!�f�+�+�>�>�>�� � � ) �COMPONENTS_DB_PATH�exists�logger�error�str�listr �execute_sql�fetchall)r �cursors r �get_sites_by_pathr( s� � � �$�$�&�&� ����;��"�#�#� � � � �v�v� � �.� /� /� ;� ;� �( )-�) � � �!� !�F�D� ��?�?�$�$�� � � r � user_infoc � � t � � � r| �;t � dt t � � � � t � � S | �(t � d� � t � � S t t � � � d| j � d�� � }d� |� � � D � � S )aq Get a set of paths to WordPress sites belonging to a particular user. Paths are sorted by their length to make sure that the main site is the last one in the list. The data is pulled from the app-version-detector database. Args: user_info: The user info with ID to get sites for. Returns: A list of paths to WordPress sites. Nr z'No user info provided for getting sitesz� WITH latest_reports AS ( SELECT MAX(id) as id, dir FROM report WHERE uid = a� GROUP BY dir ) SELECT wp.real_path 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 RTRIM(lr.dir, '/') || '%' GROUP BY wp.real_path ORDER BY length(wp.real_path) DESC c � � g | ] }|d ��S )r � r s r r z&get_sites_for_user.<locals>.<listcomp>z s � �0�0�0�s�C��F�0�0�0r ) r r r! r"