wo4hL0NddlZddlmZddlmZddlmZddlm Z m Z Gdde Z Gdd Z Gd d ZGd d ZeZGddeZGddeZGddeZGddeZGddeeZGddeZGddZGddeZGddeZGd d!eZGd"d#eeZGd$d%eeZGd&d'eZGd(d)eeZGd*d+eeZ Gd,d-eZ!Gd.d/eeZ"Gd0d1eZ#Gd2d3e Z$Gd4d5eZ%Gd6d7eeZ&Gd8d9eeZ'Gd:d;eeZ(Gd<d=eZ)Gd>d?eZ*Gd@dAeeZ+dBe,dCe-dDe,fdEZ.GdFdGeeZ/GdHdIeeeZ0GdJdKeZ1GdLdMZ2GdNdOeZ3dS)PN)Enum)List)Core)batched batched_dictceZdZdS)MessageNotFoundErrorN__name__ __module__ __qualname__W/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/contracts/messages.pyr r Drr ceZdZdZdZdZdS)UnknownMessagez& Used as stub for MessageType c td)NzMessage class is not found.)r selfs r__init__zUnknownMessage.__init__s"#@AAArcdS)NUnknownr)rnames r __getattr__zUnknownMessage.__getattr__syrN)r r r __doc__rrrrrrr s?BBBrrc8eZdZgZfdZedZxZS)MessageTc ntjdi||j|dS)Nr)super__init_subclass__ _subclassesappend)clskwargs __class__s rr!zMessageT.__init_subclass__s<!!++F+++ s#####rc*t|jSN)tupler"r$s rget_subclasseszMessageT.get_subclasses sS_%%%r)r r r r"r! classmethodr+ __classcell__r&s@rrrsXK$$$$$&&[&&&&&rrceZdZdZdZdS) _MessageTypea  Used to get specific message class. For example, >>> _MessageType().ConfigUpdate >>> _MessageType().NotExistMessage >>> cftD]}|j|kr|cStSr()Messager+r r)rrsubclss rrz_MessageType.__getattr__/s>,,..  F$&& 'rN)r r r rrrrrr0r0%s-rr0ceZdZdZdZdS) ReportTargetapiconnN)r r r APIPERSISTENT_CONNECTIONrrrr5r5:s C"rr5c<eZdZdZejZedefdZ dS) ReportablezD Mixin class for messages that should be sent to the server methodcd|D]}|t|dkr|cSdS)ao Return a subclass with the same DEFAULT_METHOD as *method*. It can be used to detect report target from message method. NOTE: it is not guaranteed that the class with the *method* is unique, in this case the first subclass found is returned, but it is tested that all such subclasses have the same TARGET. DEFAULT_METHODN)__subclasses__getattr)r$r<subclasss rget_subclass_with_methodz#Reportable.get_subclass_with_methodFsH**,,  H+;<<<<=trN) r r r rr5r9TARGETr,strrBrrrr;r;?sM /F c   [   rr;c.eZdZdZedefdZdS)Receivedz Mixin class for messages received from the server. These messages are created in the client360 plugin when receiving a request from imunify360.cloudlinux.com. actionc|D],}t|dgpt|dg}||vr|cS-td|)NRECEIVED_ACTIONSr>z*Message class is not found for "{}" action)r?r@r format)r$rGrAreceived_actionss rget_subclass_with_actionz!Received.get_subclass_with_action]s**,,  H&x1CRHH "233M )))*" 8 ? ? G G   rN)r r r rr,rDrLrrrrFrFUsE  c    [    rrFc^eZdZdZeddZedefdZeddZdS)LockableNreturncK|jtj|_|jd{VdSr()_lockasyncioLockacquirer*s rrTzLockable.acquiremsG 9  CIi!!!!!!!!!!!rcF|jduo|jSr()rQlockedr*s rrVzLockable.lockedss"y$;)9)9););;rcJ|j|jdSdSr()rQreleaser*s rrXzLockable.releasews, 9 I        ! rrON) r r r rQr,rTboolrVrXrrrrNrNjs~ E"""[" r r2r)rargsr%r&s rrzMessage.__init__sB   1!0DN%gt%t6v66666rc>d|DS)Nc&i|]\}}|dk ||S)r<r).0kvs r z#Message.payload..s#???Ah1ritemsrs rpayloadzMessage.payloads??????rcX ||S#t$r}t||d}~wwxYw)z Called when an attribute lookup has not found the attribute in the usual places A shortcut to access an item from dict N)KeyErrorAttributeError)rrexcs rrzMessage.__getattr__s@ 0:  0 0 0 &&C / 0s )$)cfdD}}||djj|S)a. Do not flood console.log with large sequences If there is a list of more than _FOLD_LIST_THRESHOLD items inside the message, then this list will be collapsed and the number of items in the list will be shown. The message itself will not be collapsed. ci|]k\}}t|drVt|jk-|t|trt |jndt|dlS)__len__)hasattrlen_FOLD_LIST_THRESHOLD isinstancerD _shorten_str_SHORTEN_STR_THRESHOLD)rdrecolxnrs rrgz$Message.__repr__..s   5ui((  E T666 %%%+|E4#>???*SZZ***766r{}({}))ricopyupdaterJr&r )r items_to_fold folded_msgs` r__repr__zMessage.__repr__sq    !JJLL    YY[[ -(((t~:JGGGrc*|Sr()rrs r__str__zMessage.__str__s}}rrY)r r r rr>PRIORITYPROCESSING_TIME_THRESHOLDrurxrpropertyrjrrrr-r.s@rr2r2}s NH " 777777 @@X@ 0 0 0HHH,rr2c:eZdZfdZedZdZxZS) MessageListcLt|dS)Nlist)r r)rmsg_listr&s rrzMessageList.__init__s$ h'''''rc|jSr(rrs rrjzMessageList.payloads yrc d|jjdt|dgS)z@ Do not flood console.log with full MessageList rz <{} item(s)>rrJr&r rtgetrs rrzMessageList.__repr__sI N '  ! !#dhhvr&:&:";"; < <   r)r r r rrrjrr-r.s@rrrsb(((((X       rrceZdZdZdefdZdS)ShortenReprListMixinz Do not flood console.log with large sequences The method collapses messages that are a list. Instead of showing all the elements of the message, their number will be displayed. rc d|jjdt|dgS)Nrzrrirrs rrzShortenReprListMixin.__repr__sG N '  ! !#dhhw&;&;"<"< = =   rN)r r r rdictrrrrrrs9 t      rrc"eZdZdZeZdefdZdS) AccumulatablezMessages of this class will be grouped into a list of LIST_CLASS message instance by Accumulate plugin. Messages whose do_accumulate() call returns False will not be added to list.rOcdS)zAReturn True if this message is worth collecting, False otherwise.Trrs r do_accumulatezAccumulatable.do_accumulatestrN)r r r rr LIST_CLASSrZrrrrrrs@55JtrrceZdZdS)ServerConnectedNr rrrrrrrrceZdZdS)ServerReconnectedNr rrrrrrrrc*eZdZdZdZdZfdZxZS)Pingzr Will send this message on connected, reconnected events to provide central server with agent version PINGrcfttj|d<dS)Nversion)r r CoreConfigVERSION)rr&s rrz Ping.__init__s) $,Yr)r r r rr>rrr-r.s@rrrsN NH---------rrc&eZdZdZdZfdZxZS)Ackzd Notify Server that a persistent message with *seq_number* has been received by Agent. ACKc `tjdi|t||d<dS)N)per_seq_metar)r rr)r seq_numberr%r&s rrz Ack.__init__s8""6"""Z000W r)r r r rr>rr-r.s@rrrsI N111111111rrceZdZdZdZdS)NoopzG Sending NOOP to the agent to track the message in agent logs. NOOPNr r r rr>rrrrr sNNNrrc*eZdZdZdZejZdZdS) ServerConfigz. Information about server environment SERVER_CONFIGc@d|jjSNz{}()rJr&r rs rrzServerConfig.__repr__}}T^8999rN r r r rr>r5r8rCrrrrrrs<%N  F:::::rrc*eZdZdZdZejZdZdS) DomainListz* Information about server domains DOMAIN_LISTc@d|jjSrrrs rrzDomainList.__repr__)rrNrrrrrr!s<#N  F:::::rrceZdZdZdZdZdS) FilesUpdatedz/ To consume products of files.update() c||d<||d<dS)z\ :param files_type: files.Type :param files_index: files.LocalIndex files_type files_indexNr)rrrs rrzFilesUpdated.__init__2s (\)]rc\d|jj|d|dS)z? Do not flood console.log with large sequences z+{}({{'files_type':'{}', 'files_index':{}}})rrrrs rrzFilesUpdated.__repr__;s4=CC N '       rN)r r r rrrrrrrr-s<***     rrceZdZdZdZdS) UpdateFilesz9 Update files by getting message from the server UPDATENrrrrrrFsNNNrrceZdZdZdS) ConfigUpdate CONFIG_UPDATENr r r r>rrrrrN$NNNrrceZdZdZdS)Rejectz Kinda message filtering facility. Raised in order to stop message processing through plugins. Takes reason of reject as argument. N)r r r rrrrrrRs  DrrceZdZdZdS)HealthHEALTHNrrrrrr\sNNNrrceZdZdZdS) CommandInvokeCOMMAND_INVOKENrrrrrr`%NNNrrceZdZdZdS) ScanFailed SCAN_FAILEDNrrrrrrds"NNNrrceZdZdZdS) CleanupFailedCLEANUP_FAILEDNrrrrrrhrrrceZdZdZdZdS)RestoreFromBackupTaskz5 Creates a task to restore files from backup MALWARE_RESTORE_FROM_BACKUPNrrrrrrls3NNNrrc BeZdZdZhdZededededefdZ dS) cPanelEvent PANEL_EVENT>planexcludenew_pkg imunify360_avimunify360_proactiveusernamehooktsfieldscfd|D}|dkr%d|vr!d|vr|d|dkr |d|d<||||dS)Ncvi|]5\}}|jv ||6Sr)lowerALLOWED_FIELDS)rdrerfr$s rrgz/cPanelEvent.from_hook_event..sG   1wwyyC... GGIIq...rModifyusernewuser old_username)rrdata timestamprh)r$rrrrrs` rfrom_hook_eventzcPanelEvent.from_hook_event~s         H  &  V##v&"333#)&>D s$      rN) r r r r>rr,rDfloatrrrrrrrtsj"NN  "% +0 :>   [   rrceZdZdZdS) IContactSent ICONTACT_SENTNrrrrrrrrrslimitrOc|dksJt||kr$|d|dzdz d|| dzdzdn|S)z1Shorten *s* string if its length exceeds *limit*.Nz...)rt)rrs rrwrwsX 1999969!ffunna ! n 2 2E619Q;<< 2 2 2!KrceZdZdZdZdS) BackupInfoz(Information about enabled backup backend BACKUP_INFONrrrrrrs22"NNNrrceZdZdZdS) MDSReportList MDS_SCAN_LISTNrrrrrrrrrceZdZeZdS) MDSReportN)r r r rrrrrrrsJJJrrcneZdZdZdZdZdZedee fdZ edee fdZ dS) Splittablez A message list could be split into multiple batches. The split is possible for a list itself along with internal resources. Nmessagesc#K|jr|jr|D]}||jx}|V#t|}t |t rt nt}|||jD]/}|}|||j<||}|V0dSt|Ed{VdS)z Split messages' internal lists of things into batches. A field that is meant to split is defined by `BATCH_FIELD`. N) BATCH_FIELD BATCH_SIZErtypervrrrr{iter) r$rmessageri message_classbatcherbatchr new_messages r _split_itemszSplittable._split_itemss ? &s~ &# * *$[[999EB!MMMM$(MMM(25$(?(?L W")!?!?**&||~~05S_-&3mD&9&9 ))))) * * *H~~ % % % % % % % % %rc#K|jpt|}||}t||Ed{VdSr() LIST_SIZErtrr)r$r list_sizesplits rrzSplittable.batchedsSM2S]]   **5),,,,,,,,,,,r) r r r rrr rr,rrrrrrrrrs IJK&D$7&&&[&,-tM2---[---rrceZdZdZdZdS)EnsureServiceStatez-Ensure the service has the appropriate statusENSURE_SERVICE_STATENrrrrrrs77+NNNrr)4rRenumrtypingr defence360agent.contracts.configrrdefence360agent.utilsrr Exceptionr rrr0 MessageTyper5r;rFrNrr2rrrrrrrrrrrrrrrrrrrrrrDintrwrrrrrrrrr su??????77777777     9            & & & & & & & &$lnn #####4### ,     x   *     x   &;;;;;dH;;;|     '   $              G        g            - - - - -7J - - - 1 1 1 1 1': 1 1 17 : : : : :7J : : : : : : : :* : : :     7   2'8%%%%%7%%%     Y   W&&&&&GZ&&&#####*###&&&&&GZ&&&33333G333" " " " " '" " " J%%%%%7J%%%LCLLLLLL #####*### %%%%%(':%%% &-&-&-&-&-&-&-&-R,,,,,,,,,,r