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__/system.cpython-310.pyc
o

�2�f�g�@shddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZddlmZmZmZmZmZmZmZddlmZmZmZdZdZdZd	Zd
ZddiZ e�!e�"e#��Z$d
Z%dZ&eddej'fdej'fde(fde(fde(fg�Z)edde(fde(fdeejfdee(fdee*fdee*fdee*fdee(fdee(fg	�Z+edd e(fde(fde(fd!e(fg�Z,ed"d#e(fd$ee*fd%ee*fg�Z-ed&d'eee(fd(eee(fg�Z.d)Z/d*ej0d+eejfd,d-�Z1d*ej0d+eejfd.d/�Z2edd0�d+e+fd1d2��Z3d3d4�Z4edd0�d+e(fd5d6��Z5edd0�d+e(fd7d8��Z6edd0�d+e-fd9d:��Z7edd0�d+e(fd;d<��Z8edd0�d+e,fd=d>��Z9edd0�de(d+e:fd?d@��Z;edd0�d+e:fdAdB��Z<edd0�de(d+e:fdCdD��Z=edd0�de(d+e:fdEdF��Z>edd0�d+e:fdGdH��Z?edd0�d�dJe(d+e:fdKdL��Z@edd0�d+e:fdMdN��ZAedd0�d+ee(e(ffdOdP��ZBedd0�de(d+e)fdQdR��ZCdSe(d+ee(fdTdU�ZD		d�dVeee(dWeee(d+e:fdXdY�ZEdZe(d+e:fd[d\�ZFd�d^e(d_e:d+e(fd`da�ZGd�d^e(dce*d+dfddde�ZH	d�d^e(dfe(dcee*d+dfdgdh�ZIdie(d+dfdjdk�ZJ		l			]d�dmee(dneee*doe:dpeeKdqeee(e(fdre:d+ee(e(ffdsdt�ZL		l				]d�dmee(dneee*doe:dpeeKdueeeKdqeee(e(fdre:d+ee(e(ffdvdw�ZMdxe(d+dfdydz�ZNd{e(d+e:fd|d}�ZOd{e(d+ee(fd~d�ZPd+e(fd�d��ZQd+ee.fd�d��ZRdS)��N)�	lru_cache)�rmtree)�Dict�List�
NamedTuple�Optional�Sequence�Set�Tuple)�defaults�
exceptions�utilz/var/run/reboot-requiredz/var/run/reboot-required.pkgsz/etc/machine-idz/var/lib/dbus/machine-idz!/usr/share/distro-info/ubuntu.csv�GenuineIntel�intelz5(?P<release>\d+\.\d+) (LTS\s*)?(\((?P<series>\w+))?.*zd^(?P<major>[\d]+)[.-](?P<minor>[\d]+)[.-](?P<patch>[\d]+)-(?P<abi>[\d]+)-(?P<flavor>[A-Za-z0-9_-]+)$�
DistroInfo�eol�eol_esm�series�release�series_codename�
KernelInfo�uname_machine_arch�
uname_release�
build_date�proc_version_signature_version�major�minor�patch�abi�flavor�ReleaseInfo�distribution�pretty_version�CpuInfo�	vendor_id�model�stepping�RebootRequiredPkgs�standard_packages�kernel_packagesz(Mon|Tue|Wed|Thu|Fri|Sat|Sun).*�uname�returncCsft�r
t�d�dSt�d�zt�d�|j��}tj�|j	tj
j�WSty2t�d�YdSw)NzPNot attempting to use timestamp of kernel changelog because we're in a containerz3Falling back to using timestamp of kernel changelogz1/usr/share/doc/linux-image-{}/changelog.Debian.gzzUnable to stat kernel changelog)
�is_container�LOG�warning�os�stat�formatr�datetime�
fromtimestamp�st_mtime�timezone�utc�	Exception)r*�stat_result�r9�1/usr/lib/python3/dist-packages/uaclient/system.py�_get_kernel_changelog_timestampgs&�
��
�
�r;cCs�t�t|j�}|durt�d�t|�S|�d�}z	tj�	|d�}Wnt
y4t�d�t|�YSw|jdurB|jtj
jd�}|S)Nz*Unable to find build date in uname versionrz%a %b %d %H:%M:%S %Z %Yz-Unable to parse build date from uname version)�tzinfo)�re�search�RE_KERNEL_EXTRACT_BUILD_DATE�versionr-r.r;�groupr2�strptime�
ValueErrorr<�replacer5r6)r*�
date_match�date_str�dtr9r9r:�_get_kernel_build_date�s


