P.'ddlZddlZddlZddlmZddlZddlmZmZm Z ddl m Z ddl m Z ejeZdZedZdZd Zd Zd Zd Zd ZdZdZdZdZdS)N)Path)atomic_rewrite check_run CheckRunError)files)ProactiveDefencez'/usr/share/i360-php-opts/autorules.yamlz/usr/share/i360-php-optsz2/usr/share/i360-php-opts/phpimunity.compiled.rulesz/usr/bin/i360-storage-mkcustomz/usr/bin/i360-storage-newz#/usr/bin/i360-storage-replacehdb-v2cPKtjtjd} td|D}n+#t $rt dYdSwxYw||d}tdz}tj |dd 5}t|d 5}tj ||dddn #1swxYwYdddn #1swxYwYtj|tdS) NF)integrity_checkc32K|]}|ddk|VdS)namezautorules_opt.yaml.gzN).0is K/opt/imunify360/venv/lib/python3.11/site-packages/im360/subsys/proactive.py z,update_php_immunity_files..s:  & 5L(L(LA(L(L(L(L  z)PHP Immunity rules are not found in indexurlz.tmprtzutf-8)encodingw)rIndex PHP_IMMUNITYnextitems StopIterationloggerwarning localfilepathPHP_IMMUNITY_FILENAMEgzipopenshutil copyfileobjosrename)indexitem local_pathtmpsrcdsts rupdate_php_immunity_filesr-s K*E B B BE  {{}}      BCCC$$T%[11J & (C :tg 6 6 6%#t S@@% 3$$$%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Ic()))))sG+A$A87A87DC* D*C. .D1C. 2DDDcK tttgd{VdS#t$r&}td|Yd}~dSd}~wt $r&}td|Yd}~dSd}~wwxYw)Nzi360-storage is not found: %sz*Failed to apply new php immunity rules: %s)rI360_STORAGE_BINr FileNotFoundErrorrerrorr)errs rapply_php_immunity_rulesr3+sH)+@ABBBBBBBBBBB ;;; 4c::::::::: HHH A3GGGGGGGGGHs !' BA BBBcK|r\td{Vtjr>ttrt d{VdSdSdSdSN)r-rrrr existsr3_ is_updateds r update_hookr:4s-')))))))))  ) -*++2244 -+,, , , , , , , , , , -- - - - -rcK|rtjtr t tgdd{VdSt jt j}|D]^}t| |d}tt|j z |dd]dSdS)aWhen we are done with downloading /var/imunify360/files/php-immunity/v2/* files then we need to copy the files as is (no gunzip or byte-compiling) to /usr/share/i360-php-opts/ in a safe way using atomic_rewrite() as far these files are opened by i360.so using mmap() plus ensure that the files have correct permissions for cagefs (/usr/share/i360-php-opts/ directory files are visible for cagefs due to imunify360-php-i360 %post scriptlet) c4tjtSr5r%umask _RULES_UMASKrrrz)update_hook_immunity_v2..Ns28L#9#9r preexec_fnNrFi)backup permissions)r%pathr6I360_STORAGE_REPLACEHDB_BINrrrPHP_IMMUNITY_V2rrrrPHP_IMMUNITY_FILESDIRr read_bytes)r8r9r' wb_db_itemr)s rupdate_hook_immunity_v2rK>s  7>>5 6 6 ,-99        F E122++--  Je11*U2CDDEEJ % 7%%''!        rcNK|r ttgdd{VdSdS)Nc4tjtSr5r=rrrr@z/recreate_signatures_on_update..gsrx 7M7MrrA)rI360_STORAGE_NEW_BINr7s rrecreate_signatures_on_updaterOase  ! "/M/M              r)r!loggingr%pathlibrr#defence360agent.utilsrrrim360rim360.contracts.configr getLogger__name__rr rHPHP_IMMUNITY_COMPILED_RULESr/rNrFr?r-r3r:rKrOrrrrXs    JJJJJJJJJJ333333  8 $ $A788842C ***&HHH---   F     r