Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib/python3.11/site-packages/clselect/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/clselect/__pycache__/clselectctlnodejsuser.cpython-311.pyc

�

m4�f�R���ddlmZddlmZddlmZddlZddlZddlZddlmcm	cm
ZddlZddl
mZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlm Z m!Z!ddl"m#Z#m$Z$ddl%m&Z&dZ'e#Z(d&d�Z)d'd�Z*d�Z+d�Z,d'd�Z-		d(d�Z.d�Z/d'd�Z0d'd�Z1d'd�Z2d'd�Z3d'd �Z4d)d!�Z5d*d#�Z6d$�Z7d%�Z8dS)+�)�print_function)�absolute_import)�divisionN)�ConnectionError)�	iteritems)�
basestring�)�clpassenger)�clselectctl)�utils)�userdomains)�mod_makedirs)�ClSelectExcept)�ApplicationsManager)�environments�interpreters)�APP_STARTED_CONST�APP_STOPPED_CONST)�clprintzapp.jsFc�2�t||��}|s|}tj|||��}|���r|rV	t	jd���|}n"#t
$rt
j|���wxYw|�||���|S)N�version)�key)�
destroy_first)	�_get_prefixr�Environment�existsr�KeyErrorr�NoSuchAlternativeVersion�create)�user�	directoryr�env_namer�prefix�environment�interpreters        �U/opt/cloudlinux/venv/lib64/python3.11/site-packages/clselect/clselectctlnodejsuser.py�_create_environmentr'$s���
��y�
)�
)�F������*�8�T�6�B�B�K������E�=�E�	C�&�3�	�B�B�B�7�K�K�K���	C�	C�	C� �9�'�B�B�B�	C�������;�m��D�D�D��s�A�A=c��t||��}|�Qtj|��}	tj|||��}n%#t
$rt
jd|z���wxYw|d}tj	�
tj	�tj	�|������}tj
|||��}|S)N�8No such application (or application not configured) "%s"�binary)rr
�summaryr�get_using_realpath_keysrr�NoSuchApplication�os�path�basename�dirnamerr)r r!�app_summaryr#�user_summaryr*r"r$s        r&�_get_environmentr42s���
��y�
)�
)�F���"�*�4�0�0��	��7��i��V�V�K�K���	�	�	� �2�J�����
�	������
"�F��w������������0G�0G� H� H�I�I�H��*�8�T�6�B�B�K��s	�?�"A!c��tj||��\}}tj�t
j|��S�N)r�get_abs_relr.r/�joinr�DEFAULT_PREFIX)r r!�_�rel_dirs    r&rrBs1���"�4��3�3�J�A�w�
�7�<�<��3�W�=�=�=�c��ddlm}|����|��st	j||d���dS)z�
    Check whether particular interpreter version is enabled and raises
    exception if not
    :param user: user to include in exception
    r	)�node_managerzversion is not enabledN)�clselectnodejsr>�NodeManager�is_version_enabledr�UnableToSetAlternative)rr r>s   r&�_ensure_version_enabledrCGs_��-�,�,�,�,�,��#�#�%�%�8�8��A�A�5��3��'�3�5�5�	5�5�5r<c�D�|�t��}tj||��\}}|�|��}|���D]M}tj||��\}}|t
jz�|t
jz��r|cS�NdS)z�
    Return None if new_app_directory is not nested inside an existing
    user application, and the name of conflicting application otherwise
    N)rrr7�get_user_config_data�keysr.�sep�
