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: //proc/self/root/usr/lib/python3.6/site-packages/supervisor/__pycache__/http.cpython-36.pyc
3

�k�`p{�@s�ddlZddlZddlZddlZddlZddlZddlZddlZyddlZWne	k
rhddl
ZYnXddlm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�/usr/lib/python3.6/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)Ng�������?)�producer�footers�delay)�selfrrrrr�__init__)sz#deferring_chunked_producer.__init__cCsp|jrh|jj�}|tkrtS|r@dt|�}t|�d|dSd|_|jrbdjdg|j�dSdSndSdS)Nz%xs
�0s

s0

�)r�morer
�lenrr�join)r�data�srrrr.s
zdeferring_chunked_producer.more)N)rrr�__doc__rrrrrrrs
rc@s eZdZdZdd�Zdd�ZdS)�deferring_composite_producerz$combine a fifo of producers into onecCs||_d|_dS)Ng�������?)r	r)rr	rrrrAsz%deferring_composite_producer.__init__cCsJxDt|j�r@|jd}|j�}|tkr*tS|r2|S|jjd�qWdSdS)Nrr)rr	rr
�pop)r�p�drrrrEs
z!deferring_composite_producer.moreN)rrrr rrrrrrr!?sr!c@s"eZdZdZd
dd�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)Nrg�������?)r�buffer�buffer_sizer)rrr)rrrrZsz$deferring_globbing_producer.__init__cCs~xlt|j�|jkrl|jj�}|tkr(tS|rhy|j||_Wqjtk
rdt|j�t|�|_YqjXqPqW|j}d|_|S)Nr)rr(r)rrr
�	TypeErrorr)rr�rrrrr`s
z deferring_globbing_producer.moreN�)r,)rrrr rrrrrrr%Ss
r%c@s eZdZdZdd�Zdd�ZdS)�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)Nrg�������?)r�function�bytesr)rrr.rrrrxsz"deferring_hooked_producer.__init__cCsR|jrJ|jj�}|tkrtS|s4d|_|j|j�n|jt|�7_|SdSdS)Nr)rrr
r.r/r)r�resultrrrr~s
zdeferring_hooked_producer.moreN)rrrr rrrrrrr-qsr-c@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	OsNtjtj|j�}|j�}d}d}d}|jdkrT|dkrNd|krDd}qRd|d<q�d}nf|jdkr�|d	krld}q�d|kr�d
|kr�|d
dks�d}q�|jr�d|d
<d}d}q�d}n|jdkr�d}tj|j	��}|r�d	|d<|r�t
t|j��}t||g�}n|jj
d|�t|j�}t||j�}|�r&t|�}|jj|�d|j_|�rJ|jj�d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 channelrr&z1.0z
keep-alivezContent-Lengthz
Keep-AliveZ
Connectionz1.1�closezTransfer-EncodingZchunkedN)rZ
get_headerZ
CONNECTION�header�lower�versionZuse_chunkedr	Zsimple_producerZbuild_reply_headerrr!Zoutgoing�insertr-�logr%�channelZpush_with_producer�current_request�close_when_done)	r�arg�kw�
connectionZclose_itZwrap_in_chunkingZglobbingZoutgoing_headerZoutgoing_producerrrr�done�sV





zdeferring_http_request.donecCs\|jjr"|jjd}|jjd}nd}d}|jjjj|d||jtj��|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 rr&Z	localhostz%d - - [%s] "%s" %d %d
N)	r8�addr�server�loggerr7Zlog_date_string�time�requestZ
reply_code)rr/�host�portrrrr7�s
zdeferring_http_request.logcCs�i}dddd�}tj�}|j�\}}}}|r4||}x |rT|ddkrT|dd�}q6Wd|krhtj|�}|rx|dd�}|jj}|jj�|d	<t	|j
�|d
<|j|d<|j|d<d
|j
|d<|jj|d<d|d<d||d<tjjtjj||d��|d<|�r
||d<d|d<|jj�r.|jjd|d<nd|d<x�|jD]v}	|	jdd�\}
}|
j�}
|j�}|
|k�r�|�r�|||j|
�<n0ddj|
jd��j�}
|�r>|
|k�r>|||
<�q>W|S)NZCONTENT_LENGTHZCONTENT_TYPEZCONNECTION_TYPE)zcontent-lengthzcontent-typer=r�/r&�%ZREQUEST_METHOD�SERVER_PORT�SERVER_NAMEZSERVER_SOFTWAREzHTTP/ZSERVER_PROTOCOLzchannel.creation_time�ZSCRIPT_NAMEZ	PATH_INFOZPATH_TRANSLATEDZQUERY_STRINGzCGI/1.1ZGATEWAY_INTERFACEZREMOTE_ADDRz	127.0.0.1�:zHTTP_%s�_�-)�os�getcwd�	split_urir�unquoter8r@�command�upper�strrE�server_nameZSERVER_IDENTr5Z
creation_time�path�normpathrr?r3�splitr4�strip�get)r�envZ
header2envZworkdirrV�params�query�fragmentr@r3�key�valuerrr�cgi_environment�sR



