NineSec Team Shell
Server IP : 184.107.3.203  /  Your IP : 216.73.216.51
Web Server : Apache
System : Linux dedicated2.avenfashion.com.ph 4.18.0-553.40.1.el8_10.x86_64 #1 SMP Mon Feb 10 12:11:18 EST 2025 x86_64
User : adminteladeoro ( 1015)
PHP Version : 8.2.28
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /usr/lib/python3.6/site-packages/sos/__pycache__/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //usr/lib/python3.6/site-packages/sos/__pycache__/component.cpython-36.pyc
3

~�g(S�@s�ddlZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
m
Z
ddlmZddlm
Z
ddlmZddlmZdd	lmZdd
lmZddlmZmZGdd
�d
�ZGdd�d�ZdS)�N)�fill)�SUPPRESS)�datetime)�getpass)�rmtree)�Path)�__version__)�TarFileArchive)�
SoSOptions)�TempFileUtil�	shell_outc
@s�eZdZdZdZiZdZdZdZdZ	dddddddddd	dd
d�Z
dd
dddgZdd�Zdd�Z
dd�Zdd�Zd9dd�Zdd�Zdd�Zedd ��Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd:d+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Z dS);�SoSComponenta�Any sub-command that sos supports needs to subclass SoSComponent in
    order to be properly supported by the sos binary.

    This class contains the standardized entrypoint for subcommands, as well as
    building out supported options from both globally shared option lists, and
    options supported by that specific subcommand.

    When sos initializes, it will load an unintialized instance of each class
    found within one recursion of the module root directory that subclasses
    SoSComponent.

    If sos is able to match the user-specified subcommand to one that exists
    locally, then that SoSComponent is initialized, logging is setup, and a
    policy is loaded. From there, the component's execute() method takes over.

    Added in 4.0
    ZunsetTF�autoz/etc/sos/sos.confN��r)�batch�compression_type�config_file�debug�encrypt�encrypt_key�encrypt_pass�quiet�threads�tmp_dir�sysroot�	verbosityzsos_logs/sos.logzsos_reports/manifest.jsonzsos_commands/process/ps_*zsos_commands/selinux/ps_*z+sos_commands/systemd/systemctl_status_--allcCs�||_||_||_d|_d|_d|_d|_d|_yddl}|j|j	|j
��Wn6tk
r�}ztj
jd|�d��WYdd}~XnXt|jd�|_|jr�|j�|jj|j�|j�|_|j�rH|j�}t�|_tjj|�s�tj|tj��rd|�d�}|d7}tjj|�|j d	�||_!t"j#d
|j!d�|_t$|j�|_|j%�|jdk	�r�|jj&dt'�|jj&d
dj(|j��|jj&dt)j*��|jj&dd�|jj&dd�|jj&dd�|jj&d|j�|jj&d|j+�|jj&d|j,j-�|jj.d�dS)NFrz'Notice: Could not set SIGTERM handler: �
)�arg_defaultsztemporary directory � z"does not exist or is not writable
�zsos.)�prefix�dir�version�cmdlineZ
start_timeZend_timerZrun_timeZcompression�tmpdirZtmpdir_fs_type�policyZ
components)/�parser�argsr$�exit_process�archiver%�
tempfile_util�manifest�signal�SIGTERM�get_exit_handler�	Exception�sys�stdout�writer
�
_arg_defaults�opts�load_policy�load_local_policy�updater�load_options�configure_logging�get_tmpdir_default�SoSMetadata�os�path�isdir�access�W_OK�stderr�_exitZsys_tmp�tempfileZmkdtempr�_setup_logging�	add_fieldr�joinrZnow�	tmpfstyper&Zos_release_name�add_section)�selfr'Zparsed_argsZcmdline_argsr-�errr%�msg�rM�/usr/lib/python3.6/component.py�__init__RsT&

