<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
3
mi*                 @   s  d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d d	lmZmZ y4d dlZd dlZd d
lmZmZmZmZmZmZ W nD ek
r   d dljZd dljZeZeZeZeZe Ze Ze!Z"Y nX d dl#Z#e#j$dddZ%e&e%dse%j#e%_'e%j'Z(dZ)dZ*dddddZ+dd e+j, D Z-d dlm.Z. e.j/ Z0ej1 Z2dd Z3dd Z4dd Z5ee6dd d!Z7e6d"d#d$Z8d6d&d'Z9d7e6d(d)d*Z:d+d, Z;ed-d.d/Z<d8d0d1Z=d2d3 Z>d4d5 Z?dS )9    N)up2dateUtils)up2dateErrors)up2dateAuth)	rhnserver)
up2dateLog)
statistics)getPlatform)ustrsstr)ListType	TupleType
StringTypeUnicodeTypeDictTypeDictionaryTypezrhn-client-toolsT)Zfallbackugettextz/etc/sysconfig/rhnz/etc/sysconfig/rhn/jwt.tokenZ
shared_prosharedsoloadmin)zCloudLinux OS Shared ProzCloudLinux OS SharedzCloudLinux OS SolozCloudLinux OS Adminc             C   s   i | ]\}}||qS  r   ).0kvr   r   /usr/lib/python3.6/rhnreg.py
<dictcomp>4   s   r   )configc               C   s   t jtd t jS )NsystemIdPath)osaccesscfgR_OKr   r   r   r   
registered<   s    r!   c             C   s   t jj| }t j|t jsdS t j| t jrLyt j| | d  W n
   dS t j| t jt j	B t
dd}t j|d}z|jt| W d|j  X dS )z; Write a file to disk that is not readable by other users. Fz.saveZ0600   wNT)r   pathdirnamer   W_OKF_OKrenameopenO_WRONLYO_CREATintfdopenwriter
   close)Zsecure_fileZfile_contentsZdir_namefdZfd_filer   r   r   _write_secure_file?   s    
r1   c             C   s   t td | }|S )Nr   )r1   r   )systemIdresr   r   r   writeSystemIdU   s    r4   )tokenallowTransitionc             C   sn   ddl }ddl}|jjds dS dd| g}|r8|jd |j|}|j \}}|jdkrjtj	d||f  dS )zH
    Execute binary file which we use as hook for jwt token updates
    r   Nz /opt/cloudlinux/venv/bin/python3z/usr/sbin/cl-pre-jwt-updatez--new-tokenz--allow-transitionz7Pre jwt update hook failed with stdout=%s and stderr=%s)

subprocessr   r$   existsappendPopencommunicate
returncodeloglog_me)r5   r6   r7   r   cmdpstdoutstderrr   r   r   _execute_pre_jwt_update_hookZ   s    



rC   )r6   c             C   sj   ddl }ddl}|jjds dS dg}| r4|jd |j|}|j \}}|jdkrftj	d||f  dS )zH
    Execute binary file which we use as hook for jwt token updates
    r   Nz /opt/cloudlinux/venv/bin/python3z/usr/sbin/cl-post-jwt-updatez--allow-transitionz8Post jwt update hook failed with stdout=%s and stderr=%s)
r7   r   r$   r8   r9   r:   r;   r<   r=   r>   )r6   r7   r   r?   r@   rA   rB   r   r   r   _execute_post_jwt_update_hookm   s    


rD   Fc             C   s   t j }y|jj| }W nF tjk
r.   dS  tjtjtjtj	fk
r^   t
jtj   dS X t|| tt| t| dS )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)r   Z	RhnServerZup2dateZgetJWTTokenr   UnknownMethodExceptionZAuthenticationTicketErrorZRhnUuidUniquenessErrorCommunicationErrorZ$AuthenticationOrAccountCreationErrorr=   Zlog_exceptionsysexc_inforC   r1   	JWT_TOKENrD   )r2   r6   Zxmlrpm_serverresultr   r   r   getAndWriteJWTTokenToFile   s    

