-zh d dl Z d dlZd dlZd dlmZ d dlmZmZmZ d dl m Z mZ d dlm Z d dlmZ d dlmZ d dlmZ e j e Z dd edz d edz deedz edz f fdZ G d de Z G d de ZdS ) N)ValidationError)CommonEndpoints RootEndpointsbind)Scopeis_root_user)MessageType)get_wordpress_incidents)get_installed_sites_paginated)get_domain_pathsusersite_searchreturnc x t j }t rt d| d}| s t j | j }t d| | n<# t $ r/ t d| t d| d w xY w||fS ||fS )a Determine the user_id and site_path for filtering WordPress incidents. Three calling contexts: 1. Root user: Can query all incidents or filter by specific user 2. Non-root user: Can only query their own incidents (user/site_search ignored) 3. Proxy service: Both user and site_search must be set, restricted to that site Args: user: Username to filter by site_search: Site path to filter by Returns: Tuple of (user_id, site_path) to filter by, or (None, None) for all Raises: KeyError: If the specified user doesn't exist ValueError: If proxy service call is missing required parameters z-Root user querying incidents, user filter: %sNz(Filtering incidents for user %s (uid=%d)zUser not found: %szUser 'z' not found) osgetuidr loggerdebugpwdgetpwnampw_uidKeyErrorwarning)r r current_uiduser_ids i/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/simple_rpc/wordpress_security_plugin.pyget_user_id_and_site_for_queryr s , )++K~~ $DdKKK ;,t,,3>g ; ; ;3T:::9999::: ; ####s 5A8 89B1c e Zd Zej Z edd d Z edd d Z edd d Z edd d Z d S )WordpressEndpointswordpress-pluginzinstall-on-new-sitesc p K | j t j d d {V d S )Ninstall_on_new_sitesaction_sinkprocess_messager WordpressPluginActionselfs r wordpress_plugin_installz+WordpressEndpoints.wordpress_plugin_installD sZ j((-5KLLL ztidy-upc p K | j t j d d {V d S )Ntidy_upr# r% r) s r wordpress_plugin_tidy_upz+WordpressEndpoints.wordpress_plugin_tidy_upJ sY j((-Y??? r, updatec p K | j t j d d {V d S )Nupdate_existingr# r% r) s r wordpress_plugin_updatez*WordpressEndpoints.wordpress_plugin_updateP sZ j((-5FGGG r, zinstall-and-updatec p K | j t j d d {V d S )Ninstall_and_updater# r% r) s r #wordpress_plugin_install_and_updatez6WordpressEndpoints.wordpress_plugin_install_and_updateV sZ j((-5IJJJ r, N)__name__ __module____qualname__r AV_IM360SCOPEr r+ r/ r3 r6 r, r r r A s NE T 455 65 T i(( )( T h'' (' T 233 43 r, r c e Zd Zej Z edd ddedz dedz ded ed edz dedz dedz d edz dedz dedz de dz de e fd Z edd dd ZdS )WordpressCommonEndpointsr zlist-incidentsN2 r r r limitoffsetby_abuser_ipby_country_code by_domainsearchsincetoorder_byr c @ K t || \ }} n/# t $ r"}t t | |d}~ww xY wt |||||||| | | | }|D ]:}| d |d<