zSoSComponent.__init__cCs^y.ddl}|jj|jj|jd�|_|jj|_Wntk
rL|jd�YnX|jj	�|_
dS)Nr)rZ
probe_runtime)Zsos.policiesZpolicies�loadr5r�
load_prober&�KeyboardInterruptrCZis_rootZ_is_root)rJ�sosrMrMrNr7�szSoSComponent.load_local_policycCst�dS)N)�NotImplementedError)rJrMrMrN�execute�szSoSComponent.executecs�fdd�}|S)Ncsd�_�j�dS)NT)r)rC)Zsignum�frame)rJrMrN�exit_handler�sz3SoSComponent.get_exit_handler.<locals>.exit_handlerrM)rJrWrM)rJrNr/�szSoSComponent.get_exit_handlercCs(|r|jjd�|jj|�t|��dS)Nr)�ui_log�error�
SystemExit)rJrYrLrMrMrNrC�szSoSComponent._exitcCs�|jjrtjj|jj�}ntjdd�p(d}tjdd�r\tjdd�r\tjjtjd�|jd��}td|���j	�|_
|j
dkr�td	�tj
d
�|S)z�If --tmp-dir is not specified, provide a default location.
        Normally this is /var/tmp, but if we detect we are in a container, then
        use a standardized env var to redirect to the host's filesystem instead
        ZTMPDIRNz/var/tmpZHOSTZ	container�/zstat --file-system --format=%T Ztmpfsz�WARNING: tmp-dir is set to a tmpfs filesystem. This may increase memory pressure and cause instability on low memory systems, or when using --all-logs.�)r5rr=r>�abspath�getenvrG�lstripr�striprH�print�timeZsleep)rJr%rMrMrNr;�s

zSoSComponent.get_tmpdir_defaultcs6dd��jj�j�D�}|r2t�fdd�|D��SdS)NcSsg|]}|jd�r|�qS)�list)�
startswith)�.0�orMrMrN�
<listcomp>�sz6SoSComponent.check_listing_options.<locals>.<listcomp>c3s|]}t�j|�VqdS)N)�getattrr5)re�opt)rJrMrN�	<genexpr>�sz5SoSComponent.check_listing_options.<locals>.<genexpr>F)r5�dict�keys�any)rJr5rM)rJrN�check_listing_options�sz"SoSComponent.check_listing_optionscCst�dS)ziThis should be overridden by each subcommand to add its own unique
        options to the parser
        N)rT)�clsr'rMrMrN�add_parser_options�szSoSComponent.add_parser_optionsc
	sZt�j|jj|j�|jdd�d�}|jdd�}�x$|j�D�]\}}||jj�ks:|dgdgkrbq:|dkr�xFdD]>}t	|�t	t
||��@��rpt||�fd	d
�t
||�D��qpW|dk�r8t
||�}dd
�|D�}d
d
�|D�}	x6t	|�t	|	�@D]"���d���fdd
�|D�}�q�Wt||tt	|�t	|�B��q:||j|kr:t|||�q:W|S)a.(Re-)apply options specified via the cmdline to an options instance

        There are several cases where we may need to re-apply the options from
        the cmdline over previously loaded options - for instance when an
        option is specified in both a config file and cmdline, or a preset and
        the cmdline, or all three.

        Use this to re-apply cmdline option overrides to anything that may
        change the default values of options

        Positional arguments:

            :param opts:        SoSOptions object to update

        F)Z
preset_filter)rNr�enable_plugins�skip_plugins�only_pluginscsg|]}|�kr|�qSrMrM)re�x)�commonrMrNrg�sz;SoSComponent.apply_options_from_cmdline.<locals>.<listcomp>ZplugoptscSsg|]}|jd�d�qS)�=r)�split)re�vrMrMrNrg�scSsg|]}|jd�d�qS)rvr)rw)rerxrMrMrNrg�srvcsg|]}|j��s|�qSrM)rd)re�oopt)�cstringrMrNrgs)rqrrrs)rqrrrs)
r
Z	from_argsr'�
parse_argsr$rk�itemsrrl�setrh�setattrrc)
rJr5ZcmdoptsZcodictri�valryZ	oplugoptsZvalnamesZ	ovalnamesrM)rurzrN�apply_options_from_cmdline�s.
$