�
rH)�maxsizecCs�d}ztd�}|��d}Wntyt�d�Ynwt��}|j��}t	|�}|j
��}t�t
|�}|durLt�d|�t||||dddddd�	St||||t|�d��t|�d��t|�d��|�d	�|�d
�d�	S)Nz/proc/version_signature�z*failed to process /proc/version_signature.zFailed to parse kernel: %s)	rrrrrrrrrrrrrr)�	load_file�splitr7r-r.r/r*�machine�striprHrr=�match�RE_KERNEL_UNAMEr�intrA)r�proc_version_signature_fullr*rrr�uname_matchr9r9r:�get_kernel_info�sH�

��rTcsnddlm}t��std��dd�|�D�}dd�t�d�D�}dd�|D��d	d�|D�}�fd
d�|D�S)Nr)�get_installed_packages_namesz9get_installed_ubuntu_kernels needs to be executed as rootcSsg|]}d|vr|�qS)�linux-image-r9)�.0�packager9r9r:�
<listcomp>��
�z0get_installed_ubuntu_kernels.<locals>.<listcomp>cSs$g|]}dtd|g�dvr|�qS)zLinux kernel�filer��subp)rWr[r9r9r:rY�s
�z/boot/vmlinu[x|z]-*cS�g|]
}|td�d��qS)rVN��len)rW�package_namer9r9r:rY�s�cSr^)z/boot/vmlinu?-Nr_)rW�	file_namer9r9r:rY�s��csg|]}|�vr|�qSr9r9)rWr@��linux_image_versionsr9r:rY�rZ)�uaclient.aptrUr
�we_are_currently_root�RuntimeError�glob)rU�linux_image�vmlinux_kernel_files�vmlinuz_versionsr9rcr:�get_installed_ubuntu_kernels�s(�����
�rlcCstddg�\}}|��S)N�dpkgz--print-architecture)r]rN)�out�_errr9r9r:�
get_dpkg_arch��rpcCszztdg�\}}|��WStjy<ztd�}d|vs!d|vr%WYdSd|vr-WYdSWYdSty;YYdSww)N�systemd-detect-virtz/proc/1/cgroup�docker�buildkit�buildah�podman�)r]rNr�ProcessExecutionErrorrKr7)rn�_�
proc_1_cgroupr9r9r:�
get_virt_type�s
��r{cCs�td�}i}dD]}t�d�|�|tj�}|r |�d�}|||<q|�dd�}|�d�}|�d�}tt�||�|r=t	|�nd|rFt	|�d�Sdd�S)	Nz
/proc/cpuinfo)r$r%r&z^{}\s*:\s*(?P<info>\w*)�infor$rwr%r&)
rKr=r>r1�	MULTILINErA�getr#�CPU_VENDOR_MAPrQ)�cpu_info_content�cpu_info_values�field�	cpu_match�value�vendor_id_baser%r&r9r9r:�get_cpu_info�s,�
�



��r�cCs�ddlm}ddlm}|��}|jr!|j�di��d�}|r!|S|��}ttfD]}t	j
�|�r>t|��
d�}|r>|Sq)|rC|Stt���}|�|�|S)z�
    Get system's unique machine-id or create our own in data_dir.
    We first check for the machine-id in machine-token.json before
    looking at the system file.
    r)�
