CasperSecurity

Current Path : /lib/python3/dist-packages/cloudinit/cmd/devel/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/cmd/devel/__pycache__/logs.cpython-310.pyc

o

쑛hN7�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	m	Z	m
Z
ddlmZm
Z
mZmZmZmZmZddlmZddlmZddlmZmZddlmZdd	lmZmZmZeej e�!e"��Z#Gd
d�de�Z$e$dd
�e$dd�e$dd�gZ%e$dd�e$dd�e$dd�e$dd�e$dd�e$dd�e$dd�e$d d!�e$d"d#�e$d$d%�e$d&d%�e$d'd(�gZ&	dcd)eej'd*ej'fd+d,�Z(d-ee)d.ej*d/e)d*ee)fd0d1�Z+d-ee)d.ej*d/e)d*dfd2d3�Z,d4ej*d5ej*d6e-d*dfd7d8�Z.d9ej*d6e-d*dfd:d;�Z/d9ej*d*dfd<d=�Z0d9ej*d6e-d*dfd>d?�Z1d@e
e)efd*eej*fdAdB�Z2e�*dC�fdDej*d*eej*fdEdF�Z3dGej*d*eej*fdHdI�Z4dJej*d*eej*fdKdL�Z5d9ej*d@e
e)efdJej*dGej*d6e-d*dfdMdN�Z6e�*dO�e�*dP�dQfdRe)d@e
e)efdJej*dGej*d6e-d*dfdSdT�Z7dUe8d*dfdVdW�Z9		Q	XdddRe)dUe8dYe-dZe-d*df
d[d\�Z:d]e)d^ej;d*e8fd_d`�Z<e"dak�r�e�=e<dbe(��>���dSdS)ezGDefine 'collect-logs' utility and handler to include in cloud-init cmd.�N)�datetime�timezone)�Any�Dict�Iterator�List�
NamedTuple�Optional�cast)�loggers)�Init)�ProcessExecutionError�subp)�tempdir)�copy�get_config_logfiles�
write_filec@seZdZUeed<eed<dS)�
ApportFile�path�labelN)�__name__�
__module__�__qualname__�str�__annotations__�rr�:/usr/lib/python3/dist-packages/cloudinit/cmd/devel/logs.pyrs
rz(/var/log/installer/autoinstall-user-data�AutoInstallUserDataz/autoinstall.yaml�AutoInstallYAMLz'/etc/cloud/cloud.cfg.d/99-installer.cfg�InstallerCloudCfgz//var/log/installer/ubuntu_desktop_installer.log�UdiLogz-/var/log/installer/subiquity-server-debug.log�SubiquityServerDebugz-/var/log/installer/subiquity-client-debug.log�SubiquityClientDebugz%/var/log/installer/curtin-install.log�	CurtinLogz0/var/log/installer/subiquity-curtin-install.conf�CurtinInstallConfigz8/var/log/installer/curtin-install/subiquity-initial.conf�CurtinConfigInitialz:/var/log/installer/curtin-install/subiquity-curthooks.conf�CurtinConfigCurtHooksz8/var/log/installer/curtin-install/subiquity-extract.conf�CurtinConfigExtractz=/var/log/installer/curtin-install/subiquity-partitioning.conf�CurtinConfigPartitioningz(/var/log/installer/curtin-error-logs.tar�CurtinErrorz$/var/log/installer/curtin-errors.tarz(/var/log/installer/block/probe-data.json�	ProbeData�parser�returncCsh|s	tjddd�}|jdddddd	d
�|jddd
dd�|jddddddd�|jdddddd�|S)a2Build or extend and arg parser for collect-logs utility.

    @param parser: Optional existing ArgumentParser instance representing the
        collect-logs subcommand which will be extended to support the args of
        this utility.

    @returns: ArgumentParser with proper argument configuration.
    zcollect-logsz)Collect and tar all cloud-init debug info)�prog�descriptionz	--verbosez-v�countr�	verbosityzBe more verbose.)�action�default�dest�helpz	--tarfilez-tzcloud-init.tar.gzzOThe tarfile to create containing all collected logs. Default: cloud-init.tar.gz)r2r4z--include-userdataz-uF�
store_true�userdataz?DEPRECATED: This is default behavior and this flag does nothing)r2r1r3r4z--redact-sensitivez-rz�Redact potentially sensitive data from logs. Sensitive data may include passwords or keys in user data and root read-only files.)r2r1r4)�argparse�ArgumentParser�add_argument)r+rrr�
get_parserOsF���	�
�r:�cmd�	file_path�msgc
Cs�|jjddd�zt|�j}Wn"ty1}zt|t|��t�d|�d}WYd}~|Sd}~wwt||�t�d||j	�|S)zCHelper which runs a command and writes output or error to filename.T��parents�exist_ok�collecting %s failed.N�collected %s to file '%s')
�parent�mkdirr�stdoutr
rr�LOG�debug�stem)r;r<r=�output�errr�_write_command_output_to_file�s��
rKc
Cs�|jjddd�z|�d��}tj|||d�Wd�n1s!wYWn tyG}zt|t|��t�	d|�WYd}~dSd}~wwt�	d||j
�dS)z�Helper which runs a command and writes output or error to filename.

    `subprocess.call` is invoked directly here to stream output to the file.
    Otherwise memory usage can be high for large outputs.
    Tr>�w)rE�stderrNrArB)rCrD�open�
subprocess�call�OSErrorrrrFrGrH)r;r<r=�frJrrr�_stream_command_output_to_file�s����rSr�out_dir�include_sensitivecCsd|��r*|s|��jtj@r"|jddd�t||�t�d|�dSt�d|�dSt�d|�dS)z-Collect a file into what will be the tarball.Tr>zcollected file: %sz#sensitive file %s was not collectedzfile %s did not existN)	�is_file�stat�st_mode�S_IROTHrDrrFrG�trace)rrTrUrrr�
_collect_file�s
r[�log_dircCs|tD]}t�||jdd��j}tt�|j�|dd�q|r:tD]}t�||jdd��j}tt�|j�|dd�q dSdS)z'Obtain subiquity logs and config files.�NT)rU)�INSTALLER_APPORT_FILES�pathlib�PathrrCr[� INSTALLER_APPORT_SENSITIVE_FILES)r\rU�src_file�destination_dirrrr�_collect_installer_logs�s"
�
��rdcCs@tddg|ddd�}tgd�|ddd�}|s|pd	}d
Sd
S)z8Include cloud-init version and dpkg version in the logs.�
cloud-initz	--version�versionzcloud-init --version�r;r<r=)z
dpkg-queryz--showz-f=${Version}
rezdpkg-versionzdpkg versionz
not-availableN)rK)r\rf�dpkg_verrrr�_collect_version_info�s���ricCsL|rtdg|ddd�tgd�|ddd�tgd�t�|d	�d
d�dS)z0Include dmesg and journalctl output in the logs.�dmesgz	dmesg.txtzdmesg outputrg)�
journalctlz--boot=0�-o�
short-precisezjournal.txtzsystemd journal of current boot)rkz	--boot=-1rlrmzjournal-previous.txtz systemd journal of previous bootN)rSr_r`)r\rUrrr�_collect_system_logs�s ��

�rn�log_cfgccs �t|�D]}t�|�VqdS)z7Get paths for cloud-init.log and cloud-init-output.log.N)rr_r`)rorrrr�_get_cloudinit_logs�s��rpz
/etc/cloud�
etc_cloud_dirc#s6�|d|ddg��fdd�|�d�D�EdHdS)z�Get paths for all files in /etc/cloud.

    Excludes:
      /etc/cloud/keys because it may contain non-useful sensitive data.
      /etc/cloud/templates because we already know its contents
    �keys�	templatesz99-installer.cfgc3s(�|]}|j�vr|j�vr|VqdS�N)�namerC)�.0r��ignorerr�	<genexpr>s���z!_get_etc_cloud.<locals>.<genexpr>z**/*N��glob)rqrrwr�_get_etc_clouds�
�
�r|�	cloud_dirc	Cs:t�|�d�|�d�|�d�dd�|�d�D�|�d��S)zkGet paths for files in /var/lib/cloud.

    Skip user-provided scripts, semaphores, and old instances.
    zdata/*z
handlers/*zseed/*css�|]	}|��r|VqdSrt)rV)rv�prrrrys�z%_get_var_lib_cloud.<locals>.<genexpr>z
instance/*zinstance/handlers)�	itertools�chainr{�r}rrr�_get_var_lib_clouds�r��run_dircCs
|�d�S)z�Get all paths under /run/cloud-init except for hook-hotplug-cmd.

    Note that this only globs the top-level directory as there are currently
    no relevant files within subdirectories.
    �*rz�r�rrr�_get_run_dir$s
r�cCs�t|�t||�t||�t|�D]}t||t�|�j�d�d�qt	�
t�t|d�t
|d��D]}t||t�|�j�d�|�q2dS)z8Collect all cloud-init logs into the provided directory.�/Tr�r�N)rirnrdrpr[r_r`rC�relative_torr�r|r�r�)r\ror�r}rU�logfilerrr�_collect_logs_into_tmp_dir-s(

����r�z/run/cloud-initz/var/lib/cloudT�tarfilecCs�tj�|�}t�tj����d�}t	|d��*}t
�||�}t|||||d�t
dd|d|t|��|�d�d�g�Wd	�n1sCwYt�d
|�d	S)a�Collect all cloud-init logs and tar them up into the provided tarfile.

    :param tarfile: The path of the tar-gzipped file to create.
    :param log_cfg: The cloud-init base configuration containing logging cfg.
    :param run_dir: The path to the cloud-init run directory.
    :param cloud_dir: The path to the cloud-init cloud directory.
    :param include_sensitive: Boolean, true means include sensitive data.
    zcloud-init-logs-%Y-%m-%d)�dir)r\ror�r}rU�tar�czfz-Cr��NzWrote %s)�osr�abspathr�nowr�utc�date�strftimerr_r`r�rr�replacerF�info)r�ror�r}rU�dir_name�tmp_dirr\rrr�collect_logsNs.�����r�r0cCs^t��|dkrtj}n|dkrtj}ntj}t�|�t��}|�	t�
d��t�|�dS)z�Set up the logger for CLI use.

    The verbosity controls which level gets printed to stderr. By default,
    DEBUG and TRACE are hidden.
    rr]z%(message)sN)r�
reset_logging�logging�INFO�DEBUG�TRACErF�setLevel�
StreamHandler�setFormatter�	Formatter�
addHandler)r0�level�handlerrrr�
_setup_loggerws
r�F�redact_sensitive�include_userdatacCs|t|�t��dkrtd��|rt�d�tgd�}|��t||j	t
�|jj
�t
�|jj�|d�|s<t�d�dSdS)z:Handle calls to 'cloud-init collect-logs' as a subcommand.rz!This command must be run as root.z;The --include-userdata flag is deprecated and does nothing.)�ds_deps)r�ror�r}rUz�WARNING:
Sensitive data may have been included in the collected logs.
Please review the contents of the tarball before sharing or
rerun with --redact-sensitive to redact sensitive data.N)r�r��getuid�RuntimeErrorrF�warningr�read_cfgr��cfgr_r`�pathsr�r})r�r0r�r��initrrr�collect_logs_cli�s*�
���r��_name�argsc
Cs^t���}zt|j|j|j|jd�WdSty.}zt|t	j
d�WYd}~dSd}~ww)z}Handle the CLI interface to the module.

    Parse CLI args, redirect all exceptions to stderr, and return an exit code.
    )r0r�r�r�r)�fileNr])r:�
parse_argsr�r0r�r�r6�	Exception�print�sysrM)r�r�rJrrr�handle_collect_logs_args�s
���r��__main__r�rt)rTF)?�__doc__r7rr�r�r_rWrOr�rr�typingrrrrrr	r
�
cloudinit.logr�cloudinit.stagesr�cloudinit.subpr
r�cloudinit.temp_utilsr�cloudinit.utilrrr�CustomLoggerType�	getLoggerrrFrrar^r8r:rr`rKrS�boolr[rdrirnrpr|r�r�r�r��intr�r��	Namespacer��exitr�rrrr�<module>sJ$��	��������&��
�9���
����
����
���
���
�
�
�	��
�	�
����
�$��
����
�)�����
�!
�
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY