OwlCyberSecurity - MANAGER
Edit File: wizard.cpython-311.opt-1.pyc
� �����hJ9���������������������������d�dl�Z�d�dlZd�dlZd�dlZd�dlZd�dlmZmZmZm Z �d�dl Z d�dlmZ�d�dl mZmZmZ�d�dl mZmZ�d�dlmZ�ddlmZ�dd lmZ�dd lmZmZmZ�ddlmZmZmZm Z m!Z!�ddl"m#Z#m$Z$�dd l%m&Z&�ddl'm(Z(m)Z)m*Z*��G�d��d������������Z+dS�)�����N)�Any�Optional�Dict�NoReturn)�FormattedException)�run_command�ExternalProgramFailed�get_cl_version)�get_package_db_errors� is_ubuntu)�NoSuchModule����)�acquire_config_access)�Config)�run_installation�ALL_MODULES�get_supported_modules)�WizardStatus�ModuleStatus�CRASH_LOG_PATH�FILE_MARKER_PATH� MAIN_LOG_PATH)�CancelModuleException�InstallationFailedException)�parse_cloudlinux_wizard_opts)�is_background_process_running�run_background�setup_loggerc��������������������������e�Zd�ZdZej��������ej��������ej��������gZej ��������ej��������ej ��������gZd��Zd��Z ed����������������Zd��Zdd�Zd��Zd ��Zd ��Zd��Zd��Zd ��Zd��Zd��Zd��Zd��Zedd���������������ZdS�)�CloudlinuxWizardzAMain class for working with Wizard that exposes high level logic.c������������������n�����d�|�_���������t������������������������|�_��������t����������dt����������������������|�_��������d�S�)Nzwizard.main)�_optsr����_supported_modulesr���r����log��selfs��� �py/clwizard/wizard.py�__init__zCloudlinuxWizard.__init__>���s,�������� �"7�"9�"9���� �}�=�=���������c�����������������������t����������|������������|�_�������� �|�j��������j��������dk����r�|�������������������������������������|������������������������������������r#|�j��������j��������s|����������������������dd��������������|�������������������������������������|�j��������j��������rt�������������������������n�|�� ��������������������|�j��������j����������������������n�|�j��������j��������dk����rJ|�������������������������������������|�j��������j��������r|�� �����������������������������������nq|�������������������������������������n\|�j��������j��������dk����r |����������������������|�j��������j���������������������n,|�j��������j��������dk����r|�������������������������������������nt$�����������|�j��������j��������d v�r|������������������������������������s$|�j��������j��������dk����r<|������������������������������������s(|�������������������������������������|�������������������������������������|�������������������������������������dS�#�t,����������$�r[}|�j�����������������������������d t3����������|�������������������������|����������������������|j��������|j��������|j��������d��������������Y�d}~dS�d}~wt:����������$�r�|����������������������d d��������������Y�dS�t<����������$�r[}|�j�����������������������������dt3����������|�������������������������|����������������������dtA����������j!������������������������������������Y�d}~dS�d}~ww�xY�w)zv CL Wizard main function :param argv: command line arguments for wizard :return: None �installzInstallation already finishedr�����result� exit_code)�options�status�cancel�finish)r+���r1���z;Got an error while running cloudlinux-wizard, message: '%s')r-����context�detailsr.���Nz<Module installation failed, see the log for more informationz&Unknown error in cloudlinux-wizard, %szVUnknown error occured, please, try again or contact CloudLinux support if it persists.)r-���r4���)"r���r"���� subparser�_validate_system�is_installation_finished�force�_print_result_and_exit�_prepare_for_installation�no_asyncr����run_background_installation� json_data�initial�_get_initial_status�_get_modules_statuses�_cancel_module_installation�module�create_completion_marker�NotImplementedError�is_all_modules_installed�run_collecting_statistics�run_cagefs_force_updater���r$����error�str�messager3���r4���r���� Exception� exception� traceback� format_exc)r&����argv�errs��� r'����runzCloudlinuxWizard.runC���s^������2�$�7�7�� �> ��z�#�y�0�0��%�%�'�'�'��0�0�2�2���4�:�;K����/�/�>�!��0���������.�.�0�0�0��:�&��S�$�&�&�&�&��4�4�T�Z�=Q�4�R�R�R�R���%��1�1��%�%�'�'�'��:�%��1��,�,�.�.�.�.��.�.�0�0�0�0���%��1�1��0�0���1B�C�C�C�C���%��1�1��-�-�/�/�/�/�)�)��� �$�(=�=�=��1�1�3�3��>��� �$��0�0��9V�9V�9X�9X�0���.�.�0�0�0��,�,�.�.�.��'�'�)�)�)�)�)��!�� �� �� ��H�N�N�M�s�SV�x�x� �� �� �� �'�'��{�C�K���XY�� (�� �� �� �� �� �� �� �� �� ������+�� �� �� ��'�'�U��� (�� �� �� �� �� �� ���� �� �� ��H���G��S���R�R�R��'�'�@�!�,�.�.�� (�� �� �� �� �� �� �� �� �� ����� ���s,����G#G;��; K&�AI�$K&� K&�AK!�!K&c�������������������J�����t�����������j�����������������������������t����������������������S��N)�os�path�isfiler�����r)���r'���r7���z)CloudlinuxWizard.is_installation_finished����s��������w�~�~�.�/�/�/r)���c������������������*���� �t����������j��������t�����������������������|�j�����������������������������d�������������d�S�#�t ����������t����������f$�rJ}|�j�����������������������������dt����������|�������������������������|�� ��������������������dd��������������Y�d�}~d�S�d�}~ww�xY�w)NzWizard execution completez:Wizard 'finish' command called more than once, error: '%s'z-Wizard 'finish' command called more than oncer���r,���) rT����mknodr���r$����info�OSError�IOError�warningrI���r9���)r&���rP���s��� r'���rC���z)CloudlinuxWizard.create_completion_marker����s������� ��H�%�&�&�&��H�M�M�5�6�6�6�6�6����!�� �� �� ��H���L�c�RU�h�h� �� �� �� �'�'�F�RS�� (�� �� �� �� �� �� �� �� �� ����� ���s����37��B�?B � BNc����������������������t�����������j��������d�d�����������}|���������������������d�������������t������������������������5�}t ������������������������r|����������������������dd��������������|�|���������������������|�������������t����������|������������j��������}||_ ��������d�d�d��������������n#�1�swxY�w�Y���|����������������������d|��������������d�S�)Nz --no-asynczMUnable to start a new installation because a background task is still workingr���r,����success)r-����pid) �sysrO����appendr���r���r9����set_modulesr���r`���� worker_pid)r&���r/����cmd�configrd���s��� r'���r<���z,CloudlinuxWizard.run_background_installation����s ������h�q�q�q�k��� � �<� � � � "� $� $�� +���-�.�.�� ��+�+�9���,���������"��"�"�7�+�+�+��(��,�,�0�J� *�F�� +�� +�� +�� +�� +�� +�� +�� +�� +�� +�� +����� +�� +�� +�� +� � �#�#�9�*�#�E�E�E�E�Es����AB�B �#B c������������������R�����t�������������������������|����������������������d��������������dS�dS�)z; Check that wizard supports current system Nz�Could not identify the CloudLinux version. Restart your system. If you have the same problem again - contact CloudLinux support.�r-���)r ���r9���r%���s��� r'���r6���z!CloudlinuxWizard._validate_system����sD����������#��'�'�.�� (�� �� �� �� �� ��$�#r)���c����������������������t������������������������rfg�d�} �t����������|������������}|�j�����������������������������d|�������������dS�#�t����������$�r(}|�j�����������������������������d||��������������Y�d}~dS�d}~ww�xY�wg�d�} �t����������|������������}|�j�����������������������������d|�������������dS�#�t����������$�r(}|�j�����������������������������d||��������������Y�d}~dS�d}~ww�xY�w) z� Prepare the enviroment before performing the installation. This function updates the package lists if run on Ubuntu, expires Yum cache when running on RHEL-based systems. )zapt-getz-q�updatezapt-get update output: %sz!Error during apt-get update: '%s')�exc_infoN)�yumz-qy�cleanzexpire-cachez!yum clean expire-cache output: %sz)Error during yum clean expire-cache: '%s')r���r���r$���rZ���r ���rH����r&���re����outrP���s��� r'���r:���z*CloudlinuxWizard._prepare_for_installation����s+�������;�;�� _�-�-�-�C� W�!�#�&�&���� � �:�C�@�@�@�@�@��(�� W�� W�� W�����B�C�RU��V�V�V�V�V�V�V�V�V����� W�����:�9�9�C� _�!�#�&�&���� � �B�C�H�H�H�H�H��(�� _�� _�� _�����J�C�Z]��^�^�^�^�^�^�^�^�^����� _���s/����*A���� A2� A-�-A2�:*B&��& C�0C�Cc������������������&�����|�j���������|���������j��������S�)zGet path to module log file)r#����LOG_FILE)r&����module_names��� r'����_get_module_log_pathz%CloudlinuxWizard._get_module_log_path����s�������&�{�3�<�<r)���c������������������0����g�}t������������������������5�}|����������������������|������������}|�j��������D�]�} �|���������������������|������������}|���������������������|������������}n#�t ����������$�r�Y��:w�xY�w|||d�}|t����������j��������t����������j��������fv�r|�� ��������������������|������������|d<���|� ��������������������|��������������� �ddd�������������n#�1�swxY�w�Y���|t����������j��������k����r|�� ��������������������||t������������������������|�� ��������������������||��������������dS�)z? Get information about background worker state )r0����name�status_time�log_fileN)� wizard_status�modules� crash_log)rx���ry���)r����_get_wizard_stater#����get_module_status�get_module_status_timer ���r����FAILED�AUTO_SKIPPEDrs���rb���r����CRASHEDr9���r���)r&���ry���rf����stateru���r0���rv���� module_statuss��� r'���r@���z&CloudlinuxWizard._get_modules_statuses����s��������� "� $� $�� .���*�*�6�2�2�E��/�� .�� .���#�5�5�d�;�;�F�"(�"?�"?��"E�"E�K�K��#��������H������%� �#.�!��!� � ��l�1�<�3L�M�M�M�04�0I�0I�$�0O�0O�M�*�-����}�-�-�-�-� .� .�� .�� .�� .�� .�� .�� .�� .�� .�� .�� .����� .�� .�� .�� .� ��L�(�(�(��'�'�#�W��� (�� �� �� �� �#�#�%��#�I�I�I�I�Is5����C�*A�C� A)�&C�(A)�)AC�C�Cc����������� �������.����t������������������������}|r|����������������������|��������������dS�|����������������������d��|�j�������������������������������������������D���������������t ����������t����������t����������������������t����������|�j��������������������z ����������������������������dS�)zg Get initial modules status that is used by lvemanager to display wizard pages rh���c������������������N�����i�|�]"\��}}|�|����������������������������������������������������#S�rW���)�initial_status)�.0rr����clss��� r'���� <dictcomp>z8CloudlinuxWizard._get_initial_status.<locals>.<dictcomp>����s@������������(��S�� �����!5�!5�!7�!7�����r)���)ry����unsuppored_by_cpN)r���r9���r#����items�list�setr���)r&���� error_messages��� r'���r?���z$CloudlinuxWizard._get_initial_status����s������� �.�/�/� ��� ��'�'�}�'�=�=�=�=�=��'�'����,0�,C�,I�,I�,K�,K�������"&�c�+�&6�&6��T�=T�9U�9U�&U�!V�!V�� (�� �� �� �� �� r)���c����������������������|�j������������������������������d|�������������t������������������������5�}|���������������������|������������}||�j��������v�r=|���������������������|t����������j����������������������|�j������������������������������d|�������������n,|�j������������������������������d||�������������t����������||������������� �ddd�������������dS�#�1�swxY�w�Y���dS�)z@Remove module from queue or print the error if it's not possiblez0Trying to cancel the installation of module '%s')rr���� new_statez.Module '%s' installation successfully canceledzGUnable to cancel module '%s' installation, because it is in status '%s'N) r$���rZ���r���r|����CANCELLABLE_MODULE_STATUSES�set_module_statusr���� CANCELLEDr]���r���)r&���rB���rf���r0���s��� r'���rA���z,CloudlinuxWizard._cancel_module_installation��s(������ �� � �H�&�Q�Q�Q� "� $� $�� <���-�-�f�5�5�F���9�9�9��(�(� &�,�2H��)���������� � �N�PV�W�W�W�W��� � �3��� ������,�F�F�;�;�;��X� <�� <�� <�� <�� <�� <�� <�� <�� <�� <�� <�� <����� <�� <�� <�� <�� <�� <s����BC���C�Cc������������������f����ddg}t�����������j�����������������������������d������������s|���������������������d�������������|�j�����������������������������d������������� �t ����������|������������}|�j�����������������������������d|�������������dS�#�t����������$�r&}|�j�����������������������������d|�������������Y�d}~dS�d}~ww�xY�w) z, Collects user`s statistics z/usr/sbin/cloudlinux-summaryz--send�SYNCHRONOUS_SUMMARYz--asynczCollecting statistics...z*Statistics collection command output: '%s'z(Error during statistics collection: '%s'N) rT����environ�getrb���r$���rZ���r���r ���rH���rn���s��� r'���rF���z*CloudlinuxWizard.run_collecting_statistics��s��������.�x�8���z�~�~�3�4�4�� "��J�J�y�!�!�!��� � �0�1�1�1� L��c�"�"�C��H�M�M�F��L�L�L�L�L��$�� L�� L�� L��H�N�N�E�s�K�K�K�K�K�K�K�K�K����� L���s����*B���� B0� B+�+B0c��������������������������t������������������������5�}t����������|j�������������������������������������������������������}ddd�������������n#�1�swxY�w�Y���t ������������fd�|D���������������������������S�)zy Check that all modules were either: -- installed -- canceled -- or auto-skipped Nc��������������3����*����K����|�] }|�j���������v�V����d�S�rS�����DONE_MODULES_STATUSES�r����r0���r&���s��� �r'���� <genexpr>z<CloudlinuxWizard.is_all_modules_installed.<locals>.<genexpr>3���+�����������O�O�F�6�T�7�7�O�O�O�O�O�Or)���)r���r�����statuses�values�all�r&���rf���r����s���` r'���rE���z)CloudlinuxWizard.is_all_modules_installed)��s���������#� $� $�� 6���F�O�2�2�4�4�5�5�H� 6�� 6�� 6�� 6�� 6�� 6�� 6�� 6�� 6�� 6�� 6����� 6�� 6�� 6�� 6��O�O�O�O�h�O�O�O�O�O�Os����'A�A� Ac������������������2����d}t�����������j�����������������������������|������������sdS�|ddg}|�j�����������������������������d|�������������t����������|������������}t ����������t�����������j�����������������������������d������������������������}|r|� �����������������������������������dS�dS�)z= Runs cagefsctl --force-update in background z/usr/sbin/cagefsctlNz--force-updatez--wait-lockz2Starting cagefs force-update in the background: %s�CL_TEST_SYSTEM) rT���rU���rV���r$���rZ���r����boolr����r�����communicate)r&���� cagefsctl_binre����cagefsctl_proc�is_test_environments��� r'���rG���z(CloudlinuxWizard.run_cagefs_force_update5��s��������.� ��w�~�~�m�,�,�� ��F��.� �>���� � �J�C�P�P�P�'��,�,��"�2�:�>�>�2B�#C�#C�D�D���� )��&�&�(�(�(�(�(� )�� )r)���c�������������������������|j����������t����������j��������S� �t����������j��������|j����������������������n�#�t����������j��������$�r��t ����������|j�������������������������������������������������������}t������������fd�|D���������������������������rt����������j ��������cY�S�t����������d��|D���������������������������r't����������d��|D���������������������������st����������j��������cY�S�t����������j ��������cY�S�w�xY�wt����������j��������S�)Nc��������������3����*����K����|�] }|�j���������v�V����d�S�rS���r����r����s��� �r'���r����z5CloudlinuxWizard._get_wizard_state.<locals>.<genexpr>V��r����r)���c��������������3����J���K����|�]}|t�����������j��������t�����������j��������fv�V����d�S�rS���)r���r~���r�����r����r0���s��� r'���r����z5CloudlinuxWizard._get_wizard_state.<locals>.<genexpr>Z��sF�����������������|�2�L�4J�K�K�����������r)���c��������������3����4���K����|�]}|t�����������j��������fv�V����d�S�rS���)r���� INSTALLINGr����s��� r'���r����z5CloudlinuxWizard._get_wizard_state.<locals>.<genexpr>]��s-����������V�V�6�&�\�%<�$>�>�V�V�V�V�V�Vr)���)rd���r����IDLE�psutil�Process� NoSuchProcessr����r����r����r�����DONE�anyr~���r�����IN_PROGRESSr����s���` r'���r{���z"CloudlinuxWizard._get_wizard_stateE��s������ ���$��$�$� (��N�6�,�-�-�-�-���#�� (�� (�� (���F�O�2�2�4�4�5�5�H��O�O�O�O�h�O�O�O�O�O�� )�#�(�(�(�(�������"*����������� +���V�V�X�V�V�V�V�V� +��$�*�*�*�*��'�'�'�'�! (����$��'�'s����0��AC�>C�C�Cr_���r���c������������������������|�t����������j�����������������������d�}|���������������������|�������������t����������t����������j��������|dd��������������������������t����������j��������|�������������dS�)z� Print data in default format for web and exit :param dict extra: extra fields for the response, usually we expect 'context' here )r-���� timestamp����T)�indent� sort_keysN)�timerj����print�json�dumpsra����exit)r-���r.����extrarJ���s��� r'���r9���z'CloudlinuxWizard._print_result_and_exitc��s^�������$�$�)�+�+�>�>�����u���� �d�j���d�;�;�;�<�<�<��������r)���rS���)r_���r���)�__name__� __module__�__qualname__�__doc__r����PENDINGr~���r����r����� INSTALLEDr���r����r(���rQ����staticmethodr7���rC���r<���r6���r:���rs���r@���r?���rA���rF���rE���rG���r{���r9���rW���r)���r'���r ���r ���-���sx�������������K�K�� ������#��� �����!���>��>��>� E��E��E�N��0��0���\�0������F��F��F��F�, �� �� �_��_��_�,=��=��=�J��J��J�:�����$<��<��<�( L�� L�� L� P�� P�� P�)��)��)� (��(��(�<�� �� �� ���\� �� �� r)���r ���),r����rT���ra���r����rM����typingr���r���r���r���r�����clcommonr����clcommon.utilsr���r ���r ���r���r����clwizard.configr ���rf���r���r���ry���r���r���r���� constantsr���r���r���r���r���� exceptionsr���r����parserr����utilsr���r���r���r ���rW���r)���r'����<module>r�������s����������� � � � �� � � � ���������������0��0��0��0��0��0��0��0��0��0��0��0�� � � � ��'��'��'��'��'��'�������������������� �<��;��;��;��;��;��;��;��(��(��(��(��(��(��)��)��)��)��)��)��������������I��I��I��I��I��I��I��I��I��I�����������������������������K��J��J��J��J��J��J��J��0��0��0��0��0��0��������������������A��A��A��A��A��A��A��A��A��Ar)���