a íÕ;j(ã@sddlZddlZddlZddlZddlZddlZddlZddlmZm Z m Z m Z m Z m Z dZdZdd„Ze jdd „ƒZd d „ZdRd d„ZdZdddœZdSdd„Zdd„Zdd„Zdd„Ze jdd„ƒZe jdd„ƒZ e jd d!„ƒZ!d"d#„Z"d$d%„Z#d&d'„Z$d(d)„Z%d*d+„Z&d,d-„Z'd.d/„Z(d0d1„Z)d2e#fd3e"fd4e$fd5e%fd6e&fd7e'fd8e(ffZ*d9d:„Z+d;d<„Z,d=d>„Z-e j.e j/d?d@dA„ƒZ0e j.e j/d?dBdC„ƒZ1e je j.e j/d?dDdE„ƒƒZ2e j.e j/ddFdGdH„ƒZ3e j.e j/ddFdIdJ„ƒZ4e j.e j/d?dKdL„ƒZ5e j.e j/dMdFdNdO„ƒZ6dPdQ„Z7dS)TéNé)ÚconfigÚ constantsÚ log_utilsÚ process_utilsÚselinuxÚutilsz/usr/libexec/kcare/virt-whatz/proccCs2tjdd…dkrt ¡Sddl}|jddSdS)Né)éérF)Zfull_distribution_name)ÚsysÚ version_infoÚplatformZlinux_distributionÚdistro)r©rú4/usr/libexec/kcare/python/kcarectl/platform_utils.pyÚ get_distrosrcCs t ¡dS)Nr )rÚunamerrrrÚget_system_unamesrcCsdtjdtjdfS)Nz%s.%srr)r r rrrrÚget_python_version$srFc Csžtƒtjdœ}t ¡r^tjddddtt  ¡ƒgdd\}}}|sN|  ¡d}nd |}||d <|rlt   |¡St |ƒ}d }|D]}|d |||f7}q|| ¡S) N)Úpython_versionÚ agent_versionZpsz-Zz --no-headersz--pidT)Ú catch_stdoutrz error: %sÚselinux_contextÚz%s: %s )rrÚVERSIONrZis_selinux_enabledrÚ run_commandÚstrÚosÚgetpidÚsplitÚjsonÚdumpsÚsortedÚrstrip) Úis_jsonÚinfoÚrcÚstdoutÚstderrrZ info_keysZinfo_strZinfo_keyrrrÚapp_info(s þ& r*z/sys/firmware/efi/efivarsz$8be4df61-93ca-11d2-aa0d-00e098032b8cz$605dab50-e046-4300-abb6-3dd810dd8b23)ÚglobalÚshimécCs^tj td||f¡}tj |¡s&dSt|dƒ}| |¡WdƒS1sP0YdS)Nz%s-%sÚrb)rÚpathÚjoinÚ EFIVARS_PATHÚexistsÚopenÚread)ÚnameÚvendorZ max_bytesZvar_pathÚvarrrrÚ_read_uefi_varIs   r8cCs@z(tdtdƒ}|r&|dd…dkWSWnty:Yn0dS)NÚ SecureBootr+éÿÿÿÿóF)r8Ú EFI_VENDORSÚ Exception)Zsecure_boot_varrrrÚis_secure_bootRs r>c Cs^zt||ƒ}|durWdSWn0tyL}zt|ƒ ¡}WYd}~n d}~00t t |¡¡S©N)r8r=rÚencoderÚnstrÚbase64Úurlsafe_b64encode)r5r6Z value_bytesÚerrrÚ_get_uefi_var_encoded]s  "rEc Cst tj td¡¡}|r0t|ƒdkr0|dd…}|tj tj t ¡¡dœ}|dsV|Sz„t dd„dDƒƒ|d<t d d „t  t ¡Dƒƒ}d |i|d <t gd ¢ƒ}|D]4}|dvsÀ| d¡r¢||vr¢t|td ƒ|d |<q¢Wn4ty}zt t|ƒ¡WYd}~n d}~00|S)NÚcmdlinei)rFÚhas_efirGcss |]}|t|tdƒfVqdS)r+N)rEr<©Ú.0r7rrrÚ róz#secure_boot_info..)r9Z SetupModer+cSs4g|],}| td¡r|dttdƒ d…‘qS)r,rr)Úendswithr<ÚlenrHrrrÚ trKz$secure_boot_info..Úvarsr,)Z MokListRTZ MokListXRTZMokListTrustedRTZ SbatLevelRT)Z HSIStatusZ MokIgnoreDBZRT)rÚ try_to_readrr/r0ÚPROC_DIRrMr2Údirnamer1Údictr#ÚlistdirÚsetrLrEr<r=rÚlogwarnr)rFr&Z shim_varsZshim_exclude_varsr7ÚerrrrrÚsecure_boot_infohs& ÿ  $rXc Csttjrhz&t t ¡ddddtj¡dd}Wqptjyd}zt |¡t   ¡}WYd}~qpd}~00nt   ¡}|S)Nrr ) rÚ REPORT_FQDNÚsocketÚ getaddrinfoÚ gethostnameÚ AI_CANONNAMEÚgaierrorrÚlogerrorrÚnode)ÚhostnameÚgerrrÚ get_hostname€s&  rccCsTtj td¡}tj |¡rPt|dƒ}| ¡}ttt |  ¡dƒƒƒ}|  ¡|SdS)NÚuptimeÚrrz-1) rr/r0rQÚisfiler3ÚreadlinerÚintÚfloatr Úclose)Z uptime_fileÚfÚlineÚresultrrrÚ get_uptimes  rncCs tj t¡rt tg¡ ¡SdS)Nz no-virt-what)rr/rfÚVIRTWHATrÚ check_outputÚstriprrrrÚget_virts rrcCs tj d¡S)Nz/usr/local/cpanel/cpanel©rr/rfrrrrÚ is_cpanel¤srtcCs tj d¡S)Nz/usr/local/psa/admin/©rr/ÚisdirrrrrÚis_plesk©srwcCs tj d¡S)Nz/usr/local/interworx/rurrrrÚ is_interworx®srxcCs tj d¡S)Nz/usr/local/ispmgr/rurrrrÚ is_ispmanager³srycCs tj d¡S)Nz/usr/local/directadmin/plugins/rurrrrÚis_directadmin¸srzcCs tj d¡S)Nz/usr/local/hostingcontroller/rurrrrÚis_hosting_controller½sr{cCs tj d¡S)Nz/hsphere/sharedrurrrrÚ is_hsphereÂsr|cCstdd„dDƒƒS)z:Softaculous markers checked by the kcdoctor.sh detect_cp()css|]}tj |¡VqdSr?)rr/r2)rIr/rrrrJÊsÿz"has_softaculous..)z/usr/local/softaculousz*/usr/local/cpanel/whostmgr/cgi/softaculousz*/usr/local/directadmin/plugins/softaculous)ÚanyrrrrÚhas_softaculousÇsþr~ZPleskZcPanelZ InterWorxZ ISPmanagerZ DirectAdminzHosting ControllerzH-SpherecCs2tj tj tdd¡¡o0tj tj tdd¡¡ S)NZvzZveinfoÚversion)rr/r2r0rQrrrrÚinside_vz_containerásr€cCsdttj tdd¡ƒ ¡vS)Nz/lxc/Ú1Zcgroup)r3rr/r0rQr4rrrrÚinside_lxc_containeråsr‚cCs tj d¡S)Nz /.dockerenvrsrrrrÚinside_docker_containerésrƒ)ÚloggercCsFt tj td¡¡}|sdS| dd¡\}}}}t|ƒt|ƒt|ƒfS)NÚloadavgú r )rrPrr/r0rQr ri)r…Zm1Zm5Zm15Ú_rrrÚget_load_averageís rˆcsDt tj td¡¡}|sdSd‰t‡fdd„dd„| ¡DƒDƒƒS)z!Returns dict of memory info in kBÚmeminfoN)ZMemTotalZMemFreeZ SwapTotalZSwapFreec3s&|]\}}|ˆvr|t|ƒfVqdSr?)rh)rIÚkÚv©Z filter_paramsrrrJrKzget_mem_info..css"|]}t d|¡dd…VqdS)z[\s:]+Nr ©Úrer ©rIrlrrrrJrK)rrPrr/r0rQrSÚ splitlines)r‰rrŒrÚ get_mem_info÷s r‘c Cs¼t tj td¡¡}|sdSdd„| d¡Dƒ}t|ƒttdd„|Dƒƒƒ|d  d¡t |d  d d¡ƒ|d  d ¡t |d  d d¡ƒt |d  d d¡ƒ|d  d ¡|d  dd¡ ¡dœ S)NÚcpuinfocSs&g|]}|rtdd„| ¡Dƒƒ‘qS)css|]}t d|¡VqdS)z\s*:\s*NrrrrrrJ rKz*get_cpu_info...)rSr)rIZ cpu_linesrrrrN sþz get_cpu_info..z css"|]}| d¡| d¡fVqdS)z physical idzcore idN)Úget)rIZcpurrrrJrKzget_cpu_info..rÚ vendor_idÚmodelz model namez cpu familyÚsteppingÚ microcodeÚflagsr) Z logical_coresZphysical_coresr”r•Z model_nameZ cpu_familyr–r—r˜) rrPrr/r0rQr rMrUr“rh)r’ZcpusrrrÚ get_cpu_infos þ   ÷r™)r„Údefault_returncCstdd„t t¡DƒƒS)NcSsg|]}| ¡r|‘qSr)Úisdigit)rIÚdrrrrN rKz%get_process_count..)rMrrTrQrrrrÚget_process_countsrcCs(t tj td¡¡}t|pd ¡dƒS)Nzsys/fs/file-nrÚ0r)rrPrr/r0rQrhr )Zfd_inforrrÚget_opened_files_count#srŸcCs$t d¡D]\}}}t|ƒSdS)Nz/sys/kernel/debug/kvm)rÚwalkrM)Ú_rootÚdirsÚ_filesrrrÚget_vm_count_kvm*s r¤)rrcCs(dd„}|dƒ|dƒ|dƒ|dƒfS)z8Return tuple of total numbers of TCP and UDP connectionscSs4t tj td|¡¡}|sdStt| ¡ƒddƒS)NÚnetrr) rrPrr/r0rQÚmaxrMr)ÚprotoÚrecordsrrrÚconn_records_count7sz9get_network_connections_count..conn_records_countZtcpZtcp6ZudpZudp6r)r©rrrÚget_network_connections_count2srªc Cs,tƒ\}}tƒtƒtƒtƒtƒtƒ||dœS)N)Z load_averageZmem_infoZcpu_infoZvm_countZ processesZ open_filesZtcp_connectionsZudp_connections)rªrˆr‘r™r¤rrŸ)Zconn_tcpZconn_udprrrÚget_performance_metricsAs ør«)F)r-)8rBr!rrrŽrZr rrrrrrrÚAnyÚDictÚOptionalÚTuplerorQrÚcachedrrr*r1r<r8r>rErXrcrnrrrtrwrxryrzr{r|r~ZCONTROL_PANEL_PROBESr€r‚rƒÚ catch_errorsrVrˆr‘r™rrŸr¤rªr«rrrrÚs~    þ      ù