403Webshell
Server IP : 162.241.203.86  /  Your IP : 216.73.216.183
Web Server : Apache
System : Linux br1002.hostgator.com.br 5.14.0-687.36.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Aug 7 05:40:49 EDT 2026 x86_64
User : luxlic01 ( 6532)
PHP Version : 8.3.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/libexec/kcare/python/kcarectl/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/libexec/kcare/python/kcarectl/__pycache__/doctor.cpython-39.pyc
a

��;j _�.@s dZddlZddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZmZm
Z
mZmZddlmZddlmZmZmZdZdZdZd	Zd
ZdZ dZ!d
Z"dZ#dZ$dZ%dZ&Gdd�de	j'�Z(Gdd�de)�Z*dd�Z+dd�Z,dd�Z-dd�Z.Gdd�de)�Z/d d!�Z0d"d#�Z1d�d%d&�Z2d'd(�Z3ej4d)d*��Z5d+d,�Z6d-d.�Z7d/d0�Z8d1d2�Z9d3d4�Z:d5d6�Z;d7d8�Z<d9d:�Z=d;d<�Z>d=d>�Z?d?d@�Z@dAdB�ZAdCdD�ZBdEdF�ZCe/dGe3�e/dHe2dIgdJdK��e/dLe5�e/dMe6�e/dNe7�e/dOe2dOg��e/dPe8�e/dQe0dR��e/dSe0dT��e/dUe0dV��e/dWe0dX��e/dYe0dZ��e/d[e0d\��e/d]e0d^��e/d_e0d`��e/dae0db��e/dce1ddde��e/dfe9�e/dge1dhdi��e/dje:�e/dke;�gZDe+dldm�Ee"��e+dndn�e+dodp�Ee"��e+dqdr�e,dsdt�e+dudv�e-dwdx�e-dydz�e-d{d|�e-d}d~�e-dd��e-d�d��e-d�d��e-d�d��e-d�d��e,d�d��e-d�d��e,d�e�e-d�d��e+d�d��e+d�d��e+d�d��e+d�d��e.d�e<�e+d�d��e,d�d��e.d�e>�e+d�d��e+d�d��e.d�e?�e,d�d��e+d�d��e.d�e@�e+d�d��Ee"��e,d�e�e,d�d��e.d�eA�e.d�eB�e+d�d��e+d�d��e+d�d��e.d�eC�e+d�d��e+d�d��g,ZFejGejHd��d�d���ZId�d�d��ZJdS)�aODoctor v2 vitals collector (KPT-5984).

Python port of the kcdoctor.sh (1.0-8) vitals collection: gathers the
same data set into a DataPackage-based archive processed by the patch
server generic uploads pipeline.

