3 0Q=j.@sddlZddlZddlZddlmZddlmZddlmZddlmZddlmZddlm Z ddl m Z dd l m Z mZy4ddlZddlZdd lmZmZmZmZmZmZWnDek rddljZddljZeZeZeZe Ze!Ze!Ze"Z#YnXddl$Z$e$j%d d d Z&e'e&ds e&j$e&_(e&j(Z)dZ*dZ+dddddZ,dde,j-DZ.ddlm/Z/e/j0Z1ej2Z3ddZ4ddZ5ddZ6e e7dd d!Z8e7d"d#d$Z9d6d&d'Z:d7e7d(d)d*Z;d+d,Zd2d3Z?d4d5Z@dS)9N) up2dateUtils) up2dateErrors) up2dateAuth) rhnserver) up2dateLog) statistics) getPlatform)ustrsstr)ListType TupleType StringType UnicodeTypeDictTypeDictionaryTypezrhn-client-toolsT)Zfallbackugettextz/etc/sysconfig/rhnz/etc/sysconfig/rhn/jwt.tokenZ shared_prosharedsoloadmin)zCloudLinux OS Shared ProzCloudLinux OS SharedzCloudLinux OS SolozCloudLinux OS AdmincCsi|]\}}||qSr).0kvrr/usr/lib/python3.6/rhnreg.py 5sr)configcCstjtdtjS)N systemIdPath)osaccesscfgR_OKrrrr registered=sr!cCstjj|}tj|tjsdStjj|rJytj||dWn dStj|tjtj Btj Btj Btj Bd}ytj |d}Wn tk rtj|YnXz|jt|Wd|jXdS)z; Write a file to disk that is not readable by other users. Fz.saveiwNT)rpathdirnamerW_OKlexistsrenameopenO_WRONLYO_CREAT O_NOFOLLOWO_EXCL O_CLOEXECfdopen Exceptionclosewriter )Z secure_fileZ file_contentsZdir_namefdZfd_filerrr_write_secure_file@s*    r3cCsttd|}|S)Nr)r3r)systemIdresrrr writeSystemIddsr6)tokenallowTransitioncCszddl}ddl}|jjds dSddg}|r6|jd|j||jd}|j|jd\}}|j dkrvt j d ||fdS) 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#existsappendPopenPIPE communicateencode returncodeloglog_me)r7r8r;rcmdpstdoutstderrrrr_execute_pre_jwt_update_hookis   rI)r8cCsjddl}ddl}|jjds dSdg}|r4|jd|j|}|j\}}|jdkrftj d||fdS)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     rJFcCstj}y|jj|}WnFtjk r.dStjtjtjtj fk r^t j t j dSXt|t st|dkstjd| rt|ttfrt|nd}t jdt|j|fdSt||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 getJWTTokenrUnknownMethodExceptionZAuthenticationTicketErrorZRhnUuidUniquenessErrorCommunicationErrorZ$AuthenticationOrAccountCreationErrorrCZ log_exceptionsysexc_info isinstancestrlenrematchbytesrDtype__name__rIr3 JWT_TOKENrJ)r4r8Z xmlrpm_serverresultZ result_lenrrrgetAndWriteJWTTokenToFiles*  rY)human_readablec CsFd}tjj|sdSt| }|jjd}|r4|St|SQRXdS)Nz/opt/cloudlinux/cl_editionr )rr#r<r(readstrip_human_readable_to_product)rZZedition_cache_filefZ raw_editionrrrgetServerEditions  r`c CsVy t|}WnPtjk rH}ztd|jtjdWYdd}~Xntjk r\dSXt}|d}||krxdS|rtdj t |t |dtdtjd|sRtj j stdtdt |dt |d }d dd }|j |} | dk rJtj} | | kr6td ||d | dtjdn|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.)checkKeyrrLprinterrmsgrMexitrKr`format_product_to_human_readabler9isattygetrZcount_server_users_askConfirmation) activationKeyZ strictEditionZsilentMigrationZlicenseInformationeZcurrentEditionZlicenseEditionmessageZedition_to_users_limitZlicense_users_limitZusers_on_serverrrrcheckLicenseKeysB       rp)confirmationMessagecCs2t|td}|jdkr.tdtjddS)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|tjtjtjd}tj}|dk rJ||d<|rlx|jD]\}} | ||<qXW|rz||d<n||d<||d<|dk r||d<n(tj j d rd ntj j d rd 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_idr7usernamepasswordrbz/etc/cloudlinux-edition-solorz/etc/cloudlinux-edition-adminrr)AssertionErrorrZ getVersionZ getOSReleaseZgetArchrZ getSystemIditemsrr#r<rRegistrationRhnServer registrationZ new_system) rtruZ profileNamer7otherrbZ auth_dictZ system_id_xmlkeyitemsretrrrregisterSystem s.     rcCstj}|jj|}|S)zG Check the activation key and return it's edition and customer )rrxryZ license_check)rmr}r~rrrrd9s rdcGsg}x|D]}t|}|tkr(t|}nZ|tkrDtdd|D}n>|tkr\dd|D}n&|tksl|tkrtdd|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)rirrr Nsz%_encode_characters..cSsg|] }t|qSr)r)rrrrr Psz&_encode_characters..cSsg|]\}}t||qSr)r)rnamevalrrrrRsrarN) rUr r r tupler rrdictrwr=rQ)argsrXr|Z item_typerrrrDs   r)F)F)NNNNNN)ArrRrMZup2date_clientrrrrrrZup2date_client.pkgplatformrZrhn.i18nr r ZurlparseZ xmlrpclibtypesr r r rrr ImportErrorZ urllib.parseparseZ xmlrpc.clientZclientlistrrTrPrintZlonggettextZ translationthasattrr_Z SYSID_DIRrWr^rwrirZinitUp2dateConfigrZinitLogrCr!r3r6boolrIrJrYr`rprlrrdrrrrr sl       $      $ %>  *