AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/sos/report/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python3/dist-packages/sos/report/__pycache__/__init__.cpython-310.pyc
o

���b�(�@s6ddlZddlZddlZddlZddlZddlmZddlZddlZddl	m
Z
mZmZm
Z
mZmZmZddlmZddlZddlmZmZddlZddlmZddlmZddlmZddlZdd	lmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(dd
l)m*Z*ej+ej,fZ-dd
d�Z.dd�Z/gd�Z0Gdd�de�Z1dS)�N)�datetime)�ImporterHelper�SoSTimeoutError�bold�sos_get_command_output�TIMEOUT_DEFAULT�listdir�
is_executable)�rmtree)�ThreadPoolExecutor�TimeoutError)�_sos)�__version__)�SoSComponent)
�Report�Section�Command�
CopiedFile�CreatedFile�Alert�Note�PlainTextReport�
JSONReport�
HTMLReport)�
SoSCleanerF�, cCs�g}|}|r
t|�d}nd}|D]}t|�t|�t|�dkr(|�|�|}|||}q|t|�d�|krC|dt|��}|�|�|S)N� ��H)�len�append)�
first_line�items�indent�sep�lines�line�newline�item�r)�5/usr/lib/python3/dist-packages/sos/report/__init__.py�_format_list)s

r+cCst�d�|�d�S)z� This function will format --since arg to append 0s if enduser
    didn't. It's used in the _get_parser.
    This will also be a good place to add human readable and relative
    date parsing (like '2 days ago') in the future z{:<014s}z%Y%m%d%H%M%S)r�strptime�format)�dater)r)r*�
