wo4h.ddlZddlZddlmZddlmZmZmZddlm Z ddl m Z ddl m Z mZddlmZddlmZd ZGd d eZd ed edeefdZdeefdZdeeeffdZd edefdZdededefdZdedefdZd edefdZdS)N)Path)DictListOptional)logger)instance) MyImunifyupdate_users_protection) HostingPanel) safe_fileopsz .myimunify_idceZdZdZdS)MyImunifyIdErrorz5Exception representing issues related to MyImunify idN)__name__ __module__ __qualname____doc__[/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/contracts/myimunify_id.pyrrs????rruser protectionreturncKtj|\}}|t||g|d{Vt jd|| t |d{V}n#t$rYdSwxYw|S)z5Save subscription type to the DB and generate id filerNz(Applied setting MyImunify=%s for user %s)r get_or_createsaver rinfo_get_or_generate_idr)sinkrr myimunify_ myimunify_ids radd_myimunify_userr#s *555LIq NN !$ ; ;;;;;;;; K:JMMM066666666 tt sA44 BBc NKg}td{V}td{V}tj5t |D]\}}tj |\}}| | |i dd|||j | |i ddd dddn #1swxYwY|S)zP Get a list of MyImunify users, their subscription types and unique ids Nremaillocale)r%usernamer"rr') r get_user_details_myimunify_user_to_idrdb transactionsorteditemsr rappendgetr)users user_detailsmyimunify_user_to_idr myimunify_uidrecordr!s rget_myimunify_usersr6&s~ E%88::::::::L!6!8!8888888  " "  #)*>*D*D*F*F#G#G   D-!/T:::IFA LL)--dB77;;GRHH $$1"("3*..tR88<%>>>>>>>Jt      H/    L=tSVV    HHHH   sA BB!#B  BcKt|d{V} t|S#ttf$r1t jj}t||d{VcYSwxYw)zS Read MyImunify id if exists or generate a new one and write into the file N)_get_myimunify_id_file_read_idFileNotFoundErrorruuiduuid1hex _write_id)rid_filer"s rrrOs+400000000G6   / 0666z||' |W555555555556s(?A*)A*r"rFcKd|d} tjt||d{Vn6#ttf$r"}t jd|t|d}~wwxYw|S)zWrite MyImunify id to filezE# DO NOT EDIT # This file contains MyImunify id unique to this user  Nz1Unable to write myimunify_id in user home dir: %s)r write_textr;OSErrorPermissionErrorrr:r)r"rFtextr=s rrErE[s      &%c'llD9999999999 _ %&&& H!LLLA%& s(3A&A!!A&c.|d5}t|D]?}|r;|ds&|x}r|ccdddS@ dddn #1swxYwYt )zRead MyImunify id from filer#N)openreversed readlines startswithstripr)rFfliner"s rr@r@ks c  (aQ[[]]++ ( (D (DOOC00 (#'::<</<(''' (((((((( (((((((((((((((( sAB7BB  B cK tj|}t|jtz }|s|jstjd|t tj t|d{Vnf#ttf$r"}tjd|t|d}~wwxYwn/#t$r"}tjd|t|d}~wwxYw|S)z((** ' 7>>>&& ."(W6666666666#W- . . . Eq'A-  . . &&& '...A%& Ns/C>'B&&C7CC D 'DD )rXrBpathlibrtypingrrr%defence360agent.contracts.permissionsrdefence360agent.modelrdefence360agent.myimunify.modelr r +defence360agent.subsys.panels.hosting_panelr defence360agent.utilsr r[ Exceptionrr;boolr#r6r*rrEr@r?rrrrjs ''''''''''888888******NNNNNNNNDDDDDD......(@@@@@y@@@!% c]&4:.T#s(^$ 6C 6C 6 6 6 6 #       d s    str