Scalar and short values are consolidated into a single ``doctor.json``
(the eportal doctor precedent), one field each, instead of a tiny
archive entry per value; bulk data (logs, command dumps, package lists,
sysfs tunables, crash artifacts) stays as separate archive entries. The
1:1 inventory of collected items lives in
docs/features/KPT-5984-doctor-v2/parity-inventory.md.
�N)	�auth�config�delivery_kit�
http_utils�kcare�	log_utils�platform_utils�serverid�utils)�run_command)�	HTTPError�URLError�httplibz2.0-1z/boot/grub2/grub.cfgz/etc/kdump.confz/var/log/dpkg.logz/etc/apt/sources.list*z/etc/yum.repos.d/*z/var/log/libcare/*.logi'z/sys)zenable*znr_*zmax_*z*cnt*)z /sys/kernel/debug/tracing/eventsz/sys/kernel/tracing/eventsz/sys/devices)z
[0-9]*.logzkmsg*logc@s eZdZdZdZedd��ZdS)�KcarectlDoctorPackagezkcarectl-doctorz/upload/kcarectl-doctor/cCstjS�N)r�DOCTOR_REPORT_MAX_SIZE_BYTES)�self�r�,/usr/libexec/kcare/python/kcarectl/doctor.py�max_size;szKcarectlDoctorPackage.max_sizeN)�__name__�
__module__�__qualname__�	data_type�
upload_uri�propertyrrrrrr7src@s eZdZdZdd�Zdd�ZdS)�CollectionSpecz�A single bulk vitals item ported from kcdoctor.sh.

    Collection failures are recorded in errors.log and never abort the
    report: an unhandled exception inside the package context manager
    would remove the whole archive.
    cCs||_||_dSr)�arcname�_collect)rr�collectrrr�__init__LszCollectionSpec.__init__c
CsPz|�||j�Wn8tyJ}z |�d�|j|��WYd}~n
d}~00dS�Nzfailed to collect {0}: {1})rr�	Exception�	log_error�format)r�data_package�errr�applyQszCollectionSpec.applyN�rrr�__doc__r r'rrrrrDsrcs�fdd�}t||�S)z4`run "<cmd>"` kcdoctor.sh helper (no shell features)cs|�|��dSr)�
add_stdout�r%r��cmdrrr]szrun_spec.<locals>.collect�r)rr-rrr,r�run_specYsr/cs�fdd�}t||�S)z4`dump "<path>"` kcdoctor.sh helper for regular filescs|j|�d�dS)N��src_path)�add_filer+��pathrrrhszdump_spec.<locals>.collectr.�rr4rrr3r�	dump_specdsr6cs�fdd�}t||�S)z�`dump "<path>"` for /proc and /sys files.

    tar reports them as 0-size so they are first read into memory
    (see the same approach in anomaly.prepare_kernel_anomaly_report).
    cs`tj���s |�d����dSt�d��"}|j||��d�Wd�n1sR0YdS)N�file not found: {0}�rb��
data_bytes)�osr4�existsr#r$�openr2�read)r%r�fr3rrrws
zproc_dump_spec.<locals>.collectr.r5rr3r�proc_dump_specos	r@cCs
t||�Srr.)r�fnrrr�
callable_spec�srBc@s eZdZdZdd�Zdd�ZdS)�	FieldSpecz�A single doctor.json field ported from kcdoctor.sh.

    Collection failures are recorded in errors.log and never abort the
    report; a collector returning None omits the field (e.g. a
    distro-specific source file absent on this system).
    cCs||_||_dSr)�keyr)rrDrrrrr �szFieldSpec.__init__c
Cs^z|��}Wn:tyF}z"|�d�|j|��WYd}~dSd}~00|durZ|||j<dSr!)rr"r#r$rD)rr%�report�valuer&rrrr'�szFieldSpec.applyNr(rrrrrC�srCcs�fdd�}|S)z�`dump "<path>"` as a doctor.json string field.

    Read in binary (non-utf8 safe) and decoded leniently; an absent
    distro-specific source file simply omits the field (None).
    csRtj���sdSt�d��$}|���dd���Wd�S1sD0YdS)Nr8�utf-8�replace)r;r4r<r=r>�decode�strip)r?r3rrr�szread_field.<locals>.collectr)r4rrr3r�
read_field�srKcs"t�t�|�����fdd�}|S)z�`grep <pattern> <path>` as a doctor.json list-of-lines field.

    Match on bytes (like collect_apt_sources) so a non-utf8 byte cannot
    lose a line; the matched lines are decoded leniently for the JSON.
    csXtj���sdSt�d��}|����}Wd�n1s<0Y�fdd�|D�S)Nr8cs"g|]}��|�r|�dd��qS)rGrH)�searchrI��.0�line)�regexrr�
<listcomp>��z/grep_field.<locals>.collect.<locals>.<listcomp>)r;r4r<r=r>�
splitlines)r?�lines�r4rPrrr�s
*zgrep_field.<locals>.collect)�re�compiler
�bstr)r4�patternrrrUr�
grep_field�s
rZFcs��fdd�}|S)z@`run "<cmd>"` captured as a doctor.json field instead of a file.cs0t�ddd�\}}}|pd��}�r,|��S|S)NT��catch_stdout�catch_stderr�)rrJrS)�_�stdout�text��argv�as_linesrrr�szcmd_field.<locals>.collectr)rcrdrrrbr�	cmd_field�srecCstSr)�DOCTOR_VERSIONrrrr�collect_doctor_version�srgcCs>z$t�t�d��}t�|�����WSty8YdS0dS)z�the public IP of the machine as seen by the patch server.

    Cached: the main_ip and server_id fields share one HTTP roundtrip
    per run.
    ZmyipZNAN)r�urlopenr
�get_patch_server_url�nstrr>rJr")�responserrr�get_main_ip�s
rlcCs$t��}|st��dd�}t�|�S)N�.r_)r	�get_serveridrlrHr
rj)�	server_idrrr�collect_server_id�srpcCst��Sr)r�get_kernel_hashrrrr�collect_kernel_id�srrcCs>i}dD]0}tdd|gddd�\}}}|p.d��||<q|S)N)�a�r�m�p�o�uname�-Tr[r^)rrJ)�result�flagr_r`rrr�
collect_uname�s
r|cCs\tj�t�sdSttd�� }|���dd�}Wd�n1s@0Ydd�|��D�S)z7`grep vmlinuz /boot/grub2/grub.cfg | sed 's/root=.*//'`Nr8rGrHcSs"g|]}d|vrt�dd|��qS)Zvmlinuzzroot=.*r^)rV�subrMrrrrQrRz)collect_grub2_entries.<locals>.<listcomp>)r;r4r<�	GRUB2_CFGr=r>rIrS)r?rarrr�collect_grub2_entries	s
.rcCstt�t��Sr)�sorted�glob�YUM_REPOS_GLOBrrrr�collect_yum_repossr�cCsdd�tjD�}|t��d�S)z8presence-only port of the kcdoctor.sh detect_cp() probescSsg|]\}}|�r|�qSrr)rN�name�proberrrrQrRz)collect_control_panel.<locals>.<listcomp>)�cpZsoftaculous)r�CONTROL_PANEL_PROBES�has_softaculous)Zpanelsrrr�collect_control_panelsr�cCs@tddgddd�\}}}|j|tj|p(d�dd�dd	�d
�dS)z`ipcs -m | sed -e s/-/=/g`�ipcsz-mTr[r^ry�=rG��encodingr9N)rr2r
rXrH)r%rr_r`rrr�collect_ipcs%sr�cCs|tj�t�s |�d�t��dSttd��&}dd�|����D�}Wd�n1sV0Y|j	|d�
|�dd�dS)z$`grep ' install ' /var/log/dpkg.log`r7Nr8cSsg|]}d|vr|�qS)s	 install rrMrrrrQ4rRz,collect_dpkg_install_log.<locals>.<listcomp>�
r9)r;r4r<�DPKG_LOGr#r$r=r>rSr2�join)r%rr?rTrrr�collect_dpkg_install_log,s4r�c
Cs�tj�d�stj�d�rd}nZtj�d�rtd}zt|d�Wqxtyp}z|�d�|��WYd}~qxd}~00nd}|�||�dS)	Nz/usr/bin/rpmz/bin/rpmzFrpm -q -a --queryformat="%{N}|%{V}-%{R}|%{arch}|%{INSTALLTIME:date}\n"z
/usr/bin/dpkgzJ/usr/bin/dpkg-query -W -f "${binary:Package}|${Version}|${Architecture}\n"zdpkg.logzfailed to collect dpkg.log: {0}zecho "unknown package manager")r;r4r<r�r"r#r$r*)r%r�packages_cmdr&rrr�collect_packages9s(r�c
s\t�d��g}tt�t��D]N}tj�|�r`t�|�D]&\�}}|�	�fdd�t|�D��q6q|�
|�q|s�|�d�t��dSg}|D]�}z6t
|d��}|��}Wd�n1s�0YWnDt�y
}	z*|�d�||	��WYd}	~	q�WYd}	~	n
d}	~	00tjd�|�d	d
��|�	��fdd�|��D��q�|j|d�|�dd
�dS)z/`grep -rE '^(deb|URIs)' /etc/apt/sources.list*`s^(deb|URIs)c3s|]}tj��|�VqdSr)r;r4r�)rNr�)�rootrr�	<genexpr>UrRz&collect_apt_sources.<locals>.<genexpr>r7Nr8�failed to read {0}: {1}z{0}:rGr�c3s |]}��|�r�|VqdSr)rLrM)�prefixrPrrr�jrRr�r9)rVrWr�r��APT_SOURCES_GLOBr;r4�isdir�walk�extend�appendr#r$r=r>r"r
rXrSr2r�)
r%r�filesr4r_�namesrTr?�contentr&r)r�rPr�r�collect_apt_sourcesLs*
 *" r�c	Cstt�t��}|s&|�d�t��dSg}|D]�}zDt|d��&}|����td�}Wd�n1sj0YWnBt	y�}z*|�d�||��WYd}~q.WYd}~n
