#~/BFVddlZddlZddlZddlmZmZddlmZddlm Z ddl m Z ddl m Z ddlmZddlmZmZdd lmZdd lmZdd lmZmZdd lmZGd deZGddeZGddeZGddeZGddeZ GddeZ!dS)N)ListTuple) DoesNotExist)run_in_executor)ips_for_country)csf)SourceInterface)Country CountryList)IPList)GlobalWhitelist)local_dns_from_resolv_conflocal_ip_addresses)validatec2eZdZdZdZdZdZdZdZdS)DBIPListCacheSourcecd||_tjj|j|tjj|j|tjj|j |tjj |j |dSN) listnamer Signalsaddedconnect _on_addeddeleted _on_deletedcleared _on_clearedupdated _on_updated)selfrs N/opt/imunify360/venv/lib/python3.11/site-packages/im360/model/cache_sources.py__init__zDBIPListCacheSource.__init__s  $$T^X>>>&&t'7BBB&&t'7BBB&&t'7BBBBBcT|j||j|jdSNip expiration)rsendr'r(r senderr's r!rzDBIPListCacheSource._on_addeds& 2=AAAAAr#c>|j||dSN)r'rr)r*s r!rzDBIPListCacheSource._on_deleted"s# $2&&&&&r#c:|j|dSr)rr))r r+s r!rzDBIPListCacheSource._on_cleared%s $r#cT|j||j|jdSr%)rr)r'r(r*s r!rzDBIPListCacheSource._on_updated(s) $25R]CCCCCr#cbKfd}ttj|d{VS)NcNttjtjtjtjjktj Sr) listr selectr'r(wherer is_expiredtuplesexecuter sr!r4z-DBIPListCacheSource.fetch_all..select,sj fi):;;v$-788)+++,,  r#)loopcb)rasyncioget_event_loop)r r4s` r! fetch_allzDBIPListCacheSource.fetch_all+sP     %'*@*B*BvNNNNNNNNNNr#N) __name__ __module__ __qualname__r"rrrrr>r#r!rrs|CCCBBB'''   DDD O O O O Or#rcheZdZfdZed dZedZdZdZ dZ fdZ xZ S) CountryIPListCacheSourcect|tjj|j|tjj|j|dSr) superr"r rrr#_CountryIPListCacheSource__on_addedr%_CountryIPListCacheSource__on_deleted)r r __class__s r!r"z!CountryIPListCacheSource.__init__9s^ """!))$/8DDD#++D,=xHHHHHr#Nc< tjtjtj|k}n#t$rgcYSwxYw|sgStt|dS)z+ Return country's ip list. r) r r4coder5idr7firstrr3r) country_idr country_codes r!__selectz!CountryIPListCacheSource.__select?s  w|,,wzZ/00 L    III  IOLO44555sA#A&& A54A5cL||D] }||dSr)!_CountryIPListCacheSource__select)clsrNactionsubnets r! __on_signalz$CountryIPListCacheSource.__on_signalQs8ll:..  F F6NNNN  r#c F|dfddS)NrNc>j|dS)Nrr&)rr)xr s r!z5CountryIPListCacheSource.__on_added..[sdjoodqQo??r#$_CountryIPListCacheSource__on_signal)r _senderkwargss` r! __on_addedz#CountryIPListCacheSource.__on_addedXs9  < ? ? ? ?     r#c F|dfddS)NrNc<j|Sr-r.rYs r!r[z7CountryIPListCacheSource.__on_deleted..`sDL,=,=dq,=,I,Ir#r\)r r+r_s` r! __on_deletedz%CountryIPListCacheSource.__on_deleted^s9  < "I"I"I"I     r#cg}tjtjttjtjktj|jk }|D] \}|dt|Dz }!|S)N)oncg|]}|dfS)rrB).0rZs r! z8CountryIPListCacheSource.__fetch_all..nsBBBqQFBBBr#) r r4r rKjoinrLrNr5rr7r8r)r ips country_codesrOs r! __fetch_allz$CountryIPListCacheSource.__fetch_allcs  w| , , T'wz[-CCT E E U;'4=8 9 9 VXX WYY  - C CO\ BBOL$A$ABBB BCC r#cKttj|jd{V}|t d{VzSr)rr<r=$_CountryIPListCacheSource__fetch_allrFr>)r country_subnetsrIs r!r>z"CountryIPListCacheSource.fetch_allqst /  " $ $d&6! !       (9(9(;(;";";";";";";< __classcell__)rIs@r!rDrD8sIIIII 666\6"[         =========r#rDceZdZdZdZdS)ConstantCacheSourcec(d|D|_dS)Ncg|]}|dfSrrBrgr's r!rhz0ConstantCacheSource.__init__..{s...Bb$Z...r#_ips)r rjs r!r"zConstantCacheSource.__init__zs..#... r#cK|jSrrxr9s r!r>zConstantCacheSource.fetch_all}syr#N)r?r@rAr"r>rBr#r!rtrtys2///r#rtceZdZdZdS)GlobalwhitelistCacheSourcecfKtdtjd{VDS)z":rtype: iterable[(ip, expiration)]c3K|]}|dfV dSrrBrws r! z7GlobalwhitelistCacheSource.fetch_all..s&FF2RJFFFFFFr#N)r3r loadr9s r!r>z$GlobalwhitelistCacheSource.fetch_alls>FF/C/E/E)E)E)E)E)E)EFFFFFFr#N)r?r@rAr>rBr#r!r|r|s(GGGGGr#r|czeZdZeejddeeedffdZ dZ dS)&WhitelistCacheSourceFromSystemSettings)maxsizereturnNcttttjjt }dt tjt|DS)Ncg|]}|dfSrrBrws r!rhzEWhitelistCacheSourceFromSystemSettings._fetch_all..s,   J   r#) mapstrrIPipv6_to_64networkrset itertoolschainr)rS local_ipss r! _fetch_allz1WhitelistCacheSourceFromSystemSettings._fetch_allso X[24F4H4HII     : < z0WhitelistCacheSourceFromSystemSettings.fetch_alls   r#) r?r@rArq functools lru_cacherrrrr>rBr#r!rrsqY###  4c4i 01    $#[  !!!!!r#rc eZdZdZdZdZdS)WhitelistCacheSourceFromCSFc||_dSr) csf_files)r rs r!r"z$WhitelistCacheSourceFromCSF.__init__s "r#c ttdtjd|jDD}d|DS)Nc3 K|] \}}|V dSrrB)rgr'_s r!rz5WhitelistCacheSourceFromCSF._fetch..s:Br#c3>K|]}tj|VdSr)r ips_from_file)rgfs r!rz5WhitelistCacheSourceFromCSF._fetch..s-CCqc'**CCCCCCr#cg|]}|dfSrrBrws r!rhz6WhitelistCacheSourceFromCSF._fetch..s444rT 444r#)r3rrrr)r ips_from_filess r!_fetchz"WhitelistCacheSourceFromCSF._fetchsj &_CCDNCCC    54^4444r#c.K|Sr)rr9s r!r>z%WhitelistCacheSourceFromCSF.fetch_alls{{}}r#N)r?r@rAr"rr>rBr#r!rrsA### 5 5 5r#r)"r<rrtypingrrpeeweer$defence360agent.model.simplificationr"im360.internals.core.ipset.countryr im360.subsysrim360.utils.tree_cacher im360.model.countryr r im360.model.firewallr im360.model.global_whitelistr im360.utils.netrrdefence360agent.utilsrrrDrtr|rrrBr#r!rs)@@@@@@>>>>>>22222244444444''''''888888+*****OOOOO/OOOD>=>=>=>=>=2>=>=>=B/GGGGGGGG !!!!!_!!!$/r#