l#gOddlmZddlZddlZddlZddlZddlZddlZddddZdZ dZ dZ d d gZ d \Z ZZed ed iZe dee ee iZdZGddZdZdZdZdZdZdZdZdZdZdZdZdZidededed ed!ed"ed#ed$ed%ed&ed'ed(ed)ed*ed+ed,ed-eeed.Z d5d0Z!d1e"fd2Z# d5ej$d3d4Z%dS)6) defaultdictNT),: ) sort_keysindent separators z /bin/lessz /bin/more)successwarningserrorWARNINGERRORctjdtdtDd}|t |dSt j|g|tj dS)NPAGERc3XK|]%}tj|!|V&dSN)ospathisfile).0ps N/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/utils/cli.py zpager..s5>>QBGNN1,=,=>q>>>>>>)inputstdout) renvirongetnextPAGERSprint subprocessrunencodesysr)datapagers rr)r)st JNN>>&>>>EE  E } d wdkkmmCJGGGGGGrcdeZdZdZ ddZejfdZedZ edZ dS) TablePrintercbi|_tt|_i|_i|_dSr)_headersrlist_mappers_right_aligned_widths)selfs r__init__zTablePrinter.__init__'s+ #D))   rNFc|r ||j|<|r ||j|<||j|<|r|n||j|<dSr)r/r1r0upperr-)r2fieldmappers max_width right_alignheaders rset_field_propertiesz!TablePrinter.set_field_properties-s\  +#*DM%  ,"+DL %0E")/BvvU[[]] erc fd|D}d|D}g}|D]}g}t|D]\} } || } j| D] } | | } t| } t | || krQj| } | r#t | | kr| d| dz dz} t | || <|| ||t||d|D]?}t||j | d@dS)Ncjg|]/}j||0S)r-r r5)rr6r2s r z&TablePrinter.print..=s3OOOu4=$$UEKKMM::OOOrc,g|]}t|Sr>)len)rr6s rr?z&TablePrinter.print..>s222#e**222rr z...F) enumerater r/strrAr1appendr# _format_rowr0)r2fieldsitemsfileheaderswidthsrowsitemrowir6vmapperr8s` rr#zTablePrinter.print<sOOOOOOO22'222  DC%f--  5HHUOO"mE2""Fq AAFFq66F1I%% $ 0 0 7 7I 7SVVi%7%7o A o.6 #AF1I 1 KK     dw66777  C   !4!8!8!F!F      rcZ|r||S||Sr)rjustljust)valuewidthr9s r _add_paddingzTablePrinter._add_paddingVs.  &;;u%% %{{5!!!rchfdt|D}d|S)NcZg|]'\}}t||(Sr>)r+rV)rrNrT right_alignedrJs rr?z,TablePrinter._format_row..^sC   5  % %eVAY F F   rz )rBjoin)columnsrJrYcolss `` rrEzTablePrinter._format_row\sK     %g..   yyr)NNFN) __name__ __module__ __qualname__r3r;r'rr# staticmethodrVrEr>rrr+r+&s C C C C), 4""\" \rr+c||ndS)Nzn/ar>rTs rn_arces%5550rc(|t|n|Sr)intrbs rto_intrfis*3u:::5rcfd}|S)Nc\t|tr|S|Sr) isinstancedictr )rTr6s r extractorz extract_field..extractorns, eT " " $99U## # rr>)r6rks` r extract_fieldrlms$ rct}|D] }|j| |d|D|dS)Ncg|] }|d S)rr>)rrLs rr?zprint_table..zs111Ta111r)r+r;r#)r( field_propstablepropss r print_tablerrvsV NNE++""E*** KK11[111488888rcdtgfdtgfdtdgfdtgfdtgfdtgff}t||dS)N timestampabusercountrycodetimesnameseverity)rfrcrlrrr(ros rprint_incidentsr|}se vh C5 ]6**+, 3% # cU Kk"""""rcttj}|D],}|dd}|dkr ||z |d<'d|d<-dS)N expirationrttl)retimer )r(nowrLr~s radd_ttlrse dikk  CXXlA.. >>$s*DKKDKK rcnt|dddtdgff}t||dS)Niprrvrwrrlrrr{s rprint_graylistrsE DMMM ]6**+,K k"""""rcrt|dddtdgfddf}t||dS)Nrrrvrw) imported_from)commentrr{s r print_bwlistrsK DMMM ]6**+, Kk"""""rct|ttfrt|rt }t|dt rdt |d}|dtdg| ||dS|D]}t|dSdSt|dS)Nrrvrw)r7) rir.tuplerAr+rjsortedkeysr;rlr#)r(printerrrLs r guess_printerrs$u &&  t99 "nnG$q'4(( d1gllnn--,, f(=(='>- dD)))))   D$KKKK    d rct|trt|dSttj|ddS)NF)default_flow_style)rirCr#yamldumpr(s r yaml_printerrsF$9 d  di77788888rct|trt|dSttj|dSr)rirCr#jsondumpsrs r json_printerrsA$  d  djrc Vt|tr*td|ddSg}|D]B}|d|d|d|drdndCtd |dS) Nz Status: {}statuszEvent: {}, Path: {}{}eventrnativez native )rirjr#formatrDrZ)r(resulthooks r hook_printerrs$ ! l!!$x.1122222  D MM'..ML"&x.8JJb     dii     r)configshow)eular)r ) whitelist)rrr.) blacklist)rrr.)graylist)rrr.)malwarez on-demandr)feature-managementdefaults)rr)renable)rdisable)rr )radd)rdelete))rr.)rz add-nativeFc|r,|rtni}ttj|fi|dSt|t }||d|dnddS)NrGOK)PRETTY_JSON_ARGSr#rrPRINTERSr r)methodris_json is_verbose pretty_args print_funs rprint_responsersP*4<&&"  dj//;//00000LL77  VZZ%8%8%D&//$OOOOOrr(ct|tsdS|dgD]}t|tjdS)Nr rH)rirjr r#r'stderr)r(warnings rprint_warningsrsX dD ! !88J++(( gCJ'''''((rrc|r.|rtni}ttj||ifi|dSt |t t fr(|D]#}tt|d||$dSt||dS)Nrr)rr#rrrir.r_CLI_MSG_PREFIX)rmessagesrrrHrmsgs r print_errorrs'*4<&&"  dj&(+;;{;;<<<<< hu . . ' L L/&"9"9"933?dKKKKK L L ( & & & & & &r)FF)& collectionsrrrr$r'rrrEXITCODE_NOT_FOUNDEXITCODE_WARNINGEXITCODE_GENERAL_ERRORr"SUCCESSrrr EXIT_CODESr)r+rcrfrlrrr|rrrrrrrrrrjrrrr>rrrs######  !%+NN { #8%Iug6 Q  ! HHH<<<<<<<<~111666999 # # #### # # #"999    ! ! !    e  o L       L    >  '  '  #L %l &| "<  \! " # $#('   .PPPP(((((16 '?Bz ' ' ' ' ' ' 'r