z'SoSComponent.apply_options_from_cmdlinecCsnt|jd�}x |jjD]}|jtkrd|_qW|j|jj|jj	�d|j
ksVd|j
krf|j|jjd�tj�dkr�tj
jtj�d�}tj
j|�r�|j||jj	�|j|�}d|_t|d��rj|j|jdk�r|jj|j�|_|j�stjjd	|j�d
��|jj�|_d|_|j�s"|jj�|_|j|jj�|j|�}t|jjd��rj|jjjdk�rj|j|jjj�|S)
zxCompile arguments loaded from defaults, config files, and the
        command line into a usable set of options
        )rNz--cleanz--mask�cleanrz.config/sos/sos.conf�presetzUnknown preset: 'z'
Tr) r
r4r'Z_actions�defaultrZupdate_from_confr(rZ	componentr$r=�getuidr>rGr�home�existsr�r��hasattrr&Zfind_presetr1rBr3Zprobe_presetZlist_presets�merger5r�set_loggers_verbosity)rJr5ZoptionZuserconfrMrMrNr9	s8



zSoSComponent.load_optionscCsry4|jr|jj�|jr"|jj�|jr2t|j�Wn8tk
rl}ztd|�d|j���WYdd}~XnXdS)NzFailed to finish cleanup: z
Contents may remain in )r*�cleanupr+r�r%rr0ra)rJrKrMrMrNr�<s

zSoSComponent.cleanupcCsbd}tjjd�r&tjjd�|j_d}n tjjd�rFtjjd�|j_d}|jj|�|jj|�dS)NzFNo encryption environment variables set, archive will not be encryptedZ
SOSENCRYPTKEYz+Encryption key set via environment variableZSOSENCRYPTPASSz2Encryption passphrase set via environment variable)	r=�environ�getr5rr�soslog�inforX)rJrLrMrMrN�_set_encrypt_from_env_varsJsz'SoSComponent._set_encrypt_from_env_varscCs�|jjs�d}x|d
kr$td�j�}qW|dkr<td�|j_q�|dkrRtd�|j_q�|dkrd|j�q�d|j_d|j_|jj	d�|j
jd	�n|j�dS)N�P�K�E�NzLSpecify encryption method [P]assphrase, [K]ey, [E]nv vars, [N]o encryption: zSpecify encryption passphrase: zSpecify encryption key: z@User specified --encrypt, but chose no encryption when prompted.zArchive will not be encrypted)r�r�r�r�)r5r�input�upperrrrr�r�r�rXZwarning)rJZ_encrMrMrN�_get_encryption_methodVs 

z#SoSComponent._get_encryption_methodcCs�|jjr|j�|jjp|jj|jj|jjd�}|s>|jj�}tjj	|j
|�}|jjdkr�|jj�}|||j
|j|jj
||j|j�|_n"t||j
|j|jj
||j|j�|_|jj|jjdk�dS)N)r�keyZpasswordrr\)r5rr�rrr&Zget_archive_namer=r>rGr%rZget_preferred_archiverrr,r*r	Z	set_debugr)rJ�nameZenc_optsZarchive_nameZauto_archiverMrMrN�
setup_archivens&




zSoSComponent.setup_archivecCsb|jj�}xR|jD]H}xBt|�j|�D]0}tjj||�}xdD]}|jj||d�q>Wq&WqWdS)N�(--upload-pass[\s=]+)\S+�$(--upload-url[\s=]+\S+://.*:)([^@]*)�!(--upload-s3-secret-key[\s=]+)\S+z
\1********)r�r�r�)	r*Zget_archive_path�files_with_upload_passwdrZglobr=r>�relpathZdo_file_sub)rJZ	_arc_pathr>�f�rerMrMrN�_obfuscate_upload_passwords�s
z(SoSComponent._obfuscate_upload_passwordscCsJtjtj�}|jtjd��|j|jjdkr2tj	ntj
�|jj|�dS)Nz%(message)sr )
�logging�
StreamHandlerr1r2�setFormatter�	Formatter�setLevelr5r�DEBUG�INFOrX�
addHandler)rJZ
ui_consolerMrMrN�add_ui_log_to_stdout�s
z!SoSComponent.add_ui_log_to_stdoutcCs\t|dd�r|r|jjtj�t|dd�rX|rJ|jjdkrJ|jjtj�n|jjtj�dS)N�flog�consoler )	rhr�r�r�r�r5rr�ZWARNING)rJrrMrMrNr��sz"SoSComponent.set_loggers_verbositycCshtjd�|_|jjtj�d|_|j�sn|j�|_tj	|j�|_|jj
tjd��|jjtj�|jj
|j�|jjs�tj	tj�|_|jj
tjd��|j|jj�|jj
|j�n4tj	tj�}|j
tjd��|jtj�|jj
|�tjd�|_|jj|jjdk�rtjntj�|j��sR|j�|_tj	|j�}|j
tjd��|jj
|�|jj�sd|j�dS)z�Creates the log handler that shall be used by all components and any
        and all related bits to those components that need to log either to the
        console or to the log file for that run of sos.
        rSNz&%(asctime)s %(levelname)s: %(message)sz%(message)sZsos_uir )r�Z	getLoggerr�r�r�r�rn�
