Uname : Linux premium36.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Soft : LiteSpeed
Ip : 198.54.115.237
Port : 443
~
/
opt
/
imunify360
/
venv
/
lib
/
python3.11
/
site-packages
/
imav
/
wordpress
/
__pycache__
[ HOME ]
Exec
Submit
File Name : cli.cpython-311.pyc
� 3Ri�* � �| � d Z ddlZddlZddlZddlmZ ddlmZ ddlm Z m Z mZ ddlm Z mZ ddlmZmZmZ ddlmZ dd lmZ ej e� � Zd edefd�Zd edefd�Zdedefd�Zdefd�Zdefd�Z defd�Z!defd�Z"defd�Z#defd�Z$defd�Z%defd�Z& ed�� � defd�� � Z'd� Z(defd�Z)dS )u This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. Copyright © 2019 Cloud Linux Software Inc. This software is also available under ImunifyAV commercial license, see <https://www.imunify360.com/legal/eula> � N)�Path)� StrictVersion)� check_run� CheckRunError�async_lru_cache)�PLUGIN_PATH�PLUGIN_SLUG)�build_command_for_user�get_php_binary_path� wp_wrapper)�log_message)�WPSite�version_str�returnc � � t | t � � sdS | � � � }|sdS t |� � dS # t $ r Y dS w xY w)z1Validate if a string is a valid semantic version.FT)� isinstance�str�stripr � ValueError)r �trimmed_strs �G/opt/imunify360/venv/lib/python3.11/site-packages/imav/wordpress/cli.py�_validate_semverr - su � � �k�3�'�'� ��u� �#�#�%�%�K�� ��u���k�"�"�"��t��� � � ��u�u����s �A � A�A�outputc �b � | sdS | � � � }|sdS t |� � dk r+|d � � � }t |� � r|S t |� � dk r+|d � � � }t |� � r|S t dd| iddd � � � dS )z� Extract version from WP CLI output, trying both first and last parts. Args: output: The raw output from WP CLI Returns: The extracted version string or None if no valid version found Nr � ���zMFailed to extract valid semver version from WP CLI output. Output: '{output}'r �warning� wordpressz#wp-plugin-version-extraction-failed)�format_args�level� component�fingerprint)�split�lenr r r )r �parts� first_part� last_parts r �_extract_version_from_outputr( ? s� � � � ��t� �L�L�N�N�E�� ��t� �5�z�z�A�~�~��1�X�^�^�%�%� ��J�'�'� ��� �5�z�z�A�~�~��"�I�O�O�%�%� ��I�&�&� ��� � ��v�&���9� � � � � �4� �sitec � � K � t | � � � d{V ��}|dz dz dz }|� � � sdS t j d� � } t |� � 5 }|D ][}|� |� � }|rB|� d� � }t |� � r|c cddd� � S ddd� � dS �\ ddd� � n# 1 swxY w Y n4# t $ r'}t � d||� � Y d}~dS d}~ww xY wdS )z� Parse the version of imunify-security plugin by reading the main plugin file. Args: site: WordPress site object containing docroot path Returns: str: Plugin version or None if not found or invalid N�plugins�imunify-securityzimunify-security.phpz\* Version:\s*([0-9.]+)r z=Failed to read plugin file to determine version number %s: %s)�get_content_dir�exists�re�compile�open�search�groupr � Exception�logger�error) r* �content_dir�plugin_file�version_pattern�f�line�match�version�es r �_parse_version_from_plugin_filer@ k s� � � � � (��-�-�-�-�-�-�-�-�K��i��"4�4�7M�M� � ����� ��t��j�!;�<�<�O�� �+� � � $�!�� $� $��'�.�.�t�4�4��� $�#�k�k�!�n�n�G�'��0�0� $�&��� $� $� $� $� $� $� $� $� $� $� $� $� $� $� $� $� $�$� $� $� $� $� $� $� $� $� $� $� $� $���� $� $� $� $��� � � � ����K�� � � � � �t�t�t�t�t����� ���� �4sU �C �AC � C �-C �.C �;C �=C � C � C �C �C � D�D�Dc � �\ K � t j | j � � j }t | |� � � d{V ��}g t || j � � �d�d�t t � � �d�d�}t ||� � }t � d|� �� � t |� � � d{V �� dS )zFInstall the Imunify Security WordPress plugin on given WordPress site.N�plugin�install� --activate�--forcezInstalling wp plugin � �pwd�getpwuid�uid�pw_namer r �docrootr r r r6 �infor �r* �username�php_path�args�commands r �plugin_installrR � s� � � � ��|�D�H�%�%�-�H�(��x�8�8�8�8�8�8�8�8�H�� �H�d�l� +� +���� �� �K��� � �� � �D� %�X�t�4�4�G� �K�K�1��1�1�2�2�2� �G� � ���������r) c � �\ K � t j | j � � j }t | |� � � d{V ��}g t || j � � �d�d�t t � � �d�d�}t ||� � }t � d|� �� � t |� � � d{V �� dS )z� Update the Imunify Security WordPress plugin on given WordPress site. Currently, this is the same as install, but in the future it may differ. NrB rC rD rE zUpdating wp plugin rF rM s r � plugin_updaterT � s� � � � � �|�D�H�%�%�-�H�(��x�8�8�8�8�8�8�8�8�H�� �H�d�l� +� +���� �� �K��� � �� � �D� %�X�t�4�4�G� �K�K�/�g�/�/�0�0�0� �G� � ���������r) c � �> K � t j | j � � j }t | |� � � d{V ��}g t || j � � �d�d�t �d�}t ||� � }t � d|� �� � t |� � � d{V �� dS )z<Uninstall the imunify-security wp plugin from given wp site.NrB � uninstallz--deactivatezUninstalling wp plugin )rG rH rI rJ r r rK r r r6 rL r rM s r �plugin_uninstallrW � s� � � � ��|�D�H�%�%�-�H�(��x�8�8�8�8�8�8�8�8�H�� �H�d�l� +� +���� �� � � ��D� %�X�t�4�4�G� �K�K�3�'�3�3�4�4�4� �G� � ���������r) c � �t K � t j | j � � j }t | |� � � d{V ��}g t || j � � �d�d�t �d�}t ||� � }t � d|� �� � t |� � � d{V ��}|� d� � � � � }t |� � S # t $ r+}t � d|j � � Y d}~dS d}~wt$ $ r&}t � d|� � Y d}~dS d}~ww xY w) z� Get the version of the imunify-security wp plugin installed on given WordPress site. Uses WP CLI to get the version. NrB �getz--field=versionzGetting wp plugin version �utf-8z0Failed to get wp plugin version. Return code: %sz-Failed to decode wp plugin version output: %s)rG rH rI rJ r r rK r r r6 rL r �decoder r( r r7 � returncode�UnicodeDecodeError)r* rN rO rP rQ �resultr r? s r �_get_plugin_versionr_ � s} � � � � �|�D�H�%�%�-�H�(��x�8�8�8�8�8�8�8�8�H�� �H�d�l� +� +���� �� � � ��D� %�X�t�4�4�G� �K�K�6�W�6�6�7�7�7�� ��)�)�)�)�)�)�)�)�����w�'�'�-�-�/�/��+�F�3�3�3��� � � ����>� �L� � � � �t�t�t�t�t������ � � ����D�a�H�H�H��t�t�t�t�t��������s% � A C � D7� D� D7�D2�2D7c � � K � t | � � � d{V ��}|r|S n2# t $ r%}t � d|� � Y d}~nd}~ww xY wt � d� � t | � � � d{V ��S )z� Get the version of the imunify-security wp plugin installed on given WordPress site. First tries to parse the version from the plugin file, then falls back to WP CLI. Nz,Failed to parse version from plugin file: %sz/Plugin version not found in file, trying WP CLI)r@ r5 r6 r rL r_ )r* r>