Spamworldpro Mini Shell
Spamworldpro


Server : Apache/2.4.52 (Ubuntu)
System : Linux webserver 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2 x86_64
User : www-data ( 33)
PHP Version : 8.1.2-1ubuntu2.21
Disable Function : NONE
Directory :  /lib/python3/dist-packages/uaclient/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/uaclient/__pycache__/actions.cpython-310.pyc
o

���f9�@s\ddlZddlZddlZddlZddlZddlZddlZddlmZm	Z	ddl
mZmZm
Z
mZmZmZmZmZddl
mZddl
mZmZddl
mZddl
mZmZmZddlmZdd	lmZm Z m!Z!m"Z"dd
l#m$Z$m%Z%ddl&m'Z'm(Z(m)Z)m*Z*e�+�Z,e�-e�.e/��Z0dZ1d
Z2de
j3dej4dejfdd�Z5	d9de
j3deej6dej4dejde7f
dd�Z8	d9de
j3de9de7de7ddf
dd�Z:	d:de
j3dejddfdd �Z;dd!ddd"�de
j3d#e9d$e7d%e9de7d&e	ee9fd'd(�Z<ddd)�de
j3d*e	e9d+e7fd,d-�Zd.e9ddfd/d0�Z=	d;d.e9d1e	ee>ddfd2d3�Z?de
j3fd4d5�Z@de
j3d6e9fd7d8�ZAdS)<�N)�List�Optional)�api�clouds�config�contract�entitlements�event_logger�
exceptions�	livepatch)�log)�messages�secret_manager)�status)�system�timer�util)�AutoAttachCloudInstance)�APPARMOR_PROFILES�CLOUD_BUILD_INFO�DEFAULT_CONFIG_FILE�DEFAULT_LOG_PREFIX)�
machine_token�notices)�AttachmentData�attachment_data_file�machine_id_file�timer_jobs_state_file)zapt-news.servicezesm-cache.servicezua-timer.servicezua-timer.timerzua-auto-attach.pathzua-auto-attach.servicezua-reboot-cmds.servicezubuntu-advantage.service�
�cfg�contract_client�attached_atcCs<ddlm}t�t|d��tj|d�||�|��dS)Nr��update_motd_messages�r!�r)�uaclient.timer.update_messagingr#r�writer�	ua_statusr�update_activity_token)rr r!r#�r*�2/usr/lib/python3/dist-packages/uaclient/actions.py�_handle_partial_attach9s
r,F�services_to_be_enabled�silentc

CsDd}g}g}z'|D]"}t||j|j|d�\}	}
||	M}|	s$|�|j�q	tj|jd�q	WnJtjyH}zt�|j�t	|||�|�d}~wtj
yY|�|j�d}Yntyw}zd}|�|j�|�|�WYd}~nd}~ww|s�t	|||�t�|�|r�tj
dd�t||�D�d��tjdd�|D�d��dS)	NT)r�name�variantr.)�serviceFcSs,g|]\}}|tjjt|�t��d�f�qS))�	error_msg�log_path)r
�UNEXPECTED_ERROR�format�str�pro_log�get_user_or_root_log_file_path)�.0r/�	exceptionr*r*r+�
<listcomp>rs����z,_enable_default_services.<locals>.<listcomp>)�failed_servicescSsg|]}|tjf�qSr*)r
�!E_ATTACH_FAILURE_DEFAULT_SERVICES)r9r/r*r*r+r;�s��)�enable_entitlement_by_namer/r0�append�event�service_processedr
�ConnectivityError�service_failedr,�UbuntuProError�	Exception�services_failed�AttachFailureUnknownError�zip�AttachFailureDefaultServices)
rr-r r!r.�retr<�unexpected_errors�enable_by_default_service�ent_ret�reason�exc�er*r*r+�_enable_default_servicesFs^
��
���
������rQ�token�allow_enable�returnc
Cs�ddlm}ddlm}tj�|�t�|�}t	�
|�}tjjtj
jd�}|j||d�}	t��j}
|	�di��di�}tdd	�|�d
g�D��}|�di��di��d
d�}
|
rvt�|
�}|
|
krjtj|j|jd��tjtjj|j|jd�|�|	�z||�Wntjy�}z|� �|�d}~wwtj!�"�|	�di��dt�!|��}t#�|�|r�t	�$||�%��}t&|||||d�t'�t(|d��||�t)�*�dS)aC
    Common functionality to take a token and attach via contract backend
    :raise ConnectivityError: On unexpected connectivity issues to contract
        server or inability to access identity doc from metadata service.
    :raise ContractAPIError: On unexpected errors when talking to the contract
        server.
    r)�+check_entitlement_apt_directives_are_uniquer")�tz)�contract_token�
