KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.4.41 (Ubuntu)
System : Linux vmi1525618.contaboserver.net 5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022 x86_64
User : www-data ( 33)
PHP Version : 8.2.12
Disable Function : NONE
Directory :  /lib/python3/dist-packages/certbot/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/certbot/__pycache__/util.cpython-38.pyc
U

�]\L�@sDdZddlZddlZddlZddlmZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlmZmZddlmZddlmZddlmZddlmZdd	lmZe
j	�d
�r�ddlZdZndZe�e�Z e�!d
d�Z"e�!dd�Z#dZ$dZ%dZ&ej'�(d�Z)e�*�Z+e�Z,e j-fdd�Z.dd�Z/dd�Z0dd�Z1dd�Z2dUd d!�Z3dVd#d$�Z4d%d&�Z5dWd(d)�Z6dXd+d,�Z7d-d.�Z8d/d0�Z9d1d2�Z:d3d4�Z;d5d6�Z<d7d8�Z=dYd:d;�Z>d<d=�Z?dZd>d?�Z@e
�Ad@�ZBdAdB�ZCGdCdD�dDejD�ZEdEdF�ZFdGdH�ZGdIdJ�ZHdKdL�ZIdMdN�ZJdOdP�ZKdQdR�ZLdSdT�ZMdS)[zUtilities for all Certbot.�N)�OrderedDict)�Tuple�Union)�	constants)�errors)�lock)�os)�
filesystem�linuxTF�Keyzfile pem�CSRzfile data formzzz)z$The following error was encountered:z{0}zWEither run as root, or set --config-dir, --work-dir, and --logs-dir to writeable paths.c	Cs�ztj|tjtjdd�}Wn8ttfk
rRdd�|�}||�t�|��YnX|��\}}|j	dkr�dd�|�||f}||�t�|��||fS)z�Run the script with the given params.

    :param list params: List of parameters to pass to Popen
    :param callable log: Logger method to use for errors

    T)�stdout�stderr�universal_newlineszUnable to run the command: %s� rzError while running %s.
%s
%s)
�
subprocess�Popen�PIPE�OSError�
ValueError�joinrZSubprocessError�communicate�
returncode)Zparams�log�proc�msgr
r�r�./usr/lib/python3/dist-packages/certbot/util.py�
run_scriptCs(�

�
rcCsTtj�|�\}}|rt�|�Stjd�tj�D]}t�tj�||��r0dSq0dS)z�Determine whether path/name refers to an executable.

    :param str exe: Executable path or name

    :returns: If exe is a valid executable
    :rtype: bool

    �PATHTF)r�path�splitr	Z
is_executable�environ�pathsepr)Zexer �_rrr�
exe_existsas	
r%cCs&tstt�|tkr"t�|�t|<dS)z�Lock the directory at dir_path until program exit.

    :param str dir_path: path to directory

    :raises errors.LockError: if the lock is held by another process

    N)�_LOCKS�atexit_register�_release_locksrZlock_dir)Zdir_pathrrr�lock_dir_until_exitusr)cCsNt�t�D]6}z|��Wq
d�|�}tj|dd�Yq
Xq
t��dS)Nz(Exception occurred releasing lock: {0!r}T��exc_info)�sixZ
itervaluesr&�release�format�logger�debug�clear)Zdir_lockrrrrr(�s
r(c
Cs^zt|||�t|�Wn@tk
rX}z"tjddd�t�t�|���W5d}~XYnXdS)ahEnsure directory exists with proper permissions and is locked.

    :param str directory: Path to a directory.
    :param int mode: Directory mode.
    :param bool strict: require directory to be owned by current user

    :raises .errors.LockError: if the directory cannot be locked
    :raises .errors.Error: if the directory cannot be made or verified

    zException was:Tr*N)	�make_or_verify_dirr)rr/r0r�Error�PERM_ERR_FMTr.)�	directory�mode�strict�errorrrr�set_up_core_dir�sr9��c