d}~00t
jd�|�dd�}|�|d�
|��q.|j|d�
|�dd	�dS)
z%`tail -n10000 /var/log/libcare/*.log`r7Nr8r�z==> {0} <==
rGr�r�r9)r�r��LIBCARE_LOGS_GLOBr#r$r=r>rS�LOG_TAIL_LINESr"r
rXr�r�r2)	r%r�paths�chunksr4r?rTr&�headerrrr�collect_libcare_logsos8"r�cs�tj�tj�sdS|�|d�tj��t�tj�D]`\}}}t|�D]L�t	�fdd�t
D��rDtj�|��}tj�|tj�}|j
d�|�|d�qDq2dS)z3crashreporter artifacts from /var/cache/kcare/dumpsN�
ls -lR {0}c3s|]}t��|�VqdSr��fnmatch�rNrY�r�rrr��rRz&collect_crash_dumps.<locals>.<genexpr>zcrashreporter/{0}r0)r;r4r�r�
KDUMPS_DIRr*r$r�r��any�CRASH_DUMP_PATTERNSr��relpathr2)r%rr�r_r�r4Zrel_pathrr�r�collect_crash_dumps�sr�cCs�tj�t�sdSt��}tj�|�s(dS|�|d�|��t	t
�
tj�|d���D]8}tj�|�sdqR|jd�tj�
|��tj�|d�d�qRdS)Nr��*zkdump/{0}/vmcore-dmesg.txtzvmcore-dmesg.txtr0)r;r4r<�
KDUMP_CONFr�get_kdump_rootr�r*r$r�r�r�r2�basename)r%r�
kdump_rootZevtrrr�
collect_kdump�s�r�c	
s�g}t�t�D]�\}}}|�t�r0g|dd�<qt|�D]��t�fdd�tD��r8tj�	|��}z6t
|d��}|��}Wd�n1s�0YWnty�d}Yn0|�
t�d�|��|d�q8q|j|d�	|�d�dS)	zGtunables gathered by the kcdoctor.sh get_sysfs_info() `find /sys` callsNc3s|]}t��|�VqdSrr�r�r�rrr��rRz'collect_sysfs_config.<locals>.<genexpr>r8rRzcat {0}
r�r9)r;r��
SYSFS_ROOT�
startswith�SYSFS_EXCLUDE_PREFIXESr�r��SYSFS_NAME_PATTERNSr4r�r=r>r"r�r
rXr$r2)	r%rr�r��dirsr�r4r?r�rr�r�collect_sysfs_config�s
*
"r�Zdoctor_versionZ	virt_whatz/usr/libexec/kcare/virt-whatT)rdZmain_iproZ	kernel_id�daterxZredhat_releasez/etc/redhat-releaseZdebian_versionz/etc/debian_versionZ
os_releasez/etc/os-releaseZissuez
/etc/issueZsysconfig_kernelz/etc/sysconfig/kernelZproc_uptimez/proc/uptimeZproc_loadavgz
/proc/loadavgZproc_cmdlinez
/proc/cmdline�proc_versionz
/proc/versionZdefault_grubz/etc/default/grub�DEFAULTZ
grub2_entriesZ	sshd_portz/etc/ssh/sshd_configZPortZyum_repos_dZ
control_panel�syslogztail -n{0} /var/log/syslog�dmesg�messagesztail -n{0} /var/log/messages�ls_var_cache_kcarezls -lR /var/cache/kcare/z
kcare.confz/etc/sysconfig/kcare/kcare.conf�cpuinfozcat /proc/cpuinfoZproc_vmstatz/proc/vmstatZproc_devicesz
/proc/devicesZproc_diskstatsz/proc/diskstatsZproc_mdstatz/proc/mdstatZproc_meminfoz
/proc/meminfoZ
proc_swapsz/proc/swapsZproc_filesystemsz/proc/filesystemsZproc_mountsz/proc/mountsZproc_interruptsz/proc/interruptsz	grub.confz/boot/grub/grub.conf�proc_modulesz
/proc/modulesz	grub2.cfgZ
proc_zoneinfoz/proc/zoneinfoZls_boot_configsz:ls /etc/grub.conf /boot/grub/grub.conf /boot/grub/menu.lstZls_bootzls -l /bootZprintenvZ	dmidecoder��sysctlz	sysctl -azsysctl.confz/etc/sysctl.confz
packages.listZlspciz	lspci -vvZdpkg_lzdpkg -lZapt_sourceszyum.confz
/etc/yum.confZyum_repolistzyum repolistZlibcare_logszkcarectl.logz tail -n{0} /var/log/kcarectl.logz
kdump.confz
kcare-cronz/etc/cron.d/kcare-cronzcrashreporter/lszkdump/lsZ	aa_statusz	aa-statusZsestatusZkprobes_listz"cat /sys/kernel/debug/kprobes/listZsysfs_configZlsblkzlsblk -fZdfzdf -h)�loggercCsht�}|�Ji}tD]}|�||�q|�d|�tD]}|�|�q6Wd�n1sZ0Y|S)Nzdoctor.json)r�FIELD_SPECSr'�add_json�
FILE_SPECS)r%rE�field�specrrr�prepare_doctor_reports*r�cCs|s
tjr4|rdnd}tjd�|�dd�|�dSt��durXtjddd�|�dSt�}|durzt�d�|�dSz�z0|�	�}tjd	�|�dd�t
�d
�|��WnFtt
tjtjfy�}z"t�d�|��|�WYd}~n
d}~00W|��n
|��0dS)a�Collect and upload the doctor report via the generic uploads proxy.

    PUTs the archive to ``/upload/kcarectl-doctor/`` -- the same modern
    pipeline as ``kernel-anomaly`` -- which ePortal proxies transparently
    to the patch server, so no ePortal change is required. Any 2xx reply
    is success, including the ``REDUCED_REPORT`` ``204`` where the proxy
    intentionally drops the report (``send()`` returns without raising, so
    we do not fall back).

    Falls back to the legacy ``kcdoctor.sh`` flow (``fallback``) when:

    * ``force_fallback`` (the ``--doctor --fallback`` CLI flag) or
      ``config.FORCE_DOCTOR_FALLBACK`` is set -- the rollout kill-switch.
      ``--fallback`` is the one-off, per-invocation form; the config knob
      is settable per host in kcare.conf or pushed fleet-wide via the
      ``KC-Flag-Force-Doctor-Fallback`` feature flag. Either forces the
      legacy flow on every host, registered or not, before the new path
      is even considered;
    * the host is not registered, i.e. there is no auth string (OQ-4: the
      proxy upload requires auth, so the new path is not even attempted);
    * report collection failed (``prepare_doctor_report`` returned None);
    * the new route is unavailable on an older patch server / ePortal --
      a 404 / 405 / 403, surfaced as ``HTTPError``, or a connection-level
      failure. ``send()`` drives ``http_utils.upload_file`` (raw
      ``httplib``, not ``urllib``), so transport failures surface as an
      ``OSError`` subclass -- ``socket.timeout``, ``ConnectionRefused``,
      ``socket.gaierror`` (DNS), ``ssl.SSLError`` -- or an
      ``httplib.HTTPException``, *not* ``URLError``; all of these mean the
      new path is unusable. ``upload_file`` raises only on status >= 400,
      so a redirect is not treated as a failure; the proxy and patch
      server never redirect uploads.

    :param fallback: legacy ``kcdoctor.sh`` runner, injected by the caller
        (KPT-6065) to keep this module free of an ``__init__`` import cycle.
    :param force_fallback: when True (``--doctor --fallback``), skip the v2
        path and run ``fallback`` directly; the per-invocation form of
        ``config.FORCE_DOCTOR_FALLBACK``.
    z--fallback requestedzFORCE_DOCTOR_FALLBACK is setz.doctor: {0}; using the legacy kcdoctor.sh flowF)�	print_msgNzAdoctor: host is not registered; using the legacy kcdoctor.sh flowzCdoctor: report collection failed; using the legacy kcdoctor.sh flowzdoctor: report uploaded as {0}z,Please provide this filename to support: {0}zJdoctor: report upload unavailable ({0}); using the legacy kcdoctor.sh flow)r�FORCE_DOCTOR_FALLBACKr�loginfor$r�get_http_auth_stringr��logwarn�sendr
�
print_wrapperrr
r�
HTTPException�socket�error�remove_archive)�fallback�force_fallback�srcr%�upload_name�errrrr�send_doctor_report-s8)
��
r�)F)F)Kr)r�r�r;rVr��kcarectlrrrrrrrr	r
Zkcarectl.process_utilsrZ
kcarectl.py23rr
r�Any�Callable�Dict�List�Optionalrfr~r�r�r�r�r�r�r�r�r�r��DataPackager�objectrr/r6r@rBrCrKrZrerg�cachedrlrprrr|rr�r�r�r�r�r�r�r�r�r�r�r$r��catch_errorsr�r�r�rrrr�<module>s�,







#��0


Youez - 2016 - github.com/yon3zu
LinuXploit