rK   )human_readablec          	   C   sF   d}t jj|sdS t| }|j jd}| r4|S t| S Q R X d S )Nz/opt/cloudlinux/cl_editionr   
)r   r$   r8   r)   readstrip_human_readable_to_product)rL   Zedition_cache_filefZraw_editionr   r   r   getServerEdition   s    
rR   c             C   sV  yt | }W nP tjk
rH } ztd|j  tjd W Y d d }~X n tjk
r\   d S X t }|d }||krxd S |rtdj	t
| t
| d td tjd |sRtjj std td t
|  dt
|  d	}d
dd}|j|}	|	d k	rJtj }
|
|	kr6td||  d|
 d tjd n| d||  d}t| d S )Nz%s   editionzWARNING: 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}.)Zcurrent_editionZnew_editionz0Run clnreg_ks manually to complete registration.a   Error: 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.   )r   r   z@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.)checkKeyr   rF   printerrmsgrG   exitrE   rR   format_product_to_human_readablestdinisattygetr   Zcount_server_users_askConfirmation)activationKeyZstrictEditionZsilentMigrationZlicenseInformationeZcurrentEditionZlicenseEditionmessageZedition_to_users_limitZlicense_users_limitZusers_on_serverr   r   r   checkLicenseKey   sB    




rc   )confirmationMessagec             C   s2   t |  td}|j dkr.t d tjd dS )zS
    Prints message and makes sure that client is ready for edition migration.
    z Do you want to continue? [N/y]: yzAborted.rS   N)rW   inputlowerrG   rY   )rd   Zresponser   r   r   r_      s
    r_   c             C   s   |t j t j t j d}tj }|dk	r2||d< |rTx|j D ]\}}	|	||< q@W |rb||d< n| |d< ||d< |dk	r||d< n(tjj	drd	ntjj	d
rdnd|d< t
j }
|
jj|}|S )ziWrapper for the old xmlrpc to register a system. Activates subscriptions
    if a reg num is given.

    )Zprofile_nameZ
os_releaseZrelease_nameZarchitectureNZ	system_idr5   usernamepasswordrT   z/etc/cloudlinux-edition-solor   z/etc/cloudlinux-edition-adminr   r   )r   Z
getVersionZgetOSReleaseZgetArchr   ZgetSystemIditemsr   r$   r8   r   RegistrationRhnServerregistrationZ
new_system)rh   ri   ZprofileNamer5   otherrT   Z	auth_dictZsystem_id_xmlkeyitemsretr   r   r   registerSystem   s*    


rr   c             C   s   t j }|jj| }|S )zG
    Check the activation key and return it's edition and customer
    )r   rk   rl   Zlicense_check)r`   rp   rq   r   r   r   rV     s    rV   c              G   s   g }x| D ]}t |}|tkr(t|}nZ|tkrDtdd |D }n>|tkr\dd |D }n&|tksl|tkrtdd |j	 D }|j
| q
W t|dkr|d S t|S dS )	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.
        c             s   s   | ]}t |V  qd S )N)_encode_characters)r   ir   r   r   	<genexpr>4  s    z%_encode_characters.<locals>.<genexpr>c             S   s   g | ]}t |qS r   )rs   )r   rt   r   r   r   
<listcomp>6  s    z&_encode_characters.<locals>.<listcomp>c             S   s   g | ]\}}t ||qS r   )rs   )r   namevalr   r   r   rv   8  s    rS   r   N)typer   r	   r   tupler   r   r   dictrj   r9   len)argsrJ   ro   Z	item_typer   r   r   rs   *  s    

rs   )F)F)NNNNNN)@r   rG   Zup2date_clientr   r   r   r   r   r   Zup2date_client.pkgplatformr   Zrhn.i18nr	   r
   ZurlparseZ	xmlrpclibtypesr   r   r   r   r   r   ImportErrorZurllib.parseparseZxmlrpc.clientZclientlistrz   bytesstrr{   r,   ZlonggettextZtranslationthasattrr   _Z	SYSID_DIRrI   rP   rj   r[   r   ZinitUp2dateConfigr   ZinitLogr=   r!   r1   r4   boolrC   rD   rK   rR   rc   r_   rr   rV   rs   r   r   r   r   <module>	   sj   $



>  
*