a mi*@sddlZddlZddlmZddlmZddlmZddlmZddlmZddlmZddl m Z dd l m Z m Z z4ddlZddlZdd lmZmZmZmZmZmZWnFeyddlmZddlmZeZeZeZeZe Ze Ze!Z"Yn0ddl#Z#e#j$d d d Z%e&e%dse%j#e%_'e%j'Z(dZ)dZ*dddddZ+dde+,DZ-ddlm.Z.e./Z0e1Z2ddZ3ddZ4ddZ5ee6dd d!Z7e6d"d#d$Z8d6d&d'Z9d7e6d(d)d*Z:d+d,Z;ed-d.d/Zd4d5Z?dS)9N) up2dateUtils) up2dateErrors) up2dateAuth) rhnserver) up2dateLog) statistics) getPlatform)ustrsstr)ListType TupleType StringType UnicodeTypeDictTypeDictionaryTypezrhn-client-toolsT)fallbackugettextz/etc/sysconfig/rhnz/etc/sysconfig/rhn/jwt.tokenZ shared_prosharedsoloadmin)zCloudLinux OS Shared ProzCloudLinux OS SharedzCloudLinux OS SolozCloudLinux OS AdmincCsi|]\}}||qSr).0kvrr9/usr/lib/python3.9/site-packages/up2date_client/rhnreg.py 4sr)configcCsttdtjSNZ systemIdPath)osaccesscfgR_OKrrrr registered<sr"cCstj|}t|tjsdSt|tjrPzt||dWnYdS0t|tjtj Bt dd}t |d}z| t |W|n |0dS)z; Write a file to disk that is not readable by other users. Fz.saveZ0600wT)rpathdirnamerW_OKF_OKrenameopenO_WRONLYO_CREATintfdopenwriter close)Z secure_fileZ file_contentsZdir_namefdZfd_filerrr_write_secure_file?s  r2cCsttd|}|Sr)r2r )systemIdresrrr writeSystemIdUsr5)tokenallowTransitioncCsnddl}ddl}|jds dSdd|g}|r8|d||}|\}}|jdkrjt d||fdS)H Execute binary file which we use as hook for jwt token updates rN /opt/cloudlinux/venv/bin/python3z/usr/sbin/cl-pre-jwt-updatez --new-token--allow-transitionz7Pre jwt update hook failed with stdout=%s and stderr=%s subprocessrr%existsappendPopenZ communicate returncodelogZlog_me)r6r7r<rcmdpstdoutstderrrrr_execute_pre_jwt_update_hookZs      rF)r7cCsjddl}ddl}|jds dSdg}|r4|d||}|\}}|jdkrft d||fdS)r8rNr9z/usr/sbin/cl-post-jwt-updater:z8Post jwt update hook failed with stdout=%s and stderr=%sr;)r7r<rrBrCrDrErrr_execute_post_jwt_update_hookms     rGFc Cst}z|j|}WnFtjy.YdStjtjtjtj fy^t j t YdS0t||tt|t|dS)z Get a JWT token from CLN and save it to the file :param systemId: content of file `/etc/sysconfig/rhn/systemid` :return: None N)rZ RhnServerZup2dateZ getJWTTokenrUnknownMethodExceptionZAuthenticationTicketErrorZRhnUuidUniquenessErrorCommunicationErrorZ$AuthenticationOrAccountCreationErrorrAZ log_exceptionsysexc_inforFr2 JWT_TOKENrG)r3r7Z xmlrpm_serverresultrrrgetAndWriteJWTTokenToFiles   rN)human_readablecCsld}tj|sdSt|<}|d}|rB|WdSt|WdS1s^0YdS)Nz/opt/cloudlinux/cl_editionr )rr%r=r*readstrip_human_readable_to_product)rOZedition_cache_filefZ raw_editionrrrgetServerEditions  rUc CsXz t|}WnRtjyJ}z$td|jtdWYd}~nd}~0tjy^YdS0t}|d}||krzdS|rtdj t |t |dtdtd|sTtj stdtdt |dt |d }d dd }| |} | durLt} | | kr8td ||d | dtdn|d||d}t|dS)Nz%seditionzWARNING: Automatic registration in yum transactions is only available when edition matches the provided license. Your current edition is {current_edition} and your license is {new_edition}.)Zcurrent_editionZ new_editionz0Run clnreg_ks manually to complete registration.aError: interactive input required for edition migration, but tool is running in non-interactive mode. Please try running the tool again in interactive shell or add `--migrate-silently` flag to accept allquestions and perform the edition migration silently.za edition installed on your server does not match license you are trying to register server with: zh. Migration is required. You may lose access to the services which are not supported by the new edition.)rrz@The license you are trying to register with allows a maximum of z% hosting accounts which is less than z) users detected on this server. Aborting.zG Also, the license you are trying to register with allows a maximum of zM hosting accounts. Make sure that your system complies with this requirement.)checkKeyrrIprinterrmsgrJexitrHrUformat_product_to_human_readablestdinisattygetrZcount_server_users_askConfirmation) activationKeyZ strictEditionZsilentMigrationZlicenseInformationeZcurrentEditionZlicenseEditionmessageZedition_to_users_limitZlicense_users_limitZusers_on_serverrrrcheckLicenseKeysX         rf)confirmationMessagecCs2t|td}|dkr.tdtddS)zS Prints message and makes sure that client is ready for edition migration. z Do you want to continue? [N/y]: yzAborted.rVN)rZinputlowerrJr\)rgZresponserrrrbs  rbc Cs|dur|dusJd|tttd}t}|durJ||d<|rh|D]\}} | ||<qV|rv||d<n||d<||d<|dur||d<n(tj d rd ntj d rd nd |d<t } | j |} | S)ziWrapper for the old xmlrpc to register a system. Activates subscriptions if a reg num is given. Nz)username and password usage is deprecated)Z profile_nameZ os_releaseZ release_nameZ architectureZ system_idr6usernamepasswordrWz/etc/cloudlinux-edition-solorz/etc/cloudlinux-edition-adminrr)rZ getVersionZ getOSReleaseZgetArchrZ getSystemIditemsrr%r=rRegistrationRhnServer registrationZ new_system) rkrlZ profileNamer6otherrWZ auth_dictZ system_id_xmlkeyitemsretrrrregisterSystems6     rucCst}|j|}|S)zG Check the activation key and return it's edition and customer )rrnroZ license_check)rcrsrtrrrrYs rYcGsg}|D]}t|}|tkr&t|}nZ|tkrBtdd|D}n>|tkrZdd|D}n&|tksj|tkrtdd| D}| |qt |dkr|dSt|SdS) u All the data we gathered from dmi, bios, gudev are in utf-8, we need to convert characters beyond ord(127) - e.g ® to unicode. css|]}t|VqdS)N_encode_charactersrirrr 4z%_encode_characters..cSsg|] }t|qSrrvrxrrr 6r{z&_encode_characters..cSsg|]\}}t||qSrrv)rnamevalrrrr|8r{rVrN) typer r r tupler rrdictrmr>len)argsrMrrZ item_typerrrrw*s   rw)F)F)NNNNNN)@rrJZup2date_clientrrrrrrZup2date_client.pkgplatformrZrhn.i18nr r urlparseZ xmlrpclibtypesr r r rrr ImportError urllib.parseparseZ xmlrpc.clientZclientlistrbytesstrrr-Zlonggettext translationthasattrr_Z SYSID_DIRrLrSrmr^rZinitUp2dateConfigr ZinitLogrAr"r2r5boolrFrGrNrUrfrbrurYrwrrrr sp       $       >  ,