machine_token)�machine_id_file�machineTokenInfo�	machineId�
)�uaclient.filesr��uaclient.files.state_filesr��get_machine_token_filer~�read�ETC_MACHINE_ID�DBUS_MACHINE_IDr/�path�existsrK�rstrip�str�uuid�uuid4�write)�cfgr�r��machine_token_file�
machine_id�fallback_machine_idr��contentr9r9r:�get_machine_ids.���
r�cCs�t�}|�dd�}t�dd|�dd��}|�dd�}|�dd�}|r$|sSt�t|�}|s7tj|�dd�|d	��|��}|pB|�d
d�}|sKtj	|d��|pR|�dd�}t
|||��|d
�S)N�NAME�UNKNOWNz\.\d LTSz LTS�VERSIONrw�VERSION_CODENAME�
VERSION_ID)�orig_ver�mod_verr)r@r)r!rrr")�_parse_os_releaser~r=�subrO�REGEX_OS_RELEASE_VERSIONr�ParsingErrorOnOSReleaseFile�	groupdict�MissingSeriesOnOSReleaseFiler �lower)�
os_releaser!r"rrrO�
match_dictr9r9r:�get_release_info8s0���r�cC�tddg�\}}||vS)N�/usr/bin/ubuntu-distro-infoz--supported-esmr\�rrnror9r9r:�is_ltsXrqr�cC�tt�j�S�N)r�r�rr9r9r9r:�is_current_series_lts^�r�cCr�)Nr�z--supportedr\r�r9r9r:�is_supportedcrqr�cCs,t|�sdStdd|dg�\}}t|�dkS)zCReturn True when Ubuntu series supports ESM and is actively in ESM.Fr�z--seriesz-yeolr)r�r]rQr�r9r9r:�
is_active_esmis
�r�cCr�r�)r�r�rr9r9r9r:�is_current_series_active_esmtr�r��/run�run_pathc	Cs~ztdg�WdStjyYnwz	tgd��WdSttfy'YnwdD]}tj�||�}tj�|�r<dSq*dS)z>Checks to see if this code running in a container of some sort�ischrootF)rr�--quietz--containerT)�container_typezsystemd/container)	r]rrx�IOError�OSErrorr/r��joinr�)r��filenamer�r9r9r:r,ys$
���r,cCs.ddlm}|��D]
}d|jvrdSq
dS)z�Returns True if any package installed has "ubuntu-desktop" in the name.

    This includes ubuntu-desktop, ubuntu-desktop-minimal, kubuntu-desktop, etc.
    r)�aptzubuntu-desktopTF)�uaclientr��get_installed_packages�name)r�rXr9r9r:�
is_desktop�s
�r�cCsdztd�}Wn
tytd�}Ynwi}|��D]}|�dd�\}}|r/|���d�||<q|S)Nz/etc/os-releasez/usr/lib/os-release�=rJ�")rK�FileNotFoundError�
splitlinesrLrN)�
file_contents�data�line�keyr�r9r9r:r��s��r�c
Cs�ztt���}Wntyt���w|D]C}|�d�}|d|krY|dkr*d}nd|dvr4|dn|d}t|d|d	|dtj�	|dd
��
�tj�	|d
��
�d�Sqtj|d��)
N�,��xenialz
2026-04-23�LTSr��rJz%Y-%m-%d)rrrrr)r)rK�DISTRO_INFO_CSVr�r�r�MissingDistroInfoFilerLrr2rB�date�MissingSeriesInDistroInfoFile)r�linesr��valuesrr9r9r:�get_distro_info�s(�

��
r��programcCsrtjj|vrt|�r|Sdd�tj�dd��tj�D�}dd�|D�}|D]}tj�||�}t|�r6|Sq%dS)z;Find whether the provided program is executable in our PATHcSsg|]}|�d��qS)r�)rN�rW�pr9r9r:rY�s
�zwhich.<locals>.<listcomp>�PATHrwcSsg|]}tj�|��qSr9)r/r��abspathr�r9r9r:rY�sN)	r/r��sep�is_exe�environr~rL�pathsepr�)r��paths�normalized_pathsr��program_pathr9r9r:�which�s��r��installed_pkgs�installed_pkgs_regexcCs�tj�t�sdS|dur|durdSzttt��d��}Wn
ty'YdSw|dur7t	|�
|��dkr7dS|durO|D]}|D]}t�||�rMdSqAq=dS)a�Check if the system needs to be rebooted.

    :param installed_pkgs: If provided, verify if the any packages in
        the list are present on /var/run/reboot-required.pkgs. If that
        param is provided, we will only return true if we have the
        reboot-required marker file and any package in reboot-required.pkgs
        file. When both installed_pkgs and installed_pkgs_regex are
        provided, they act as an OR, so only one of the two lists must have
        a match to return True.
    :param installed_pkgs_regex: If provided, verify if the any regex in
        the list matches any line in /var/run/reboot-required.pkgs. If that
        param is provided, we will only return true if we have the
        reboot-required marker file and any match in reboot-required.pkgs
        file. When both installed_pkgs and installed_pkgs_regex are
        provided, they act as an OR, so only one of the two lists must have
        a match to return True.
    FNTr�r)