_format_since;sr/)�auto�always�nevercsbeZdZdZdZdZidd�dd�dd�dd	�d
d�dd�d
d�dd�dd	�dg�dg�dd�dd�dd�dg�dg�dd�idg�dd	�dd�dd�dd�dd�d d!�d"g�d#g�d$g�d%d�d&d�d'd�d(d�d)d�d*d	�d+g��id,d�d-e�d.e�d/g�d0d�d1d�d2d�d3g�d4d�d5d�d6d�d7d�d8d�d9d�d:d�d;d�d<d	��d=d	i�Z�fd>d?�Ze	d@dA��Z
e	dBdC��ZdDdE�ZdFdG�Z
dHdI�ZdJdK�ZdLdM�ZdNdO�ZdPdQ�ZdRdS�ZdTdU�Zd�dVdW�ZdXdY�ZdZd[�Zd\d]�Zd^d_�Zd`da�Zdbdc�Zddde�Zedfdg��Zd�dhdi�Zdjdk�Z dldm�Z!dndo�Z"dpdq�Z#drds�Z$dtdu�Z%d�dwdx�Z&dydz�Z'd{d|�Z(d}d~�Z)dd��Z*d�d��Z+d�d��Z,d�d��Z-d�d��Z.d�d��Z/d�d��Z0d�d��Z1d�d�d��Z2d�d��Z3d�d��Z4d�d��Z5d�d��Z6d�d��Z7d�d��Z8d�d��Z9d�d��Z:d�d��Z;d�d��Z<d�d��Z=d�d��Z>d�d��Z?d�d��Z@d�d��ZAd�d��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZF�ZGS)��	SoSReportzaRun a set of commands and file collections and save them to a report for
    future analysis
    z.Collect files and command output in an archiveT�
alloptionsF�all_logs�build�case_idr�chrootr0�clean�container_runtime�keep_binary_files�desc�domains�disable_parsers�dry_run�
estimate_only�experimental�enable_plugins�keywords�keyword_fileN�plugopts�label�list_plugins�list_presets�
list_profiles�log_size��map_file� /etc/sos/cleaner/default_mapping�
skip_commands�
skip_files�skip_plugins�
namespaces�	no_report�no_env_vars�no_postproc�	no_update�note�only_plugins�preset�plugin_timeout�cmd_timeout�profiles�since�verify�allow_system_changes�	usernames�upload�
upload_url�upload_directory�upload_user�upload_pass�
upload_method�upload_no_ssl_verify�upload_protocol�
add_preset�
del_presetcs�tt|��|||�g|_g|_g|_t�|_d|_||_	d|_
d|_i|_|�
�|��|j��|_|jj�d�|_|jj|jdkre|j�|jj�|_|jsetj�d|jj�|j��|_d|j_|jsn|j��|_|j�|jj�|�|j�|_t |jjd�r�|jjj!dkr�t"d�|�#�|�$�d	}|jj
|_
|jj
r�d
}n
|j�%�r�|j
t&j'kr�d}|j(�)d|j
|f�|jj*t+vr�|j(�,d
|jj*�t-�.�|j/�0�|�1d�|�2�|�3�|�4�dS)N�/�reportrXzUnknown preset: '%s'
T�	verbosityrz~
WARNING: It is not recommended to set verbosity via the preset as it might have
unforseen consequences for your report logs.
�default�cmdline�policyzset sysroot to '%s' (%s)zinvalid chroot mode: %s�)5�superr3�__init__�loaded_plugins�skipped_plugins�all_options�set�env_vars�archive�_args�sysrootrX�estimated_plugsizes�print_header�
_set_debugro�is_root�_is_root�manifest�
components�add_section�	report_md�opts�arg_defaults�find_preset�sys�stderr�write�probe_presetrH�merge�apply_options_from_cmdline�hasattrrl�print�_setup_logging�_set_directories�in_container�osr$�soslog�debugr8�chroot_modes�error�logging�shutdown�
tempfile_utilr9�_exit�_check_container_runtime�_get_namespaces�_get_hardware_devices)�self�parser�argsrn�msg��	__class__r)r*rr�sZ�


zSoSReport.__init__c
Cs&|�dd�}|jddddddd	�|jd
ddddd	�|jd
dddtdd�|jdddddd	�|jddddd�|jddddddd	�|jdddd �|jd!d"tdd#d$d%�|jd&dd'd(�|jd)dd*d(�|jd+dd,dd-d	�|jd.d/d0d1td2gd3�|jd4d5d6d0d7td8gd3�|jd9d:dd;d<d�|jd=d>dd?dd@d	�|jdAddBd(�|jdCddDddEd	�|jdFddGtdHdIdJ�|jdKddLd �|jdMdNd0dOtdPgd3�|jdQddRddSd	�|jdTddUddVd	�|jdWddXddYdZ�|jd[tdd#d\d%�|jd]d^d0d_td`gd3�|jdadtdbddc�|jdddded �|jdfddgd �|jdhdidjd0dktgdldJ�|jdmgd0dndodp�|jdqgd0drdsdp�|jdtdduddvd	�|jdwddxddyd	�|jdzddd{d|�|jd}dd~d �|jddd�d �|jd�dd�d �|jd�dd�d �|jd�dgd��d�d��|jd�ddd�d��|jd�dgd��d�d��|��}|jd�tdd�d��|jd�tdd�d��|�d�d��}|jd�d�d�d�ddd�d��|jd�d�gd0d�d��|jd�d0gd�d�d��|jd�d0gd�d�d��|jd�dd�d�d��|jd�ddd�d�d��|jd�d�d�d�d��|jd�ddd�d�dp�|jd�d�gd0d�d��dS)�NzReport Optionsz.These options control how report collects dataz-az--alloptions�
store_truer4Fz%enable all options for loaded plugins)�action�destrm�helpz
--all-logsr5z-collect all available logs regardless of sizez--since�storer\zbEscapes archived files older than date. This will also affect --all-logs. Format: YYYYMMDD[HHMMSS])r�r�rm�typer�z--buildr6z;preserve the temporary directory and do not package resultsz	--case-idr7zspecify case identifier)r�r�r�z-cz--chrootr8r0zHchroot executed commands to SYSROOT [auto, always, never] (default=auto)z--container-runtimezLDefault container runtime to use for collections. 'auto' for policy control.)rmr�z--descz
--descriptionrzDescription for a new preset)r�r�rmr�z	--dry-runz#Run plugins but do not collect data)r�r�z--estimate-onlyzzApproximate disk space requirements for a real sos run; disables --clean and --collect, sets --threads=1 and --no-postprocz--experimentalrAzenable experimental pluginsz-ez--enable-plugins�extendrBzenable these plugins)r�r�r�r�rmz-kz--plugin-optionz
--plugoptsrEz7plugin options in plugname.option=value format (see -l)z--labelz--namerFz"specify an additional report labelz-lz--list-pluginsrGz)list plugins and available plugin optionsz--list-presetsz#display a list of available presetsz--list-profilesrIzBdisplay a list of available profiles and plugins that they includez
--log-sizerJrKz)limit the size of collected logs (in MiB))r�r�r�rmr�z--namespaceszDlimit number of namespaces to collect output for - 0 means unlimitedz-nz--skip-pluginsrPzdisable these pluginsz--no-reportrRz disable plaintext/HTML reportingz
--no-env-varsrSz$Do not collect environment variablesz
--no-postprocrTzDisable all post-processing)rmr�r�r�z--notezBehaviour notes for new presetz-oz--only-pluginsrWzenable these plugins onlyz--presetzA preset identifier)r�r�r�rmz--plugin-timeoutzset a timeout for all pluginsz
--cmd-timeoutz%set a command timeout for all pluginsz-pz	--profilez
--profilesr[z)enable plugins used by the given profilesz--skip-commandsrNzdo not execute these commands)rmr�r�r�z--skip-filesrOzdo not collect these filesz--verifyr]z+perform data verification during collectionz--allow-system-changesr^zJRun commands even if they can change the system (e.g. load kernel modules)z--uploadz+Upload archive to a policy-default location)r�rmr�z--upload-urlz&Upload the archive to specified serverz--upload-directoryz$Specify upload directory for archivez
--upload-userz'Username to authenticate to server withz
--upload-passz'Password to authenticate to server withz--upload-method)r0�put�postz HTTP method to use for uploading)rm�choicesr�z--upload-no-ssl-verifyz'Disable SSL verification for upload url)rmr�r�z--upload-protocol)r0�https�ftp�sftpz$Manually specify the upload protocol�--add-presetz#Add a new named command line preset)r�r�r�z--del-presetz$Delete the named command line presetzCleaner/Masking Optionsz7These options control how data obfuscation is performedz--cleanz	--cleanerz--maskr9zObfuscate sensitive information)r�rmr�r�z	--domainsr=z$Additional domain names to obfuscatez--disable-parsersr>zCDisable specific parsers, so that those elements are not obfuscated)r�rmr�r�z
--keywordsrCzList of keywords to obfuscatez--keyword-filerDz&Provide a file a keywords to obfuscate)rmr�r�z--no-updaterUz%Do not update the default cleaner mapz
--map-filerLrMz;Provide a previously generated mapping file for obfuscation)r�rmr�z--keep-binary-filesr;zGKeep unprocessable binary files in the archive instead of removing themz--usernamesr_zList of usernames to obfuscate)�add_argument_group�add_argumentr/�str�int�add_mutually_exclusive_group)�clsr��
report_grp�
preset_grp�cleaner_grpr)r)r*�add_parser_options�s��
����
�
��
����
�
�
�
���
��
�����
�
���
�
�
���
��������
�
��
�
��
�����

