HEX
Server: Apache
System: Linux 162-240-236-42.bluehost.com 3.10.0-1160.114.2.el7.x86_64 #1 SMP Wed Mar 20 15:54:52 UTC 2024 x86_64
User: bt667 (1004)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //usr/libexec/kcare/python/kcarectl/auth.pyc
�
��	ic@s ddlZddlZddlZddlZddlmZmZmZmZm	Z	m
Z
mZmZm
Z
ddlmZmZmZed�Zd�Zd�Zd�Zed	�Ze
jd
��Zd�Zd�Zd
�Zd�Zd�Zd�Zdd�Z d�Z!dS(i����Ni(	tconfigt	constantsterrorst
http_utilstipv6_supportt	log_utilstplatform_utilstserveridtutils(t	HTTPErrortURLErrort	urlencodecCsd}y�tj�}|dkr;|s7tjd�ndStj�dj|�}tj	|�}t
j|j��}t
j
|�}|ddkr�tj�|s�tjd�q�n+|s�tj|�tjd|d�nWn,tk
r}|stj||�qnXdS(Ns1Error unregistering server: cannot find server ids&/unregister_server.plain?server_id={0}tsuccessttruesServer was unregisteredsError unregistering server: tmessage(tNoneRtget_serveridRtlogerrorRtget_registration_urltformatRturlopenRtnstrtreadtdata_as_dicttrm_serveridtloginfoR	tprint_cln_http_error(tsilentturlt	server_idtresponsetcontenttreste((s*/usr/libexec/kcare/python/kcarectl/auth.pyt
unregisters*

cCs[tjd�tj�}|dkr)dStj�tj�}ddl}|dkrg|jd�n|jj�t	dd�}t	dd�}tj
|j�|jj��tj
|j�|jj��tj
|j�|j
j��xetrVtjd
�t|�\}}}|dkr�|r�tj|�t|�|jd�q�q�WdS(NsHRegister auto-retry has been enabled, the system can be registered laterii����s	/dev/nulltrsa+i<iii (Rt
print_wrappertostforktsetsidtsystexittstdouttflushtopentdup2tfilenotstdintstderrtTruettimetsleept
_try_registerRt
set_server_idt_set_auth_token(RtpidR(tsitsotcodeRt
auth_token((s*/usr/libexec/kcare/python/kcarectl/auth.pyt_register_retry&s,


	


cCs6|dk	r2tjd|�r2td|��n|S(Ns	^[\w.-]+$sInvalid value received: %s(Rtretmatcht
ValueError(tvalue((s*/usr/libexec/kcare/python/kcarectl/auth.pyt_validate_urlsafe_encoding@scCs�yutj|�}|jjtjd�}tjtj	|j
���}t|d�t|jd��t|�fSWnOt
tfk
r�}tj||�dStk
r�tjjd|�dSXdS(NR:Rs)Exception while trying to register URL %s(NNN(NNN(RRtheaderstgetRtAUTH_TOKEN_HEADERRRRRRtintRAR	R
RRt	Exceptiontkcarelogt	exception(RRR;R R!((s*/usr/libexec/kcare/python/kcarectl/auth.pyR4Fs0
cCs�ytt�Wn!tk
r1tjjd�nXtj�}td|fd|fg�}dj	t
j�|�}t|�\}}}|dkr�t
j|�t|�tjd�dS|dkr�tjd�n�|d	kr�tjd
�n�|dkrtjd�nj|d
kr-tjd�nN|dkrItjd�n2|dkretjd�ntjdj	|��|r�t|�dS|p�dS(Ns9Exception while trying to unregister URL before register.thostnametkeys{0}/register_server.plain?{1}isServer RegisteredisAccount LockedisInvalid Keyis}You have reached maximum registered servers for this key. Please go to your CLN account, remove unused servers and try again.is[IP is not allowed. Please change allowed IP ranges for the key in KernelCare Key tab in CLNisEThis IP was already used for trial, you cannot use it for trial againisfThis IP was banned. Please contact support for more information at https://www.kernelcare.com/support/sUnknown Error {0}i����(R"R1RFRRGRHRtget_hostnameRRRRR4RR5R6RRR<(RJtretryRItqueryRR:RR;((s*/usr/libexec/kcare/python/kcarectl/auth.pytregisterTs>





cCstjtj�S(N(Rttry_to_readRtAUTH_TOKEN_DUMP_PATH(((s*/usr/libexec/kcare/python/kcarectl/auth.pyt_get_auth_token|scCs!|s
dStjtj|�dS(N(Rtatomic_writeRRP(R;((s*/usr/libexec/kcare/python/kcarectl/auth.pyR6�scOs�|jdd�}|jdt�r-t}n	tj}tj|�rXtj|||�Stj|t	�t
�d|�}tj|dd�tj�|||�S(Ntmethodt
check_licensetcounti(
tpopRR1t_check_auth_retryRtcheck_urlopen_retrytis_local_urlturlopen_basethttp_requesttget_http_auth_stringRQRRL(RtargstkwargsRStchecktrequest((s*/usr/libexec/kcare/python/kcarectl/auth.pyturlopen_auth�s		!cCsAtj�}|r=tjtjtjdj|d����SdS(Ns{0}:{1}t
kernelcare(	RRRRtbase64t	b64encodetbstrRR(R((s*/usr/libexec/kcare/python/kcarectl/auth.pyR\�s+cCsLt|t�r5|jdkr(t|�S|jdkSt|t�rHtSdS(Ni�i�i�(i�i�(t
isinstanceR	R:t_handle_forbiddenR
R1(R!tstate((s*/usr/libexec/kcare/python/kcarectl/auth.pyRW�s

cCs"d|krtStjrtj�}tj�d}|rQ|dj|�7}ny7tj	t
j|dt�j
��}tj|�}Wn*tk
r�}tj||dt�dSX|s�|jd�r�tjjdj|��dS|ddkrt|d<tjd�tSt�ndS(
sIn case of 403 error we should check what's happen.
    Case #1. We are trying to register unlicensed machine and should try to register trial.
    Case #2. We have a valid license but access restrictions on server are not consistent yet
             and we had to try later.
    tlicenses/check.plains?server_id={0}tretry_on_500R*NR:sUnexpected CLN response: {0}t0t1s$Unable to access server. Retrying...(RkRl(R1RtCHECK_CLN_LICENSE_STATUSRRRRRRRRRtFalseRRR
RRRCRGterrorRt_register_trial(RhRRRtinfotex((s*/usr/libexec/kcare/python/kcarectl/auth.pyRg�s*	$

cCs$tj�}|rtj�dj|�}y�tj|�}tj|j	��}tj
|�}|sx|jd�r�tjdj|��dSt
|d�}|dkr�tjd�dStdd�}|dkr�tjd�n|SWq tk
r}tj||�dSXnt�SdS(	Ns/check.plain?server_id={0}R:sUnexpected CLN response: {0}iisKey-based valid license foundtkey_checkeds No valid key-based license found(RRRRRRRRRRRRCR$REt_get_license_info_by_ipR
RR(RRRRR R:tlicense_typeR!((s*/usr/libexec/kcare/python/kcarectl/auth.pytlicense_info�s,
icCstj�d}y�tj|�}tj|j��}tj|�}|dj�dkr�t	|d�}|dkr�tj
dj|d��dS|dkr�|d}tj|d	�j
d
�}tj
dj||��dS|dkr?|dkr?|d}tj|d	�j
d
�}tj
d
j||��n|dkr�|dkr�d|kr�tj
dj|d��q�tj
d�q�n(|jdd�}tj
dj|��WnTtk
r�}	tj|	|�n2tk
r}
tj
dj|
|j���nXdS(Ns/check.plainRR
R:isValid license found for IP {0}tipitexpire_dates%Y-%m-%ds?You have a trial license for the IP {0} that will expire on {1}is0Your trial license for the IP {0} expired on {1}isThe IP {0} hasn't been licenseds This server hasn't been licensedRts"Error retrieving license info: {0}s1Unexpected CLN response, cannot find {0} key:
{1}(RRRRRRRRtlowerRER$Rtparse_response_datetstrftimeRCR
RRtKeyErrortstrip(RsRRRR R:Rwtexpires_strRR!RJ((s*/usr/libexec/kcare/python/kcarectl/auth.pyRt�s<

#cCs|tjjtjd�}tjj|�r.dSy"tjtj	�d�}t
jt
j|j
���}y�|dj�dkr�t
j|ddt�|ddkr�tj|d|d	��ntjd
j|d��dS|ddkrt
j|ddt�tjd��ntjd
��Wn"tk
rN}tj|��nXWn%tk
rw}tj|j��nXdS(Nstrial-requesteds/trial.plainRR
Ryt
ensure_dirtexpiredRwtcreateds3Requesting trial license for IP {0}. Please wait...tnasInvalid Licensei����(R%tpathtjoinRtPATCH_CACHEtexistsRRRRRRRRRzRRR1RtAlreadyTrialedExceptionRRRRt
KcareErrortUnableToGetLicenseExceptionR}R	R:(t
trial_markRR tkeR!((s*/usr/libexec/kcare/python/kcarectl/auth.pyRps*("RcR%R=R2RyRRRRRRRRRtpy23R	R
RRnR"R<RAR4RNtcachedRQR6RaR\RWRgRvRtRp(((s*/usr/libexec/kcare/python/kcarectl/auth.pyt<module>s&@			(		
				)	#