startswith)�new_app_directoryr �apps_manager�abs_app_pathr:�full_config�existing_app�existing_app_abs_paths        r&�_get_existing_nesting_app_forrOSs�����*�,�,���'��.?�@�@�O�L�!��3�3�D�9�9�K�#�(�(�*�*� � ��#(�#4�T�<�#H�#H� ��q��2�6�!�-�-�.C�b�f�.L�M�M�	 �����	 ��4r<c
�:�|	�t��}	|�tjd���t||��|�t}|�i}|�d}t|||	��}|�tj|���tj|��}t|||��}|�
��j}
tj
||||	j|
|||
���tj||��|s2tj|��}t#j|||��}|d}|||t&||g|d�}|
r|
|d<|	�|||��	|	�||||��dS#t,$r0}t/jdd	t3|��d
���Yd}~dSd}~wwxYw)a�
    Create application
    :param user: unix user name
    :param directory: application path in user's home (app-root)
    :param alias: alias (app-uri)
    :param version: version of interpreter
    :param doc_root: doc_root
    :param app_mode: application mode for nodejs
    :param env_vars: dict with enviroment variables
    :param startup_file: main application file
    :param domain_name: domain name
    :param apps_manager: Application Manager. Class that responsible
           for gathering and writing information about applications
    :param passenger_log_file: Passenger log filename to write to app's .htaccess
    :return: None
    NzNot passed version as argument�
production)�doc_root�startup_file�passenger_log_file�domain)�nodejs_versionrU�app_uri�
app_statusrS�app_mode�config_files�env_varsrT�text�ERROR��status�message)rr�	WrongDatarC�DEFAULT_STARTUP_FILErO�BusyApplicationRootr�	get_aliasr'r%r*r
�	configure�INTERPRETER�restartr+rr,�DEFAULT_APP_STATE�add_app_to_config�add_env_vars_for_htaccess�	Exceptionr�
print_diag�str)r r!�aliasrrRrYr[rS�domain_namerJrT�conflicting_appr$r*�summary_datar2�app_data�errs                  r&rrfs��&��*�,�,�����&�'G�H�H�H��G�T�*�*�*���+����������3�I�t�\�R�R�O��"��0��A�A�A��!�%�(�(�E�%�d�I�w�?�?�K�
�
$�
$�
&�
&�
-�F���$�	�5�,�2J�F�#+�,�-?�A�A�A�A����i�(�(�(��,�"�*�4�0�0���3�D�)�\�R�R��!�(�+��"���(�%����	�	�H��=�*<��&�'��"�"�4��H�=�=�=�M��.�.�t�Y��(�S�S�S�S�S���M�M�M���6�g�#�c�(�(�#K�#K�L�L�L�L�L�L�L�L�L�����M���s�E � 
F�*%F�Fc��d}tj�tj|��j|d��}tj�|��r=	tj|��nZ#t$rtj
dd|iz���wxYwtj�|��rtj|���tj�|d��}tj�|��st|d��	tj||��dS#t$rtjd|z���wxYw)	z�
    Creates symlink to app's node_modules in app_root
    :param username: user name
    :param environment_path: Path to app's virtual environment
    :param app_root: Application root
    :return: None
    z�Cloudlinux NodeJS Selector demands to store node modules for application in separate folder (virtual environment) pointed by symlink called "node_modules". That`s why application should not contain folder/file with such name in application root�node_modulesz"Can`t remove symlink %(link_name)s�	link_namezlib/node_modulesi�zError creating symlink. N)r.r/r8�pwd�getpwnam�pw_dir�islink�remove�OSErrorr�RemoveSymlinkErrorr�SymlinkErrorr�symlink�CreateSymlinkError)�username�environment_path�app_rootr`rv�link_tos      r&�_create_symlink_to_node_modulesr��sW��3�G�����S�\�(�3�3�:�H�n�U�U�I�	�w�~�~�i� � �	3�	��I�i� � � � ���	�	�	� �3�4��i�(�)���
�	����

����	�	"�	"�3��)�'�2�2�2��g�l�l�+�-?�@�@�G�
�7�>�>�'�"�"�%��W�e�$�$�$�V�
�
�7�I�&�&�&�&�&���V�V�V��/�0J�W�0T�U�U�U�V���s�A0�0$B�D1�1"Ec���|�t��}|�||��}	|�|�||d|��n<#t$r/}t	jddt
|��d���Yd}~nd}~wwxYw|�d��tkr�tj
|��j}d�|d|g��}	tj|��n#t$rYnwxYw|�+|�|||��}t#j|��|�||��	t#j||��n#t*j$rYnwxYwdSt/||��}	t1j||	��\}
}	tj|
��n#t$rYnwxYwt#j|��}|�||��}
	t1j|||��n*#t8$r|
rYdSt+jd|z���wxYwt#j||��	t#j||��dS#t*j$rYdSwxYw)	aa
    Destroy web app with specified directory for specified user
    :param user: username
    :param app_directory: application directory
    :param doc_root: Document root for selected domain
    :param apps_manager: Application Manager. Class that responsible
           for gathering and writing information about applications
    :return: None
    Nr\r]r^rX�/�nodevenvr))r�get_app_configrjrkrrlrm�getrrwrxryr8�shutil�rmtreer|�get_htaccess_by_appdirr
�$remove_passenger_lines_from_htaccess�remove_app_from_configrgr�MissingApprootDirectoryrrr7r+r,rra�unconfigure)r �
app_directoryrRrJ�
app_configrs�	user_home�
nodevenv_path�htaccess_filenamer#�abs_dirr:r3�
app_in_configs              r&�destroyr��s�����*�,�,���,�,�T�=�A�A�J�M����2�2�4���h�W�W�W����M�M�M���6�g�#�c�(�(�#K�#K�L�L�L�L�L�L�L�L�����M�����~�~�l�#�#�'8�8�8��L��&�&�-�	����)�Z��!G�H�H�
�	��M�-�(�(�(�(���	�	�	��D�	������ ,� C� C�D�-�Ya� b� b���<�=N�O�O�O��+�+�D�-�@�@�@�	����m�4�4�4�4���5�	�	�	��D�	������
��}�
-�
-�F��"�4��0�0�J�G�Q�
��
�g�������
�
�
���
�����&�t�,�,�L� �7�7��m�L�L�M�<�
�%�d�M�<�H�H�H�H���<�<�<��	<��4�4� �*�+g�-:�,;�<�<�
<�<������D�-�0�0�0�
���D�-�0�0�0�0�0���1�
�
�
����
���sq�A�
A<�
%A7�7A<�C$�$
C1�0C1�8E�E �E �F#�#
F0�/F0�G5�5H�H�5I�I�Ic�T�|�t��}|�||��}|�tjd|z���|�d��t
krdS|�|||��|�||t
��tj	||��dS)a`
    Starts web app with specified directory for specified user
    :param user: username
    :param app_directory: application directory
    :param doc_root: Document root for selected domain
    :param apps_manager: Application Manager. Class that responsible
           for gathering and writing information about applications
    :return: None
    Nr)rX)
