ր3lddlZddlZddlZddlZddlmZddlmZmZm Z ddl m Z ddl m Z ddlmZmZddlmZddlmZd Zd Zd Zed ZGd deZdedede efdZdeefdZdeeeffdZ dedefdZ!dededefdZ"dedefdZ#dedefdZ$dedefdZ%dS)N)Path)DictListOptional)logger)instance) MyImunifyupdate_users_protection) HostingPanel) safe_fileopsz .myimunify_idzE# DO NOT EDIT # This file contains MyImunify id unique to this user 0123456789abcdefceZdZdZdS)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_usersr8.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)z Read MyImunify id if exists and valid, or generate a new one and write into the file. Malformed files are regenerated. N)_get_myimunify_id_file_read_idFileNotFoundErrorruuiduuid1hex _write_id)rid_filer$s rr r Ws +400000000G6   / 0666z||' |W555555555556s(?A*)A*r$rHcKt|zdz} tjt||d{Vn6#tt f$r"}t jd|t|d}~wwxYw|S)zWrite MyImunify id to file Nz1Unable to write myimunify_id in user home dir: %s) _BANNERr write_textr=OSErrorPermissionErrorrr<r)r$rHtextr?s rrGrGds \ !D (D&%c'llD9999999999 _ %&&& H!LLLA%& s(:A- A((A-c tjt|tjtjz}n#t $rt $rtwxYw tj tj |j sttj |d}| d}n#t$rtwxYw tj|n#tj|wxYwt!|S)anRead and validate MyImunify id from file. Raises MyImunifyIdError if malformed. Opens with O_RDONLY | O_NONBLOCK and verifies via fstat() that the fd refers to a regular file before reading. This eliminates the TOCTOU window between a path-level type check and the actual read (e.g. an attacker replacing the file with a FIFO between the two). i zutf-8)osopenr=O_RDONLY O_NONBLOCKrCrMrstatS_ISREGfstatst_modereaddecodeUnicodeDecodeErrorclose _parse_id)rHfddatarOs rrBrBos WS\\2;#> ? ?  |BHRLL011 #" "wr4  {{7##     T??s(9<AAB98C$9C  C$$C:rOc*d}|D]r}|}|s|dr/|tt |t kst d|Dst|}s|t|S)z`Read line by line: skip comments (#). First non-comment line must be valid id; nothing after it.N#c3(K|] }|tvVdS)N)_HEX).0cs r z_parse_id..s&'='=aT '='='='='='=r) splitlinesstrip startswithrlen_ID_LENall)rOid_lineliness rr]r]sG!!   JJLL   <<      " " q66W  C'='=1'='='=$=$= " " NrcK tj|}t|jtz } t jt|n#t$r|j stj d|t t jt|d{Vn6#tt f$r"}tj d|t|d}~wwxYwYnXt $rtj d|twxYw#t"$r"}tj d|t|d}~wwxYw|S)z((** ' 7>>>&& ."(W6666666666#W- . . . Eq'A-  .76  # # # L:G D D D" " #% &&& '...A%&* NsLD !A?D'B?>D?C2C--C22D7&D E *EE )&rQrqrUrDpathlibrtypingrrr%defence360agent.contracts.permissionsrdefence360agent.modelrdefence360agent.myimunify.modelr r +defence360agent.subsys.panels.hosting_panelr defence360agent.utilsr rtrKrk frozensetrc Exceptionrr=boolr%r8r,r rGrBr]rArrrrs@ ''''''''''888888******NNNNNNNNDDDDDD......(O y#$$@@@@@y@@@!% c]&4:.T#s(^$ 6C 6C 6 6 6 6#ds4CC&str