3 0Q=jŽ.ã@sîddlZddlZddlZddlmZddlmZddlmZddlmZddlmZddlm Z ddl m Z dd l m Z mZy4ddlZddlZdd lmZmZmZmZmZmZWnDek rôddljZddljZeZeZeZe Ze!Ze!Ze"Z#YnXddl$Z$e$j%d d d �Z&e'e&dƒ�s e&j$e&_(e&j(Z)dZ*dZ+dddddœZ,dd„e,j-ƒDƒZ.ddlm/Z/e/j0ƒZ1ej2ƒZ3dd„Z4dd„Z5dd„Z6e e7dœd d!„Z8e7d"œd#d$„Z9d6d&d'„Z:d7e7d(œd)d*„Z;d+d,„Zd2d3„Z?d4d5„Z@dS)9éN)Ú up2dateUtils)Ú up2dateErrors)Ú up2dateAuth)Ú rhnserver)Ú up2dateLog)Ú statistics)Ú getPlatform)ÚustrÚsstr)ÚListTypeÚ TupleTypeÚ StringTypeÚ UnicodeTypeÚDictTypeÚDictionaryTypezrhn-client-toolsT)ZfallbackÚugettextz/etc/sysconfig/rhnz/etc/sysconfig/rhn/jwt.tokenZ shared_proÚsharedÚsoloÚadmin)zCloudLinux OS Shared ProzCloudLinux OS SharedzCloudLinux OS SolozCloudLinux OS AdmincCsi|]\}}||“qS©r)Ú.0ÚkÚvrrú/usr/lib/python3.6/rhnreg.pyú 5sr)ÚconfigcCstjtdtjƒS)NÚ systemIdPath)ÚosÚaccessÚcfgÚR_OKrrrrÚ registered=sr!cCsÆtjj|ƒ}tj|tjƒsdStjj|ƒrJytj||dƒWn dStj|tjtj Btj Btj Btj Bdƒ}ytj |dƒ}Wn tk r¢tj|ƒ‚YnXz|jt|ƒƒWd|jƒXdS)z; Write a file to disk that is not readable by other users. Fz.savei€ÚwNT)rÚpathÚdirnamerÚW_OKÚlexistsÚrenameÚopenÚO_WRONLYÚO_CREATÚ O_NOFOLLOWÚO_EXCLÚ O_CLOEXECÚfdopenÚ ExceptionÚcloseÚwriter )Z secure_fileZ file_contentsZdir_nameÚfdZfd_filerrrÚ_write_secure_file@s*    r3cCsttd|ƒ}|S)Nr)r3r)ÚsystemIdÚresrrrÚ writeSystemIddsr6)ÚtokenÚallowTransitioncCszddl}ddl}|jjdƒs dSddg}|r6|jdƒ|j||jd�}|j|jƒd�\}}|j dkrvt j d ||fƒdS) zH Execute binary file which we use as hook for jwt token updates rNz /opt/cloudlinux/venv/bin/python3z/usr/sbin/cl-pre-jwt-updatez--new-token-stdinz--allow-transition)Ústdin)Úinputz7Pre jwt update hook failed with stdout=%s and stderr=%s) Ú subprocessrr#ÚexistsÚappendÚPopenÚPIPEÚ communicateÚencodeÚ returncodeÚlogÚlog_me)r7r8r;rÚcmdÚpÚstdoutÚstderrrrrÚ_execute_pre_jwt_update_hookis   rI)r8cCsjddl}ddl}|jjdƒs dSdg}|r4|jdƒ|j|ƒ}|jƒ\}}|jdkrftj d||fƒdS)zH Execute binary file which we use as hook for jwt token updates rNz /opt/cloudlinux/venv/bin/python3z/usr/sbin/cl-post-jwt-updatez--allow-transitionz8Post jwt update hook failed with stdout=%s and stderr=%s) r;rr#r<r=r>r@rBrCrD)r8r;rrErFrGrHrrrÚ_execute_post_jwt_update_hook|s     rJFcCsÜtjƒ}y|jj|ƒ}WnFtjk r.dStjtjtjtj fk r^t j t j ƒŽdSXt|tƒ s†t|ƒdks†tjd|ƒ r¼t|ttfƒrœt|ƒnd}t jdt|ƒj|fƒdSt||ƒ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 Ni@z2\A[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\Zzn/azIInvalid JWT token received from server (type=%s, len=%s), skipping update)rZ RhnServerZup2dateZ getJWTTokenrÚUnknownMethodExceptionZAuthenticationTicketErrorZRhnUuidUniquenessErrorÚCommunicationErrorZ$AuthenticationOrAccountCreationErrorrCZ log_exceptionÚsysÚexc_infoÚ isinstanceÚstrÚlenÚreÚmatchÚbytesrDÚtypeÚ__name__rIr3Ú JWT_TOKENrJ)r4r8Z xmlrpm_serverÚresultZ result_lenrrrÚgetAndWriteJWTTokenToFile�s*  rY)Úhuman_readablec CsFd}tjj|ƒsdSt|ƒ� }|jƒjdƒ}|r4|St|SQRXdS)Nz/opt/cloudlinux/cl_editionrÚ )rr#r<r(ÚreadÚstripÚ_human_readable_to_product)rZZedition_cache_fileÚfZ raw_editionrrrÚgetServerEdition´s  r`c CsVy t|ƒ}WnPtjk rH}ztd|jƒtjdƒWYdd}~Xntjk r\dSXtƒ}|d}||krxdS|r¨tdj t |t |d�ƒtdƒtjdƒ|�sRtj j ƒsÈtdƒtdƒt |›dt |›d �}d dd œ}|j |ƒ} | dk �rJtjƒ} | | k�r6td ||›d | ›d�ƒtjdƒn|›d||›d�}t|ƒdS)Nz%séÚeditionz½WARNING: 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.)ÚcheckKeyrrLÚprintÚerrmsgrMÚexitrKr`ÚformatÚ_product_to_human_readabler9ÚisattyÚgetrZcount_server_usersÚ_askConfirmation) Ú activationKeyZ strictEditionZsilentMigrationZlicenseInformationÚeZcurrentEditionZlicenseEditionÚmessageZedition_to_users_limitZlicense_users_limitZusers_on_serverrrrÚcheckLicenseKeyÃsB       rp)ÚconfirmationMessagecCs2t|ƒtdƒ}|jƒdkr.tdƒtjdƒdS)zS Prints message and makes sure that client is ready for edition migration. z Do you want to continue? [N/y]: ÚyzAborted.raN)rer:ÚlowerrMrg)rqZresponserrrrls  rlc CsÜ|dkr|dkstdƒ‚|tjƒtjƒtjƒdœ}tjƒ}|dk rJ||d<|rlx|jƒD]\}} | ||<qXW|rz||d<n||d<||d<|dk rœ||d<n(tj j d ƒr¬d ntj j d ƒr¼d nd |d<t j ƒ} | j 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_idr7ÚusernameÚpasswordrbz/etc/cloudlinux-edition-solorz/etc/cloudlinux-edition-adminrr)ÚAssertionErrorrZ getVersionZ getOSReleaseZgetArchrZ getSystemIdÚitemsrr#r<rÚRegistrationRhnServerÚ registrationZ new_system) rtruZ profileNamer7ÚotherrbZ auth_dictZ system_id_xmlÚkeyÚitemÚsÚretrrrÚregisterSystem s.     rcCstjƒ}|jj|ƒ}|S)zG Check the activation key and return it's edition and customer )rrxryZ license_check)rmr}r~rrrrd9s rdcGs°g}xŠ|D]‚}t|ƒ}|tkr(t|ƒ}nZ|tkrDtdd„|Dƒƒ}n>|tkr\dd„|Dƒ}n&|tksl|tkr‚tdd„|j ƒDƒƒ}|j |ƒq Wt |ƒ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_characters)rÚirrrú Nsz%_encode_characters..cSsg|] }t|ƒ‘qSr)r€)rr�rrrú Psz&_encode_characters..cSsg|]\}}t||ƒ‘qSr)r€)rÚnameÚvalrrrrƒRsrarN) rUr r r Útupler rrÚdictrwr=rQ)ÚargsrXr|Z item_typerrrr€Ds   r€)F)F)NNNNNN)ArrRrMZup2date_clientrrrrrrZup2date_client.pkgplatformrZrhn.i18nr r ZurlparseZ xmlrpclibÚtypesr r r rrrÚ ImportErrorZ urllib.parseÚparseZ xmlrpc.clientZclientÚlistr†rTrPr‡ÚintZlongÚgettextZ translationÚtÚhasattrrÚ_Z SYSID_DIRrWr^rwrirZinitUp2dateConfigrZinitLogrCr!r3r6ÚboolrIrJrYr`rprlrrdr€rrrrÚ sl       $      $ %>  *