MOON
Server: Apache
System: Linux server2.shieldcogroup.com 3.10.0-1160.119.1.el7.tuxcare.els12.x86_64 #1 SMP Fri Nov 8 05:49:38 UTC 2024 x86_64
User: jacom (1029)
PHP: 8.1.34
Disabled: exec,passthru,shell_exec,system
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	urlencodecCs#d}y�tj�}|dkr;|s7tjd�ndStj�dj|�}tj	|�}t
j|j��}t
j
|�}|ddkr�tj�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_serveridtclear_cachetloginfoR	tprint_cln_http_error(tsilentturlt	server_idtresponsetcontenttreste((s*/usr/libexec/kcare/python/kcarectl/auth.pyt
unregisters,


cCsetjd�tj�}|dkr)dStj�tj�}ddl}|dkrg|jd�n|jj�t	dd�}t	dd�}tj
|j�|jj��tj
|j�|jj��tj
|j�|j
j��xotr`tjd
�t|�\}}}|dkr�|r�tj|�t|�tj�|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_tokenRR(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_encodingGscCs�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_HEADERRRRRRtintRBR	R
RRt	Exceptiontkcarelogt	exception(RRR<R!R"((s*/usr/libexec/kcare/python/kcarectl/auth.pyR5Ms0
cCs�ytt�Wn!tk
r1tjjd�nXtj�}td|fd|fg�}dj	t
j�|�}t|�\}}}|dkr�t
j|�t|�t
j�tjd�dS|dkr�tjd�n�|d	kr�tjd
�n�|dkrtjd�nj|d
kr7tjd�nN|dkrStjd�n2|dkrotjd�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#R2RGRRHRIRtget_hostnameRRRRR5RR6R7RRRR=(RKtretryRJtqueryRR;RR<((s*/usr/libexec/kcare/python/kcarectl/auth.pytregister[s@






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_writeRRQ(R<((s*/usr/libexec/kcare/python/kcarectl/auth.pyR7�scOs�|jdd�}|jdt�r-t}n	tj}tj|�rXtj|||�Stj|t	�t
�d|�}tj|dd�tj�|||�S(Ntmethodt
check_licensetcounti(
tpopRR2t_check_auth_retryRtcheck_urlopen_retrytis_local_urlturlopen_basethttp_requesttget_http_auth_stringRRRRM(RtargstkwargsRTtchecktrequest((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+cCs8t|t�r(|jdkr(t|�Stj||�S(Ni�i�(i�i�(t
isinstanceR	R;t_handle_forbiddenRRY(R"tstate((s*/usr/libexec/kcare/python/kcarectl/auth.pyRX�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...(RlRm(R2RtCHECK_CLN_LICENSE_STATUSRRRRRRRRRtFalseRRR
RRRDRHterrorRt_register_trial(RiRRR tinfotex((s*/usr/libexec/kcare/python/kcarectl/auth.pyRh�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(RRRRRRRRRRRRDR%RFt_get_license_info_by_ipR
RR(RRRR R!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}(RRRRRRRRtlowerRFR%Rtparse_response_datetstrftimeRDR
RRtKeyErrortstrip(RtRRR R!R;Rxtexpires_strRR"RK((s*/usr/libexec/kcare/python/kcarectl/auth.pyRu�s<

#cCs�tjjtjd�}tjj|�r.dSy,tjtj	�d�}t
jt
j|j
���}y�|dj�dkr�t
j|ddt�tj�|ddkr�tj|d|d	��ntjd
j|d��dS|ddkr$t
j|ddt�tjd��ntjd
��Wn"tk
rX}tj|��nXWn%tk
r�}tj|j��nXdS(Nstrial-requesteds/trial.plainRR
Rzt
ensure_dirtexpiredRxtcreateds3Requesting trial license for IP {0}. Please wait...tnasInvalid Licensei����(R&tpathtjoinRtPATCH_CACHEtexistsRRRRRRRRR{RSR2RRtAlreadyTrialedExceptionRRRRt
KcareErrortUnableToGetLicenseExceptionR~R	R;(t
trial_markRR!tkeR"((s*/usr/libexec/kcare/python/kcarectl/auth.pyRqs,
("RdR&R>R3RzRRRRRRRRRtpy23R	R
RRoR#R=RBR5ROtcachedRRR7RbR]RXRhRwRuRq(((s*/usr/libexec/kcare/python/kcarectl/auth.pyt<module>s&@			.		
			)	#