r/r�r��REBOOT_FILE_CHECK_PATH�setrK�REBOOT_PKGS_FILE_PATHrLr�r`�intersectionr=r>)r�r��reboot_required_pkgs�pkg_name�	pkg_regexr9r9r:�
should_reboot�s,����r�r�cCstj�|�ot�|tj�Sr�)r/r��isfile�access�X_OK)r�r9r9r:r�sr�Tr��decodecCsHt|d��}t�d|�|��}Wd�n1swY|�d�S)z!Read filename and decode content.�rbzReading file: %sN�utf-8)�openr-�debugr�r�)r�r��streamr�r9r9r:rKs

�
rK��modecCs@t�d|�tjtj�|�dd�t�|���t�	||�dS)NzCreating file: %sT��exist_ok)
r-r�r/�makedirsr��dirname�pathlib�Path�touch�chmod)r�r�r9r9r:�create_filesrr�c
Csd}tj�|�}|rt�|���}t�|j�}|dur|}n|dur$d}zLtjtj�	|�dd�t
jddtj�	|�d�}t�
d||j�|�|�d	��|��|��t�|j|�|rgt�|j|j|j�t�|j|�WdSty�}z|dur�t�|j�|�d}~ww)
a_Write content to the provided filename encoding it if necessary.

    We preserve the file ownership and permissions if the file is present
    and no mode argument is provided.

    @param filename: The full path of the file to write.
    @param content: The content to write to the file.
    @param mode: The filesystem mode to set on the file.
    Nr�Tr�wbF)r��delete�dirz*Writing file %s atomically via tempfile %sr�)r/r�r�rrr0�S_IMODE�st_moderr�tempfile�NamedTemporaryFiler-r�r�r��encode�flush�closer�chown�st_uid�st_gid�renamer7�unlink)r�r�r��tmpf�is_file_present�	file_stat�f_mode�er9r9r:�
write_file#s>�����r�	file_pathcCs>zt�|�t�d|�WdStyt�d|�YdSw)z<Remove a file if it exists, logging a message about removal.zRemoved file: %sz*Tried to remove %s but file does not existN)r/rr-r�r�)rr9r9r:�ensure_file_absentNs
�rF�args�rcs�capture�timeout�override_env_vars�pipe_stdouterrcCsjdd�|D�}d}d}i}	|rtj}tj}ddd�}	|dur i}itj�|	�|�}
|dur0dg}t�d�|��}ztj||||
d�}|j|d	�\}
}Wn5t	y�z |
r\|
j
d
dd�nd
}|rg|j
d
dd�nd
}tj||j
||d��tytj|d��ww|
r�|
j
d
dd�nd
}|r�|j
d
dd�nd
}|j
|vr�tj||j
||d��|r�t�d||j
|�||fS)a�Run a command and return a tuple of decoded stdout, stderr.

    @param args: A list of arguments to feed to subprocess.Popen
    @param rcs: A list of allowed return_codes. If returncode not in rcs
        raise a ProcessExecutionError.
    @param capture: Boolean set True to log the command and response.
    @param timeout: Optional float indicating number of seconds to wait for
        subp to return.
    @param override_env_vars: Optional dictionary of environment variables.
        If None, the current os.environ is used for the subprocess.
        If defined, these env vars get merged with the current process'
        os.environ for the subprocess, overriding any values that already
        existed in os.environ.

    @return: Tuple of utf-8 decoded stdout, stderr
    @raises ProcessExecutionError on invalid command or returncode not in rcs.
    @raises subprocess.TimeoutError when timeout specified and the command
        exceeds that number of seconds.
    cSs$g|]}t|t�r|n|�d��qS)r�)�
isinstance�bytesr)rW�xr9r9r:rYrs�z_subp.<locals>.<listcomp>NzC.UTF-8)�LANG�LC_ALLr� )�stdout�stderr�env)r#r��ignore)�errorsrw)�cmd�	exit_coder,r-)r1zRan cmd: %s, rc: %s stderr: %s)�
subprocess�PIPEr/r�r
�redact_sensitive_logsr��Popen�communicater�r�rrx�
returncode�UnboundLocalErrorr-r�)r r!r"r#r$r%�
bytes_argsr,r-�set_lang�
merged_env�redacted_cmd�procrn�err�
out_result�
err_resultr9r9r:�_subpWsn�
����

��rB�retry_sleepsc

Cs�|dur|��nd}	zt||||||d�\}}W||fStjy[}	z2|r7t�t|	��t�d|	j|	j	�|s:�t�t|	��t�dt
|��t�|�
d��WYd}	~	nd}	~	wwq)a�Run a command and return a tuple of decoded stdout, stderr.

     @param subp: A list of arguments to feed to subprocess.Popen
     @param rcs: A list of allowed return_codes. If returncode not in rcs
         raise a ProcessExecutionError.
     @param capture: Boolean set True to log the command and response.
     @param timeout: Optional float indicating number of seconds to wait for a
         subp call to return.
     @param retry_sleeps: Optional list of sleep lengths to apply between
        retries. Specifying a list of [0.5, 1] instructs subp to retry twice
        on failure; sleeping half a second before the first retry and 1 second
        before the next retry.
     @param override_env_vars: Optional dictionary of environment variables.
        If None, the current os.environ is used for the subprocess.
        If defined, these env vars get merged with the current process'
        os.environ for the subprocess, overriding any values that already
        existed in os.environ.

    @return: Tuple of utf-8 decoded stdout, stderr
    @raises ProcessExecutionError on invalid command or returncode not in rcs.
    @raises subprocess.TimeoutError when timeout specified and the command
        exceeds that number of seconds.
    NT)r$r%zStderr: %s
Stdout: %szRetrying %d more times.r)�copyrBrrxr-r�r�r.r-r,r`�time�sleep�pop)
r r!r"r#rCr$r%rnr?rr9r9r:r]�s2 
�
����r]�folder_pathcCs<z
t|�t�d|�WdStyt�d|�YdSw)NzRemoved folder: %sz,Tried to remove %s but folder does not exist)rr-r�r�)rHr9r9r:�ensure_folder_absent�s�rI�service_namecCs.ztddd|g�WdStjyYdSw)a^
    Get if the systemd job is active in the system. Note that any status
    different from "active" will make this function return False.
    Additionally, if the system doesn't exist we will also return False
    here.

    @param service_name: Name of the systemd job to look at

    @return: A Boolean specifying if the job is active or not
    �	systemctlz	is-activer�FT)r]rrx)rJr9r9r:�is_systemd_unit_active�s��rLc
