h%"dZddlZddlZddlZddlmZddlmZddlm Z ddl m Z m Z ddl mZddlmZmZdd lmZdd lmZmZdd lmZmZdd lmZdd lmZddlmZm Z m!Z!ddl"m#Z#m$Z$ddl%m&Z'ej(e)Z*GddeZ+dS)u  This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program.  If not, see . Copyright © 2019 Cloud Linux Software Inc. This software is also available under ImunifyAV commercial license, see N)suppress)randint)TimeoutExpired)ANTIVIRUS_MODE CustomBilling) HookEvent) AV_DEFAULT_ID LicenseCLN) MessageSource)CLNCLNError)APIErrorIndependentAgentIDAPI) hosting_panel)PanelException) await_forrecurring_checkretry_on)DAYHOUR)LicenseceZdZeZeZeZdezZdZ dZ dZ dZ de egfdZdede egfd Zdefd Zeeee eez d ZdZeedZdS) CheckLicensechd|_d|_d|_d|_d|_d|_d|_dS)NF)loopsinkcheck_hooks_taskcheck_license_taskcheck_iaid_token_taskexpiring_calledexpired_calledselfs O/opt/imunify360/venv/lib/python3.11/site-packages/imav/plugins/check_license.py__init__zCheckLicense.__init__2s>  $"&%)"$#cK||_||_|j||_|j||_dSN)rr create_task check_hooksr_recurring_checkr)r$rrs r% create_sourcezCheckLicense.create_source;sg  $ 5 5d6F6F6H6H I I"&)"7"7  ! ! # ## # r'c`K|j|j|jr|jt t j5|jd{V|jd{V|jd{VddddS#1swxYwYdSr))rcancelrr rasyncioCancelledErrorr#s r%shutdownzCheckLicense.shutdownCs $$&&& &&(((  % 0  & - - / / / g, - - - -) ) ) ) ) ) ) )' ' ' ' ' ' ' ', , , , , , , , - - - - - - - - - - - - - - - - - -s.(B##B'*B'cK tj|d{Vd{Vn#tj$rYdSt$r<t dtj|jd{VYnHt$r<t dtj|jd{VYnwxYw)NTz-Token signatures verification timeout expiredz*An exception occurred during license check) r0sleep_checkr1rloggererror RETRY_TIMEOUT Exception exceptionr#s r%r,zCheckLicense._recurring_checkMs 8 8m$++--$7$7$7$7$7$78888888888)   ! 8 8 8 LMMMmD$677777777777 8 8 8  !MNNNmD$677777777777 8 8s28C ACACCreturncKtr-tjs!tjs tjr d|jfS|dd{VS)NFIPL)key)rr IP_LICENSE UPGRADE_URLUPGRADE_URL_360TOKEN_UPDATE_PERIOD_register_by_keyr#s r%_register_by_ipzCheckLicense._register_by_ipZsd  7-": 7( 7M,I 7d666**u*555555555r'r>cK tj|d{Vd|jtd|jdzzfS#t$r.}t d|d|jfcYd}~Sd}~wtj$rt$r.}t d|d|j fcYd}~Sd}~wwxYw)z Try to register imunify key in CLN. :param str key: key to register :return: tuple of (bool, float): (success, timeout) NTrzFailed to register: %sF) r registerrBrr r6warningr0r1r9r7r8)r$r>es r%rCzCheckLicense._register_by_key`s -,s## # # # # # # #1G4+q055  3 3 3 NN3Q 7 7 7$22 2 2 2 2 2 2%     - - - LL11 5 5 5$,, , , , , , , -s/;A B= #A3-B=3B=#B82B=8B=cK|d{V\}}|sLtjr9tjd{Vx}r||d{V\}}|S)z Try to register any available license for the current customer. IPL license has the highest priority. Returns the timeout value. N)rDPatchmanLicense is_activeget_imunify_keyrC)r$ registeredtimeoutr>_s r%_register_linked_licensez%CheckLicense._register_linked_licensets %)$8$8$:$::::::: G >o799 >+;=========s >#'#8#8#=#======= 7r')seconds)on_errorrOc<Ktjd{VdSr))rensure_is_activated_and_validr#s r%_iaid_token_checkzCheckLicense._iaid_token_checks-#ACCCCCCCCCCCr'chKtd|jrp|jsW|jt t j5|jd{Vdddn #1swxYwY|jr1|j | |_tdtj } | d{Vt_ n9#t$r,}td||jcYd}~Sd}~wwxYwtjtjr&tjrGt-jr4td|d{VSt3j}tj}td||d|z }|dt4kr ||jkstj |dkrK t9j|d{V|jS t3j}td||jz|z }|d kr|jS||jkrt?|j}|d ztAd |d zzS#tB$r}t"d |tjr&tjr2t-jr|d{VcYd}~S|jcYd}~Sd}~wwxYw|jS) NzCheckin IAID tokenzChecking tokenzFailed to get users count: %sz*Server is not registered, skipping checkinzChecking token expiration %rtoken_expire_utcidlimitrrFzCLN API error: %s)#r6infor doner/rr0r1rr*rVr HostingPanel users_countr rr7r8 get_token cache_clear is_registeredis_freerKrLrQtimer rBr refresh_tokengetintrr rH)r$panelrInowtokentoken_will_be_expireds r%r5zCheckLicense._checks;  ()))  & 1.3355 1  & - - / / /'011 1 100000000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 )-)>)>&&((**D &  $%%%*,, &+0+<+<+>+>%>%>%>%>%>%>J " " & & & LL8! < < <% % % % % % % & ((***(**; 0!##; 0 )++; 0 KKD E E E6688888888 8)++C(**E KK6 > > >$)*<$=$C !d },,*T-EEE*U7^;;$!/66666666?#77@&)++C" ".d6N0N *-11#77,t/GGG03D4L0M0M-0A50A599= 2 2 2NN#6:::&4662%-//2,5772 &*%B%B%D%DDDDDDDDDDDDD#1111111 2F//s[/B  B B :$D E)!E EE# L N*&A-N%N*N%N*%N*cKttj}td}|dS||krG|js>t j|}|j |d{Vd|_dSdS||j z |cxkr|krIndS|j s@t j |}|j |d{Vd|_ dSdSdS)Nlicense_expire_utc)exp_timeT) rgrdr r`rfr"rLicenseExpiredrprocess_messageHOOK_EXPIRING_TIME_DELTAr!LicenseExpiring)r$ time_now_utcrnhooks r%r+zCheckLicense.check_hookssG49;;'' <<))++//0DEE   F | # #& + /BBBi//555555555&*### + + t4 4| N N N Nh N N N N N N' , 0(CCCi//555555555'+$$$ O N , ,r'N)__name__ __module__ __qualname__rrBrr8HOOK_CHECK_TIMEOUTrqr&r-r2r,boolfloatrDstrrCrQrrrrVr5rr+r'r%rr,sGM 3w$$$   --- 8 8 86e}6666 -#-4-----(     Xh4!8!8!8#*MMMDDNMDX0X0X0t_'((,,)(,,,r'r),__doc__r0loggingrd contextlibrrandomr subprocessr defence360agent.contracts.configrr%defence360agent.contracts.hook_eventsr!defence360agent.contracts.licenser r !defence360agent.contracts.pluginsr defence360agent.internals.clnr r defence360agent.internals.iaidrrdefence360agent.subsys.panelsr"defence360agent.subsys.panels.baserdefence360agent.utilsrrrdefence360agent.utils.commonrrimav.patchman.licenserrK getLoggerrur6rr|r'r%rs* %%%%%%JJJJJJJJ;;;;;;GGGGGGGG;;;;;;77777777JJJJJJJJ777777======FFFFFFFFFF22222222<<<<<<  8 $ $D,D,D,D,D,=D,D,D,D,D,r'