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 :  /usr/lib/python3/dist-packages/uaclient/jobs/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


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

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

F��cm9�@s�dZddlZddlZddlZddlmZddlmZddlm	Z	m
Z
ddlmZm
Z
mZmZmZmZddlmZddlmZdd	lmZmZmZmZmZd
ZdZdZd
ZdZ ej!Gdd�dej"��Z#ej!Gdd�dej"��Z$dZ%dej&de
e#e'ffdd�Z(edd�de
e)e)ffdd��Z*de)de)fdd�Z+de)d e	e)fd!d"�Z,dej&d#ej-j.d$e#d%e'd&e)d'e)d(e)d)e)fd*d+�Z/dej&d,e)ddfd-d.�Z0dej&d,e)ddfd/d0�Z1dej&de2fd1d2�Z3d3d4�Z4dej&fd5d6�Z5dS)7a%
Update messaging text for use in MOTD and APT custom Ubuntu Pro messages.

Messaging files will be emitted to /var/lib/ubuntu-advantage/message-* which
will be sourced by apt-hook/hook.cc and various /etc/update-motd.d/ hooks to
present updated text about Ubuntu Pro service and token state.
�N)�	lru_cache)�exists)�List�Tuple)�config�contract�defaults�entitlements�system�util)�identity)�ApplicationStatus)�ANNOUNCE_ESM_APPS_TMPL�'CONTRACT_EXPIRED_MOTD_GRACE_PERIOD_TMPL�"CONTRACT_EXPIRED_MOTD_NO_PKGS_TMPL�CONTRACT_EXPIRED_MOTD_PKGS_TMPL�CONTRACT_EXPIRED_MOTD_SOON_TMPLzhttps://ubuntu.com/16-04zhttps://ubuntu.com/azure/prozhttps://ubuntu.com/16-04/azurezhttps://ubuntu.com/aws/prozhttps://ubuntu.com/gcp/proc@s eZdZdZdZdZdZdZdS)�ContractExpiryStatusr����N)�__name__�
__module__�__qualname__�NONE�ACTIVE�ACTIVE_EXPIRED_SOON�EXPIRED_GRACE_PERIOD�EXPIRED�r r �@/usr/lib/python3/dist-packages/uaclient/jobs/update_messaging.pyr"src@s8eZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dS)
�ExternalMessagezmotd-no-packages-apps.tmplzmotd-no-packages-infra.tmplzmotd-packages-apps.tmplzmotd-packages-infra.tmplz$apt-pre-invoke-no-packages-apps.tmplz%apt-pre-invoke-no-packages-infra.tmplz!apt-pre-invoke-packages-apps.tmplz"apt-pre-invoke-packages-infra.tmplz!apt-pre-invoke-esm-service-statuszmotd-esm-service-statuszmotd-esm-announceN)rrr�MOTD_APPS_NO_PKGS�MOTD_INFRA_NO_PKGS�MOTD_APPS_PKGS�MOTD_INFRA_PKGS�APT_PRE_INVOKE_APPS_NO_PKGS�APT_PRE_INVOKE_INFRA_NO_PKGS�APT_PRE_INVOKE_APPS_PKGS�APT_PRE_INVOKE_INFRA_PKGS�APT_PRE_INVOKE_SERVICE_STATUS�MOTD_ESM_SERVICE_STATUS�ESM_ANNOUNCEr r r r!r",sr"z6/usr/lib/update-notifier/update-motd-updates-available�cfg�returncCs�|jstjdfStj}tj}|jj}|dur!t�	d�tj
|fSd|kr+|kr2nntj|fS||kr=dkrDnntj|fS||krNtj
|fStj
|fS)z/Return a tuple [ContractExpiryStatus, num_days]rNz:contract effectiveTo date is null - assuming it is expired)�is_attachedrrr�!CONTRACT_EXPIRY_GRACE_PERIOD_DAYS�CONTRACT_EXPIRY_PENDING_DAYS�machine_token_file�contract_remaining_days�logging�warningrrrr)r.�grace_period�pending_expiry�remaining_daysr r r!�get_contract_expiry_status@s"
�




