a mi 5@s<dZddlZddlZddlZddlZddlmZmZddlm Z m Z zddl m Z m Z Wn"eyzddlm Z m Z Yn0ddlZejdddZeed seje_ejZd d d d ddddddddddgdfdZgdZGdddZGdddZdd Zd!d"Zd#d$Zd/d&d'Zd0d(d)Zd1d*d+Zd2d-d.Z dS)3zj This module includes the Config and Up2date Config classes use by the up2date agent to hold config info. N)idn_ascii_to_punyidn_puny_to_unicode)ustrsstr)urlsplit urlunsplitzrhn-client-toolsT)fallbackugettext)zUse a HTTP Proxyr)zRemote server URLz)https://xmlrpc.cln.cloudlinux.com/XMLRPC/)z&Remote server URL for access over IPv6z.https://ipv6.xmlrpc.cln.cloudlinux.com/XMLRPC/)zMirror list URLz>https://repo.cloudlinux.com/cloudlinux/mirrorlists/cln-mirrors)z#Whether or not debugging is enabledr)zLocation of system idz/etc/sysconfig/rhn/systemid)z4Override the automatically determined system version)z;HTTP proxy in host:port format, e.g. squid.example.com:3128r )z'The username for an authenticated proxyr )z.The password to use for an authenticated proxyr )z$To use an authenticated proxy or notr)zBNumber of attempts to make at network connections before giving up)z)The CA cert used to verify the ssl serverz'/usr/share/rhn/CLN-ORG-TRUSTED-SSL-CERTzDConfig options that can not be overwritten by a config update action) sslCACert serverURLdisallowConfChanges)Z enableProxyr serverURLipv6Z mirrorURLdebug systemIdPathZversionOverride httpProxy proxyUser proxyPasswordZenableProxyAuthZnetworkRetriesr r)rr ZtmpDirc@sleZdZdZdddZdddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZdS) ConfigFilez;class for handling persistent config options for the clientNcCsi|_||_|jr|dSN)dictfileNameloadselffilenamer9/usr/lib/python3.9/site-packages/up2date_client/config.py__init__BszConfigFile.__init__c Cs|r ||_|jdurdSt|jtjs,dSt|jd}d}|D]}|ddkrZqD||}|slqD|ddkr|dd}qDnd}|dd}t |d krqD|d}t |d}d}|d } | dkr|d| }|}d}|rr|d } |d vrt | t }nTt | dkrPz t|}WntyLYn0n"| ddkrdg}nd d| D}||f} ||jvr|j|} |dur|| df} |dur| d|f} | |j|<qD|dS)Nrr #r\=r z [comment];)rrcSsg|]}|r|qSr)strip).0valrrr z#ConfigFile.load..)rosaccessR_OKopen readlinesfindr'splitlenrrencodelocalegetpreferredencodingint ValueErrorrclose) rrfZ multilineliner2keyvaluecommentposvaluesZnewvalrrrrHsd                   zConfigFile.loadc CsF|jdurdSt|jtjsTttj|jtjsTttdtj|jdSt|jdd}t |jdt dd| d| d| d|j D]}|j |\}}| td ||ft|tgkr|g}|tvrttjj|}| td |d tt|f| d q|t|jd|jdS) Nz%s was not foundz.newwZ0644zI# Automatically generated Red Hat Update Agent config file, do not edit. z# Format: 1.0 r z%s[comment]=%s z%s=%s r& )rr,r-r.pathdirnameprint_r/chmodr7writerkeysrtype FileOptionsmapabspathjoinstrr9rename)rr:r<r>r=rrrsaves,     " zConfigFile.savecCs ||jvSrrrnamerrr __contains__szConfigFile.__contains__cCs||vSrrrTrrrhas_keyszConfigFile.has_keycCs |jSr)rrJrrrrrJszConfigFile.keyscCsdd|jDS)NcSsg|] }|dqS)r r)r(arrrr*r+z%ConfigFile.values..)rr@rXrrrr@szConfigFile.valuescCs|j|dSr)rupdate)rrrrrrZszConfigFile.updatecCs||jvr|j|dSdS)Nr rSrTrrr __getitem__s zConfigFile.__getitem__cCs0||jvr|j|}nd}|d|f|j|<dS)N)NNrrS)rrUr=r)rrr __setitem__s  zConfigFile.__setitem__cCs||jvr|j|dSdS)Nrr rSrTrrrinfos zConfigFile.info)N)N)__name__ __module__ __qualname____doc__rrrRrVrWrJr@rZr[r\r]rrrrr?s  H#rc@sveZdZdddZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZdS)ConfigNcCs.t|_|jt|r$|j|i|_dSr)rstoredrZDefaultsrruntimerrrrrs   zConfig.__init__cCs ||jvrdS||jvrdSdS)NTFrercrTrrrrVs   zConfig.__contains__cCs||vSrrrTrrrrWszConfig.has_keycCs4t|j}|jD]}||vr||q|Sr)listrerJrcappendrretkrrrrJs  z Config.keyscCs&g}|D]}|||q |SrrJrhr[rirrrr@s z Config.valuescCs*g}|D]}||||fq |Srrlrirrritemss z Config.itemscCs t|Sr)r3rJrXrrr__len__szConfig.__len__cCs||j|<dSr)rerrUr=rrrr\szConfig.__setitem__cCs,||jvr|j|S||jvr(|j|SdSrrfrTrrrr[ s     zConfig.__getitem__cCs |j|Sr)rcr]rTrrrr]sz Config.infocCs|jdSr)rcrRrXrrrrRsz Config.savecCs4|j||jD]}||jvr&q|j|=qdSr)rcrrJre)rrrkrrrrs   z Config.loadcCs ||j|<||jvr|j|=dSr)rcrerorrrset"s  z Config.set)N)r^r_r`rrVrWrJr@rmrnr\r[r]rRrrprrrrrbs   rbcCs^t}d}|d}|rZ|dddkr2|dd}|d}tt|d|d<d|}|S)zkreturns proxy string in format hostname:port hostname is converted to Punycode (RFC3492) if needed Nrzhttp://:r)initUp2dateConfigr2rPrrO)cfgproxyZ proxyHostpartsrrrgetProxySetting)s   rwcCs:t|}tt|dtt|d|d|d|dfS)z=returns url where hostname is converted to Punycode (RFC3492)rr r%)rrrrr)urlsrrrconvert_url_to_puny;sr|cCs&t|trdd|DSt|gSdS)z Internal function to process server URL to Punycode format. Processes both single URLs and lists of URLs. :param serverUrl: URL or list of URLs to process. :return: List of processed URLs in Punycode format. cSsg|] }t|qSr)r|)r(irrrr*Kr+z$processServerURL..N) isinstancergr|)Z serverUrlrrrprocessServerURLAs rFcCs^t}t|d}t|d}||f}||f}|r6|Sddlm}|}|dkrZ|rZ|S|S)a Return a pair of server URLs (primary and fallback) based on the preferred interface. :param registration: If True, it indicates that the URLs are being fetched for registration purposes. If that is the case, the function will always use IPv4 URLs with IPv6 as fallback, regardless of the preferred_interface setting. Assumed false by default, expected to be specified explicitly when needed. :return: Pair of server URL configs, first is the primary, second is the fallback. r rr) up2dateAuthZIPv6)rsrZup2date_clientrZgetPreferredInterface) registrationrtZipv4_urlZipv6_urlZipv4_primary_pairZipv6_primary_pairrZpreferred_interfacerrrgetServerURLPairPs     rcCst|ddS)az Return the primary server URL from config based on preferred_interface. If preferred_interface=IPv6 in system_id, returns serverURLipv6 if available. Otherwise returns normal serverURL. Note: the config may have one value or a list of values, but this function always returns a list. :return: List of server URLs with hostnames converted to Punycode. rrrrrrr getServerURLws rcCst|ddS)z Determine the fallback server URL from system_id. The fallback server URL is the one that is *not* set as preferred_interface. If preferred_interface is IPv6, it returns serverURL (i.e. IPv4 host), otherwise serverURLipv6. rr rrrrrgetFallbackServerURLsr/etc/sysconfig/rhn/up2datecCsNztWntydaYn0tdkrJt|adtd<tjrJdtd<tS)zsV  O '