NineSec Team Shell
Server IP : 184.107.3.203  /  Your IP : 216.73.216.51
Web Server : Apache
System : Linux dedicated2.avenfashion.com.ph 4.18.0-553.40.1.el8_10.x86_64 #1 SMP Mon Feb 10 12:11:18 EST 2025 x86_64
User : adminteladeoro ( 1015)
PHP Version : 8.2.28
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /usr/lib/python3.6/site-packages/sos/upload/targets/__pycache__/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //usr/lib/python3.6/site-packages/sos/upload/targets/__pycache__/redhat.cpython-36.opt-1.pyc
3

��ZhX)�@s�ddlZddlZddlmZddlmZmZddlmZddl	m
Z
ddlmZ
yddlZdZWnek
rxdZYnXGd	d
�d
e�ZdS)�N)�UploadTarget)�
convert_bytes�TIMEOUT_DEFAULT)�DeviceAuthorizationClass)�
RHELPolicy)�_sosTFcs�eZdZdZdZdZdZd'�fdd�	ZdZd	Z	e	Z
d
ZdZdZ
dd
�Z�fdd�Zdd�Zdd�Zdd�Zdd�Zd(dd�Zdd�Zdd�Zdd �Zd)�fd!d"�	Zd#d$�Z�fd%d&�Z�ZS)*�RHELUploadTargetzVhttps://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/auth/devicezPhttps://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/tokenzRed Hat Upload TargetZredhatNcst�j|||d�dS)N)�parser�args�cmdline)�super�__init__)�selfr	r
r)�	__class__��/usr/lib/python3.6/redhat.pyr
!szRHELUploadTarget.__init__zhttps://api.access.redhat.comzsftp://sftp.access.redhat.com�posti@cCst|jdt�S)z.Return true if we are running in a RHEL system�policy)�
isinstance�commonsr)rrrr�check_distribution-sz#RHELUploadTarget.check_distributioncst�j|�|jdj|_dS)N�cmdlineopts)r�pre_workr�upload_directory)rZhook_commons)rrrr1szRHELUploadTarget.pre_workcCs@|jdjr|jjtd��|jdjs<|j|_|jjd�dS)NrzVThe option --upload-user has been deprecated in favour of device authorization in RHELz&No case id provided, uploading to SFTP)rZupload_user�ui_log�info�_�case_id�RH_SFTP_HOST�
upload_url)rrrr�prompt_for_upload_user7s
z'RHELUploadTarget.prompt_for_upload_usercCs |jdjr|jjtd��dS)NrzVThe option --upload-pass has been deprecated in favour of device authorization in RHEL)rZupload_passrrr)rrrr�prompt_for_upload_passwordBsz+RHELUploadTarget.prompt_for_upload_passwordcCs�d|jdj�d�}yj|jr"|jS|jdjr:|jdjS|jdjdkrP|jS|jdjr||jdj|jd�r||jSWn4tk
r�}z|jjd|���WYdd}~XnX|j	�|��S)Nz/support/v1/cases/rz/attachmentsZsftprz=There was a problem while setting the remote upload target:  )
rrrZupload_protocolrZprompt_for_case_id�	Exceptionrr�RH_API_HOST)rZrh_case_api�errr�get_upload_urlJs 

zRHELUploadTarget.get_upload_urlcCsd|j��}d|iS)NzBearer Z
Authorization)�
_device_token)rZstr_authrrr�_get_upload_https_auth`sz'RHELUploadTarget._get_upload_https_authTcCshd|jjd�d||j�fi}t|j|j�}|j�|_|jj	d|j
����tj|j
�||j�|td�S)z�If upload_https() needs to use requests.post(), use this method.

        Policies should override this method instead of the base upload_https()

        :param archive:     The open archive file object
        �file�/�z/Device authorized correctly. Uploading file to )�files�headers�verify�timeout���)�name�split�_get_upload_headersr�client_identifier_url�token_endpoint�get_access_tokenr&rr�get_upload_url_string�requestsrr%r'r)r�archiver-r+�RHELAuthrrr�_upload_https_postds
z#RHELUploadTarget._upload_https_postcCs|j�j|j�rddd�SiS)NZfalsezno-cache)Z	isPrivatez
cache-control)r%�
startswithr#)rrrrr2}s
z$RHELUploadTarget._get_upload_headerscCs4|j�j|j�rdS|j�j|j�r(dS|j|j�S)NzRed Hat Customer PortalzRed Hat Secure FTP)r%r;r#rZ_get_obfuscated_upload_urlr)rrrrr6�s
z&RHELUploadTarget.get_upload_url_stringcCsL|jjd�d}|jdjr2|jdj�d|��}|jrHtjj|j|�}|S)z�The RH SFTP server will only automatically connect file uploads to
        cases if the filename _starts_ with the case number
        r)r*rrr/)Zupload_archive_namer1rrr�os�path�join)rZfnamerrr�_get_sftp_upload_name�sz&RHELUploadTarget._get_sftp_upload_namec
s�|jjd�d|j�kr"t�j�Sts.td��d}d}|js�yt|j	|j
�}Wn:tk
r�}zdt|�krx|jj
d�WYdd}~XnX|j�|_|jr�|jj
d|j����|jd}d}|j�r8|j�}	tj||	d	d
�}|jdk�rtj|j�d}tj|j�d
}n*|jjd|j�d|j����|jjd�n~ddi}
tj|tj|
�d	d�}|jdk�r�tj|j�}|d}|d
}|jj
td|�d���n|jjd|j�d|j����|�r�|�r�t�j||d�Std��dS)z�Override the base upload_sftp to allow for setting an on-demand
        generated anonymous login for the RH SFTP server if a username and
        password are not given
        z//r*zPpython3-requests is not installed and is required for obtaining SFTP auth token.Nzend user deniedz:Device token authorization has been cancelled by the user.z/Device authorized correctly. Uploading file to z/support/v2/sftp/token�
)r,r.��Zusername�tokenz$DEBUG: auth attempt failed (status: z): zUUnable to retrieve Red Hat auth token using provided credentials. Will try anonymous.ZisAnonymousT)�datar.zUser z^ used for anonymous upload. Please inform your support engineer so they may retrieve the data.z)DEBUG: anonymous request failed (status: )�user�passwordz1Could not retrieve valid or anonymous credentials)rr1r%r�upload_sftp�REQUESTS_LOADEDr"r&rr3r4�strrrr5r6r#r'r7rZstatus_code�json�loads�text�debug�error�dumpsr)
rrDrEZ_tokenZ_userr9r$Zurl�retr,ZadataZanonZresp)rrrrF�sV


zRHELUploadTarget.upload_sftpcCs@tjj|�}||jkr<|jjtdt|j��d���|j|_	dS)NzLSize of archive is bigger than Red Hat Customer Portal limit for uploads of z  via sos http upload. 
)
r<r=�getsize�_max_size_requestrZwarningrrrr)rr8�sizerrr�check_file_too_big�s

z#RHELUploadTarget.check_file_too_bigcs�y*|j�j|j�r|j|�t�j|�}Wnhtk
r�}zLd}|jj|j�sP�|jj	t
d|�d|j����|j|_t�j|�}WYdd}~XnX|S)zOverride the base upload_archive to provide for automatic failover
        from RHCP failures to the public RH dropbox
        Fz0Upload to Red Hat Customer Portal failed due to z	. Trying N)r%r;r#rSr�upload_archiver"rrrMrr)rr8Zuploadedr$)rrrrT�s
zRHELUploadTarget.upload_archive)NNN)T)NN)�__name__�
__module__�__qualname__r3r4Zupload_target_nameZupload_target_idr
r#rZ_upload_urlZ_upload_methodr&rQrrr r!r%r'r:r2r6r?rFrSrT�
__classcell__rr)rrrs0

Kr)r<rIZsos.upload.targetsrZ
sos.utilitiesrrZsos.policies.authrZsos.policies.distros.redhatrZsosrrr7rG�ImportErrorrrrrr�<module>	s


NineSec Team - 2022