r:)�maxsizecCs�t��\}}t��d}d}d}d}d}|dur*|�d�}|�d�}|�d�}|}|dk}|dur9|s9tjdfS|dus?|rE|rEtdfS|rM|sMtd	fS|rU|rUt	d
fS|r]|s]t
dfS|re|setdfStjdfS)
N�seriesF�aws�gce�azure�xenial�z
 for 16.04z	 on Azurez for 16.04 on Azurez on AWSz on GCP)r�get_cloud_typer
�get_platform_info�
startswithr�BASE_UA_URL�XENIAL_ESM_URL�
AZURE_PRO_URL�AZURE_XENIAL_URL�AWS_PRO_URL�GCP_PRO_URL)�cloud�_r<�is_aws�is_gcp�is_azure�non_azure_cloud�	is_xenialr r r!�get_contextual_esm_info_url[s2




rR�msg�	tmpl_filecCsB|r
t�||�dSt�|�|�d�rt�|�dd��dSdS)zhWrite a template to tmpl_file.

    When msg is empty, remove both tmpl_file and the generated msg.
    �.tmplrAN)r
�
write_file�ensure_file_absent�endswith�replace)rSrTr r r!�_write_template_or_remove}s

�rZ�msg_dir�msg_template_namescCs"|D]}tdtj�||��qdS)NrA)rZ�os�path�join)r[r\�namer r r!�_remove_msg_templates�s�ra�ent�
expiry_statusr9�	pkgs_file�no_pkgs_file�motd_pkgs_file�motd_no_pkgs_filecCs$d}}	}
}|j���dd�}d�|�}
|��dtjkr`|tjkr-t	j|d�}
|
}n3|tj
krQtj|}|j
j}|durBd}n|�d	�}tj||d
�}
|
}n|tjkr`tj|
|jd�}
t}tj�|jd�}t|	tj�||��t|tj�||��t|tj�||��t|
tj�||��dS)
a�Write any related template content for an ESM service.

    If no content is applicable for the current service state, remove
    all service-related template files.

    :param cfg: UAConfig instance for this environment.
    :param ent: entitlements.base.UAEntitlement,
    :param expiry_status: Current ContractExpiryStatus enum for attached VM.
    :param remaining_days: Int remaining days on contrat, negative when
        expired.
    :param *_file: template file names to write.
    rA�-rLz{{{}_PKG_COUNT}}r)r9N�Unknownz%d %b %Y)�expired_dater9)�pkg_num�service�messages)r`�upperrY�format�application_statusr
�ENABLEDrrrrrr1r3�contract_expiry_datetime�strftimerrrrr]r^r_�data_dirrZ)r.rbrcr9rdrerfrg�pkgs_msg�no_pkgs_msg�
motd_pkgs_msg�motd_no_pkgs_msg�tmpl_prefix�tmpl_pkg_count_var�grace_period_remaining�exp_dt�
exp_dt_strr[r r r!� _write_esm_service_msg_templates�sH

�
�
�
���r~r<c	CsRtjj}tjj}tjj}tjj}tjj}tjj}tjj}tj	j}	t
j�|j
d�}
tj|dd�}||�}tj|jdd�}
t|
pA|j�}tj|dd�}||�}t|�\}}tj}d}d}t�|�rr|��d|krkd	}n|tjkrrd	}|sv|}|r�t|||||||	|�n
t|
|||	|gd
�|r�t||||||||�dSt|
||||gd
�dS)z�Write messaging templates about available esm packages.

    :param cfg: UAConfig instance for this environment.
    :param series: string of Ubuntu release series: 'xenial'.
    rm�esm-apps�r.r`�features.allow_beta�r�
path_to_valuez	esm-infraFrT)r[r\N)r"r'�valuer)r(r*r#r%r$r&r]r^r_rtr	�entitlement_factoryr�is_config_value_truer.�bool�is_betar:r
rqr
�
is_active_esmrprr2r~ra)r.r<�apps_no_pkg_file�
apps_pkg_file�infra_no_pkg_file�infra_pkg_file�motd_apps_no_pkg_file�motd_apps_pkg_file�motd_infra_no_pkg_file�motd_infra_pkg_filer[�apps_cls�	apps_inst�config_allow_beta�
apps_valid�	infra_cls�
infra_instrcr9�enabled_status�msg_esm_apps�
msg_esm_infrar r r!�write_apt_and_motd_templates�s��

���
��
�r�cCs�tj|dd�}||�}tj}|��d|k}tj|jdd�}t|p$|j	�}t
j�|j
d�}t
j�|tjj�}	|rN|rNt�\}
}t�|	dtj|
d��d	St�|	�d	S)
aWrite human-readable messages if ESM is offered on this LTS release.

    Do not write ESM announcements if esm-apps is enabled or beta.

    :param cfg: UAConfig instance for this environment.
    :param series: string of Ubuntu release series: 'xenial'.
    rr�rr�r�rm�
)�urlN)r	r�r
rqrprr�r.r�r�r]r^r_rtr"r-r�rRr
rVrrorW)r.r<r�r�r��apps_not_enabledr��
apps_not_betar[�
esm_news_filer�rLr r r!�write_esm_announcement_message$s"�
�r�c
Cst�d�tj�|jd�}tj�|�st�|�t�	�d}t�
|�sEtD]}tj�||j�}t�
|�|�d�rBt�
|�dd��q%dSt|�\}}|tjtjfvrWt|�t||�t||�z	t�dg�WdSty�}zt�dt|��WYd	}~dSd	}~ww)
acEmit templates and human-readable status messages in msg_dir.

    These structured messages will be sourced by both /etc/update.motd.d
    and APT UA-configured hooks. APT hook content will orginate from
    apt-hook/hook.cc

    Call apt-esm-hook to render final human-readable
    messages.

    :param cfg: UAConfig instance for this environment.
    z.Updating Ubuntu Pro messages for APT and MOTD.rmr<rUrATz&/usr/lib/ubuntu-advantage/apt-esm-hookzfailed to run apt-esm-hook: %sN)r5�debugr]r^r_rtr�makedirsr
rC�is_ltsr"r�rWrXrYr:rrr�update_contract_expiryr�r��subp�	Exception�str)r.r[r<�msg_enum�msg_pathrcrL�excr r r!�update_apt_and_motd_messagesAs:




��

���r�c
Cs\tt�r%z	t�tdg�Wnty$}zt�|�WYd}~nd}~wwt�gd��dS)Nz--force)�sudo�	systemctl�restartzmotd-news.service)r�UPDATE_NOTIFIER_MOTD_SCRIPTr
r�r�r5�	exception)r�r r r!�refresh_motdos��r�cCs�|j}|�dd�}|�di��di��dd�}t�|�}|�||�}|�di��di��dd�}|r7t�|�n|jj}|jj|krQ||ddd<|j�	|�dSdS)N�machineTokenrA�machineTokenInfo�contractInfo�id�effectiveTo)
�
machine_token�getr�UAContractClient�get_updated_contract_infor�parse_rfc3339_dater3rr�write)r.�
orig_tokenr��contract_id�contract_client�resp�resp_expiry�
new_expiryr r r!r�~s2
�
�
���
���r�)6�__doc__�enumr5r]�	functoolsr�os.pathr�typingrr�uaclientrrrr	r
r�uaclient.cloudsr�(uaclient.entitlements.entitlement_statusr
�uaclient.messagesrrrrrrFrGrHrIrJ�unique�Enumrr"r��UAConfig�intr:r�rRrZra�base�
UAEntitlementr~r�r�r�r�r�r�r r r r!�<module>sj 	��

�!
�������
�@T.

Anon7 - 2022
AnonSec Team