attachment_dt�machineTokenInfo�contractInfocss,�|]}|�d�dkr|�d�|fVqdS)�type�supportN)�get)r9rPr*r*r+�	<genexpr>�s���z$attach_with_token.<locals>.<genexpr>�resourceEntitlementsr\�affordances�
onlySeriesN)�release�series_codename�	machineId)rr-r r!r.r$)+�uaclient.entitlementsrUr&r#r�secrets�
add_secretr�get_machine_token_filer�UAContractClient�datetime�now�timezone�utc�add_contract_machiner�get_release_info�seriesr]�dict�get_distro_infor
�AttachFailureRestrictedReleaserbrcr�add�Notice�LIMITED_TO_RELEASEr'�%EntitlementsAPTDirectivesAreNotUnique�delete�get_machine_id�cache_clearr�get_enabled_by_default_servicesrrQrrr�start)rrRrSr.rUr#�machine_token_filer r!�new_machine_token�current_seriesrZ�support_resource�only_series�allowed_releaserP�
machine_idr-r*r*r+�attach_with_token�sv


�
�
�
�
��
��

�
��r�T�cloudcCs0t�|�}|j|d�}|d}t|||d�dS)a\
    :raise ConnectivityError: On unexpected connectivity issues to contract
        server or inability to access identity doc from metadata service.
    :raise ContractAPIError: On unexpected errors when talking to the contract
        server.
    :raise NonAutoAttachImageError: If this cloud type does not have
        auto-attach support.
    )�instance�
contractToken)rRrSN)rri�%get_contract_token_for_cloud_instancer�)rr�rSr �
tokenResponserRr*r*r+�auto_attach�s

�r��)�access_onlyr0r.�
extra_argsr/r�r0r�c	Csftj|||||d�}|st�tjj|jd��|�t	�
��\}}|r/|s/t�tjj|jd��||fS)z�
    Constructs an entitlement based on the name provided. Passes kwargs onto
    the entitlement constructor.
    :raise EntitlementNotFoundError: If no entitlement with the given name is
        found, then raises this error.
    )rr/r0r�r�)�title)r�entitlement_factoryr@�infor
�
ENABLING_TMPLr5r��enabler�ProgressWrapper�ENABLED_TMPL)	rr/r�r0r.r��entitlementrMrNr*r*r+r>�s�r>)�simulate_with_token�show_allr�r�cCs:|rtj|||d�\}}||fStj||d�}d}||fS)z6
    Construct the current Pro status dictionary.
    )rrRr��rr�r)r(�simulate_statusr)rr�r�rrJr*r*r+rs	
�	�r�filenamec
Cs�gd�}d}d}z	t�|�\}}Wn'tjy8}zt�dt|��t�d�|�t|��WYd}~dSd}~ww|r[g}|�	d�D]
}t
�||�rO|�|�qBt�|d�
|��dSdS)z�
    Helper which gets ubuntu_pro apparmor logs from the kernel from the last
    day and writes them to the specified filename.
    )�
journalctlz-bz-kz--since=1 day agoz7apparmor=\".*(profile=\"ubuntu_pro_|name=\"ubuntu_pro_)Nz!Failed to collect kernel logs:
%s�{}-error�
)r�subpr
�ProcessExecutionError�LOG�warningr6�
write_filer5�split�re�searchr?�join)r��cmd�apparmor_re�kernel_logs�_rP�
apparmor_logs�kernel_liner*r*r+�_write_apparmor_logs_to_file*s$$��
��r��return_codesc
Csjz
tj|��|d�\}}Wntjy,}zt�d�|�t|��WYd}~dSd}~wwt�||�dS)zCHelper which runs a command and writes output or error to filename.)�rcsr�N)rr�r�r
r�r�r5r6)r�r�r��outr�rPr*r*r+�_write_command_output_to_fileCs$��r�cs,�jpt�jtjjtg�fdd�tjD��S)Nc3s(�|]}t|tjj�r|��jVqdS�N)�
issubclassr�repo�RepoEntitlement�	repo_file)r9�entitlement_clsr%r*r+r^Vs��
�z#_get_state_files.<locals>.<genexpr>)	�cfg_pathr�log_filer�ua_file�pathrr�ENTITLEMENT_CLASSESr%r*r%r+�_get_state_filesOs�
��r��
output_dirc
Cs�tdd�|��td�tj�d�|��tdd�|��tdd�|��td	�d
�dd�tD���d
�|��tD]}td�|�d�||�ddgd�q9t|dd�\}}t�d�|�t	j
|tjd��t�
�}t�d�|�t	�
|��t|�}t��r�t��dt�nt��g}t|�D]7\}}	zt�t�|	��}
t�tj�|d�|��|
�Wq�ty�}zt�d|	t|��WYd}~q�d}~ww|t�td�D]K}tj�|��rzt�|�}
Wnty�}zt�d|t|��WYd}~q�d}~wwt�|
�}
t���r	t�||
�t�tj�|tj� |��|
�q�t!d�|��t"D]1}tj�|��rRz	t#�$||�W�q"t�yQ}zt�d|t|��WYd}~�q"d}~ww�q"dS)zG
    Write all relevant Ubuntu Pro logs to the specified directory
    zcloud-idz{}/cloud-id.txtz	{} statusz{}/livepatch-status.txtzsystemctl list-timers --allz{}/systemd-timers.txtzujournalctl --boot=0 -o short-precise -u cloud-init-local.service -u cloud-init-config.service -u cloud-config.servicez{}/cloud-init-journal.txtzjournalctl -o short-precise {}� cSsg|]}d|vrd�|��qS)z.servicez-u {})r5)r9�sr*r*r+r;ysz collect_logs.<locals>.<listcomp>z{}/pro-journal.txtzsystemctl status {}z	{}/{}.txtr�)r�Fr�z{}/pro-status.json)�clsz{}/environment_vars.jsonNz
user{}.logz&Failed to collect user log file: %s
%s�*zFailed to load file: %s
%sz{}/apparmor_logs.txtzFailed to copy file: %s
%s)%r�r5r�
LIVEPATCH_CMDr��UA_SERVICESrrr��json�dumpsr�DatetimeAwareJSONEncoder�get_pro_environmentr��we_are_currently_rootr7�get_all_user_log_files�USER_LOG_COLLECTED_LIMIT�get_user_log_file�	enumerate�redact_sensitive_logs�	load_file�osr�rEr�r�r6�globr�isfile�basenamer�r�shutil�copy)
rr�r1�
pro_statusr��env_vars�state_files�user_log_files�log_file_idxr��contentrP�fr*r*r+�collect_logs^s�
�
���	���
������
�����

������r�)F)Tr�)Brjr�r��loggingr�r�r��typingrr�uaclientrrrrrr	r
rrr7r
rrr(rrr�uaclient.cloudsr�uaclient.defaultsrrrr�uaclient.filesrr�uaclient.files.state_filesrrrr�get_event_loggerr@�	getLogger�replace_top_level_logger_name�__name__r�r�r��UAConfigrir,�EnableByDefaultService�boolrQr6r�r�r>r��intr�r�r�r*r*r*r+�<module>s�(
��
������
�F�����
�V���
�������

�%���
���
�
�

Spamworldpro Mini