관리-도구
편집 파일: plesk.cpython-311.pyc
� b��f� � � � d Z ddlZddlZddlmc mZ ddlmZ ddl m Z ddlmZ ddl mZmZ dd lmZ dd lmZmZ G d� de� � ZdS ) zM This module contains classes implementing X-Ray Manager behaviour for Plesk � N)�ChainMap)� phpinfo_utils� )�BaseManager� )�XRayManagerError�XRayMissingDomain)� DomainInfo)�user_mode_verification�with_fpm_reload_restrictedc � � e Zd ZdZdddddddd d ddd d�Zdefd�Zeede de fd�� � � � Zede fd�� � Zde defd�Zde de fd�ZdS )�PleskManagerzA Class implementing an X-Ray manager behaviour for Plesk z/opt/plesk/php/5.4/etc/php.dz/opt/plesk/php/5.5/etc/php.dz/opt/plesk/php/5.6/etc/php.dz/opt/plesk/php/7.0/etc/php.dz/opt/plesk/php/7.1/etc/php.dz/opt/plesk/php/7.2/etc/php.dz/opt/plesk/php/7.3/etc/php.dz/opt/plesk/php/7.4/etc/php.dz/opt/plesk/php/8.0/etc/php.dz/opt/plesk/php/8.1/etc/php.dz/opt/plesk/php/8.2/etc/php.dz/opt/plesk/php/8.3/etc/php.d)zplesk-php54zplesk-php55zplesk-php56zplesk-php70zplesk-php71zplesk-php72zplesk-php73zplesk-php74zplesk-php80zplesk-php81zplesk-php82zplesk-php83�returnc �6 � t | j | j � � S )z� Get supported PHP versions :return: a chained map with basic supported versions and Plesk supported versions )r �VERSIONS�VERSIONS_Plesk)�selfs �I/opt/cloudlinux/venv/lib64/python3.11/site-packages/xray/manager/plesk.py�supported_versionszPleskManager.supported_versions1 s � � �� ��+�-� -� -� �domain_namec �� �� d� }t �fd�| � � � D � � d� � }|�-| j � dd�i�� � t �� � �|\ }}}| j � d�||� � | j rIt j |��� � }t �|� d � � |j d ||j |�� � S t � ||� � |d|v |� � � S )z� Retrieve information about given domain from control panel environment: PHP version, user of domain, fpm status :param domain_name: name of domain :return: a DomainInfo object c � � d| v rd}nSd| v rd| � d� � d � �}n0d� | � d� � dd� � � }|S ) z� Resolve version for lsphp handlers :param h: original Plesk php handler id :return: resolved alt-php* version zlsphp-customz alt-php56�lsphpzalt-php�-���Nr )�split�join)�h�vers r �resolve_lsphp_versionz;PleskManager.get_domain_info.<locals>.resolve_lsphp_versionD sf � � ��"�"�!����A���2�������R� 0�2�2����h�h�q�w�w�s�|�|�B�Q�B�/�0�0���Jr c 3 �4 �K � | ]}|d �k �|V � �dS )r N� )�.0�itemr s �r � <genexpr>z/PleskManager.get_domain_info.<locals>.<genexpr>R s= �� � � � 4� 4�T� ��G�{�2�2� !�2�2�2�2�4� 4r Nz#Domain does not exist on the serverr )�extraz@Retrieved domain info: domain %s owned by %s uses php version %s)�domainz plesk-phpT)�name�panel_php_version�php_ini_scan_dir�is_selector_applied�user� panel_fpm�handler�fpm)r) r* r- r. r/ ) �next�query_db�logger�warningr �info�phpinfo_moder �get_php_configurationr �get_full_php_version�absolute_ini_scan_dir� is_php_fpm)r r r! �domain_datar( r- r/ �configs ` r �get_domain_infozPleskManager.get_domain_info: sg �� � � � � � 4� 4� 4� 4�T�]�]�_�_� 4� 4� 4�59�;� ;�����K��� E�'4�k�&B� � D� D� D�#�K�0�0�0� +����g�����N���w� (� (� (� �� !�"�8��[�*� *� *�F�� �"(�"=�"=�k�"J�"J�!'�!=� %)�� �+�� !� !� !� !� � �"7�"7��"@�"@���7�*��!� !� !� !r c # �" K � d� } d}t j dd|dgdd | � � �� � } t j d� |j � � � � }|� d � � D ]W}|� d � � j }|� d� � j }|� d� � j }|||fV � �XdS # t j $ r7}t t d � � t |j � � z � � |�d}~ww xY w)z� Query Plesk database through plesk db utility and yeild parsed xml result :return: tuple(domain_name, domain_user, domain_handler) c �R � dt j � dd� � vrddiS dS )a plesk db utility needs to be able to find mysql executable, which resides in /usr/bin. If we do not have it in PATH, the error will be thrown: 'exec: "mysql": executable file not found in $PATH' z/usr/bin�PATH� N)�os�environ�getr# r r �check_path_envz-PleskManager.query_db.<locals>.check_path_env| s/ � � �������!;�!;�;�;�� �+�+��tr z�select d.name,s.login,h.php_handler_id from (select id, name from domains union select dom_id, name from domain_aliases) d join hosting h on d.id=h.dom_id join sys_users s on h.sys_user_id=s.idz/usr/sbin/plesk�dbz--xmlT)�capture_output�text�envrA �rowz./field[@name='name']z./field[@name='login']z./field[@name='php_handler_id']z,Failed to parse XML from plesk db output: %sN) � subprocess�run�ET� fromstringr �stdout�iter�findrH � ParseErrorr �_�str) rE �query�result�rootrJ r � user_namer/ �es r r2 zPleskManager.query_dbt sM � � � � � � � X����!2�!%�!&�!(�!*� 04�$�$2�N�$4�$4�6� 6� 6�� _��=������!7�!7�8�8�D��y�y��'�'� 6� 6��!�h�h�'>�?�?�D���H�H�%=�>�>�C� ��(�(�#D�E�E�J��!�9�g�5�5�5�5�5� 6� 6�� �}� _� _� _�"��@�A�A�C�� �DV�DV�V�X� X�]^� _����� _���s �BC �D�2D � D�domain_infoc �V �� �fd�}d�j v rd�j v p |� � S �j S )z� Check if selector is enabled specifically for Plesk panel :param domain_info: a DomainInfo object :return: True if yes, False otherwise c �B �� � j r� j dd� � j v S dS )z� Checks if php selector and cloudlinux selector have the same php version. :param domain_info: a DomainInfo object :return: digits as string or None ���NF)�selector_php_versionr/ )rZ s �r �same_php_in_both_selectorszPPleskManager.panel_specific_selector_enabled.<locals>.same_php_in_both_selectors� s7 �� � �/� 3�"�7��s�s��*�2�3� 3��5r r �custom)r/ r. )r rZ r_ s ` r �panel_specific_selector_enabledz,PleskManager.panel_specific_selector_enabled� sY �� � � � � � � �k�)�)�)��� 3�3� 1�.�.�0�0� 2��(�(�(r �dom_infoc � � |j S )z{ Get Plesk FPM service name :param dom_info: a DomainInfo object :return: FPM service name )r/ )r rb s r �fpm_service_namezPleskManager.fpm_service_name� s � � ��r N)�__name__� __module__�__qualname__�__doc__r r r r r rT r r= �staticmethod�tupler2 �boolra rd r# r r r r s � � � � � �� � 6�5�5�5�5�5�5�5�5�5�5�5� � �N�-�H� -� -� -� -� ��6!�3� 6!�:� 6!� 6!� 6!� �� ��6!�p �#_�e� #_� #_� #_� �\�#_�J)�:� )�$� )� )� )� )�0 �� �� � � � � � r r )rh rB rK �xml.etree.ElementTree�etree�ElementTreerM �collectionsr � xray.internalr �baser �internal.exceptionsr r �internal.typesr �internal.user_plugin_utilsr r r r# r r �<module>ru s ��� � � � � � � � � � "� "� "� "� "� "� "� "� "� � � � � � � '� '� '� '� '� '� � � � � � � E� E� E� E� E� E� E� E� '� '� '� '� '� '�� � � � � � � �[ � [ � [ � [ � [ �;� [ � [ � [ � [ � [ r