• File: util.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/lib/python2.7/site-packages/certbot/util.pyc
  • Date Modified: 10/08/2021 7:08 AM
  • File size: 20.52 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit

_c@sdZddlZddlZddlZddlmZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZe
j	jdZerYddlZneje Z!ej"d
dZ#ej"ddZ$dZ%dZ&dZ'ej(j)d;Z*ej+Z,eZ-dZ.e!j/dZ0dZ1dZ2dZ3dZ4de5dZ6ddd Z8d!Z9d"dd#Z:d$dd%Z;d&Z<d'Z=d(Z>d)Z?d*Z@d+d,ZAd-ZBe5d.ZCe
jDd/ZEd0ZFd1ejGfd2YZHd3ZId4ZJd5ZKd6ZLd7ZMd8ZNd9ZOd:ZPdS(<sUtilities for all Certbot.iN(tOrderedDict(tText(tTuple(tUnion(terrors(t	constants(tlock(t
filesystem(tostlinuxtKeysfile pemtCSRsfile data formssss$The following error was encountered:s{0}sWEither run as root, or set --config-dir, --work-dir, and --logs-dir to writeable paths.cstjjdks'dkr+SxMdD]E}|kr2djfd|jdD|<q2q2WS(s
    When Certbot is run inside a Snap, certain environment variables
    are modified. But Certbot sometimes calls out to external programs,
    since it uses classic confinement. When we do that, we must modify
    the env to remove our modifications so it will use the system's
    libraries, since they may be incompatible with the versions of
    libraries included in the Snap. For example, apachectl, Nginx, and
    anything run from inside a hook should call this function and pass
    the results into the ``env`` argument of ``subprocess.Popen``.

    :returns: A modified copy of os.environ ready to pass to Popen
    :rtype: dict

    tSNAPtCERTBOT_SNAPPEDtPATHtLD_LIBRARY_PATHt:c3s%|]}d|kr|VqdS(RN((t.0tx(tenv(s0/usr/lib/python2.7/site-packages/certbot/util.pys	<genexpr>Vs(sPATHR(Rtenvirontcopytjointsplit(t	path_name((Rs0/usr/lib/python2.7/site-packages/certbot/util.pytenv_no_snap_for_external_callsAs
7c
Csy4tj|dtjdtjdtdt}WnCttfk
ryddj|}||tj	|nX|j
\}}|jdkrddj|||f}||tj	|n||fS(	sRun 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

    tstdouttstderrtuniversal_newlinesRsUnable to run the command: %st isError while running %s.
%s
%s(t
subprocesstPopentPIPEtTrueRtOSErrort
ValueErrorRRtSubprocessErrortcommunicatet
returncode(tparamstlogtproctmsgRR((s0/usr/lib/python2.7/site-packages/certbot/util.pyt
run_scriptZs"		

cCsutjj|\}}|r+tj|SxCtjdjtjD](}tjtjj||rEtSqEWt	S(sDetermine whether path/name refers to an executable.

    :param str exe: Executable path or name

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

    R(
RtpathRRt
is_executableRtpathsepRR!tFalse(texeR,t_((s0/usr/lib/python2.7/site-packages/certbot/util.pyt
exe_existsys	
 cCs9tsttn|tkr5tj|t|<ndS(sLock 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(t_LOCKStatexit_registert_release_locksRtlock_dir(tdir_path((s0/usr/lib/python2.7/site-packages/certbot/util.pytlock_dir_until_exits
cCsbxQtjtD]@}y|jWqdj|}tj|dtqXqWtjdS(Ns(Exception occurred releasing lock: {0!r}texc_info(	tsixt
itervaluesR3treleasetformattloggertdebugR!tclear(tdir_lockR*((s0/usr/lib/python2.7/site-packages/certbot/util.pyR5scCscyt|||t|Wn>tk
r^}tjddttjtj	|nXdS(shEnsure 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

    sException was:R9N(
tmake_or_verify_dirR8R"R>R?R!RtErrortPERM_ERR_FMTR=(t	directorytmodetstrictterror((s0/usr/lib/python2.7/site-packages/certbot/util.pytset_up_core_dirsicCsytj||Wnftk
r|}|jtjkrv|rytj||rytjd|t|fqyq}nXdS(sMake 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.

    sE%s exists, but it should be owned by current user with permissions %sN(	RtmakedirsR"terrnotEEXISTtcheck_permissionsRRCtoct(RERFRGt	exception((s0/usr/lib/python2.7/site-packages/certbot/util.pyRBstwcCs]d}|dk	r|f}nd}tj|tjtjBtjB|}tj|||S(sSafely 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``.

    (N((tNoneRtopenRtO_CREATtO_EXCLtO_RDWRtfdopen(R,RFtchmodt	open_argstfdopen_argstfd((s0/usr/lib/python2.7/site-packages/certbot/util.pyt	safe_opens	&cCsxtrtjj|||}y,t|d|d|tjj|fSWn+tk
r}}|jtjkr~q~nX|d7}qWdS(NRWRFi(	R!RR,RR[tabspathR"RKRL(R,tfilename_pattcountRWRFtcurrent_pathterr((s0/usr/lib/python2.7/site-packages/certbot/util.pyt_unique_files	
ic
sCtjj|\}t|dfdddd|d|S(sSafely 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

    R]csd|fS(Ns%04d_%s((R^(ttail(s0/usr/lib/python2.7/site-packages/certbot/util.pyt<lambda>sR^iRWRF(RR,RRa(R,RWRF((Rbs0/usr/lib/python2.7/site-packages/certbot/util.pytunique_files
ic
stjj|d}yt|d||fSWn+tk
r`}|jtjkraqanXt|dfdddd|d|S(sSafely 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.

    s%s.confRWR]csd|fS(Ns%s-%04d.conf((R^(tfilename(s0/usr/lib/python2.7/site-packages/certbot/util.pyRcsR^iRF(RR,RR[R"RKRLRa(R,ReRWRFtpreferred_pathR`((Res0/usr/lib/python2.7/site-packages/certbot/util.pytunique_lineage_names
cCsCytj|Wn+tk
r>}|jtjkr?q?nXdS(s!Remove a file that may not exist.N(RtremoveR"RKtENOENT(R,R`((s0/usr/lib/python2.7/site-packages/certbot/util.pyt
safely_removes
cCsbt}xR|D]J}y|jt|Wqtjk
rYtjd|dtqXqW|S(sRemoves 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

    sNot suggesting name "%s"R9(tsettaddtenforce_le_validityRtConfigurationErrorR>R?R!(t	all_namestfiltered_namestname((s0/usr/lib/python2.7/site-packages/certbot/util.pytget_filtered_names%s		
cCs
tdtS(sc
    Get OS name and version

    :returns: (os_name, os_version)
    :rtype: `tuple` of `str`
    tpretty(tget_python_os_infoR/(((s0/usr/lib/python2.7/site-packages/certbot/util.pytget_os_info6scCsCtrtjdt}nts)|r?djtdtS|S(s^
    Get OS name and version string for User Agent

    :returns: os_ua
    :rtype: `str`
    RsR(t_USE_DISTROtdistroRqR!RRt(tos_info((s0/usr/lib/python2.7/site-packages/certbot/util.pytget_os_info_ua@s
cCstrtjjdSgS(s
    Get a list of strings that indicate the distribution likeness to
    other distributions.

    :returns: List of distribution acronyms
    :rtype: `list` of `str`
    R(RvRwtlikeR(((s0/usr/lib/python2.7/site-packages/certbot/util.pytget_systemd_os_likeNs	s/etc/os-releasecCs|d}tjj|s dSt|d}|j}WdQXx=|D]5}|jj|rKt|jt|SqKWdS(s
    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`
    t=ttrN(	RR,tisfileRRt	readlineststript
startswitht_normalize_stringtlen(tvarnametfilepatht
var_stringtfhtcontentstline((s0/usr/lib/python2.7/site-packages/certbot/util.pytget_var_from_file[s


cCs"|jddjddjS(sV
    Helper function for get_var_from_file() to remove quotes
    and whitespaces
    t"R}t'(treplaceR(torig((s0/usr/lib/python2.7/site-packages/certbot/util.pyRqscCstjtjtjtj}|\}}}|j}|jdrtrtj	|}|dr}|d}n|dr|d}qn|jdrFy:t
jddgdt
jdt
jd	t
d
t}WnGtk
r)t
jddgdt
jdt
jd	t
d
t}nX|jdjd}na|jd
r~|jdd}|jdd}n)tjdrtjd}nd}||fS(s
    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	iitdarwins/usr/bin/sw_verss-productVersionRRRRtsw_verss
tfreebsdt-t.R}(tplatformtsystem_aliastsystemR<tversiontlowerRRvRwtlinux_distributionRRR R!RR"R%trstript	partitiont	win32_ver(Rstinfotos_typetos_verR1R)((s0/usr/lib/python2.7/site-packages/certbot/util.pyRtxsB
		



s![a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+$cCsCtj|dk	r/|jdo.d|kStjd|tS(s$Scrub email address before using it.Rs..sInvalid email address: %s.N(tEMAIL_REGEXtmatchRQRR>twarningR/(temail((s0/usr/lib/python2.7/site-packages/certbot/util.pyt
safe_emailstDeprecatedArgumentActioncBseZdZddZRS(s1Action to log a warning when an argument is used.cCstjd|dS(NsUse of %s is deprecated.(R>R(tselftunused1tunused2tunused3t
option_string((s0/usr/lib/python2.7/site-packages/certbot/util.pyt__call__sN(t__name__t
__module__t__doc__RQR(((s0/usr/lib/python2.7/site-packages/certbot/util.pyRscCslttjkrIttjtr4tjjtqItjtf7_n||dtdtjd|dS(sAdds 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.

    tactionthelptnargsN(Rtconfigargparset#ACTION_TYPES_THAT_DONT_NEED_A_VALUEt
isinstanceRkRltargparsetSUPPRESS(tadd_argumentt
argument_nameR((s0/usr/lib/python2.7/site-packages/certbot/util.pytadd_deprecated_arguments
	
cCst|}tjd|s9tjdj|n|jd}t|dkrutjdj|nxh|D]`}|jdrtjdj||n|j	dr|tjdj||q|q|W|S(	suChecks 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

    s^[A-Za-z0-9.-]*$sP{0} contains an invalid character. Valid characters are A-Z, a-z, 0-9, ., and -.Ris{0} needs at least two labelsRs1label "{0}" in domain "{1}" cannot start with "-"s/label "{0}" in domain "{1}" cannot end with "-"(
tenforce_domain_sanitytreRRRnR=RRRtendswith(tdomaintlabelstlabel((s0/usr/lib/python2.7/site-packages/certbot/util.pyRms&
cCsy5t|tjr'|jd}n|jdWn tk
rWtjdnX|j}|j	dr}|d n|}xJddgD]<}|j
dj|rtjd	j||qqWy)tj
|tjd
j|Wntjk
rnXdj|}t|dkrLtjd
j|n|jd}x_|D]W}|stjdj|nt|dkrbtjdj||qbqbW|S(sMethod 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
    sutf-8tasciisbNon-ASCII domain names not supported. To issue for an Internationalized Domain Name, use Punycode.u.ithttpthttpss{0}://s[Requested name {0} appears to be a URL, not a FQDN. Try again without the leading "{1}://".sRequested name {0} is an IP address. The Let's Encrypt certificate authority will not issue certificates for a bare IP address.s*Requested domain {0} is not a FQDN becauseis{0} it is too long.Rs{0} it contains an empty label.i?s{0} label {1} is too long.(RR:tbinary_typetdecodetencodetUnicodeErrorRRnRRRR=tsockett	inet_atonRHRR(RtschemeR*Rtl((s0/usr/lib/python2.7/site-packages/certbot/util.pyRs<



"cCs.d}t|tjr!d}n|j|S(s"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

    s*.u*.(RR:t	text_typeR(Rtwildcard_marker((s0/usr/lib/python2.7/site-packages/certbot/util.pytis_wildcard_domain;s
	cCstjj|jddS(sConverts a normalized version to a strict version.

    :param str normalized: normalized version string

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

    s.devta(t	distutilsRt
StrictVersionR(t
normalized((s0/usr/lib/python2.7/site-packages/certbot/util.pytget_strict_versionKs
cCs|tjkpd|kS(s
    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:
    tstaging(RtSTAGING_URI(tsrv((s0/usr/lib/python2.7/site-packages/certbot/util.pyt
is_stagingXscOstjt|||dS(sSets 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(tatexittregistert_atexit_call(tfunctargstkwargs((s0/usr/lib/python2.7/site-packages/certbot/util.pyR4cs	cOs&ttjkr"|||ndS(N(t_INITIAL_PIDRtgetpid(RRR((s0/usr/lib/python2.7/site-packages/certbot/util.pyRos(s$The following error was encountered:s{0}sWEither run as root, or set --config-dir, --work-dir, and --logs-dir to writeable paths.(QRRRtcollectionsRtdistutils.versionRRKtloggingRRRRtsysRR:tacme.magic_typingRRRtcertbotRtcertbot._internalRRtcertbot.compatRRRRvRwt	getLoggerRR>t
namedtupleR
Rt
ANSI_SGR_BOLDtANSI_SGR_REDtANSI_SGR_RESETtlinesepRRDRRR3RRHR+R2R8R5RIR/RBRQR[RaRdRgRjRrRuRyR{RRRttcompileRRtActionRRRmRRRRR4R(((s0/usr/lib/python2.7/site-packages/certbot/util.pyt<module>s							
		
				
		
	7			 	A