K6h#BdZddlZddlZddlmZddlmZmZddlm Z ddl m Z ddl m Z mZmZddlmZmZmZmZdd lmZdd lmZmZmZdd lmZdd lmZdd lm Z ddl!m"Z"m#Z#ddl$m%Z%ddl&m'Z'm(Z(m)Z)m*Z*ej+e,Z-dZ.dZ/de0fdZ1Gdde"Z2dS)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 N)PatchmanConfig)PATCHMAN_PACKAGEPATCHMAN_SERVICE_NAME)PatchmanCustomIntegration) PatchmanError) FeatureStatusPatchmanFeatureRealtimeFeature)DomainPathUser patchman_db)License)get_current_ipis_ipv4 is_private_ip)REALTIME_SERVICE_NAME)Core) MessageType) RootEndpointsbind) hosting_panel) check_runfinally_happened OsReleaseInfo os_versionzpatchman-clientz/usr/local/patchman/patchmandreturncBtjtjzSN)rid_likeDEBIANP/opt/imunify360/venv/lib/python3.11/site-packages/imav/patchman/rpc/endpoints.py is_debianr%8s  " "]%9 99r#ceZdZdZedd ddZeddddZed Zed Z d Z dd Z eddddZ edddZ edddZedddZeddddZeddddZdS)PatchmanEndpointsz/etc/patchman/license/keypatchmanusersFNc jK|rt||}ntj}|d{V}t t t tgtj d5}|D]}|d}|dpd} |d} |dpd} |d } |d } t j || | | | | }|d }|D]C}|d }t j ||}|d}|D]}tj ||Dd|j icdddS#1swxYwYdS)asWrites the users and their domains to database. Patchman go agent executes this endpoint to fill the database. In case of custom integration it retrieves the user-defined parameters from Patchman Portal and passes it here. :param custom_integration: true if custom integration, false by default :param integration_type: only for custom integration, file or script :param metadata_path: only for custom integration, path to file or script that represent metadata (File type 1 or Script 1 from https://docs.imunify360.com/Patchman_custom_integration.pdf) Nr)) target_dirprefixusernameemaillanguageparentlevel suspended)namer.r0r1r2r3domainsdomain)r4userpaths)r4r6path) rr HostingPanelpatchman_usersrr r r rTMPDIRcreatedatabase)selfcustom_integrationintegration_type metadata_pathhpr;db user_data user_namer.r0r1r2r3r7r5 domain_data domain_namer6r8 path_names r$r)zPatchmanEndpoints.users?s&  .*+;]KKBB+--B!0022222222  64 T[    ) + C C %j1 !'*0b$Z0"8,2!'*%k2 {"%!' $I.#*CCK"-h"7K#] $GGGF'0E%*CC  6BBBBBC CBK(; ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )s1B*D((D,/D,registercKtj|j}|jdd|d5}||ddddS#1swxYwYdS)z~ Writes a key to Patchman's key file. Patchman automatically checks for registration every 5 seconds. T)parentsexist_okwN)pathlibr KEYFILEr1mkdiropenwrite)r?regkey keyfile_pathfs r$rJzPatchmanEndpoints.registerxs |DL11 !!$!>>>   s # # q GGFOOO                  s A00A47A4ctSr)r r?s r$patchman_featurez"PatchmanEndpoints.patchman_feature   r#ctSr)r rXs r$realtime_featurez"PatchmanEndpoints.realtime_featurerZr#cK|jd{Vdd}|tjtjfvS)Nitemsstatus)rYr_r INSTALLING INSTALLEDr?r_s r$ is_installedzPatchmanEndpoints.is_installedsL-4466666666@J-2M4KLLLr#rcK|d{Vr"tdtdSt rdnd}|ddtg}t s8|ddt tg}t ds|dgz }t|d{V|j tj t d{VdS) Nz%s package already installedzapt-getyumz-yinstallswap7z--allowerasingservice)rcloggerinforr%OLD_PATCHMAN_PACKAGEr startswithr_sinkprocess_messagerEnsureServiceStater)r?package_managercmds r$_migrate_patchmanz#PatchmanEndpoints._migrate_patchmans*""$$ $ $ $ $ $ $  KK68H I I I F'0{{=))i1AB{{ * $ C<<**3// *())nnj((  *3H I I I           r#rfcK|rt|std|s,t}t|rtd|rt jdd||jd{Vt|jj tj ddd{Vr:|j tjt d{VdSdS) z Install imunify-patchman packagezOnly ipv4 address is supportedzCan't automatically detect the outbound IP on this machine, since you're using a NAT. Please manually provide the outbound IPv4 address that we should use.networkipN  max_triesdelayri)r ValueErrorrrrsetrYrfr has_statusrrarorprrqr)r? ip_address current_ips r$rfzPatchmanEndpoints.installsX  ?gj11 ?=>> > '))JZ((  *  <  y$ ; ; ;#++---------!  ! ,  #            *,,.7LMMM            r#migratec*KtjtstddSt jstddS| d{VdS)z.Migrate old patchman agent to imunify-patchmanzThere is nothing to migrateNz#Unsupported license type to migrate) rOr OLD_PATCHMAN_BINexistsrkrlrhas_clean_modewarningrtrXs r$rzPatchmanEndpoints.migrates|,--4466  KK5 6 6 6 F%''  NN@ A A A F$$&&&&&&&&&&&r# uninstallcHK|jd{VdS)z"Uninstall imunify-patchman packageN)rYremoverXs r$rzPatchmanEndpoints.uninstall5#**,,,,,,,,,,,r#r_cK|jd{Vdd|jd{VdddS)zGet patchman statusNr^r_)r_realtime)rYr_r\rXs r$ get_statuszPatchmanEndpoints.get_statuss{"299;;;;;;;;WE $4;;========wG    r#rcK|jd{Vdd}|tjkrt dt jst d|jd{Vt|jj tjddd{Vr:|j tjt d{VdSdS) z#Install imunify-realtime-av packageNr^r_z6Can't install realtime package, install patchman firstz8Realtime is not enabled for the current Patchman licenserxryrzri)rYr_rrarrhas_realtime_enabledr\rfrrrorprrqrrbs r$install_realtimez"PatchmanEndpoints.install_realtimesV-4466666666@J ], , ,H +-- J #++---------!  ! ,  #            *,,.7LMMM            r#cHK|jd{VdS)z%Uninstall imunify-realtime-av packageN)r\rrXs r$uninstall_realtimez$PatchmanEndpoints.uninstall_realtimerr#)FNNr)rN)__name__ __module__ __qualname__rPrr)rJpropertyrYr\rcrtrfrrrrrr"r#r$r'r'<s)G T*g! 6)6)6)6)p T*j!!"!!!X!!!X!MMM    0 T*i  ! 4 T*i  ''! ' T*k""--#"- T*h       T*i,,-,. T*k:..--/.---r#r')3__doc__loggingrOimav.patchman.configrimav.patchman.constantsrr imav.patchman.custom_integrationrimav.patchman.exceptionsrimav.patchman.featurerr r imav.patchman.modelr r r rimav.patchman.licenserimav.patchman.utilsrrrimav.subsys.realtime_avr defence360agent.contracts.configr"defence360agent.contracts.messagesr defence360agent.rpc_tools.lookuprrdefence360agent.subsys.panelsrdefence360agent.utilsrrrr getLoggerrrkrmrboolr%r'r"r#r$rs*//////KKKKKKKKFFFFFF222222 @???????????))))))FFFFFFFFFF999999111111::::::@@@@@@@@777777  8 $ $(2:4::::}-}-}-}-}- }-}-}-}-}-r#