Csnzt�||�WnXtk
rh}z:|jtjkrV|rXt�||�sXt�d|t|�f��n�W5d}~XYnXdS)a�Make sure directory exists with proper permissions.

    :param str directory: Path to a directory.
    :param int mode: Directory mode.
    :param bool strict: require directory to be owned by current user

    :raises .errors.Error: if a directory already exists,
        but has wrong permissions or owner

    :raises OSError: if invalid or inaccessible file names and
        paths, or other arguments that have the correct type,
        but are not accepted by the operating system.

    zE%s exists, but it should be owned by current user with permissions %sN)	r	�makedirsr�errno�EEXISTZcheck_permissionsrr3�oct)r5r6r7Z	exceptionrrrr2�s
��r2�wcCsHd}|dk	r|f}d}tj|tjtjBtjBf|��}tj||f|��S)z�Safely open a file.

    :param str path: Path to a file.
    :param str mode: Same os `mode` for `open`.
    :param int chmod: Same as `mode` for `filesystem.open`, uses Python defaults
        if ``None``.

    rN)r	�openr�O_CREAT�O_EXCL�O_RDWR�fdopen)r r6�chmodZ	open_argsZfdopen_args�fdrrr�	safe_open�s	 rGc
Csntj�|||��}zt|||d�tj�|�fWStk
r^}z|jtjkrN�W5d}~XYnX|d7}qdS)N)rEr6�)rr rrG�abspathrr<r=)r �filename_pat�countrEr6Zcurrent_path�errrrr�_unique_file�s
�rM�cs*tj�|�\}�t|�fdd�d||d�S)z�Safely finds a unique file.

    :param str path: path/filename.ext
    :param int chmod: File mode
    :param str mode: Open mode

    :returns: tuple of file object and file name

    csd|�fS)Nz%04d_%sr�rK��tailrr�<lambda>��zunique_file.<locals>.<lambda>r�rJrKrEr6)rr r!rM)r rEr6rrPr�unique_file�s

�rU�c
sptj�|d��}zt||d�|fWStk
rT}z|jtjkrD�W5d}~XYnXt|�fdd�d||d�S)aSafely finds a unique file using lineage convention.

    :param str path: directory path
    :param str filename: proposed filename
    :param int chmod: file mode
    :param str mode: open mode

    :returns: tuple of file object and file name (which may be modified
        from the requested one by appending digits to ensure uniqueness)

    :raises OSError: if writing files fails for an unanticipated reason,
        such as a full disk or a lack of permission to write to
        specified location.

    z%s.conf)rENcsd�|fS)Nz%s-%04d.confrrO��filenamerrrRrSz%unique_lineage_name.<locals>.<lambda>rHrT)rr rrGrr<r=rM)r rXrEr6Zpreferred_pathrLrrWr�unique_lineage_name�s
�rYc
CsDzt�|�Wn0tk
r>}z|jtjkr.�W5d}~XYnXdS)z!Remove a file that may not exist.N)r�removerr<ZENOENT)r rLrrr�
safely_removes
r[c	CsNt�}|D]>}z|�t|��Wq
tjk
rFtjd|dd�Yq
Xq
|S)z�Removes names that aren't considered valid by Let's Encrypt.

    :param set all_names: all names found in the configuration

    :returns: all found names that are considered valid by LE
    :rtype: set

    zNot suggesting name "%s"Tr*)�set�add�enforce_le_validityr�ConfigurationErrorr/r0)Z	all_namesZfiltered_names�namerrr�get_filtered_namess	racCs