rr�rrar�r�update_htaccess_file�set_app_statusr
rg�r r�rRrJr�s     r&�startr�s�����*�,�,���,�,�T�=�A�A�J����&�'c�)6�(7�8�8�	8��~�~�l�#�#�'8�8�8����%�%�d�M�8�D�D�D�����m�5F�G�G�G����m�,�,�,�,�,r<c��|�t��}|�||��}|�tjd|z���|�d��t
krt
|||��dStj||��dS)ab
    Restarts web app with specified directory for specified user
    :param user: username
    :param app_directory: application directory
    :param doc_root: Document root for selected domain
    :param apps_manager: Application Manager. Class that responsible
           for gathering and writing information about applications
    :return: None
    Nr)rX)	rr�rrar�rr�r
rgr�s     r&rgrg:s�����*�,�,���,�,�T�=�A�A�J����&�'c�)6�(7�8�8�	8��~�~�l�#�#�'8�8�8�
�d�M�8�,�,�,�,�,���D�-�0�0�0�0�0r<c�~�|�t��}|�||��}|�tjd|z���|�d��t
krdS|�||||��}tj|��|�	||t
��tj
||��dS)a_
    Stops web app with specified directory for specified user
    :param user: username
    :param app_directory: application directory
    :param doc_root: Document root for selected domain
    :param apps_manager: Application Manager. Class that responsible
           for gathering and writing information about applications
    :return: None
    Nr)rX)rr�rrar�rr�r