�zSoSReport.add_parser_optionscCs�|�d�|�d�|�d�|�d�|jdd�}|�d�|�d�|jd	d�}|�d
td�td�f�|�d
td��dddd�}d}|D]}|jd�|||�dd�qJ|�|�dS)NzSoS Report Detailed Helpz�The report command is the most common use case for SoS, and aims to collect relevant diagnostic and troubleshooting data to assist with issue analysis without actively performing that analysis on the system while it is in use.z�Additionally, sos report archives can be used for ongoing inspection for pre-emptive issue monitoring, such as that done by the Insights project.z�The typical result of an execution of 'sos report' is a tarball that contains troubleshooting command output, copies of config files, and copies of relevant sections of the host filesystem. Root privileges are required for collections.zHow Collections Are Determined)�titlez�SoS report performs it's collections by way of 'plugins' that individually specify what files to copy and what commands to run. Plugins typically map to specific components or software packages.aEPlugins may specify different collections on different distributions, and some plugins may only be for specific distributions. Distributions are represented within SoS by 'policies' and may influence how other SoS commands or options function. For examplepolicies can alter where the --upload option defaults to or functions.zSee Alsoz>For information on available options for report, see %s and %szsos report --helpzman sos-reportz.The following %s sections may be of interest:
zsos helpz'Information on the plugin design of sosz!Information on a specific $pluginz+How sos operates on different distributions)zreport.pluginszreport.plugins.$plugin�policiesrz		{:<36}{}F)r')�	set_title�add_textr�rr-)r��section�psec�ssec�
help_lines�helpln�lnr)r)r*�display_helpysH
�����	�����zSoSReport.display_helpcCstdtdtf��dS)Nz
%s
zsosreport (version %s))r��_r�r�r)r)r*r|�szSoSReport.print_headercCs(|��|��d�|��|��d�|_dS)N)�block�fibre)�storage�network�namespaced_network)�_get_block_devs�_get_fibre_devs�_get_network_devs�_get_network_namespace_devices�devicesr�r)r)r*r��s��zSoSReport._get_hardware_devicescCs�|jjdkrc|jj��}|dvri|j_|j�d�dS|jjs,d|}|j�|�dS||jj��vrJd�	dd�|jj��D��}t
d||f��|jj||jjd	<|j�d
|jjd	j�dSdS)a[Check the loaded container runtimes, and the policy default runtime
        (if set), against any requested --container-runtime value. This can be
        useful for systems that have multiple runtimes, such as RHCOS, but do
        not have a clearly defined 'default' (or one that is determined based
        entirely on configuration).
        r0)�none�off�diabledz0Disabled all container runtimes per user option.zZWARNING: No container runtimes are active, ignoring option to set default runtime to '%s'
rcss�|]	}|dkr|VqdS)rmNr)��.0�pr)r)r*�	<genexpr>�s��z5SoSReport._check_container_runtime.<locals>.<genexpr>zSCannot use container runtime '%s': no such runtime detected. Available runtimes: %srmz%Set default container runtime to '%s'N)r�r:�lowerro�runtimesr��info�warn�keys�join�	Exception�name)r��crunr��validr)r)r*r��s0������z"SoSReport._check_container_runtimec
Cszz g}gd�}|D]}tj�d|�r|�t�d|��q	|WSty<}z|j�d|�gWYd}~Sd}~ww)z�Enumerate a list of fibrechannel devices on this system so that
        plugins can iterate over them

        These devices are used by add_device_cmd() in the Plugin class.
        )�fc_host�fc_transport�fc_remote_ports�	fc_vportsz
