GOOD SHELL MAS BOY
Server: Apache/2.4.52 (Ubuntu)
System: Linux vmi1836763.contaboserver.net 5.15.0-130-generic #140-Ubuntu SMP Wed Dec 18 17:59:53 UTC 2024 x86_64
User: www-data (33)
PHP: 8.4.10
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/supervisor/__pycache__/http.cpython-310.pyc
o

|��]p{�@s�ddlZddlZddlZddlZddlZddlZddlZddlZzddlZWn
e	y3ddl
ZYnwddlmZddlm
Z
ddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZGd
d�d�ZGdd�d�ZGdd�d�ZGdd�d�ZGdd�d�ZGdd�dej�Z Gdd�dej!�Z"Gdd�dej�Z#Gdd�de#�Z$Gdd �d e#�Z%Gd!d"�d"�Z&Gd#d$�d$�Z'Gd%d&�d&�Z(d'd(�Z)Gd)d*�d*�Z*Gd+d,�d,�Z+Gd-d.�d.e�Z,dS)/�N)�urllib)�sha1)�as_bytes)�	as_string)�asyncore_25)�	http_date)�http_server)�	producers)�filesys)�default_handler)�auth_handlerc@seZdZdS)�NOT_DONE_YETN)�__name__�
__module__�__qualname__�rr�1/usr/lib/python3/dist-packages/supervisor/http.pyr
sr
c@s"eZdZdZddd�Zdd�ZdS)�deferring_chunked_producera'A producer that implements the 'chunked' transfer coding for HTTP/1.1.
    Here is a sample usage:
            request['Transfer-Encoding'] = 'chunked'
            request.push (
                    producers.chunked_producer (your_producer)
                    )
            request.done()
    NcCs||_||_d|_dS�N皙�����?)�producer�footers�delay)�selfrrrrr�__init__)s
z#deferring_chunked_producer.__init__cCsj|jr3|j��}|turtS|r dt|�}t|�d|dSd|_|jr1d�dg|j�dSdSdS)Nz%xs
�0s

s0

�)r�morer
�lenrr�join)r�data�srrrr.s
zdeferring_chunked_producer.more�N�rrr�__doc__rrrrrrrs
	rc@� eZdZdZdd�Zdd�ZdS)�deferring_composite_producerz$combine a fifo of producers into onecCs||_d|_dSr)r	r)rr	rrrrAs
z%deferring_composite_producer.__init__cCsJt|j�r#|jd}|��}|turtS|r|S|j�d�t|j�sdS)Nrr)rr	rr
�pop)r�p�drrrrEs


�
z!deferring_composite_producer.moreNr#rrrrr&?sr&c@s"eZdZdZddd�Zdd�ZdS)	�deferring_globbing_producerz�
    'glob' the output from a producer into a particular buffer size.
    helps reduce the number of calls to send().  [this appears to
    gain about 30% performance on requests to a single channel]
    �cCs||_d|_||_d|_dS)Nrr)r�buffer�buffer_sizer)rrr-rrrrZ�
z$deferring_globbing_producer.__init__cCs�t|j�|jkr:|j��}|turtS|r1z|j||_Wnty0t|j�t|�|_Ynwnt|j�|jks|j}d|_|S�Nr)rr,r-rrr
�	TypeErrorr)rr �rrrrr`s
��z deferring_globbing_producer.moreN)r+r#rrrrr*Ss
r*c@r%)�deferring_hooked_producerz�
    A producer that will call <function> when it empties,.
    with an argument of the number of bytes produced.  Useful
    for logging/instrumentation purposes.
    cCs||_||_d|_d|_dS)Nrr)r�function�bytesr)rrr3rrrrxr.z"deferring_hooked_producer.__init__cCsP|jr&|j��}|turtS|sd|_|�|j�|S|jt|�7_|SdSr/)rrr
r3r4r)r�resultrrrr~s
�zdeferring_hooked_producer.moreNr#rrrrr2qsr2c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�deferring_http_requesta The medusa http_request class uses the default set of producers in
    medusa.producers.  We can't use these because they don't know anything
    about deferred responses, so we override various methods here.  This was
    added to support tail -f like behavior on the logtail handler c	OsNt�tj|j�}|��}d}d}d}|jdkr*|dkr'd|vr"d}n;d|d<n6d}n3|jdkrV|d	kr6d}n'd|vrUd
|vrG|d
dksFd}n|jrSd|d
<d}d}n
d}n|jdur]d}t�|�	��}|rjd	|d<|rzt
t|j��}t||g�}n|j�
d|�t|j�}t||j�}|r�t|�}|j�|�d|j_|r�|j��dSdS)
z� I didn't want to override this, but there's no way around
        it in order to support deferreds - CM

        finalize this transaction - send output to the http channelr�z1.0z
keep-alivezContent-Lengthz
Keep-Alive�
Connectionz1.1�closezTransfer-Encoding�chunkedN)r�
get_header�
CONNECTION�header�lower�version�use_chunkedr	�simple_producer�build_reply_headerrr&�outgoing�insertr2�logr*�channel�push_with_producer�current_request�close_when_done)	r�arg�kw�
connection�close_it�wrap_in_chunking�globbing�outgoing_header�outgoing_producerrrr�done�sb



��
��
��zdeferring_http_request.donec	Cs\|jjr|jjd}|jjd}nd}d}|jjj�|d||�t���|j|j|f�dS)z� We need to override this because UNIX domain sockets return
        an empty string for the addr rather than a (host, port) combination rr7�	localhostz%d - - [%s] "%s" %d %d
N)	rF�addr�server�loggerrE�log_date_string�time�request�
reply_code)rr4�host�portrrrrE�s
��zdeferring_http_request.logcCs�i}dddd�}t��}|��\}}}}|r||}|r0|ddkr0|dd�}|r0|ddks"d|vr9t�|�}|rA|dd�}|jj}|j��|d	<t	|j
�|d
<|j|d<|j|d<d
|j
|d<|jj|d<d|d<d||d<tj�tj�||d��|d<|r�||d<d|d<|jjr�|jjd|d<nd|d<|jD]6}	|	�dd�\}
}|
��}
|��}|
|vr�|r�|||�|
�<q�dd�|
�d����}
|r�|
|vr�|||
<q�|S)N�CONTENT_LENGTH�CONTENT_TYPE�CONNECTION_TYPE)zcontent-lengthzcontent-typerLr�/r7�%�REQUEST_METHOD�SERVER_PORT�SERVER_NAME�SERVER_SOFTWAREzHTTP/�SERVER_PROTOCOLzchannel.creation_time��SCRIPT_NAME�	PATH_INFO�PATH_TRANSLATED�QUERY_STRINGzCGI/1.1�GATEWAY_INTERFACE�REMOTE_ADDRz	127.0.0.1�:zHTTP_%s�_�-)�os�getcwd�	split_urir�unquoterFrU�command�upper�strr\�server_name�SERVER_IDENTr?�
creation_time�path�normpathrrTr=�splitr>�strip�get)r�env�
header2env�workdirr{�params�query�fragmentrUr=�key�valuerrr�cgi_environment�sZ��



�
�z&deferring_http_request.cgi_environmentcCs�ddd�}|��}|�d�dvs|�d�dkrd}nd	}d
|vr.|d
��}t�|�\}}n
|d��}|d}|d
usB|||krE|}n|d|}d||f}|dd
�dkr_|d
d�}|S)z� Functionality that medusa's http request doesn't have; set an
        attribute named 'server_url' on the request based on the Host: header
        �80�443)�http�https�HTTPS)�on�ON�SERVER_PORT_SECURE�1r�r��	HTTP_HOSTrdrcNrnz%s://%s���r`)r�rr~r�	splitport)r�default_port�environ�protocolr[�hostnamer\�
server_urlrrr�get_server_url/s$
z%deferring_http_request.get_server_urlN)rrrr$rRrEr�r�rrrrr6�sS5r6c@s2eZdZdZdZdZd
dd�Zdd�Zdd	�ZdS)�deferring_http_channelirNcCsL|durt��}|jr ||j}||jks|dkr||_dSdStj�|�S)NrTF)rXr�last_writable_checkr�http_channel�writable)r�now�elapsedrrrr�Us
zdeferring_http_channel.writablecCs�	t|j�rQ|j��}|dur|js|j��|��dSt|t�r0|j��|j|7_dS|��}|t	ur>|j
|_
dS|rK|j||_d|_
dS|j��ndSq)z Implement deferreds r7NF)r�
producer_fifo�first�
ac_out_bufferr'r9�
isinstancer4rr
r)rr(r rrr�
refill_bufferds.




�z$deferring_http_channel.refill_buffercCs�|jr
|j��dSt|j�}d|_|�d�}|r)|ds)|dd�}|r)|dr|s1|��dS|d}t�|�\}}}t�|dd��}t�	|�\}}d|vrb|r]t�
|�d|}nt�
|�}t||||||�}	|j�
�|jj�
�|dur�|�dt|�d	�|	�d
�dS|jjD]H}
|
�|	�r�z|	|_|
�|	�WdS|jj�
�t��\\}}}
}}}|j�d||||
fd	�z
|	�d�WYdSYYdSq�|	�d
�dS)z� We only override this to use 'deferring_http_request' class
        instead of the normal http_request class; it sucks to need to override
        this rz
