wo4h ddlZddlZddlZddlZddlmZddlmZddlmZm Z ddl m Z m Z ddl mZddlmZejeZdZd Zd Zed d gZd ZddZdZde eeffdZdedeeeffdZdS)N)glob)Path)TupleUnion) CharFieldModel) FilenameField) HostingPanelz.imunify.quarantinedz/var/imunify360 quarantinedz/var/wwwz/home*c2Gfddt}|S)zl Model stub for migration because we can't use migrator.orm[] due to custom field FilenameField cZeZdZGfddZedZeZdS)get_model..MalwareHitceZdZdZZdS)"get_model..MalwareHit.Meta malware_hitsN)__name__ __module__ __qualname__db_tabledatabasedbse/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/migrations/160_remove_quarantine.pyMetars%HHHHrF)nullN)rrrrr orig_filerstatusrsr MalwareHitrs`          "Mu--- rr)r)rrs` r get_modelr s? U rFc|rdS|pt}t|}||jt k}|D]8}t |j\} }|| |9tD]B} ttj | tD] } || CdSN)delete_quarantine_folderr selectwherer QUARANTINED find_quarrdelete_instanceQUARANTINE_PARENTSrospathjoin QUAR_NAME) _migratorrfakedelete_function___modelr hitpath_to_deleteparents rmigrater7)s &A)AO h  E,,..&&u|{'BCCK%cm44''' %,,"27<< #B#BCC , ,N ON + + + + ,,,rcdSr")r1r2s rrollbackr:?sDrquarantine_pathct|}|jtkrK||kr5td|t j|ddSdSdS)NzDeleting quarantine folder %sT) ignore_errors)rnamer-resolveloggerinfoshutilrmtree)r;s rr#r#Csr?++O )) 6688 8 8 3_EEE oT:::::: *) 8 8rsourcereturnct|}tttz |tdf}d}d}|jD]P} t j|j}|}n#t$rY>t$r|cYcSwxYw| |j dkr|S| ||z } t|j}n#tt f$r|cYSwxYw ||}n#t"$r|cYSwxYw|tz |fS)zy Find file in quarantine by source path. This function is copied from agent code since it is to be removed. /Nroot)rDEF_QUARr- relative_toparentspwdgetpwuidstatst_uidFileNotFoundErrorKeyErrorpw_namer?r base_home_dirpw_dir RuntimeError ValueError) rDfiledefault_resultuserr6r+resolved_placebase_dirrelatives rr'r'Ms <>// << | ,!--h77  i  ))s<+B  B' B'&B'$&D D! D!%D;; E  E )FN)loggingr*rLrBrpathlibrtypingrrpeeweerr$defence360agent.model.simplificationr +defence360agent.subsys.panels.hosting_panelr getLoggerrr@r-rIr&r)r r7r:strr#r'r9rrres\ ########?>>>>>DDDDDD  8 $ $ "   H5",,,,,   ;eCI.>;;;;'*c'*eD$J/'*'*'*'*'*'*r