/sys/class/%sz/sys/class/%s/*z#Could not get fibre device list: %sN)r��path�isdirr��globr�r�r�)r��devs�devdirs�devdir�errr)r)r*r��s���zSoSReport._get_fibre_devsc
s�zDdd�t�d�D�}td�}g�|ddkr/|d��D]}|��d�dd	�}��|�q�fd
d�|D�}tt|�t|��}|WSt	y`}z|j
�d|�gWYd}~Sd}~ww)
z�Enumerate a list of block devices on this system so that plugins
        can iterate over them

        These devices are used by add_device_cmd() in the Plugin class.
        cSsg|]}d|�qS)z/dev/%sr))r��dr)r)r*�
<listcomp>�sz-SoSReport._get_block_devs.<locals>.<listcomp>z
/sys/blockzlosetup --all --noheadings�statusr�output�:rcs"g|]
}|�d�r|�vr|�qS)�loop��
startswith�r��dev��real_loop_devicesr)r*r�s
�
�z#Could not get block device list: %sN)r�rr�
splitlines�split�replacer �listrvr�r�r�)r��device_list�loop_devices�loop_dev�loop_device�ghost_loop_devs�dev_listr�r)r�r*r��s ��zSoSReport._get_block_devscCsd|��i|_dS)Nr�)�_get_network_namespacesrQr�r)r)r*r�
s
�zSoSReport._get_namespacesc
Cs�ggggd�}z,td|jjd�r|�|���|ds1|j�d�|�|���|��|d<W|SW|St	yN}z|j�
d|�WYd}~|Sd}~ww)	aHelper to encapsulate network devices probed by sos. Rather than
        probing lists of distinct device types like we do for storage, we can
        do some introspection of device enumeration where a single interface
        may have multiple device types. E.G an 'ethernet' device could also be
        a bond, and that is pertinent information for device iteration.

        :returns:   A collection of enumerated devices sorted by device type
        :rtype:     ``dict`` with keys being device types
        )�ethernet�bridge�team�bond�nmcli)rzrzZNetwork devices not enumerated by nmcli. Will attempt to manually compile list of devices.rz'Could not enumerate network devices: %sN)r	r�rz�update�_get_nmcli_devsr�r��
_get_eth_devs�_get_bridge_devsr�r�)r��_devsr�r)r)r*r�s,���	���zSoSReport._get_network_devscCs*i}|jdD]}d|�|�i||<q|S)zqEnumerate the network devices that exist within each network
        namespace that exists on the system
        r�r)rQr
)r��_nmdevs�nmspr)r)r*r�.s


�z(SoSReport._get_network_namespace_devicesc
Cs�i}zBtd�}|ddkr8|d��dd�D] }|��\}}||vr)|g||<n||�|�|d�|�qtt|d��|d<W|Sty_}z|j�d|�WYd}~|Sd}~ww)	z�Use nmcli, if available, to enumerate network devices. From this
        output, manually grok together lists of devices.
        znmcli --fields DEVICE,TYPE devr�rr�rpNrz!Could not parse nmcli devices: %s)	rr�r�r r�rvr�r�r�)r�r�_ndevsr��dname�dtyper�r)r)r*r9s"���zSoSReport._get_nmcli_devsc
s�dg�g}|s�fdd�td|jj�D�}n?z"d|}t|�}|ddkr7|d��D]}|�vr6|�|�q+WntyT}z|j�d	||f�WYd
}~nd
}~ww|dd�|D�dd�|D�d
�S)a8Enumerate a list of ethernet network devices so that plugins can
        reliably iterate over the same set of devices without doing piecemeal
        discovery.

        These devices are used by `add_device_cmd()` when `devices` includes
        "ethernet" or "network".

        :param namespace:   Inspect this existing network namespace, if
                            provided
        :type namespace:    ``str``

        :returns:   All valid ethernet devices found, potentially within a
                    given namespace
        :rtype:     ``list``
        �bonding_masterscsg|]}|�vr|�qSr)r)r���	filt_devsr)r*r�`s��z+SoSReport._get_eth_devs.<locals>.<listcomp>z/sys/class/netz"ip netns exec %s ls /sys/class/netr�rr�z6Could not determine network namespace '%s' devices: %sNcS�g|]	}|�d�r|�qS)r	r�)r��bdr)r)r*r�s�cSr)�tunr�)r��tdr)r)r*r�tr)rr	r)	rr�rzrr�r r�r�r�)r��	namespace�	_eth_devs�_nscmd�_nsout�_nsethr�r)rr*r
Ms4
�
������zSoSReport._get_eth_devscCs�g}ztddd�}Wnty$}z|j�d|�WYd}~nd}~ww|ddkr_|d��d	d�D])}z|�|��d�Wq5ty^}z|j�d
||f�WYd}~q5d}~ww|S)z�Enumerate a list of bridge devices so that plugins can reliably
        iterate over the same set of bridges.

        These devices are used by `add_device_cmd()` when `devices` includes
        "bridge" or "network".
        z
brctl show���timeoutz&Unable to enumerate bridge devices: %sNr�rr�rpz)Could not parse device from line '%s': %s)rr�r�r�r�r r�r�)r��_bridges�_boutr��_bliner)r)r*rws(������zSoSReport._get_bridge_devscCs\g}td�}|ddkr,|d��D]}|��s |dd���r!q|�|�d�d�q|S)z�Enumerate a list of network namespaces on this system so that
        plugins can iterate over them

        Note that stderr is not collected, so no handling of error lines.
        zip netnsr�rr�Nrpr)rr��isspacer �	partition)r��out_ns�ip_netnsr&r)r)r*r�sz!SoSReport._get_network_namespacescCs4|j|j|j|j|j|j|j|jj|j|j	|j
d�S)N)�cmddir�logdir�rptdir�tmpdirr�rorzrl�cmdlineoptsr�rQ)r,r-r.r/r�rorzr�rlr�rQr�r)r)r*�get_commons�s�zSoSReport.get_commonscCs
|j��S�N)r��newr�r)r)r*�
get_temp_file��
zSoSReport.get_temp_filecCs4|j�|jd�|j�|jd�|j�|jd�dS)Ni�)rx�makedirsr,r-r.r�r)r)r*�_make_archive_paths�szSoSReport._make_archive_pathscCsd|_d|_d|_dS)N�sos_commands�sos_logs�sos_reports)r,r-r.r�r)r)r*r��s
zSoSReport._set_directoriescCs$|jjr
|jt_d|_dSd|_dS)NTF)r�r��
_exceptionr��
excepthook�
raise_pluginsr�r)r)r*r}�s

zSoSReport._set_debugcCsNttd�s
tj��st�|||�dStj|||dtjd�t�t	�
�dS)z* Wrap exception in debugger if not in tty �ps1�)�limit�fileN)r�r�r��isatty�__excepthook__�	traceback�print_exception�stdoutr��pdb�pm)�etype�eval_�etracer)r)r*r;�s�zSoSReport._exceptioncCs^|js|jrt��\}}}tj|||tjd�t�t�	|�|r+|r-|�
||�dSdSdS)N)rA)r=�exit_processr��exc_inforDrErFr�rG�post_mortem�_log_plugin_exception)r��plugname�funcrI�val�tbr)r)r*�handle_exception�s
�zSoSReport.handle_exceptioncCsXt|dd�r|jj|jtj�dd�d�t|dd�r*|jj|jtj�dd�d�dSdS)N�sos_log_filer9�sos.log�r��sos_ui_log_file�ui.log)�getattrrx�add_filerUr�r�r�rXr�r)r)r*�
_add_sos_logs�s
�

��zSoSReport._add_sos_logscsT�jj}t�jj�sdSt|d�sdS|r��|���sdSt�fdd�|jD��S)NTr[Fcsg|]}|�jjv�qSr))r�r[r�r�r)r*r��sz,SoSReport._is_in_profile.<locals>.<listcomp>)r�rWrr[r��_is_not_specifiedr��any)r��plugin_classrWr)r�r*�_is_in_profile�s
zSoSReport._is_in_profilecCs||jjvSr2)r�rP�r��plugin_namer)r)r*�_is_skipped�szSoSReport._is_skippedcC�*||�����o||jjvo||jjvSr2)r1�
check_enabledr�rBrW�r�rb�pluginClassr)r)r*�_is_inactive��

�
�zSoSReport._is_inactivecCrdr2)r1�default_enabledr�rBrWrfr)r)r*�_is_not_default�rizSoSReport._is_not_defaultcCs|jjo	||jjvSr2)r�rWrar)r)r*r]�s
�zSoSReport._is_not_specified�unknowncCs"|j�|��||���|f�dSr2)rtr r�r1)r�r_�reasonr)r)r*�_skips


�zSoSReport._skipcCs |j�|��||���f�dSr2)rsr r�r1)r�r_r)r)r*�_load
s

�zSoSReport._loadcCs�tjjj}ttjj�}|��}g|_t�|_t	|j
j�}|jj}g}|j
j
r.|�tjjj�t||�}|jj}t|j
j�}	|D]�}
tj�|
�\}}z�|||�}
t	|
�sVWq@|j�|
�}|||j
j
d�s~|j�td�|
�|j
jdkr~|�|td��Wq@|j�|�|�|�}|s�|�|td��Wq@|�|�r�|�|td��Wq@|�||�r�|�|td��Wq@|�||�r�|�|td��Wq@t |d	�r�|j�!|j�|o�|}|�"|�r�|r�|�|td
��Wq@|jD]}||	vr�|	�#|�q�|�$|�Wq@t%�y}z|j�td�|
|f�|�&�WYd}~q@d}~wwt	|	�dk�r>|j�'td�d
�(|	��|�)�|�*d�dSdS)N)rAz%plugin %s does not validate, skippingrzdoes not validate�excluded�skipped�inactive�optionalr[z
not specifiedz(plugin %s does not install, skipping: %sz+Unknown or inactive profile(s) provided: %srrp)+�sosrk�plugins�
import_pluginr�get_modules�plugin_namesrvr[rr�ro�valid_subclassesrAr �ExperimentalPlugin�tuple�validate_pluginr�r�r��splitext�match_pluginr��warningr�rlrnr`rcrhrkr�rr]�removeror�rTr�r�rIr�)r�rv�helperru�using_profiles�policy_classes�
extra_classes�valid_plugin_classesr|�remaining_profiles�plug�plugbase�ext�plugin_classesr_�
in_profile�default_profile�i�er)r)r*�load_pluginss�

�
�





������zSoSReport.load_pluginscCs@|jjr|jD]\}}|j��D]
}t|jvrd|_qqdSdS)NT)r�r4rs�options�values�bool�val_type�value)r�rPr��optr)r)r*�_set_all_options_s
���zSoSReport._set_all_optionscCs�|jjr�i}|jjD]o}z	|�d�\}}Wnty d}Ynwt|t�rH|��}|dvr1d}n|dvr8d}nzt|�}Wn	tyGYnwz	|�d�\}}Wn
ty^|}d}Ynwz||Wn
tyri||<Ynw||||<q
|j	D]^\}}||vr�||D]N}||j
vr�|j�d||f�|�
d�z|j
|�|||�|j�d	||j
|f�Wq�ty�}z|j�|�|�
d�WYd}~q�d}~ww||=q}|��D]
}|j�d
|�q�|��r�|j�d�dSdSdS)N�=T)�on�enable�enabled�true�yes)r��disable�disabled�false�noF�.z#no such option "%s" for plugin (%s)rpzSet %s plugin option to %szGWARNING: unable to set option for disabled or non-existing plugin (%s).r)r�rEr��
ValueError�
isinstancer�r�r��KeyErrorrsr�r�r�r��	set_valuer�r�r�)r�r�r�rRr�rPr�r)r)r*�
_set_tunablesfsz�
���
�
�������7zSoSReport._set_tunablescCs�ddl}|�|jj|jj�D]}|�d�d}||jvr)|j�d|�|�	d�q|jj
D]}||jvr=|j�d|�q.dS)Nrr�z=a non-existing plugin (%s) was specified in the command line.rpz+Requested to skip non-existing plugin '%s'.)�	itertools�chainr�rWrBr�rxr��fatalr�rPr)r�r��pluginrbr)r)r*�_check_for_unknown_plugins�s$
�
�
�
���z$SoSReport._check_for_unknown_pluginscCs2|jD]\}}|jD]}|j�|j|�q
qdSr2)rsr�rur )r�rbr�r�r)r)r*�_set_plugin_options�s

��zSoSReport._set_plugin_optionscCs�d}g}|jjdkr|d|jjg7}d|j_|jjs$|dg7}d|j_|jjs1|dg7}d|j_|jjr>|dg7}d|j_|jjrK|d	g7}d|j_|rW|d
d�|�7}n|d7}|d
7}|S)Nz
Estimate-only mode enabledrpz--threads=%s overriden to 1z--build enabledTz--no-postproc enabledz--clean disabledFz--upload* options disabledz", which overrides some options:
  z
  r�z

)r��threadsr6rTr9r`r�)r�r��ext_msgr)r)r*�_set_estimate_only�s,



zSoSReport._set_estimate_onlycCs^|j�d�t|j�r|j�dt|j�t|j�f�n|j�dt|j��|j�d�dS)Nrz %d profiles, %d pluginsz %d profiles)�ui_logr�rrsr[r�r)r)r*�_report_profiles_and_plugins�s
�z&SoSReport._report_profiles_and_pluginsc
Cs�|js|js|j�td��dS|jr6|j�td��|j�d�|jD]\}}|j�d||��f�q$n|j�td��|j�d�|jrk|j�td��|j�d�|jD]\}}}|j�d|||��f�qX|j�d�|j�r|j�td��|jd	d
�	�}|D]=}||}|j
}|j
dkr�|dkr�|jjp�t
}n
|d
kr�|jjp�t
}nt
}|jdkr�|jj}|j�d|j||jf�q�|j�d�|j�td��|jD]:}|jdvr�|j
|jkr�q�t|j
t�r�|j
dur�d}	nd}	n|j
}	|	dur�d	}	|j�d|jd|j|	|jf�q�n|j�td��|j�d�t|j�}
|
��td|
dd�}|D]}|j�d|��q3|��dS)Nzno valid plugins foundz,The following plugins are currently enabled:rz	 %-20s %szNo plugin enabled.z-The following plugins are currently disabled:z %-20s %-14s %sz4The following options are available for ALL plugins:rrp���r$�cmd-timeout�postprocz %-25s %-15s %sz+The following plugin options are available:)r$r�r�Tr�r�r�zNo plugin options available.z
Profiles: �r#� %s)rsrtr�r�r�r�r��get_descriptionru�get_default_plugin_optsr�r�rYrrZr�rTr<rmr�r�r�r�r[�sortr+r�)
r�rPr��	plugclassrm�	_defaults�_optr�rR�tmpoptr[r%r&r)r)r*rG�s~

��
�






��
zSoSReport.list_pluginsc	Cs�|js
|j�td��dS|j�td��|j�d�dd�}t|j�}|��|D]0}g}|jD]\}}||�rC||jvrC|�	|�q1t
d||dd�}|D]
}|j�d	|�qOq*|��dS)
Nzno valid profiles foundz%The following profiles are available:rcSs
t|d�S)Nr[)r�)�cr)r)r*�	_has_prof,r5z*SoSReport.list_profiles.<locals>._has_profz%-15s Tr�r�)r[r�r�r�r�r�r�r�rsr r+r�)	r�r�r[�profilerur�r�r%r&r)r)r*rI%s&

��zSoSReport.list_profilescCs�|jjs|j�td��dS|j�td��|j�d�|jj��D]W}|s'q"|j�|�}|j�dd|j	f�|j�dd|j
f�|jrQ|j�dd|jf�|jj
dkrs|j��}d	d
}t||ddd
�}|D]}|j�|�qj|j�d�q"dS)Nzno valid presets foundz$The following presets are available:rz%14s %szname:zdescription:znote:rz%14s zoptions:Tr)r#r$)ro�presetsr�r�r�r�r�r�r�r�r<rVr�rl�to_argsr+)r�rXr��options_strr%r&r)r)r*rH;s*
�zSoSReport.list_presetsc
Cs�|j}|�|�r|j�d|�dS|p|jj}|p|jj}z|j||||jd�WntyE}z|j�d|�WYd}~dSd}~ww|j	�
d�}|j	d|�|j	|dd�}|j�d	|d
�|�f�dS)z�Add a new command line preset for the current options with the
            specified name.

            :param name: the name of the new preset
            :returns: True on success or False otherwise
        z"A preset named '%s' already existsF)r�r<rVr�zCould not add preset: %sNr�rr?z"Added preset '%s' with options %s
rT)
ror�r�r�r�r<rVrhr�rn�indexr�r�)r�r�r<rVror��	arg_indexr�r)r)r*rhSs&
�� �zSoSReport.add_presetc
Cs�|j}|�|�s|j�d|�dSz|j|d�Wnty7}z|j�t|�d�WYd}~dSd}~ww|j�d|�dS)z�Delete a named command line preset.

            :param name: the name of the preset to delete
            :returns: True on success or False otherwise
        zPreset '%s' not foundF�r��
NzDeleted preset '%s'
T)ror�r�r�rir�r�r�)r�r�ror�r)r)r*rips
��zSoSReport.del_presetc
Cs�|j��}|jjr||��7}|jjr|j�|�dS|td�7}zt	|�WdSt
y=|j�d�|�d�YdSt
yU}z
|�d|�WYd}~dSd}~ww)Nz,Press ENTER to continue, or CTRL-C to quit.
zExiting on user cancel�rp)ro�get_msgr�r@r��batchr�r�r��input�KeyboardInterruptr�r�r�)r�r�r�r)r)r*r��s
��zSoSReport.batchcCsdt��}d}d|}tj�|j|�}|j�d|||f�|j�d|�|jj	d||dd�dS)Nz!caught exception in plugin methodz%s-plugin-errors.txtz%s "%s.%s()"zwriting traceback to %s�%s
�a)�mode)
rD�
format_excr�r�r�r-r�r�rx�
add_string)r�r��method�tracer��plugin_err_log�logpathr)r)r*rO�szSoSReport._log_plugin_exceptionc
Cs�|j��z|j�td��|��|��WdSttfyH}z"|j	t
vr7td�td|j�td�ntd|��WYd}~n,d}~wt
yo}z|j�d�|j�d�t��|j�|�WYd}~nd}~ww|�d�dS)Nz Setting up archive ...rz %s while setting up archivezError setting up archive: %sz) Unexpected exception setting up archive:rp)ro�pre_workr�r�r��
setup_archiver7�OSError�IOError�errno�fatal_fs_errorsr��strerrorr�r�rD�	print_excr��r�r�r)r)r*�prework�s.


����zSoSReport.preworkcCsZ|j�td��|jD]�\}}zM|jj�|�|�t|jj|��t	�
�}|j�d|�|j
|_
|��|��|j�|j�|jjrG|��t	�
�}|j�d|�|j�d||�Wqtyd�ttfy�}z+|jtvr�|j�d�|j�d|j�|j�d�|�d�|�|d�WYd}~qd}~wty�|�|d�YqwdS)	Nz Setting up plugins ...�setup_start�	setup_end�
setup_timerz %s while setting up pluginsrp�setup) r�r�r�rsr�rur��set_plugin_manifestrZr�nowr��	add_fieldrx�add_default_collectionsr�rwr�	_env_varsr�r]�setup_verifyr�r�r�r�r�r�r�r�rTr�)r�rPr��start�endr�r)r)r*r��sD�
�
���zSoSReport.setupcCs,g}|�dt�|jjd�|�dd�dS)zWFetch version information from all plugins and store in the report
        version filez
sosreport: %sr�zversion.txt)�contentr�N)r rrxr�r�)r��versionsr)r)r*�version�s

�zSoSReport.versioncCs�|j�td��|j�d�d}g|_g|_|jD]}|d7}|j�||df�qz:g}t|jj	��}|�
|jt|j��}Wd�n1sHwY|D]}|s[|j
�d|�qO|j�d�WdStyy|j�d�t�d�YdSw)Nz! Running plugins. Please wait ...rrrpz!Unexpected plugin task result: %sz
Exiting on user cancel
)r�r�r��pluglist�
running_plugsrsr rr�r��map�_collect_pluginr�r�r�r�r�r�r�)r��plugruncountr��results�executor�resr)r)r*�collect�s4
�����zSoSReport.collectc	Cs�td���}z>|j|ddd}|�|j|�}|jpd}t��}|j�d|�|j	|d�t��}|j�d|�|j�d||�Wn=t
y�d|d}|j�d	|�|j
�|�|j�|d�|j|ddd��|jd
d�|j��YnwWd�n1s�wY|jjr�ddlm}	|	|j���}
td
d�|
�d�D��|j|d<t�|j���D]"}tj �!|j��|�}tj �"|�r�tj �#|�s�t$|�q�t�%|�q�d
S)zaWraps the collect_plugin() method so we can apply a timeout
        against the plugin as a wholerprN�
start_timer#�end_time�run_timezPlugin %s timed outz
 %s
T)�wait��PathcS�g|]}|��j�qSr)��lstat�st_size�r��fr)r)r*r��z-SoSReport._collect_plugin.<locals>.<listcomp>�**/*)&rrs�submit�collect_pluginr$rr�r�r��resultrr�r�r�r�r�r��set_timeout_hitr��_threads�clearr�r@�pathlibr�rx�get_tmp_dir�sumr�r{r�rr�r�r��islinkr
�unlink)r�r��pool�_plug�tr$r�r�r�r��tmpdir_pathrr)r)r*r��sD

