HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //usr/lib/python3.6/site-packages/supervisor/medusa/__pycache__/http_server.cpython-36.pyc
3

�k�`ss�@sjdZddlZddlZddlZddlZddlmZddljj	Z
ddljjZ
ddljjZddljjZddljjZej�dZddlmZyddlmZmZWn$ek
r�ddlmZmZYnXGdd�d�ZGd	d
�d
e
j�ZGdd�de
j �Z!d
d�Z"ej#dej$�Z%dd�Z&d(dd�Z'dd�Z(ej#d�Z)dd�Z*e+dk�rfe,ej-�dk�rbe.dej-d��nddl/jj0Z0ddl1jj2Z2ddl3jj4Z4ddl5jj6Z6ddl7jj8Z8ddl9jj:Z:e:j;d�Z<ej=ej>�Z?e0j@ddd�ZAe2jBej-d�ZCe4j4eC�ZDe!deEej-d�e<e?�ZFeFjGeD�e6j6e6jHej-d�d e<e?d!�ZIe8j8dd"�ZJd#ej-k�r^d$d%�ZKddlLZLeLjMd&d'�ne
jN�dS))z>$Id: http_server.py,v 1.12 2004/04/21 15:11:44 akuchling Exp $�N)�as_bytes�)�counter)�unquote�
splitqueryc&@sBeZdZdZe�ZdZdZdd�Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zdcdd�Zdd�Zdd�Zejd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zddd'd(�Zd)d*�ZeZd+d,�Zd-d.�Z d/d0�Z!d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdV�%Z"dWj#de�Z$dadb�Z%dS)f�http_request���NcGs^|\|_|_|_|_|_|_g|_dttj	t
j
��d�|_g|_t
jj�|_d|_i|_dS)Nz	Medusa/%s)ZServerZDate)�channel�request�command�uri�version�header�outgoing�VERSION_STRING�	http_dateZbuild_http_date�time�
reply_headers� _http_request__reply_header_listr�request_counter�	incrementZrequest_number�
_split_uri�
_header_cache)�self�args�r�!/usr/lib/python3.6/http_server.py�__init__9szhttp_request.__init__cCs||j|<dS)N)r)r�key�valuerrr�__setitem__Pszhttp_request.__setitem__cCs
|j|S)N)r)rrrrr�__getitem__Sszhttp_request.__getitem__cCs
||jkS)N)r)rrrrr�__contains__Vszhttp_request.__contains__cCs
||jkS)N)r)rrrrr�has_keyYszhttp_request.has_keycCs8dd�|jj�D�}dj|j|j�g|�d}t|�S)NcSsg|]}d|�qS)z%s: %sr)�.0�itemrrr�
<listcomp>]sz3http_request.build_reply_header.<locals>.<listcomp>z
z

)r�items�join�response�
reply_coder)rZheader_items�resultrrr�build_reply_header\szhttp_request.build_reply_headercCs|jj||f�dS)z$ Adds a header to the reply headers N)r�append)r�namer rrr�
add_headermszhttp_request.add_headercCs|jj�g|jdd�<dS)z Clears the reply header list N)r�clearr)rrrr�
clear_headersqs
zhttp_request.clear_headerscCs�d}||jkr0|dks$|j||kr0|j|=d}g}|dk	rZ||f|jkr�||fg}d}n*x(|jD]}|d|krb|j|�d}qbW|s�|dkr�d|}nd||f}td|��x|D]}|jj|�q�WdS)z� Removes the specified header.
        If a value is provided, the name and
        value must match to remove the header.
        If the value is None, removes all headers
        with that name.rNr	z%sz%s: %szHeader '%s' not found)rrr.�LookupError�remove)rr/r Zfound_itZremoved_headers�hZsearch_valuerrr�
remove_headerys,




zhttp_request.remove_headercCsX|jdd�}dd�|D�}x6|jj�D](\}}||kr(|j||f�|j|�q(W|S)zP Get the tuple of headers that will be used
        for generating reply headersNcSsg|]\}}|�qSrr)r%�n�vrrrr'�sz2http_request.get_reply_headers.<locals>.<listcomp>)rrr(r.)r�
header_tuplesZheader_namesr7r8rrr�get_reply_headers�szhttp_request.get_reply_headerscCs6|j�}|j|j�g}|dd�|D�7}dj|�dS)zE Gets the reply header (including status and
        additional crlf)cSsg|]}d|�qS)z%s: %sr)r%r5rrrr'�sz6http_request.get_reply_header_text.<locals>.<listcomp>z
z

)r:r*r+r))rr9�headersrrr�get_reply_header_text�sz"http_request.get_reply_header_textz#([^;?#]*)(;[^?#]*)?(\?[^#]*)?(#.*)?cCsD|jdkr>|jj|j�}|j�t|j�kr4td��n
|j�|_|jS)Nz
Broken URI)r�
path_regex�matchr
�end�len�
ValueError�groups)r�mrrr�	split_uri�s


zhttp_request.split_uricCs8x2|jD](}|j|�}|j�t|�kr|j|�SqWdS)N�)rr>r?r@�group)r�head_regrF�linerCrrr�get_header_with_regex�s

z"http_request.get_header_with_regexcCsz|j�}|j}||krn|d}t|�}x:|jD]0}|d|�j�|kr.||d�}|||<|Sq.Wd||<dS||SdS)Nz: )�lowerrr@r)rrZhcr5ZhlrH�rrrr�
get_header�szhttp_request.get_headercCs,|jr|jj|�n|jdt|�d�dS)Nz*Dropping %d bytes of incoming request data�warning)�	collector�collect_incoming_data�log_infor@)r�datarrrrO�s

z"http_request.collect_incoming_datacCs"|jr|jj�n|jdd�dS)Nz-Unexpected end-of-record for incoming requestrM)rN�found_terminatorrP)rrrrrRs
zhttp_request.found_terminatorcCs>t|t�rt|�}t|t�r.tj|t|�d�}|jj|�dS)N)�buffer_size)	�
isinstance�strr�bytes�	producers�simple_producerr@rr.)r�thingrrr�push	s


zhttp_request.pushcCs |j|}||_d|j||fS)Nz
HTTP/%s %d %s)�	responsesr+r)r�code�messagerrrr*s
zhttp_request.responsecCsR||_|j|}|j||d�}t|�}t|�|d<d|d<|j|�|j�dS)N)r\r]zContent-Lengthz	text/htmlzContent-Type)r+r[�DEFAULT_ERROR_MESSAGErr@rZ�done)rr\r]�srrr�errors


zhttp_request.errorcCs<tt|j�j�}d}d}|jdkrH|dkrBd|kr8d}qFd|d<q�d}nb|jdkr�|d	kr`d}q�d|kr�d
|kr�|d
dks�d}q�|jr�d|d
<d}q�d}n|jdkr�d}tj|j��}|r�d	|d<|r�tj	tj
|j��}tj
||g�}n|jjd|�tj
|j�}|j
jtjtj||j���d|j
_|�r8|j
j�dS)
z;finalize this transaction - send output to the http channelrz1.0z
keep-alivezContent-Lengthr	z
Keep-AliveZ
Connectionz1.1�closezTransfer-EncodingZchunkedN)rL�
CONNECTIONrrJr�use_chunkedrWrXr<Zchunked_producer�composite_producerr�insertr
Zpush_with_producerZglobbing_producerZhooked_producer�log�current_request�close_when_done)rZ
connectionZclose_itZwrap_in_chunkingZoutgoing_headerZoutgoing_producerrrrr_(sP	



zhttp_request.donec	Cs�tj|�}tjr |dr tj}ntj}|dkr4d}n
d}|}t|d�\}}t|d�\}}|rld||f}nd||f}tjd|�|S)	N�rr	i�<z	-%02d%02dz	+%02d%02dz%d/%b/%Y:%H:%M:%S )rZgmtimeZdaylightZaltzoneZtimezone�divmodZstrftime)	rZwhenZgmtZtz�negr5ZremrC�offsetrrr�log_date_stringts
zhttp_request.log_date_stringcCsB|jjjj|jjdd|jjd|jtj��|j|j|f�dS)Nrz%d - - [%s] "%s" %d %d
r	)	r
�server�loggerrg�addrrorrr+)rrVrrrrg�s