Cs�z%tdddd|g�\}}|r|�d�r|�d�d��WSt�d|�WdStjyA}ztjd	||d
�WYd}~dSd}~ww)NrK�showz--property=ActiveStatez
--no-pagerzActiveState=r�rJz9Couldn't find ActiveState in systemctl show output for %sz-Failed to get ActiveState for systemd unit %s)�exc_info)r]�
startswithrLrNr-r.rrx)rJrnryrr9r9r:�get_systemd_unit_active_states2��	�
����rPcCsHt��rtjStj�d�}|rtj�|tj	�Stj�tj�
d�dtj	�S)N�XDG_CACHE_HOME�~z.cache)r
rfr�UAC_RUN_PATHr/r�r~r�r��USER_CACHE_SUBDIR�
expanduser)�xdg_cache_homer9r9r:�get_user_cache_dirs�rWcCsrztt�}Wn
tyYdSwg}g}d}|��D]}t�||�r)|�|�q|�|�qtt|�t|�d�S)Nz^(linux-image|linux-base).*)r(r))	rKr�r�rLr=rO�appendr'�sorted)�pkg_list_strr(r)�kernel_regex�pkgr9r9r:�get_reboot_required_pkgs)s ��r])r�)NN)T)r�r�)NFNNT)NFNNNT)Sr2rh�loggingr/rr=r0r3rrEr��	functoolsr�shutilr�typingrrrrrr	r
r�rrr
r�r�r�r�r�r�	getLogger�replace_top_level_logger_name�__name__r-r�rPr�r�rrQrr r#r'r?�uname_resultr;rHrTrlrpr{r�r�r��boolr�r�r�r�r�r,r�r�r�r�r�r�rKrrr�floatrBr]rIrLrPrWr]r9r9r9r:�<module>sn$����





����


��	��	�
��
�+#!


�
�
�
�6����
�+��
�����

�Z��
���
���

�8

Spamworldpro Mini