z&deferring_http_request.cgi_environmentcCs�ddd�}|j�}|jd�dks.|jd�dkr4d	}nd
}d|kr\|dj�}tj|�\}}n|dj�}|d
}|dks�|||kr�|}n|d|}d||f}|dd�dkr�|dd�}|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
        Z80Z443)�http�httpsZHTTPS�on�ONZSERVER_PORT_SECURE�1rcrbZ	HTTP_HOSTrIrHNrKz%s://%sr&rF)rdre���rg)rarZrYrZ	splitport)rZdefault_port�environZprotocolrD�hostnamerEZ
server_urlrrr�get_server_url/s$
z%deferring_http_request.get_server_urlN)rrrr r>r7rarjrrrrr1�s
S5r1c@s2eZdZdZdZdZd
dd�Zdd�Zdd	�ZdS)�deferring_http_channelirNcCsL|dkrtj�}|jr@||j}||jks2|dkr<||_dSdStjj|�S)NrTF)rBr�last_writable_checkr�http_channel�writable)rZnow�elapsedrrrrnUs
zdeferring_http_channel.writablecCs�x�t|j�r�|jj�}|dkr:|js6|jj�|j�dSt|t�r`|jj�|j|7_dS|j�}|t	kr||j
|_
dS|r�|j||_d|_
dS|jj�qdSqWdS)z Implement deferreds NF)rZ
producer_fifo�firstZ
ac_out_bufferr"r2�
isinstancer/rr
r)rr#rrrr�
refill_bufferds,




z$deferring_http_channel.refill_buffercCs�|jr|jj��n�t|j�}d|_|jd�}x|rL|drL|dd�}q0W|s^|j�dS|d}tj|�\}}}tj|dd��}tj	|�\}}d|kr�|r�tj
|�d|}n
tj
|�}t||||||�}	|jj
�|jjj
�|dk�r|jdt|�d	�|	jd
�dSx�|jjD]�}
|
j|	��ry|	|_|
j|	�Wnd|jjj
�tj�\\}}}
}}}|jjd||||
fd	�y|	jd�WnYnXYnXdS�qW|	jd
�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
rr&NrG�?zBad HTTP request: %s�errori�z'Server Error: %s, %s: file: %s line: %si�i�)r9�found_terminatorrZ	in_bufferrXr:rZ
crack_requestZjoin_headersZ
splitqueryrQr1Zrequest_counterZ	incrementr@�total_requests�log_info�reprrt�handlers�match�handle_request�
exceptions�asyncoreZcompact_traceback)rr3�linesrCrR�urir5ZrpathZrqueryr+�h�fileZfun�line�t�vZtbinforrrru�sX






z'deferring_http_channel.found_terminator)N)	rrrZac_out_buffer_sizerrlrnrrrurrrrrkLs
 rkc@s.eZdZeZdZdd�Zdd�Zd	dd�ZdS)
�supervisor_http_serverNcCs^ddlm}|s|jtj�}|j|�}||_tjj|�|j	|�g|_
|jd�|j�dS)zj Override __init__ to do logger setup earlier so it can
        go to our logger object instead of stdout r)rAN)
�supervisor.medusarAZfile_logger�sys�stdoutZunresolving_loggerr}Z
dispatcherrZ
set_socketryZsetblockingZset_reuse_addr)r�sock�
logger_objectrArrr�prebind�s


zsupervisor_http_server.prebindcCsrddlm}ddlm}|jd�|�|_|�|_|�|_|�|_|�|_	|j
d|tjtj��|j
|jf�dS)Nr)�counter)�VERSION_STRINGiz2Medusa (V%s) started at %s
	Hostname: %s
	Port:%s
)Zsupervisor.medusa.counterr�Zsupervisor.medusa.http_serverr�ZlistenZ
total_clientsrvr|Z	bytes_outZbytes_inrwrBZctimerUrE)rr�r�rrr�postbind�s
zsupervisor_http_server.postbind�infocCs,d}t|dd�dk	r|j}|jj||�dS)NrJ�ip)�getattrr�rAr7)r�message�typer�rrrrwszsupervisor_http_server.log_info)r�)	rrrrkZ
channel_classr�r�r�rwrrrrr��s
r�c@seZdZdZdd�ZdS)�supervisor_af_inet_http_serverz+ AF_INET version of supervisor HTTP server cCs�||_||_tjtjtj�}|j||�|j||f�|s�|jdd�tj�}ytj	|�}Wn"tj
k
r~td|��YnXytj|�d|_
Wn(tj
k
r�|jdd�||_
YnX|j�dS)NzComputing default hostnameZwarningz�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�rE�socket�AF_INET�SOCK_STREAMr��bindrwZgethostnameZ
gethostbynamert�
ValueErrorZ
gethostbyaddrrUr�)rr�rEr�r�rirrrrs(z'supervisor_af_inet_http_server.__init__N)rrrr rrrrrr�	sr�c@s eZdZdZdd�Zdd�ZdS)�supervisor_af_unix_http_serverz+ AF_UNIX version of supervisor HTTP server c
0Cs�||_||_d|tj�f}ytj|�Wntk
r>YnX�xjtjtjtj�}�z*|j	|�tj
||�ytj||�Wnrtk
r�|j|�}|r�tj
tj��d|}tjj|�ytj|�WnYnX|j�tjd�wDYn�Xytj||d|d�Wnbtk
�rn}	zD|	jdtjk�r\d}t||t|�tjtj��df��n�WYdd}	~	XnX|j||�PWdytj|�Wntk
�r�YnXXqDWd|_|j �dS)Nz%s.%dzUnlinking stale socket %s
g333333�?rr&z�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�rErN�getpid�unlink�OSErrorr��AF_UNIXr�r��chmod�link�	checkusedrt�errnoZ
EADDRINUSEr��stderr�writer2rBZsleep�chown�argsZEPERMr�rx�pwd�getpwuid�geteuidr�rUr�)
r�
socketname�	sockchmod�	sockchownr�Ztempnamer�Zused�msgZwhyrrrr*sZ


z'supervisor_af_unix_http_server.__init__cCs^tjtjtj�}y.|j|�|jtd��|jd�|j�Wntjk
rTdSXdSdS)NzGET / HTTP/1.0

r&FT)	r�r�r�Zconnect�sendrZrecvr2rt)rr�rrrrr�qs

z(supervisor_af_unix_http_server.checkusedN)rrrr rr�rrrrr�'sGr�c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�tail_f_producercCs>tj|�|_||_d|_|j�|j�}||kr:|||_dS)Ng�������?)�weakref�refrC�filenamer�_open�_fsize�sz)rrCr��headr�rrrr~sztail_f_producer.__init__cCs|j�dS)N)�_close)rrrr�__del__�sztail_f_producer.__del__cCs||j�y|j�}Wnttfk
r,dSX||j}|dkrJd|_dS|dkrx|jj|d�|jj|�}||_|StS)Nrrz==> File truncated <==
�)	�_followr�r�r�r�r��seek�readr
)rZnewszZbytes_addedr/rrrr�s
ztail_f_producer.morecCs0t|jd�|_tj|jj��tj|_d|_	dS)N�rbr)
�openr�r�rN�fstat�fileno�stat�ST_INO�inor�)rrrrr��sztail_f_producer._opencCs|jj�dS)N)r�r2)rrrrr��sztail_f_producer._closecCsNytj|j�tj}Wnttfk
r.dSX|j|krJ|j�|j�dS)N)	rNr�r�r�r�r�r�r�r�)rr�rrrr��s
ztail_f_producer._followcCstj|jj��tjS)N)rNr�r�r�r��ST_SIZE)rrrrr��sztail_f_producer._fsizeN)
rrrrr�rr�r�r�r�rrrrr�}s
r�c@s,eZdZdZdZdd�Zdd�Zdd�Zd	S)
�logtail_handlerzLogtail HTTP Request Handlerz/logtailcCs
||_dS)N)�supervisord)rr�rrrr�szlogtail_handler.__init__cCs|jj|j�S)N)r�
startswithrV)rrCrrrrz�szlogtail_handler.matchc
Cs�|jdkr|jd�dS|j�\}}}}d|kr:tj|�}x |rZ|ddkrZ|dd�}q<W|jdd�\}}y|jdd�\}}Wntk
r�|}d}YnXddlm}	|	|�\}
}|j	j
j|
�}|dkr�|jd	�dS|jj|�}|dkr�|jd	�dSt
|jd
|d�}
|
dk�s(tjj|
��r6|jd�dStj|
�tj}tj|�|d<d
|d<d|d<|jt||
d��|j�dS)N�GETi�rGrrFr&r�)�split_namespeci�z
%s_logfilei�z
Last-Modifiedztext/plain;charset=utf-8zContent-Type�nozX-Accel-Bufferingi)rRrtrPrrQrXr�Zsupervisor.optionsr�r�Zprocess_groupsrZZ	processesr��configrNrV�existsr��ST_MTIMEr�build_http_date�pushr�r>)rrCrVr\r]r^Zprocess_name_and_channelZprocess_namer8r�Z
group_name�groupZprocess�logfile�mtimerrrr{�sD






zlogtail_handler.handle_requestN)rrr�IDENTrVrrzr{rrrrr��s
r�c@s,eZdZdZdZdd�Zdd�Zdd�Zd	S)
�mainlogtail_handlerz!Main Logtail HTTP Request Handlerz/mainlogtailcCs
||_dS)N)r�)rr�rrrr�szmainlogtail_handler.__init__cCs|jj|j�S)N)rr�rV)rrCrrrrz�szmainlogtail_handler.matchcCs�|jdkr|jd�dS|jjj}|dks8tjj|�rF|jd�dStj|�tj	}t
j|�|d<d|d<|jt
||d��|j�dS)Nr�i�i�z
Last-Modifiedztext/plain;charset=utf-8zContent-Typei)rRrtr��optionsr�rNrVr�r�r�rr�r�r�r>)rrCr�r�rrrr{s



z"mainlogtail_handler.handle_requestN)rrrr�rVrrzr{rrrrr��s
r�c CsDg}t|j�}�x.|jD�]"}|d}|tjkrR|d|d}}t|||d�}n@|tjkr�|d}	|d}
|d}t|	|
||d�}ntd|��d	d
l	m
}d	dl	m}
d	dlm
}g}xp|jD]f\}}}y||f|�}Wn,tj�}|jj|�td
|��YnX|j||f�|jjd|�q�W|jd|
|�f�|||�}t|�}t|�}||�}tjjtjjt��}tjj|d�}tj|�}tj|�}|d}|d}|�r�||i}t||�}t||�}t||�}t||�}t||�}n|jj d|d�|j!|�|j!|�|j!|�|j!|�|j!|�|j||f�qW|S)N�familyrDrE)r�r�r�r�zCannot determine socket type %rr)�supervisor_xmlrpc_handler)�SystemNamespaceRPCInterface)�supervisor_ui_handlerzCould not make %s rpc interfacezRPC interface %r initialized�systemZui�username�passwordz:Server %r running without any HTTP authentication checkingZsection)"�
LogWrapperrAZserver_configsr�r�r�r�r�r�Zsupervisor.xmlrpcr�r�Zsupervisor.webr�Zrpcinterface_factories�	traceback�
format_exc�warn�appendr�r�r�rNrV�abspath�dirname�__file__rr
Z
os_filesystemr�supervisor_auth_handlerZcriticalZinstall_handler) r�r�Zservers�wrapperr�r�rDrEZhsr�r�r�r�r�r�Z
subinterfaces�name�factoryr$Zinst�tbZ
xmlrpchandlerZtailhandlerZmaintailhandlerZ	uihandler�hereZtemplatedirZ
filesystemZdefaulthandlerr�r�Zusersrrr�make_http_serverssr
















r�c@s eZdZdZdd�Zdd�ZdS)r�z\Receives log messages from the Medusa servers and forwards
    them to the Supervisor loggercCs
||_dS)N)rA)rrArrrrbszLogWrapper.__init__cCs@|jd�r|dd�}d|j�kr0|jj|�n|jj|�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&rtrg)�endswithr4rArtZtrace)rr�rrrr7es

zLogWrapper.logN)rrrr rr7rrrrr�_sr�c@seZdZdd�Zdd�ZdS)�encrypted_dictionary_authorizercCs
||_dS)N)�dict)rr�rrrrqsz(encrypted_dictionary_authorizer.__init__cCsX|\}}||jkrP|j|}|jd�rFtt|��j�}|dd�|kS||kSndSdS)Nz{SHA}�F)r�r�rrZ	hexdigest)rZ	auth_infor�r�Zstored_passwordZ
password_hashrrr�	authorizets



z)encrypted_dictionary_authorizer.authorizeN)rrrrr�rrrrr�psr�c@seZdZddd�ZdS)r��defaultcCstj||||�t|�|_dS)N)rrr�Z
authorizer)rr�ZhandlerZrealmrrrr�sz supervisor_auth_handler.__init__N)r�)rrrrrrrrr��sr�)-rNr�rBr�r�r�r�r�r��ImportErrorZgetpassZsupervisor.compatrrrrr�rr}rrr	r
rZsupervisor.medusa.auth_handlerrr
rr!r%r-Zhttp_requestr1rmrkr�r�r�r�r�r�r�r�r�r�rrrr�<module>sR @	5V6DI