hVGpdZddlZddlZddlZddlmZddlmZddlm Z m Z ddl m Z ddl mZmZddlmZdd lmZmZdd lmZmZdd lmZdd lmZdd lmZmZmZm 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)randint)TimeoutExpired)ANTIVIRUS_MODE CustomBilling) HookEvent) AV_DEFAULT_ID LicenseCLN) MessageSource)CLNCLNError)APIErrorIndependentAgentIDAPI) hosting_panel)PanelException) await_forrecurring_checkretry_onsafe_cancel_task)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__6s>  $"&%)"$#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'cKt|jd{Vt|jd{V|jrt|jd{VdSdSr))rrrr r#s r%shutdownzCheckLicense.shutdownGst4555555555t6777777777  % ?"4#=>> > > > > > > > > > ? ?r'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) asynciosleep_checkCancelledErrorrloggererror 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 registerrArr r5warningr1r4r8r6r7)r$r=es r%rBzCheckLicense._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)rCPatchmanLicense is_activeget_imunify_keyrB)r$ registeredtimeoutr=_s r%_register_linked_licensez%CheckLicense._register_linked_licensets %)$8$8$:$::::::: G >o799 >+;=========s >#'#8#8#=#======= 7r')seconds)on_errorrNc<Ktjd{VdSr))rensure_is_activated_and_validr#s r%_iaid_token_checkzCheckLicense._iaid_token_checks-#ACCCCCCCCCCCr'cKtd|jr3|jst |jd{V|jr1|j||_tdtj } | d{Vt_ n9#t$r,}t d||jcYd}~Sd}~wwxYwtjtjr&tjrGt'jr4td|d{VSt-j}tj}td||d|z }|dt.kr ||jkstj |dkrK t3j|d{V|jS t-j}td||jz|z }|d kr|jS||jkrt9|j}|d zt;d |d zzS#t<$r}td |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_utcidlimitrrEzCLN API error: %s) r5infor donerrr*rUr HostingPanel users_countr rr6r7 get_token cache_clear is_registeredis_freerJrKrPtimerrAr refresh_tokengetintrr rG)r$panelrHnowtokentoken_will_be_expireds r%r3zCheckLicense._checks  ()))  & ?.3355 ?#4#=>> > > > > > > > 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//sI=$C"" D,!D DD& K M-)A-M(M-M("M-(M-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) rfrcr r_rer"rLicenseExpiredrprocess_messageHOOK_EXPIRING_TIME_DELTAr!LicenseExpiring)r$ time_now_utcrmhooks 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__rrArr7HOOK_CHECK_TIMEOUTrpr&r-r/r,boolfloatrCstrrBrPrr rrUr3rr+r'r%rr0sGM 3w$$$   ??? 8 8 86e}6666 -#-4-----(     Xh4!8!8!8#*MMMDDNMDV0V0V0p_'((,,)(,,,r'r)+__doc__r1loggingrcrandomr subprocessr defence360agent.contracts.configrr%defence360agent.contracts.hook_eventsr!defence360agent.contracts.licenserr !defence360agent.contracts.pluginsr defence360agent.internals.clnr r defence360agent.internals.iaidr rdefence360agent.subsys.panelsr"defence360agent.subsys.panels.baserdefence360agent.utilsrrrrdefence360agent.utils.commonrrimav.patchman.licenserrJ getLoggerrtr5rr{r'r%rs* %%%%%%JJJJJJJJ;;;;;;GGGGGGGG;;;;;;77777777JJJJJJJJ777777====== 32222222<<<<<<  8 $ $~,~,~,~,~,=~,~,~,~,~,r'