tdd�S)zc
    Get OS name and version

    :returns: (os_name, os_version)
    :rtype: `tuple` of `str`
    F��pretty)�get_python_os_inforrrr�get_os_infosrecCs,trtjdd�}tr|s(d�tdd��S|S)z^
    Get OS name and version string for User Agent

    :returns: os_ua
    :rtype: `str`
    Trbr)�_USE_DISTRO�distror`rrd)Zos_inforrr�get_os_info_ua)s
rhcCstjdtdd�t�dd�S)z�
    Parse systemd /etc/os-release for distribution information

    :returns: (os_name, os_version)
    :rtype: `tuple` of `str`
    zXThe get_sytemd_os_like() function is deprecated and will be removed in a future release.�)�
stacklevelN)�warnings�warn�DeprecationWarningrerrrr�get_systemd_os_info7s�rncCstrt���d�SgS)z�
    Get a list of strings that indicate the distribution likeness to
    other distributions.

    :returns: List of distribution acronyms
    :rtype: `list` of `str`
    r)rfrgZliker!rrrr�get_systemd_os_likeDs	ro�/etc/os-releasec	Csn|d}tj�|�sdSt|d��}|��}W5QRX|D].}|���|�r:t|��t|�d��Sq:dS)z�
    Get single value from a file formatted like systemd /etc/os-release

    :param str varname: Name of variable to fetch
    :param str filepath: File path of os-release file
    :returns: requested value
    :rtype: `str`
    �=��rN)	rr �isfiler@�	readlines�strip�
startswith�_normalize_string�len)Zvarname�filepathZ
var_stringZfh�contents�linerrr�get_var_from_fileQs
r}cCs|�dd��dd���S)zV
    Helper function for get_var_from_file() to remove quotes
    and whitespaces
    �"rr�')�replacerv)ZorigrrrrxgsrxcCst�t��t��t���}|\}}}|��}|�d�rftrft�	|�}|drT|d}|drd|d}n�|�d�r�zt
jddgt
jdd�}Wn*t
k
r�t
jd	dgt
jdd�}YnX|��d�d
�}nH|�d�r�|�d�d}|�d
�d}n t��d�rt��d}nd}||fS)z�
    Get Operating System type/distribution and major version
    using python platform module

    :param bool pretty: If the returned OS name should be in longer (pretty) form

    :returns: (os_name, os_version)
    :rtype: `tuple` of `str`
    r
rrH�darwinz/usr/bin/sw_versz-productVersionT)r
rZsw_vers�
Zfreebsd�-�.rr)�platformZsystem_alias�systemr-�version�lowerrwrfrgZlinux_distributionrrrrr�rstrip�	partitionZ	win32_ver)rc�infoZos_typeZos_verr$rrrrrdnsD
�



�
�
rdz![a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+$cCs2t�|�dk	r"|�d�o d|kSt�d|�dS)z$Scrub email address before using it.Nr�z..zInvalid email address: %s.F)�EMAIL_REGEX�matchrwr/�warning)Zemailrrr�
safe_email�sr�c@seZdZdZddd�ZdS)�_ShowWarningz1Action to log a warning when an argument is used.NcCst�d|�dS)NzUse of %s is deprecated.)r/r�)�selfZunused1Zunused2Zunused3Z
option_stringrrr�__call__�sz_ShowWarning.__call__)N)�__name__�
__module__�__qualname__�__doc__r�rrrrr��sr�cCsJttjkr4ttjt�r$tj�t�ntjtf7_||ttj|d�dS)a�Adds a deprecated argument with the name argument_name.

    Deprecated arguments are not shown in the help. If they are used on
    the command line, a warning is shown stating that the argument is
    deprecated and no other action is taken.

    :param callable add_argument: Function that adds arguments to an
        argument parser/group.
    :param str argument_name: Name of deprecated argument.
    :param nargs: Value for nargs when adding the argument to argparse.

    )�action�help�nargsN)r��configargparseZ#ACTION_TYPES_THAT_DONT_NEED_A_VALUE�
isinstancer\r]�argparseZSUPPRESS)�add_argumentZ
argument_namer�rrr�add_deprecated_argument�s
���r�cCs�t|�}t�d|�s$t�d�|���|�d�}t|�dkrJt�d�|���|D]<}|�d�rnt�d�||���|�	d�rNt�d�||���qN|S)	auChecks that Let's Encrypt will consider domain to be valid.

    :param str domain: FQDN to check
    :type domain: `str` or `unicode`
    :returns: The domain cast to `str`, with ASCII-only contents
    :rtype: str
    :raises ConfigurationError: for invalid domains and cases where Let's
                                Encrypt currently will not issue certificates

    z^[A-Za-z0-9.-]*$zP{0} contains an invalid character. Valid characters are A-Z, a-z, 0-9, ., and -.r�riz{0} needs at least two labelsr�z1label "{0}" in domain "{1}" cannot start with "-"z/label "{0}" in domain "{1}" cannot end with "-")
�enforce_domain_sanity�rer�rr_r.r!ryrw�endswith)�domain�labelsZlabelrrrr^�s8��
�
��
��r^cCs<z$t|tj�r|�d�}|�d�Wntk
rBt�d��YnX|��}|�	d�rb|dd�n|}dD]&}|�
d�|��rjt�d	�||���qjzt�
|�t�d
�|���Wntjk
r�YnXd�|�}t|�dkr�t�d
�|���|�d�}|D]:}|�st�d�|���q�t|�dkr�t�d�||���q�|S)a�Method which validates domain value and errors out if
    the requirements are not met.

    :param domain: Domain to check
    :type domain: `str` or `unicode`
    :raises ConfigurationError: for invalid domains and cases where Let's
                                Encrypt currently will not issue certificates

    :returns: The domain cast to `str`, with ASCII-only contents
    :rtype: str
    zutf-8�asciizbNon-ASCII domain names not supported. To issue for an Internationalized Domain Name, use Punycode.r�N���)ZhttpZhttpsz{0}://z[Requested name {0} appears to be a URL, not a FQDN. Try again without the leading "{1}://".zRequested name {0} is an IP address. The Let's Encrypt certificate authority will not issue certificates for a bare IP address.z*Requested domain {0} is not a FQDN because�z{0} it is too long.z{0} it contains an empty label.�?z{0} label {1} is too long.)r�r,Zbinary_type�decode�encode�UnicodeErrorrr_r�r�rwr.�socketZ	inet_atonr8ryr!)r�Zschemerr��lrrrr��sF

��	
��

r�cCs t|tj�rd}nd}|�|�S)z�"Is domain a wildcard domain?

    :param domain: domain to check
    :type domain: `bytes` or `str` or `unicode`

    :returns: True if domain is a wildcard, otherwise, False
    :rtype: bool

    z*.s*.)r�r,Z	text_typerw)r�Zwildcard_markerrrr�is_wildcard_domain0s
r�cCstj�|�dd��S)z�Converts a normalized version to a strict version.

    :param str normalized: normalized version string

    :returns: An equivalent strict version
    :rtype: distutils.version.StrictVersion

    z.dev�a)�	distutilsr�Z
StrictVersionr�)Z
normalizedrrr�get_strict_versionBsr�cCs|tjkpd|kS)z�
    Determine whether a given ACME server is a known test / staging server.

    :param str srv: the URI for the ACME server
    :returns: True iff srv is a known test / staging server
    :rtype bool:
    Zstaging)rZSTAGING_URI)Zsrvrrr�
is_stagingPsr�cOstjt|f|�|�dS)aSets func to be called before the program exits.

    Special care is taken to ensure func is only called when the process
    that first imports this module exits rather than any child processes.

    :param function func: function to be called in case of an error

    N)�atexit�register�_atexit_call��func�args�kwargsrrrr'[s	r'cOstt��kr|||�dS)N)�_INITIAL_PIDr�getpidr�rrrr�gsr�)r:F)r?N)rNr?)rVr?)rp)F)Nr�r�r��collectionsrZdistutils.versionr�r<Zloggingr�r�r�r�sysrkr�r,Zacme.magic_typingrrZcertbotrrrZcertbot.compatrr	rwrgrfZ	getLoggerr�r/�
namedtuplerrZ
ANSI_SGR_BOLDZANSI_SGR_REDZANSI_SGR_RESET�lineseprr4r�r�r&r8rr%r)r(r9r2rGrMrUrYr[rarerhrnror}rxrd�compiler�r�ZActionr�r�r^r�r�r�r�r'r�rrrr�<module>s�





	



5
 A

Anon7 - 2021