r�r�rg)r r�rRrJr�r�s      r&�stopr�Ss�����*�,�,���,�,�T�=�A�A�J����&�'c�)6�(7�8�8�	8��~�~�l�#�#�'8�8�8���$�;�;�D�-�QY�[e�f�f���4�5F�G�G�G�����m�5F�G�G�G����m�,�,�,�,�,r<c��d}d}d}tjj�tj��t
|��stjd���d�	||���}ddi}	tj
|d	|�
��}nd#t$rW|�dd��}	tj
|d	|�
��}n%#t$rtj
||z���wxYwYnwxYw|j�
d
��}	|j�
d��}
|��	tj
|d	|�
��}n%#t$rtj
||z���wxYw|j�
d
��}|j�
d��}|	���|���ks&|
|kr|
�|
dd�dks|�(|dd�dkrtj
|||	|fz���dSdS)a@
    Check response from user's webapp before and after calling action.
    Also compare both responses
    :param domain: domain associated with webapp
    :param alias: URI associated with webapp
    :param action: called action, that make something with webapp: install modules, transit it, etc
    :return: None
    zTWeb application is inaccessible by its address "%s". The operation wasn't performed.z�The operation was performed, but check availability of application has failed. Web application is inaccessible by its address "%s" after the operation.z�The operation was performed, but check availability of application has failed. Web application responds, but its return code "%s" or content type before operation "%s" doesn't equal to contet type after operation "%s".z+Wrong action for calling in checking webappzhttps://{domain}/{alias})rUrnz
User-AgentzjMozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101209 CentOS/3.6-2.el5.centos Firefox/3.6.13F)�verify�headerszhttps://zhttp://zContent-Type�StatusN��500)�requests�packages�urllib3�disable_warnings�urllib_exceptions�InsecureRequestWarning�callablerra�formatr�r�replace�WebAppErrorr��lower)
rUrn�action�app_is_inaccessible_before�app_is_inaccessible_after�
app_is_broken�
webapp_urlr��request�before_mime_type�
before_status�after_mime_type�after_statuss
             r&�check_response_from_webappr�qs���"y��!k��m�M�
���.�.�/@�/W�X�X�X��F���V��&�'T�U�U�U�+�2�2���3���J�	�N��G�V��,�z�%��I�I�I�����V�V�V��'�'�
�I�>�>�
�	V��l�:�e�W�M�M�M�G�G���	V�	V�	V� �,�-G�*�-T�U�U�U�	V����
�G�	V������*�*�>�:�:���O�'�'��1�1�M�
�F�H�H�H�Q��,�z�%��I�I�I�����Q�Q�Q��(�)B�Z�)O�P�P�P�Q�����o�)�)�.�9�9�O��?�&�&�x�0�0�L������?�#8�#8�#:�#:�:�:�	�,�	&�	&�=�+D��WY�XY�WY�IZ�^c�Ic�Ic��(�\�"�1�"�-=��-F�-F��(��,�HX�Zi�9j�)j�k�k�k�)�(�-F�-Fs6�4B� C-�-C�C-�"C'�'C-�,C-�/E�"E)c������tjd�����tjd����d}t���}��fd�|D��}t|��dkrtjd���|d}||fS)z�
    Get info (alias and domain) about user's web application
    :param app_summary: dict -> summary info about user's web application
    :param user: str -> name of unix user
    :return: tuple -> (alias, domain)
    Nz3Was passed incorrect summary info about applicationz!Was passed incorrect name of userrnc�R��g|]#\}}tj�|�d���!|��$S)�docroot)r�realpaths_are_equal)�.0rUrRr2r s   ��r&�
<listcomp>z*_get_info_about_webapp.<locals>.<listcomp>�sN���R�R�R�'�v�x��(��x��Y�9O�P�P�R��R�R�Rr<rz-Can not found suitable domain for application)rrar
�len)r2r rn�user_domains�
found_domains�
app_domains``    r&�_get_info_about_webappr��s��������&�'\�]�]�]��|��&�'J�K�K�K��� �E��t�$�$�L�R�R�R�R�R�+7�R�R�R�M��=���Q����&�'V�W�W�W��q�!�J��*��r<�-c�N����
��|�t��}|����}	tj��|��}n5#t$r(tjd�������wxYw|dtkrd}n|d}|d}|d}	tj	����\�
}
t��|	����
����fd�}|sC	t|||�	��dS#t
j$r}tjd
|z���d}~wwxYw|��dS)a�
    Install nodejs extension to user's webapp
    :param user: name os unix user
    :param directory: directory with webapp (app-root)
    :param extension: name and version of extension
    :param skip_web_check: skip check web application after change it's properties
    :param apps_manager: Application Manager. Class that responsible
           for gathering and writing information about applications
    :return: None
    Nz%Record about application {} is absentrXTrWrUrVc�`���������tj����dS)N)�	extension�cwd)�extension_installr
rg)r�r!r$r�r s�����r&r�zinstall.<locals>.action�s5����%�%�	�s�%�C�C�C���D�)�,�,�,�,�,r<)rUrnr�z3An error occured during installation of modules. %s)
rrErr,rrrar�rr7r'r�r�)r r!r��skip_web_checkrJ�user_configrrrnr�rVr:r�rsr�r$s```          @@r&�installr��s����������*�,�,���3�3�D�9�9�K�b��0��y�+�N�N�����b�b�b��&�'N�'U�'U�V_�'`�'`�a�a�a�b�������!2�2�2������#���h�'�
��.�/�N�
�
�t�Y�
/�
/�F�C��%�d�I�~�F�F�K�-�-�-�-�-�-�-�-�-�
�
�	j�&�!���
�
�
�
�
�
��
�)�	j�	j�	j� �,�-b�eh�-h�i�i�i�����	j����	������s#�A�2A5�C-�-D�<D�Dc�l�i}ttj|����D]�\}}|dtjkr�t|||�����}|d|d|d|dd�||<d|vr*t|d��dkr|d||d<��|S)Nr%rUrn�name)rUrnr$r%�domainsr	)rr
r+rrfr4�as_deepdictr�)r �summr!�datar$s     r&r+r+�s���
�D�$�[�%8��%>�%>�?�?�
9�
9��	�4��
��"5�"A�A�A��&�t�Y��=�=�I�I�K�K���8�n��'�]�&�v�.�&�}�5�	
�
��Y�������T�)�_�!5�!5��!9�!9�)-�i��D��O�I�&���Kr<c��t|��turt�|D]$}t||t��st��%|Sr6)�type�dict�	TypeError�
isinstancer)r[�items  r&�validate_env_varsr�sL���H�~�~�T�!�!��������(�4�.�*�5�5�	��O�	��Or<)NFr6)NNNNNNNN)NN)r�FN)9�
__future__rrrr.rwr��$requests.packages.urllib3.exceptionsr�r��
exceptionsr�r��requests.exceptionsr�future.utilsr�
past.builtinsr�r
rr�clcommon.cpapir
�clcommon.utilsr�clselectexceptr�clselectnodejs.apps_managerr�clselectnodejsuserrr�baseclselectrr�
clselectprintrrbrhr'r4rrCrOrr�r�r�rgr�r�r�r�r+r��r<r&�<module>r�s���&�%�%�%�%�%�&�&�&�&�&�&�������	�	�	�	�
�
�
�
�����@�@�@�@�@�@�@�@�@�@�@�@�
�
�
�
�/�/�/�/�/�/�"�"�"�"�"�"�$�$�$�$�$�$�������������������&�&�&�&�&�&�'�'�'�'�'�'�*�*�*�*�*�*�<�<�<�<�<�<�:�:�:�:�:�:�:�:�>�>�>�>�>�>�>�>�"�"�"�"�"�"���%������
�
�
�
� >�>�>�
	5�	5�	5�����&JN�ei�CM�CM�CM�CM�LV�V�V�DL
�L
�L
�L
�^-�-�-�-�:1�1�1�1�2-�-�-�-�<6l�6l�6l�6l�r����0,�,�,�,�^���(����r<

Hacked By AnonymousFox1.0, Coded By AnonymousFox