h dZddlmZddlmZddlmZmZddlm Z ddl m Z m Z ddl mZmZmZddlmZdd lmZmZdd lmZdd lmZdd lmZdd lmZddlmZddl m!Z!ddl"m#Z#GddeZ$GddeZ%de&dzddfdZ'dS)u  This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program.  If not, see . Copyright © 2019 Cloud Linux Software Inc. This software is also available under ImunifyAV commercial license, see ) defaultdict)chain)Casefn) MessageType)MS_IMUNIFY_PATCH_ENABLEDhas_permission)CommonEndpoints RootEndpointsbind) HostingPanel)get_imunify_patch_idget_imunify_patch_purchase_url)RefreshImunifyPatchSubscription)is_imunify_patch_enabled)VulnerabilityAPI)VulnerabilityHitStatus)VulnerabilityHit) restore_hits) user_listc>eZdZeddd ddZdS)VulnerabilitiesAdminEndpointsvulnerabilitiesuserlistNc BK|r/tj|hd{V\}}t|}nN|r.tj|d{V\}}t|}ntjdd{V\}}td|D}t dt jtjkdfgd} t j t j tj |  dt j |t j } d| D} t#d{V} g} |D]}t'|}| || |g| |dt-|d{V||st/|d{Vndd|}||z}|| ||fS) zH Return list of users with summary vulnerabilities info )matchNcg|] }|d Sr).0us b/opt/imunify360/venv/lib/python3.11/site-packages/imav/malwarelib/rpc/endpoints/vulnerabilities.py zKVulnerabilitiesAdminEndpoints.vulnerabilities_user_list..Gs6661QvY666r vulnerablec(i|]}|j|jSr )rr')r!rows r# zKVulnerabilitiesAdminEndpoints.vulnerabilities_user_list..Us K K Kc3> K K Kr%)usernamedomainsvulnerable_file_countimunify_patch_user_id subscribed purchase_url)rget_matched_userslensortedrrstatusrPATCHEDselectrrSUMaliaswherein_group_byr get_domains_per_userrappendgetrr)selfoffsetlimitrsearch_users max_count users_listvulnerable_casequeryusers_vulnerabilities users_domainsresultsr/startends r#vulnerabilities_user_listz7VulnerabilitiesAdminEndpoints.vulnerabilities_user_list4s  M&8vFFFFFFFFFHAuE II  M&8vFFFFFFFFFHAuE II&/%@t%L%L%LLLLLLL Iu6666677  &*@*HH1 M N     # %''--l;;  U#(,,Z88 9 9 X&+ , , !L KU K K K*nnAACCCCCCCC   D1$77J NN $,00r::-B-F-Fa..4H3M3M-M-M-M-M-M-M", *"w5G"6j)C)27);E)BF:& NN6 " " " "'!!r%patchczKtjtj|}|#|tj|k}t t}|D]'}||j|j(| D]}t|ttj | x}r7|jt!j||dd{VdSdS)NT)filelist initiatormanual)rr6r9 orig_filer:rrrr=keys_check_imunify_patch_permissionr from_iterablevaluesrarbrVulnerabilityPatchTask)r?pathsrrH user_paths vulnerability panel_userros r#vulnerabilities_file_patchz3VulnerabilitiesEndpoints.vulnerabilities_file_patchsX '))//  & * *5 1 1    KK 0 5 =>>E && " K KM }) * 1 1-2I J J J J$//++ 8 8J +J 7 7 7 7E/ 0A0A0C0CDDEE E8 *,,2%d           r%revertcKtjtj|tjt jg}|#|tj|k}t|}t|d{V\}}d|Dd|DdS)Ncg|] }|j Sr rrr!ris r#r$zHVulnerabilitiesEndpoints.vulnerabilities_file_revert..s===C#-===r%cg|] }|j Sr rrs r#r$zHVulnerabilitiesEndpoints.vulnerabilities_file_revert..s777s}777r%) succeededfailed) rr6r9rrr:r4rr5rrr)r?rxrrHrgrrs r#vulnerabilities_file_revertz4VulnerabilitiesEndpoints.vulnerabilities_file_reverts '))//  & * *5 1 1  # ' ')?)G(H I I    KK 0 5 =>>EE{{".t"4"4444444 6==9===77777   r%)N)rOrPrQr rlr|rr r%r#rSrSos T VV,,)")")"-,)"V T VW--.-& T VX..    /.    r%rSrNreturncVtt|std|ddS)Nz%Unable to perform the command. User 'z%' does not have required permissions.)r rPermissionErrorrs r#rtrtsL 2D 9 9  A A A A     r%)(__doc__ collectionsr itertoolsrpeeweerr"defence360agent.contracts.messagesr%defence360agent.contracts.permissionsrr defence360agent.rpc_tools.lookupr r r +defence360agent.subsys.panels.hosting_panelr imav.contracts.imunify_patch_idrrimav.contracts.messagesrimav.contracts.permissionsr!imav.malwarelib.api.vulnerabilityrimav.malwarelib.configrimav.malwarelib.modelr'imav.malwarelib.vulnerabilities.storagerimav.malwarelib.utilsrrrSstrrtr r%r#rs*$#####:::::: EDDDDDDCCCCC??????>>>>>>999999222222@@@@@@++++++9-9-9-9-9-M9-9-9-xN N N N N N N N b #*       r%