l#gddlZddlZddlZddlmZmZmZmZddlm Z m Z ej e Z Gdde ZdS)N) CharField FloatField IntegerField TextField)instanceModelceZdZdZedZedZedZedZ e Z e dZ GddZed d Zed Zd S)InfectedDomainListzDDomains with bad reputation, used for Reputation Management feature.T) primary_key)nullFc eZdZejZdZdS)InfectedDomainList.Metainfected_domain_listN)__name__ __module__ __qualname__rdbdatabasedb_tableZ/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/model/infected_domain.pyMetar!s;)rrr2c||j|j|j}fd|D}tj|d}d}g}t|D]P\} } |dz }t||kr3| |kr-| \} } | \} }| | |d| DdQ||fS)Nc30K|]}|dv |VdS)usernameNr).0rowexisting_userss r z1InfectedDomainList.get_by_user..,s:  C O~,M,MC,M,M,M,M  rc"|d|dfS)Nrnamer)rs rz0InfectedDomainList.get_by_user..0ss:F .Lr)keyrc>g|]}|d|d|ddS) threat_typevendor timestamp)typer)r*r)rts r z2InfectedDomainList.get_by_user..>sG$$$ !" )*-(8*+H+-.{^$$$r)rdomainthreats) selectorder_byrr#r*descdicts itertoolsgroupby enumeratelenappend)clsr offsetlimitqueryfiltered_by_usergrouped max_countresultivaluegroupr/rr#s ` r get_by_userzInfectedDomainList.get_by_user%s; %% L#(CM$6$6$8$8       ;;==   # "L"L    !'**  HAu NIF e##!v++!&w!&$ $,"&$$ &- $$$     y  rc d|D}tj5|tj}|D]}|d}||vrt d|*||D]h}|d}|dvr|dd} n|dkr |d} n |d vrd } nd } | || |f|} | ||| || i d d d d S#1swxYwYd S)a Update domain reputatuion info. If threat info already exists, do not update timestamp :param domains: reputation data from server :param domains_to_users: domain -> users mapping from hosting panel :return: cJi|] }|d|d|df|d!S)r#r(r)r*r)rrs r z6InfectedDomainList.refresh_domains..TsB   vY-(!H+ 6+   rr<zUsers for domain %s not found.r))zgoogle-safe-browsingzyandex-safe-browsingdetailsr(spamhaus) phishtank openphishz spam domainTHREAT_TYPE_UNSPECIFIED)rr#r(r)r*N) r0r3rratomicdeleteexecutetimeloggerwarninggetcreate) r9domainsdomains_to_usersexistingnow domain_infor.userr)r(r*s rrefresh_domainsz"InfectedDomainList.refresh_domainsJs  ZZ\\''))   [   ! !   JJLL " " ")++C&   $W-!111NN#CVLLL,V4D(2F"'2)&<]&K :--&1)&< #===&3 &? ( f5s!!IJJ!%#$/%"+ #                    sCD55D9<D9N)rr)rrr__doc__ridrrr#r(rr*rr)r classmethodrDr\rrrr r sNN $ ' ' 'Byd###H 9% D)'''K I YD ! ! !F********"!"!"!["!H,,[,,,rr )r4loggingrQpeeweerrrrdefence360agent.modelrr getLoggerrrRr rrrrds 21111111  8 $ $ffffffffffr