get_temp_fileZsos_log_filer�r�r�r�r�r5rr1r2r�r�rrBZERRORrXZsos_ui_log_filer�)rJZconsole_errZui_fhandlerrMrMrNrE�s<




zSoSComponent._setup_loggingcCs
|jj�S)N)r+�new)rJrMrMrNr��szSoSComponent.get_temp_filecCs4d}d}x&|j�D]}|t||dd�d}qW|S)N�PrF)Zreplace_whitespacer)�
splitlinesr)rJrL�widthZ_fmt�linerMrMrN�_fmt_msg�s
zSoSComponent._fmt_msg)rN)r)!�__name__�
__module__�__qualname__�__doc__Zdescrr:r6rQZ
root_requiredr4r�rOr7rUr/rCr;rn�classmethodrpr�r9r�r�r�r�r�r�r�rEr�r�rMrMrMrNr
sX8

<3
	.r
c@sVeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	gfdd�Z
ddd�ZdS)r<a8This class is used to record metadata from a sos execution that will
    then be stored as a JSON-formatted manifest within the final tarball.

    It can be extended by adding further instances of SoSMetadata to represent
    dict-like structures throughout the various sos bits that record to
    metadata
    cCs
i|_dS)N)�_values)rJrMrMrNrO�szSoSMetadata.__init__ccs"x|jj�D]}|dVqWdS)Nr )r�r|)rJ�itemrMrMrN�__iter__�szSoSMetadata.__iter__cCs
|j|S)N)r�)rJr�rMrMrN�__getitem__�szSoSMetadata.__getitem__cCs
|j|S)N)r�)rJ�attrrMrMrN�__getattr__�szSoSMetadata.__getattr__cCs||j|<dS)z@Add a key, value entry to the current metadata instance
        N)r�)rJZ
field_name�contentrMrMrNrF�szSoSMetadata.add_fieldcCst�|j|<|j|S)zCAdds a new instance of SoSMetadata to the current instance
        )r<r�)rJZsection_namerMrMrNrI�szSoSMetadata.add_sectioncCs t|t�std��||j|<dS)z�Add a named list element to the current instance. If content is not
        supplied, then add an empty list that can alter be appended to
        zcontent added must be listN)�
isinstancerc�	TypeErrorr�)rJZ	list_namer�rMrMrN�add_lists
zSoSMetadata.add_listNcCstj|dd�|d�S)z�Convert contents of this SoSMetdata instance, and all other nested
        instances (sections), into a json-formatted output.

        Used to write manifest.json to the final archives.
        cSst|dt|��S)Nr�)rh�str)rfrMrMrN�<lambda>sz&SoSMetadata.get_json.<locals>.<lambda>)r��indent)�json�dumps)rJr�rMrMrN�get_jsonszSoSMetadata.get_json)N)r�r�r�r�rOr�r�r�rFrIr�r�rMrMrMrNr<�sr<)r�r�r=rDr1rb�textwrapr�argparserrrZshutilrZpathlibrrSrZsos.archiver	Zsos.optionsr
Z
sos.utilitiesrrr
r<rMrMrMrN�<module>s(G

NineSec Team - 2022