HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/ipaclient/plugins/__pycache__/otptoken.cpython-36.pyc
3

�d[e��@sddlmZddlZddlmZddlmZmZmZm	Z	ddlm
Z
ddlmZm
Z
ddlmZddlmZdd	lmZdd
lmZddlZddlZddlZddlmZddlZddlZejr�eZ e�Z!e!ddd
�Gdd�de��Z"Gdd�dej#j$�Z$e!�Gdd�de��Z%dS)�)�print_functionN)�MethodOverride)�api�Str�Password�_)�errors)�add_message�ResultFormattingError)�Registry)�Local)�create_https_connection)�API_VERSION)�StringIOT)�overrideZno_failcs$eZdZdd�Z�fdd�Z�ZS)�otptoken_addc
Cs�t�}tj�}|j|�|j�|j|dd�ttjdd�}|dkrNt	j
d�}y|j�j|�}Wn,t
k
r�t||ttd�d�d�dSXtjj�r�|jjjj�}t|j�d�}	|	|kr�t||ttd�d�d�|S)NF)�out�tty�encodingzuUnable to display QR code using the configured output encoding. Please use the token URI to configure your OTP device)�messagerzRQR code width is greater than that of the output tty. Please resize your terminal.)r�qrcodeZQRCodeZadd_dataZmake�print_ascii�getattr�sys�stdout�locale�getpreferredencoding�getvalue�encode�UnicodeErrorr	r
r�isattyrZBackend�textuiZ
get_tty_width�len�
splitlines)
�self�output�uri�versionZ	qr_output�qrrZqr_codeZoutput_widthZ
qr_code_width�r)�/usr/lib/python3.6/otptoken.py�_get_qrcode0s8


zotptoken_add._get_qrcodecs�d|kr
n|jjjrd|d<nt|d<|djdd�}|dk	r`|jdd�r`|j|||d�}nd}tt|�j||f|�|�}|dk	r�t	d�|j
tjj
�d�t	d�|S)	Nr'z2.0�resultr&Z	no_qrcodeF�
)r)r�envZskip_version_checkr�getr+�superr�output_for_cli�printrrrr )r$r!r%�args�optionsr&r(�rv)�	__class__r)r*r1Zs 


zotptoken_add.output_for_cli)�__name__�
__module__�__qualname__r+r1�
__classcell__r)r))r6r*r.s*rc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�HTTPSHandlerz=Opens SSL HTTPS connections that perform hostname validation.cKs||_tjjj|�dS)N)�_HTTPSHandler__kwargs�urllib�requestr;�__init__)r$�kwargsr)r)r*r?yszHTTPSHandler.__init__cKs |jj�}|j|�t|f|�S)N)r<�copy�updater
)r$�hostr@Ztmpr)r)r*Z__inners

zHTTPSHandler.__innercCs|j|j|�S)N)Zdo_open�_HTTPSHandler__inner)r$Zreqr)r)r*�
https_open�szHTTPSHandler.https_openN)r7r8r9�__doc__r?rDrEr)r)r)r*r;vsr;c@s|eZdZed�ZdZeded�d�eded�dd	�ed
ed�dd	�eded
�dd	�fZeded�d�fZ	dd�Z
dd�ZdS)�
otptoken_synczSynchronize an OTP token.zX-IPA-TokenSync-Result�userzUser ID)�labelZpasswordrF)rIZconfirmZ
first_codez
First CodeZsecond_codezSecond Codeztoken?zToken IDc
sTd|jdii}ttjj|jjj��}|ddks4t�|dj	dd�|d<tjj
|�}dd	�|jD���fd
d�|j�D�}|r�|ddk	r�|d|d<tjj
|�}|jd
�}ttjjtjjtjjd�}tjj|�j||�}|j�dk�r|j�j|jd�|d|j<|j�|d|jdk�rPddd�j|d|jd�}	tjtd�|	d��|S)Nr,�unknownrZhttps�z/xmlz/session/sync_tokencSsh|]
}|j�qSr))�name)�.0�xr)r)r*�	<setcomp>�sz(otptoken_sync.forward.<locals>.<setcomp>csi|]\}}|�kr||�qSr)r))rM�k�v)r4r)r*�
<dictcomp>�sz)otptoken_sync.forward.<locals>.<dictcomp>�tokenzutf-8)Zcafile�tls_version_min�tls_version_max���okzError contacting server!zInvalid Credentials!)�errorzinvalid-credentialszUnknown Error!zUnable to synchronize token: %s)r)�header�listr=�parseZurlparserr.Z
xmlrpc_uri�AssertionError�replaceZ
urlunparse�
takes_options�itemsZ	urlencoderr;Ztls_ca_certrTrUr>Zbuild_opener�openZgetcode�infor/�closerZExecutionErrorr)
r$r3r@ZstatusZsegmentsZsync_uriZqueryZhandlerZrsp�msgr))r4r*�forward�s4
zotptoken_sync.forwardcOs|jd�dS)NzToken synchronized.)Zprint_plain)r$r!r,�keysr4r)r)r*r1�szotptoken_sync.output_for_cliN)r7r8r9rrFrYrrr^Z
takes_argsrdr1r)r)r)r*rG�s$rG)&Z
__future__rrZipaclient.frontendrZipalibrrrrrZipalib.messagesr	r
Zipalib.plugablerZipalib.frontendrZipalib.utilr
Zipapython.versionrrrZsix�iorZurllib.parser=Zurllib.requestZPY3�strZunicode�registerrr>r;rGr)r)r)r*�<module>s.G