����
zSoSReport._collect_pluginc	
Cs�z|\}}|j|dd}|j�|�Wn
tyYdSwt|j�}dd||f|dd�dd�|jD��f}|�|�z^|��z|j�	|�Wn	t
yVYnwz|j�	|�Wn	t
yhYnwd	}t|j�t|jj
�kr�|jr�d
ddd�dd�|jD��f}|js�|js�d}|r�|�|�WdSWdSty�YdSttfy�}z)|jtvr�|j�d
|j�|j�d|j�t�d�|�|d�WYd}~dSd}~wty�|�|d�YdSw)NrpFz  Starting %-5s %-15s %sz%d/%dz
[Running: %s]rcs��|]}|VqdSr2r)r�r)r)r*r�/��z+SoSReport.collect_plugin.<locals>.<genexpr>rz  Finishing plugins %-12s %scsrr2r)r�r)r)r*r�Drz
  Finished running pluginsz!
 %s while collecting plugin dataz& Data collected still available at %s
r�)rsr�r r�rr��ui_progressr�r�r�r�r�r�r�rr�r�r�r�r�r�r�r/r�r�rT)	r�r��countrPr��numplugs�status_liner�r�r)r)r*r$sn�

�
�����
��
��zSoSReport.collect_plugincCsR|jjdkr|jjsd|�d�}nd|}|jjs'tj�|�tj��dSdS)Nrz
%s�Zr�)	r�rlr��ljust�quietr�rFr��flush)r�rr)r)r*rYs�zSoSReport.ui_progresscCs@|jsdSd�dd�dd�|jD�D��d}|j�|d�dS)Nr�cSsg|]
\}}d||f�qS)z%s=%sr))r�r�rRr)r)r*r�es�z.SoSReport.collect_env_vars.<locals>.<listcomp>cSs0g|]}tj�|�dur|dtj�|�f�qS)Nz%s)r��environ�get)r�r�r)r)r*r�gs��environment)rwr�rxr�)r��envr)r)r*�collect_env_varsbs
��zSoSReport.collect_env_varsc
Cs�t�}|jD]p\}}t|d�}|jD]	}|�t|��q|jr'|�t|j��|jD]}|�t	|dd|dd��q*|j
D]}|�t|ddtj
�d|��d|d	�d
��q?|jD]\}}}	|�t|tj
�d|�d��q]|�|�qtddftd
dftddff}
|
D]d\}}}
z*|��}||���}|�dd���}|�|�|��|jj|tj
�d|�d�Wq�ttfy�}z'|jt vr�|j!�"d�|j!�"d|j#|
f�|j!�"d�|�$d�WYd}~q�d}~wwdS)Nr��srcpathz..�dstpath)r��href�cmdrr,rA)r��return_coder&zsos.txt�textzsos.json�JSONzsos.html�HTMLzutf-8r�r:rWrz %s while writing %s reportrp)%rrsr�alerts�addr�custom_textr�copied_filesr�executed_commandsrr�r�r�r1�copy_stringsrrrrr4�unicode�encode�decoder�rrxr[r�r�r�r�r�r�r�r�)r�rkrPr�r��alertrr'r��tags�
formatlist�class_�filename�type_�fdr�r�r)r)r*�generate_reportslsb