zhttp_request.logZContinuezSwitching ProtocolsZOKZCreatedZAcceptedzNon-Authoritative Informationz
No Contentz
Reset ContentzPartial ContentzMultiple ChoiceszMoved PermanentlyzMoved Temporarilyz	See OtherzNot Modifiedz	Use ProxyzBad RequestZUnauthorizedzPayment RequiredZ	Forbiddenz	Not FoundzMethod Not AllowedzNot AcceptablezProxy Authentication RequiredzRequest Time-outZConflictZGonezLength RequiredzPrecondition FailedzRequest Entity Too LargezRequest-URI Too LargezUnsupported Media TypezInternal Server ErrorzNot ImplementedzBad GatewayzService UnavailablezGateway Time-outzHTTP Version not supported)%�d�er������������i,i-i.i/i0i1i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�i�z
�<head>�<title>Error response</title>�</head>�<body>�<h1>Error response</h1>�<p>Error code %(code)d.�<p>Message: %(message)s.�</body>rEcCsdS)Nr)r�msg�levelrrrrP�szhttp_request.log_info)N)r)	r{r|r}r~rr�r�r�rE)&�__name__�
__module__�__qualname__r+rrrdrNrr!r"r#r$r-r0r2r6r:r<�re�compiler=rDrIrLrOrRrZr*raZ	reply_nowr_rorgr[r)r^rPrrrrr&s�	
(				
L
rc@s�eZdZdZdZe�Zdd�Zdd�ZdZ	d	d
�Z
dd�Zd Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)!�http_channelr	�NcCs`tjj�|_t�|_tjj||�||_	||_
|jd�d|_t
tj��|_|j|_|j�dS)Ns

�)r��channel_counterr�channel_numberrr�asynchat�
async_chatrrprrZset_terminator�	in_buffer�intrZ
creation_time�	last_used�check_maintenance)rrp�connrrrrrr�s
zhttp_channel.__init__cCs&tjj|�dd�}d||j|jfS)Nr	z<%s channel#: %s requests:%s>���)r�r��__repr__r�r)r�arrrrr��s
zhttp_channel.__repr__i�cCs|j|js|j�dS)N)r��maintenance_interval�maintenance)rrrrr��szhttp_channel.check_maintenancecCs|j�dS)N)�kill_zombies)rrrrr��szhttp_channel.maintenance�rkcCsLttj��}x:ttjj��D](}|j|jkr||j|jkr|j	�qWdS)N)
r�r�list�asyncoreZ
socket_map�values�	__class__r��zombie_timeoutrb)rZnowr
rrrr��s
zhttp_channel.kill_zombiescCs2tjj||�}|jjjt|��ttj��|_	|S)N)
r�r��sendrp�	bytes_outrr@r�rr�)rrQr,rrrr�szhttp_channel.sendcCsVy2tjj||�}|jjjt|��ttj��|_	|St
k
rPtjd�YnXdS)NzOut of Memory!)
r�r��recvrp�bytes_inrr@r�rr��MemoryError�sys�exit)rrSr,rrrr�szhttp_channel.recvcCs6tj�dd�\}}|tkr&||��ntjj|�dS)Nr)r��exc_info�
SystemExitr�r��handle_error)r�tr8rrrr�s
zhttp_channel.handle_errorcGsdS)Nr)rrrrrrg$szhttp_channel.logcCs$|jr|jj|�n|j||_dS)N)rhrOr�)rrQrrrrO+sz"http_channel.collect_incoming_datacCs�|jr|jj��n�|j}d|_|jd�}x|rH|drH|dd�}q,W|sZ|j�dS|d}t|�\}}}t|dd��}t|�\}}d|kr�|r�t|�d|}nt|�}t	||||||�}	|j
j�|jj
j�|dk�r|jdt|�d�|	jd	�dSx�|jjD]�}
|
j|	��ry|	|_|
j|	�Wnb|jjj�tj�\\}}}
}}}|jd
||||
fd�y|	jd�WnYnXYnXdS�qW|	jd�dS)
Nr�s
rr	�%�?zBad HTTP request: %srai�z'Server Error: %s, %s: file: %s line: %si�i�)rhrRr��splitri�
crack_request�join_headersrrrrrrp�total_requestsrP�reprra�handlersr>Zhandle_request�
exceptionsr�Zcompact_traceback)rr�linesrrr
rZrpathZrqueryrKr5�fileZfunrHr�r8ZtbinforrrrR3sT




zhttp_channel.found_terminatorcCs:|jr
dSt|j�r6|jj�}t|d�r2|j�SdSdS)Nr	�stalled)Z
ac_out_bufferr@Z
producer_fifo�first�hasattrr�)r�prrr�writable_for_proxyzs



zhttp_channel.writable_for_proxyii)r�r�r�Zac_out_buffer_sizerhrr�rr�r�r�r�r�r�r�r�r�rgrOrRr�rrrrr��s"	
Gr�c@sdeZdZdeZeZddd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zddd�Z
dd�Zdd�ZdS)�http_serverzHTTP Server (V%s)NcCsP||_||_tjj|�|jtjtj�g|_	|s>t
jtj
�}|j�|j||f�|jd�|jj�\}}|s�|jdd�tjtj��}ytj|�d|_Wn(tjk
r�|jdd�||_YnX||_t�|_t�|_t�|_t�|_t�|_|�st
jtj
�}|�rt
j||�|_
nt
j |�|_
|jdt!t"j#t"j"��|j|f�dS)NizComputing default hostnamerMrzCannot do reverse lookupz2Medusa (V%s) started at %s
	Hostname: %s
	Port:%d
)$�ip�portr��
dispatcherrZ
create_socket�socketZAF_INETZSOCK_STREAMr�rq�file_loggerr��stdoutZset_reuse_addrZbindZlistenZgetsocknamerPZ
gethostbynameZgethostnameZ
gethostbyaddr�server_nameraZserver_portr�
total_clientsr�r�r�r�Zresolving_loggerZunresolving_loggerrrZctime)rr�r��resolver�
logger_object�hostrrrr�sH
zhttp_server.__init__cCsdS)Nrr)rrrr�writable�szhttp_server.writablecCsdS)Nr)rrrr�handle_read�szhttp_server.handle_readcCs|jS)N)Z	accepting)rrrr�readable�szhttp_server.readablecCsdS)Nr)rrrr�handle_connect�szhttp_server.handle_connectcCsn|jj�y|j�\}}Wn@tjk
r<|jdd�dStk
rZ|jdd�dSX|j|||�dS)Nz+warning: server accept() threw an exceptionrMz*warning: server accept() threw EWOULDBLOCK)r�rZacceptr�rarP�	TypeError�
channel_class)rr�rrrrr�
handle_accept�s
zhttp_server.handle_acceptrcCs$|r|jj|�n|jjd|�dS)Nr)r�r.rf)r�handlerZbackrrr�install_handler�szhttp_server.install_handlercCs|jj|�dS)N)r�r4)rr�rrr�remove_handler�szhttp_server.remove_handlercs�ddlm��fdd�}dd�tt|j�D�}|jrN|jj�t|jj��}nd}t	j
t	jd|jd	|j
d
|jd|jd|jd
|d||jj��d||jj��d|jdg
�g|t	jd�g�S)Nr)�
english_bytescsdj�|��S)NrE)r))r7)r�rr�
nice_bytes�sz&http_server.status.<locals>.nice_bytescSsg|]}|r|�qSrr)r%Z_frrrr'�sz&http_server.status.<locals>.<listcomp>gz<h2>%s</h2>z!<br>Listening on: <b>Host:</b> %sz<b>Port:</b> %dz#<p><ul><li>Total <b>Clients:</b> %sz<b>Requests:</b> %sz<b>Requests/Client:</b> %.1fz<li>Total <b>Bytes In:</b> %sz<b>Bytes Out:</b> %sz<li>Total <b>Exceptions:</b> %sz!</ul><p><b>Extension List</b><ul>z</ul>)Zsupervisor.medusa.utilr��map�maybe_statusr�r�r�Zas_long�floatrWreZlines_producer�SERVER_IDENTr�r�r�r�r�rX)rr�Z
handler_statsZratior)r�r�status�szhttp_server.status)NN)r)r�r�r�rr�r�r�rr�r�r�r�r�r�r�r�rrrrr��s
6
r�cCst|d�r|j�SdSdS)Nr�)r�r�)rYrrrr�s
r�zConnection: (.*)cCsZg}xPtt|��D]@}||ddkrD|d||dd�|d<q|j||�qW|S)Nrz 	r	r�r�)�ranger@r.)r;rK�irrrr�sr�r	cCs:x4|D],}|j|�}|r|j�t|�kr|j|�SqWdS)NrE)r>r?r@rF)rGr�rFrHrCrrrrL$s


rLcCs4x.|D]&}|j|�}|r|j�t|�kr|SqWdS)NrE)r>r?r@)rGr�rHrCrrr�get_header_match+s


r�z%([^ ]+) ([^ ]+)(( HTTP/([0-9.]+))$|$)cCsVtj|�}|rN|j�t|�krN|jd�r4|jd�}nd}|jd�|jd�|fSdSdS)N��r	r)NNN)�REQUESTr>r?r@rF)rKrCrrrrr�4s

r��__main__zusage: %s <root> <port>z	127.0.0.1Zfnordi'rEiU)r�r�r�iaz-pcCs&ytj�Wntk
r YnXdS)N)r��loop�KeyboardInterruptrrrr�profile_loopXsr�zprofile_loop()zprofile.out)r	)OZRCS_IDr�r�r�rZsupervisor.compatrZsupervisor.medusa.asyncore_25ZmedusaZasyncore_25r�Zsupervisor.medusa.asynchat_25Zasynchat_25r�Zsupervisor.medusa.http_daterZsupervisor.medusa.producersrWZsupervisor.medusa.loggerrqr�rZsupervisor.medusa.counterrZurllibrr�ImportErrorZurllib.parserr�r�r�r�r�r��
IGNORECASErcr�rLr�r�r�r�r@�argv�printZsupervisor.medusa.monitorZmonitorZsupervisor.medusa.filesysZfilesysZ!supervisor.medusa.default_handlerZdefault_handlerZsupervisor.medusa.ftp_serverZ
ftp_serverZsupervisor.medusa.chat_serverZchat_serverZsupervisor.medusa.resolverr�Zcaching_resolverZrsr�r�ZlgZsecure_monitor_serverZmsZ
os_filesystemZfsZdhr�Zhsr�Zdummy_authorizerZftpZcsr�ZprofileZrunr�rrrr�<module>st/=