K6hdZddlZddlZddlZddlmZddlmZddlZddl m Z ddl m Z ddl mZddlmZmZdd lmZd ZejeZGd d eZeZd edefdZed edefdZedd efdZd ede fdZdefdZ de dedzfdZ!de deddfdZ"defdZ#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) lru_cache) urlencode)Path)IndependentAgentIDAPI) HostingPanel)log_error_and_ignore safe_fileops)IMUNIFY_PATCH_PURCHASE_URLz.imunify_patch_idceZdZdS)ImunifyPatchIdErrorN)__name__ __module__ __qualname__T/opt/imunify360/venv/lib/python3.11/site-packages/imav/contracts/imunify_patch_id.pyr r (sDrr usernamereturncKt|d{V}t|x}r|St}t||d{V|S)aEnsure the Imunify.Patch ID file exists for the given user. This function checks if the Imunify.Patch ID file exists in the user's home directory. If it does not exist, it generates a new ID, writes it to the file, and returns the ID. If the file already exists, it reads and returns the existing ID. Args: username (str): The username for which to ensure the ID file. Returns: ImunifyPatchUserId: The Imunify.Patch user ID. N) _get_id_file _read_id_file _generate_id_write_id_file)rid_file_ids rensure_id_filer/sq!********GG$$$s ..C # & &&&&&&&& JrcKt|4d{Vt|d{Vcdddd{VS#1d{VswxYwYdSN)get_lockrrs rget_imunify_patch_idr!Es!!........#H--------..............................sA A  A )maxsizec(tjSr)asyncioLockr s rrrKs <>>rcK tj|}t|jtz }|s|js9td|jtd|j tj t|d{Vn#ttf$r.}tdt|t|d}~wwxYwnB#t$r5}td|td||d}~wwxYw|S)zEGet a file with Imunify.Patch user id and create it if does not existzNo such user homedir: Nz$Unable to put %s in user home dir %szNo such user: z No such user )pwdgetpwnamrpw_dirIMUNIFY_PATCH_ID_FILEexistsparentloggererrorr r touchstrPermissionErrorOSErrorKeyError)ruser_pwdres rrrPsx1<)) x''*??~~ 1>((**  FgnFFGGG)=W^== 1"(W6666666666#W- 1 1 1 :) *q0  1 1 EEE 0h00111!"<("<"<==1DE( Ns/D'CD)C==D E0EEc2tjjS)zGenerate Imunify.Patch id)uuiduuid4hexrrrrrls :<< rrc`|d5}t|D]?}|r;|ds&|x}r|ccdddS@ dddn #1swxYwYt d|ddS)zQRead Imunify.Patch id from `id_file`. If id is not found, return `None`. r#Nz Cannot parse z, file is corrupted or empty)openreversed readlines startswithstripr-warning)rflineimunify_patch_ids rrrqs c  ,aQ[[]]++ , ,D ,DOOC00 ,'+zz||3#,+++ ,,,,,,,, ,,,,,,,,,,,,,,,,  NNH7HHHIII 4sAB7BB  B rcKd|d} tjt||d{VdS#ttf$r.}t dt|t|d}~wwxYw)z$Write Imunify.Patch id to `id_file`.zI# DO NOT EDIT # This file contains Imunify.Patch id unique to this user  Nz'Unable to write %s in user home dir: %s) r write_textr0r2r1r-r.r*r )rrtextr5s rrrs      )%c'llD99999999999 _ %))) 57La   "q( )s(4A3)A..A3c rKtj}t|d{V}t}|}|d{V|gdd}t||pd||d|d}td|S)N,)iaidimunify_patch_user_id server_iprwebsites?) rget_iaidr!r get_server_ipget_domains_per_usergetrjoinr )rrNrO panel_managerrP user_domainsurl_argss rget_imunify_patch_purchase_urlr[s ! ) + +D"6x"@"@@@@@@@ NNM++--I'<<>>>>>>>>CC"qb L%:%@b" ..   H) 5 58 5 55r)$__doc__r$loggingr' functoolsr urllib.parserr7pathlibrdefence360agent.internals.iaidr+defence360agent.subsys.panels.hosting_panelrdefence360agent.utilsrr imav.contracts.configr r* getLoggerr r- Exceptionr r0ImunifyPatchUserIdrr!rrrrrr[rrrrhsI* """""" @@@@@@DDDDDDDDDDDDDD<<<<<<+  8 $ $     )   3+=,..1C....  4s8( 4 $6$=    )$)-?)D))))"6c666666r