rr7Nra�?zBad HTTP request: %s�error�z'Server Error: %s, %s: file: %s line: %si��)rH�found_terminatorr�	in_bufferr}rIr�
crack_request�join_headers�
splitqueryrtr6�request_counter�	incrementrU�total_requests�log_info�reprr��handlers�match�handle_request�
exceptions�asyncore�compact_traceback)rr=�linesrYru�urir?�rpath�rqueryr1�h�file�fun�line�t�v�tbinforrrr��sh

�
�



��
����z'deferring_http_channel.found_terminatorr")	rrr�ac_out_buffer_sizerr�r�r�r�rrrrr�Ls
 r�c@s.eZdZeZdZdd�Zdd�Zd	dd�ZdS)
�supervisor_http_serverNcCs^ddlm}|s|�tj�}|�|�}||_tj�|�|�	|�g|_
|�d�|��dS)zj Override __init__ to do logger setup earlier so it can
        go to our logger object instead of stdout r�rVN)
�supervisor.medusarV�file_logger�sys�stdout�unresolving_loggerr��
dispatcherr�
set_socketr��setblocking�set_reuse_addr)r�sock�
logger_objectrVrrr�prebind�s


zsupervisor_http_server.prebindcCsrddlm}ddlm}|�d�|�|_|�|_|�|_|�|_|�|_	|�
d|t�t���|j
|jf�dS)Nr)�counter)�VERSION_STRING�z2Medusa (V%s) started at %s
	Hostname: %s
	Port:%s
)�supervisor.medusa.counterr��supervisor.medusa.http_serverr��listen�
total_clientsr�r��	bytes_out�bytes_inr�rX�ctimerxr\)rr�r�rrr�postbind�s"
���zsupervisor_http_server.postbind�infocCs,d}t|dd�dur
|j}|j�||�dS)Nrg�ip)�getattrr�rVrE)r�message�typer�rrrr�szsupervisor_http_server.log_info)r�)	rrrr��
channel_classr�r�r�r�rrrrr��sr�c@seZdZdZdd�ZdS)�supervisor_af_inet_http_serverz+ AF_INET version of supervisor HTTP server cCs�||_||_t�tjtj�}|�||�|�||f�|s=|�dd�t��}zt�	|�}Wntj
y<td|��wz
t�|�d|_
Wntj
yZ|�dd�||_
Ynw|��dS)NzComputing default hostname�warningz�Could not determine IP address for hostname %s, please try setting an explicit IP address in the "port" setting of your [inet_http_server] section.  For example, instead of "port = 9001", try "port = 127.0.0.1:9001."rzCannot do reverse lookup)r�r\�socket�AF_INET�SOCK_STREAMr��bindr��gethostname�
gethostbynamer��
ValueError�
gethostbyaddrrxr�)rr�r\r�r�r�rrrrs0���
�z'supervisor_af_inet_http_server.__init__N)rrrr$rrrrrr�	sr�c@r%)�supervisor_af_unix_http_serverz+ AF_UNIX version of supervisor HTTP server c
Cs�||_||_d|t��f}zt�|�Wn	tyYnw	t�tjtj�}z�|�	|�t�
||�zt�||�WnFty�|�|�}|rPt�
tj��d|}tj�|�zt�|�WnY|��t�d�YWzt�|�Wqty�Yqwwz
t�||d|d�Wn)ty�}	z|	jdtjkr�d}t||t|�t�t���df���d}	~	ww|�||�Wzt�|�Wnty�Ynwzt�|�Wwty�Ywwd|_|� �dS)Nz%s.%dr7zUnlinking stale socket %s
g333333�?rz�Not permitted to chown %s to uid/gid %s; adjust "sockchown" value in config file or on command line to values that the current user (%s) can successfully chownz<unix domain socket>)!r�r\rq�getpid�unlink�OSErrorr��AF_UNIXr�r��chmod�link�	checkusedr��errno�
EADDRINUSEr��stderr�writer9rX�sleep�chown�args�EPERMr�r��pwd�getpwuid�geteuidr�rxr�)
r�
socketname�	sockchmod�	sockchownr��tempnamer��used�msg�whyrrrr*s��


����������z'supervisor_af_unix_http_server.__init__cCsXt�tjtj�}z|�|�|�td��|�d�|��WdStjy+YdSw)NzGET / HTTP/1.0

r7FT)	r�r�r��connect�sendr�recvr9r�)rrr!rrrr�qs


��z(supervisor_af_unix_http_server.checkusedN)rrrr$rr�rrrrr�'sGr�c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�tail_f_producercCsBt�|�|_||_d|_|��|��}||kr|||_dSdSr)�weakref�refrY�filenamer�_open�_fsize�sz)rrYr�headrrrrr~s�ztail_f_producer.__init__cCs|��dSr")�_close�rrrr�__del__�sztail_f_producer.__del__c	Cs||��z|��}WnttfyYdSw||j}|dkr%d|_dS|dkr<|j�|d�|j�|�}||_|StS)Nrrz==> File truncated <==
�)	�_followrr�r�rr��seek�readr
)r�newsz�bytes_addedr4rrrr�s �
ztail_f_producer.morecCs0t|jd�|_t�|j���tj|_d|_	dS)N�rbr)
�openrr�rq�fstat�fileno�stat�ST_INO�inorrrrrr�s
ztail_f_producer._opencCs|j��dSr")r�r9rrrrr��ztail_f_producer._closec	CsRzt�|j�tj}WnttfyYdSw|j|kr'|��|��dSdSr")	rqr!rr"r�r�r#rr)rr#rrrr�s�
�ztail_f_producer._followcCst�|j���tjSr")rqrr�r r!�ST_SIZErrrrr�sztail_f_producer._fsizeN)
rrrrrrrrrrrrrrr}s
rc@�,eZdZdZdZdd�Zdd�Zdd�Zd	S)
�logtail_handlerzLogtail HTTP Request Handlerz/logtailcC�
||_dSr"��supervisord�rr*rrrr��
zlogtail_handler.__init__cC�|j�|j�Sr"�r��
startswithr{�rrYrrrr��r$zlogtail_handler.matchcCs�|jdkr|�d�dS|��\}}}}d|vrt�|�}|r3|ddkr3|dd�}|r3|ddks%|�dd�\}}z
|�dd�\}}Wn
tyR|}d}Ynwddlm}	|	|�\}
}|j	j
�|
�}|durq|�d	�dS|j�|�}|dur�|�d	�dSt
|jd
|d�}
|
dus�tj�|
�s�|�d�dSt�|
�tj}t�|�|d<d
|d<d|d<|�t||
d��|��dS)N�GETr�rarr`r7r�)�split_namespecr�z
%s_logfile��
Last-Modified�text/plain;charset=utf-8�Content-Type�nozX-Accel-Bufferingr�)rur�rsrrtr}r��supervisor.optionsr2r*�process_groupsr�	processesr��configrqr{�existsr!�ST_MTIMEr�build_http_date�pushrrR)rrYr{r�r�r��process_name_and_channel�process_namerFr2�
group_name�group�process�logfile�mtimerrrr��sH


��


zlogtail_handler.handle_requestN�rrr�IDENTr{rr�r�rrrrr'��r'c@r&)
�mainlogtail_handlerz!Main Logtail HTTP Request Handlerz/mainlogtailcCr(r"r)r+rrrr�r,zmainlogtail_handler.__init__cCr-r"r.r0rrrr��r$zmainlogtail_handler.matchcCs�|jdkr|�d�dS|jjj}|dustj�|�s"|�d�dSt�|�tj	}t
�|�|d<d|d<|�t
||d��|��dS)Nr1r�r3r4r5r6r�)rur�r*�optionsrErqr{r<r!r=rr>r?rrR)rrYrErFrrrr�s



z"mainlogtail_handler.handle_requestNrGrrrrrJ�rIrJc Cs6g}t|j�}|jD�]
}|d}|tjkr'|d|d}}t|||d�}n |tjkrA|d}	|d}
|d}t|	|
||d�}ntd|��d	d
l	m
}d	dl	m}
d	dlm
}g}|jD]2\}}}z
||fi|��}Wnt��}|j�|�td
|��|�||f�|j�d|�q^|�d|
|�f�|||�}t|�}t|�}||�}tj�tj�t��}tj�|d�}t�|�}t�|�}|d}|d}|r�||i}t||�}t||�}t||�}t||�}t||�}n
|j� d|d�|�!|�|�!|�|�!|�|�!|�|�!|�|�||f�q
|S)N�familyr[r\)r�r�r�r�zCannot determine socket type %rr)�supervisor_xmlrpc_handler)�SystemNamespaceRPCInterface)�supervisor_ui_handlerzCould not make %s rpc interfacezRPC interface %r initialized�system�ui�username�passwordz:Server %r running without any HTTP authentication checking�section)"�
LogWrapperrV�server_configsr�r�r�r�r�r��supervisor.xmlrpcrMrN�supervisor.webrO�rpcinterface_factories�	traceback�
format_exc�warn�appendr�r'rJrqr{�abspath�dirname�__file__rr
�
os_filesystemr�supervisor_auth_handler�critical�install_handler) rKr*�servers�wrapperr;rLr[r\�hsrrrrMrNrO�
subinterfaces�name�factoryr)�inst�tb�
xmlrpchandler�tailhandler�maintailhandler�	uihandler�here�templatedir�
filesystem�defaulthandlerrRrS�usersrrr�make_http_serverss|

�
��






��




rvc@r%)rUz\Receives log messages from the Medusa servers and forwards
    them to the Supervisor loggercCr(r"r�)rrVrrrrbr,zLogWrapper.__init__cCsB|�d�r|dd�}d|��vr|j�|�dS|j�|�dS)z�Medusa servers call this method.  There is no log level so
        we have to sniff the message.  We want "Server Error" messages
        from medusa.http_server logged as errors at least.�
Nr�r�)�endswithr>rVr��trace)rrrrrrEes

zLogWrapper.logN)rrrr$rrErrrrrU_srUc@seZdZdd�Zdd�ZdS)�encrypted_dictionary_authorizercCr(r")�dict)rr{rrrrqr,z(encrypted_dictionary_authorizer.__init__cCsR|\}}||jvr'|j|}|�d�r#tt|����}|dd�|kS||kSdS)Nz{SHA}�F)r{r/rr�	hexdigest)r�	auth_inforRrS�stored_password�
password_hashrrr�	authorizets


z)encrypted_dictionary_authorizer.authorizeN)rrrrr�rrrrrzpsrzc@seZdZddd�ZdS)rb�defaultcCst�||||�t|�|_dSr")rrrz�
authorizer)rr{�handler�realmrrrr�sz supervisor_auth_handler.__init__N)r�)rrrrrrrrrb�srb)-rqr!rXr�r�r�r
rZr��ImportError�getpass�supervisor.compatrrrrr�rr�rrr	r
r�supervisor.medusa.auth_handlerrr
rr&r*r2�http_requestr6r�r�r�r�r�rr'rJrvrUrzrbrrrr�<module>sV� @	5V6DI