�

�
�
��
�
�
���zSoSReport.generate_reportscCs�|jD]_\}}z|�d�r|��n|j�d|�WqttfyT}z+|jtvrD|j	�
d�|j	�
d|j�|j	�
d�|�d�|�
|d�WYd}~qd}~wtyb|�
|d�YqwdS)Nr�zSkipping postproc for plugin %srz% %s while post-processing plugin datarp)rs�
get_optionr�r�r�r�r�r�r�r�r�r�r�rTr�)r�rPr�r�r)r)r*r��s,

��
�
���zSoSReport.postproccCsr|sdSz$d}t|d�}t�|�}	|�|�}|sn|�|�q|��W|��Sty8|��Y|��Sw)NFi�rb)	�open�hashlibr3�readr�closer�rT�	hexdigest)r�rx�	hash_name�	hash_size�
archive_fp�digest�hashdatar)r)r*�_create_checksum�s$



�
�
�zSoSReport._create_checksumcCs0t|d|d�}|r|�|d�|��dS)Nr��wr�)r?r�rB)r�rxrD�checksum�fpr)r)r*�_write_checksum�szSoSReport._write_checksumc
sd}d}d}d}|jjrLz%|j|j|j|j|jd�}td|d�}|�|j�	��|�
�\}}d}WntyK}ztt
d|��WYd}~nd}~ww|��|jdur]|j�|jj�|r�tj�|j|jj�}	|jtj�|	dd�dd�|jtj�|	dd	�d	d�|jtj�|	d
d�dd�|jj�rdd
lm�ddlm}
|
|j�}tdd�|�d�D��|jd<�t|j����}|j� d|�t!|j�"�dd�dd�dd�}
d��fdd�|
D��}|j� d|�|j� d�|j� d�|j� d�|j� d�|jj#�s�t�$d�}|jj%�stt
d ��zgz|�r"|j�&|�|j�'|jj�}WnLt(t)f�ya}z'td�tt
d!|j*|j�	�f��td�|j+t,v�rW|�-d"�WYd}~nd}~wt�yw|jj.�rn�YWt�$|�dSwWt�$|�nQt�$|�w|jj/�s�|jj0�r�|j�1d#�|j�	�}tj�2|�}ztj�|j|�}|�r�|�3|�}t�4||�|}Wnt(t)f�y�tt
d$|��YdSwd}|jj#�s�|�s�td%�n�z
|j�5�}|�6||�}Wnt�y�tt
d&��YdSwz	|�7|||�Wnt(t)f�ytt
d'|��Ynwtj�|jtj�2|��}|�r4|�3|�8d(d)��}t�9|�}|d*|}|d*|}z
t�4||�|}Wnt(t)f�ydtt
d+|��YdSwzt�4||�Wnt(t)f�y�tt
d,|��Ynw|jj#�s�|jj:|||||d-�n
|jj:||||d-�|jj;�s�|jj<�r�|jj#�s�z|j�=|�|j� t
d.��Wn#t�y�}z|j�>d/|�WYd}~n
d}~wwd0}|j�>|�t?�@�|jA�r�|jA��|j�r�tj�B|j��r�tC|j�dS)1NF)ror/�sys_tmpr�r�T)�in_place�hook_commonsz%ERROR: Unable to obfuscate report: %sr9rV)�
short_namerYr:z
manifest.jsonr��get_human_readabler�cSr�r)r�rr)r)r*r�rz(SoSReport.final_work.<locals>.<listcomp>r�sos_logs_reportszPEstimated disk space requirement for whole uncompressed sos report directory: %scSs|dS)Nrpr))�xr)r)r*�<lambda>sz&SoSReport.final_work.<locals>.<lambda>)�key�reverse�z,  c3s(�|]\}}d|�|dd�fVqdS)z%s: %sr)�	precisionNr))r�r��vrRr)r*r�s���z'SoSReport.final_work.<locals>.<genexpr>zFive biggest plugins:  %srz>Please note the estimation is relevant to the current options.z�Be aware that the real disk space requirements might be different. A rule of thumb is to reserve at least double the estimation.�?zCreating compressed archive...z %s while finalizing archive %srpzQ
Unable to encrypt when using --build. Encryption is only available for archives.zError moving directory: %sz Creating archive tarball failed.z:Error generating archive checksum after archive creation.
z#Error writing checksum for file: %sz.tarz-obfuscated.tarr�zError moving archive file: %szError moving checksum file: %s)rLzUploaded archive successfullyzUpload attempt failed: %szEUnable to upload archive when using --build as no archive is created.)Dr�r9ror/rNr�r�set_target_pathrx�get_archive_path�executer�r�r�r\�add_final_manifest_data�compression_typer�r�r��_name�obfuscate_filer@�
sos.utilitiesrSrr�rr�r{r�r�r��sortedr"r6�umaskr�rename_archive_root�finalizer�r�r�r�r�r�r��encrypt_pass�encrypt_keyr��basename�obfuscate_string�rename�get_preferred_hash_namerIrMr��stat�display_resultsr`ra�upload_archiver�r�r�r�r�r
)r�rx�	directoryrL�do_cleanrP�cleaner�_pathsr��_dirr�r�_sum�
bigplugins�bp_out�	old_umaskr��dir_name�	final_dirrKrD�
final_name�archivestat�archive_hash�
final_hashr�r)rRr*�
final_work�sD���
���


��
���


��
�
��

�


��

�
�
��
��
��

zSoSReport.final_workcCs|js
|j�td��dSdS)Nzno valid plugins were enabledFT)rsr�r�r�r�r)r)r*�verify_plugins�szSoSReport.verify_pluginscCs�|j�d|j�|j�d|jr|jjnd�|j�d|jj�|j�d�|j	�
�D]\}}|jj	�||�q*|j�d|jj�|j�d|jj�|j�d�d	S)
zgAdd 'global' data to the manifest, that is any information that is
        not plugin-specific
        rzrX�unsetr[r��enabled_plugins�disabled_pluginsruN)
r�r�rzrXr��add_listr�r[r�r�r"rBrP)r�rWr�r)r)r*�add_manifest_data�s�zSoSReport.add_manifest_datac	Cszd}|j�|tdd�|j�f�|jj��}dtd|jjd�|�f}|j�|�|j�dtdd�|j���f�dS)Nz[%s:%s] executing 'sos %s'r�rz'[%s:%s] using '%s' preset defaults (%s)z![%s:%s] effective options now: %s)	r�r��__name__r�rnrXr�r�r�)r�r��preset_argsr)r)r*�_merge_preset_options�s�
�zSoSReport._merge_preset_optionsc
Cs�z�|j�|���|��|��|��|��|��|��|j	j
r+|�
�t�|j	jr5|��t�|j	j
r?|�
�t�|j	jrK|�|j	j�WS|j	jrW|�|j	j�WS|��s^WdS|��|��|��|��|��|j	jsz|��|j	js�|��|j	js�|��n|j�d�|��|��WSt y�|j	j!r��t"�#dd�dks�|�$�Yn;t%y�|j�&d�|�$�|�'d�Yn$ty�}zt"�#dd�dks�|�$�t(�)|j*�WYd}~nd}~ww|�'d�dS)NFz)Skipping postprocessing of collected data�
SOS_TEST_LOGS�keepz
Exiting on user cancelr�rp)+ro�set_commonsr1r�r�r�r�r�r�r�rG�
SystemExitrIrHrhrir�r�r�r�r�r�rSr#rRr<rTr�r�r�r�r�r�r�r��getenv�cleanupr�r�r�r��exit�coder�r)r)r*r_�sl

���zSoSReport.executer2)NN)rl)rr)Hr��
__module__�__qualname__�__doc__r<�
root_requiredrr�rr�classmethodr�r�r|r�r�r�r�r�r�r�rr
rrr1r4r7r�r}�staticmethodr;rTr\r`rcrhrkr]rnror�r�r�r�r�r�r�rGrIrHrhrir�rOr�r�r�r�r�rrr#r<r�rIrMr�r�r�r�r_�
__classcell__r)r)r�r*r3Gs^��������	�
���
������������������� �!�"�#�$�%�&�'�(�)�*�+�,�-�.�/�0�1�2�3�4�7?
4
7

*



O;
K
	
,5	
7Gr3)Fr)2r�rDr�r�r�rr��sos.report.pluginsrtrdrrrrrrr	�shutilr
r@�concurrent.futuresrrrGr
r�r�
sos.componentr�sos.policies�sos.report.reportingrrrrrrrrrr�sos.cleanerr�ENOSPC�EROFSr�r+r/r�r3r)r)r)r*�<module>s0
$0
	

Anon7 - 2022
AnonSec Team