§ WèÄjãó—dZddlZddlZddlZddlZddlmZddlm Z ddl m Z ddl m ZddlmZmZdd lmZdd lmZejd ¦«ZGd „d e ¦«ZeGd„d¦«¦«ZeGd„d¦«¦«ZdS)zL This module contains utilities for ea-nginx cache disabling during tracing éN)Ú dataclass)ÚEnum)ÚOptional)Úgettexté)Únginx_cache_stat_storageÚallow_disable_nginx_cache)Ú XRayError)Ú dbm_storageÚ nginx_utilscó—eZdZdZdZdZdS)ÚCachezCache statuses enumrrN)Ú__name__Ú __module__Ú __qualname__Ú__doc__ÚENABLEDÚDISABLED©óúP/opt/cloudlinux/venv/lib64/python3.11/site-packages/xray/internal/nginx_utils.pyrrs€€€€€ØÐà€GØ€H€H€Hrrcó,—eZdZUdZeed<dZeed<dS)Ú SavedStateÚÚinitialrÚ active_tasksN)rrrrrÚ__annotations__rÚintrrrrr$s0€€€€€€à €Fà €N€N�NØ€L�#ÐÐÑÐÐrrcó—eZdZUdZeed<dd„Zedefd„¦«Z ede fd„¦«Z ede fd„¦«Z e jd e ddfd „¦«Z e jdd „¦«Z d eddfd „Zededee fd„¦«Zdd„Zdd„ZdS)ÚNginxUserCachezc Class which implements reading/writing the user's cache status from the local storage ÚusernameÚreturnNcó~—|j}t|t¦«rd|vs|dvsd|vrtd|›�¦«‚dSdS)Nú/)ú.z..úz'Invalid username for nginx cache path: )r!Ú isinstanceÚstrÚ ValueError)ÚselfÚnames rÚ __post_init__zNginxUserCache.__post_init__5s`€ðŒ}ˆÝ �d�CÑ Ô ð Q c¨T k k°T¸[Ð5HÐ5HÈFÐVZÈNÈNÝÐOÀtÐOÐOÑPÔPÐ Pð Qð QÈNÈNrcó`—d}d|j›d�}tj |¦«s tjStj |¦«r&| |¦«}|�t |¦«S| |¦«}|�t |¦«StjS)zÑ Detect if cache is enabled or disabled for user using cPanel's guidelines https://docs.cpanel.net/knowledge-base/web-services/nginx-with-reverse-proxy/#third-party-integration z/etc/nginx/ea-nginx/cache.jsonz/var/cpanel/userdata/z/nginx-cache.json)r!ÚosÚpathÚisfilerrÚget_cache_status_from_filer)r*Ú global_fileÚ user_fileÚ user_settingÚglobal_settings rÚcurrent_statuszNginxUserCache.current_status@s§€ð7ˆ ØL¨D¬MÐLÐLÐLˆ ÝŒw�~Š~˜kÑ*Ô*ð "õ”>Ð !å Œ7�>Š>˜)Ñ $Ô $ð +à×:Ò:¸9ÑEÔEˆLØÐ'ݘ\Ñ*Ô*Ð*à×8Ò8¸ÑEÔEˆØ Ð %ݘÑ(Ô(Ð (åŒ}Ðrcó(—|jtjuS)z"Check if cache is enabled for user)r6rr)r*s rÚ is_enabledzNginxUserCache.is_enabled[s€ðÔ"¥e¤mÐ3Ð3rcól— ttd¬¦«5}||jcddd¦«S#1swxYwYn_#t$r%}t d|¦«Yd}~n5d}~wt $r%t d|j›�¦«YnwxYwttj ¦«S)zu Get saved state (initial cache setting and active tasks count) of nginx cache manipulations T©Ú is_shelveNz0Failed to get saved state of nginx cache with %szNo nginx cache entry found for ) r rr!Ú RuntimeErrorÚloggerÚwarningÚKeyErrorÚinforrr©r*Ú_nginx_cache_statÚes rÚ saved_statezNginxUserCache.saved_state`s€ð  KÝÕ5ÀÐFÑFÔFð 8ÐJ[Ø(¨¬Ô7ð 8ð 8ð 8ð 8ñ 8ô 8ð 8ð 8ð 8ð 8ð 8ð 8øøøð 8ð 8ð 8ð 8ð 8øåð Rð Rð RÝ �NŠNÐMÈqÑ QÔ QÐ QÐ QÐ QÐ QÐ QÐ QøøøøÝð Kð Kð KÝ �KŠKÐI¸$¼-ÐIÐIÑ JÔ JÐ JÐ JÐ Jð Køøøõ�%œ.Ñ)Ô)Ð)s3‚>˜ 2¥ >²6¶>¹6º>¾ BÁA(Á(/BÂBÚvaluecóà— ttd¬¦«5}|||j<ddd¦«dS#1swxYwYdS#t$r&}t d|¦«Yd}~dSd}~wwxYw)zq Save state of nginx cache manipulations -- initial cache setting and active tasks count Tr:Nz+Failed to save state of nginx cache with %s©r rr!r<r=r>)r*rErBrCs rrDzNginxUserCache.saved_stateqsÕ€ð  MÝÕ5ÀÐFÑFÔFð 9ÐJ[Ø38Ð! $¤-Ñ0ð 9ð 9ð 9ñ 9ô 9ð 9ð 9ð 9ð 9ð 9ð 9ð 9øøøð 9ð 9ð 9ð 9ð 9ð 9øåð Mð Mð MÝ �NŠNÐHÈ!Ñ LÔ LÐ LÐ LÐ LÐ LÐ LÐ LÐ Løøøøð Møøøs-‚=˜ 0£ =°4´=·4¸=½ A-ÁA(Á(A-cóÜ— ttd¬¦«5}||j=ddd¦«dS#1swxYwYdS#t$r&}t d|¦«Yd}~dSd}~wwxYw)z� Delete the record of state of nginx cache manipulations -- initial cache setting and active tasks count Tr:Nz-Failed to delete state of nginx cache with %srGrAs rrDzNginxUserCache.saved_state}sÒ€ð  OÝÕ5ÀÐFÑFÔFð 5ÐJ[Ø% d¤mÐ4ð 5ð 5ð 5ñ 5ô 5ð 5ð 5ð 5ð 5ð 5ð 5ð 5øøøð 5ð 5ð 5ð 5ð 5ð 5øåð Oð Oð OÝ �NŠNÐJÈAÑ NÔ NÐ NÐ NÐ NÐ NÐ NÐ NÐ Nøøøøð Oøøøs-‚;˜ .¡ ;®2²;µ2¶;» A+ÁA&Á&A+Ú enum_memberc ó(—dd|jd|j›�g} tj|ddd¬¦«d S#tj$rc}t  d|j|j|j |j ¦«tt|¦«d|j |j dœ¬ ¦«‚d }~wtttjf$rV}tt!d  t|j¦«t|¦«¦«¦«d¬ ¦«‚d }~wwxYw) z Enable or disable cache for userz"/usr/local/cpanel/scripts/ea-nginxÚcachez --enabled=T)ÚcheckÚtextÚcapture_outputz)ÚoutÚerr)ÚflagÚextraNz'Failed to set nginx cache as {} with {})rQ)r!rEÚ subprocessÚrunÚCalledProcessErrorr=r@ÚargsÚ returncodeÚstdoutÚstderrr r(ÚOSErrorr)ÚSubprocessErrorÚ_Úformatr+)r*rIÚcmdrCs rÚsetzNginxUserCache.set‰s/€à3°W¸d¼mÐMmÐZeÔZkÐMmÐMmÐnˆð Ý ŒN˜3 d°ÀdÐ KÑ KÔ KÐ KÐ KÐ KøÝÔ,ð ^ð ^ð ^Ý �KŠKØNÐPQÔPVÐXYÔXdÐfgÔfnÐpqÔpxñ ô ð õ�C ™FœF¨À!Ä(ÐSTÔS[Ð:\Ð:\Ð]Ñ]Ô]Ð ]øøøøÝ�¥ZÔ%?Ð@ð ð ð ÝÝÐ;×BÒBÅ3À{ÔGWÑCXÔCXÕZ]Ð^_ÑZ`ÔZ`ÑaÔaÑbÔbÐirðñôð øøøøð øøøs"•/¯D¾ABÂDÂ;AD Ä DÚfilenamec ó — t|¦«5} tj|¦«}| d¦«cddd¦«S#tj$rI}t  d|t|¦«d| ¦«i¬¦«Yd}~nd}~wwxYw ddd¦«dS#1swxYwYdS#ttf$r4}t  d|t|¦«¦«Yd}~dSd}~wwxYw)z%Get the 'enabled' key from given fileÚenabledNzInvalid JSON from %s: %sÚcontents)rRzFailed to read file %s with %s) ÚopenÚjsonÚloadÚgetÚJSONDecodeErrorr=Úerrorr(ÚreadÚIOErrorrZ)r`Ú_fÚdatarCs rr1z)NginxUserCache.get_cache_status_from_file˜s‡€ð MÝ�h‘”ð / 2ð/Ýœ9 R™=œ=�Dð Ÿ8š8 IÑ.Ô.ð  /ð /ð /ð /ñ /ô /ð /ð /øõÔ+ðnðnðnÝ—L’LÐ!;¸XÅsÈ1ÁvÄvÐV`Ðbd×biÒbiÑbkÔbkÐUl�LÑmÔmÐmÐmÐmÐmÐmÐmøøøøðnøøøØmð  /ð /ð /ñ /ô /ð /ð /ð /ð /ð /ð /ð /øøøð /ð /ð /ð /ð /ð /øõ�Ð!ð Mð Mð MÝ �LŠLÐ9¸8ÅSÈÁVÄVÑ LÔ LÐ LÐ LÐ LÐ LÐ LÐ LÐ Løøøøð Møøøsg‚B>‘B1“A§B1» B>ÁB Á?BÂB1ÂB  B1Â$ B>Â1B5Â5B>Â8B5Â9B>Â>DÃ)C>Ã>Dcó —tsdS|j}|jrB | tj¦«tj|_n#t$rYnwxYw|jtjur|xj dz c_ ||_dS)zè If cache is enabled for user, disable it. Save retrieved cache status. For ENABLED initial status increment number of active tasks. Skip disabling cache if it is disallowed in constants file Nr) r rDr8r_rrrrr r©r*Ú_states rÚdisablezNginxUserCache.disable¦sž€õ)ð à ˆFàÔ!ˆà Œ?ð /ð /Ø—’�œÑ(Ô(Ð(õ"'¤�”�øõð ð ð Ø�ð øøøð Œ>�Uœ]Ð *Ð *Ø Ð Ô  1Ñ $Ð Ô à!ˆÔÐÐs™A Á AÁAcóè—|j}|jtjurP|xjdzc_|jdkr5 | tj¦«n#t $rYnwxYw|`dS||_dS)a¼ For ENABLED initial status decrement number of active tasks. Restore the cache state according to saved status: - enable if it was enabled and number of active tasks <= 0, - do nothing if it was enabled, but number of active tasks > 0, - do nothing if it was disabled. Clear the record if enable has taken place. Skip operation if cache disabling is disallowed in constants file rrN)rDrrrrr_r ros rÚrestorezNginxUserCache.restoreÀs’€ðÔ!ˆà Œ>�Uœ]Ð *Ð *Ø Ð Ô  1Ñ $Ð Ô àÔ" aÒ'Ð'ðØ—H’H�Uœ]Ñ+Ô+Ð+Ð+øÝ ðððØ�DðøøøàÐ$Ø�à!ˆÔÐÐs·AÁ A$Á#A$)r"N)rrrrr(rr,Úpropertyrr6Úboolr8rrDÚsetterÚdeleterr_Ú staticmethodrr1rqrsrrrr r ,sš€€€€€€ððð €M€M�Mð Qð Qð Qð Qðð ðððñ„Xðð4ð4˜Dð4ð4ð4ñ„Xð4ðð*˜Zð*ð*ð*ñ„Xð*ð Ôð M ð M°ð Mð Mð MñÔð MðÔð Oð Oð OñÔð Oð ˜uð ¨ð ð ð ð ðð M¨Sð M°X¸d´^ð Mð Mð Mñ„\ð Mð"ð"ð"ð"ð4"ð"ð"ð"ð"ð"rr )rreÚloggingÚos.pathr.rSÚ dataclassesrÚenumrÚtypingrÚxrayrr\Ú constantsrr Ú exceptionsr Úutilsr Ú getLoggerr=rrr rrrúrƒstðððð € € € Ø€€€Ø€€€ØÐÐÐØ!Ð!Ð!Ð!Ð!Ð!ØÐÐÐÐÐØÐÐÐÐÐàÐÐÐÐÐàJÐJÐJÐJÐJÐJÐJÐJØ!Ð!Ð!Ð!Ð!Ð!ØÐÐÐÐÐà ˆÔ ˜=Ñ )Ô )€ðððððˆDñôðð ðððððñôñ „ðð ðj"ðj"ðj"ðj"ðj"ñj"ôj"ñ „ðj"ðj"ðj"r