403Webshell
Server IP : 217.160.0.135  /  Your IP : 216.73.217.85
Web Server : Apache
System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64
User : sws1074145052 ( 1074145052)
PHP Version : 8.3.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/flup/server/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/flup/server/__pycache__/fcgi_base.cpython-311.pyc
�

#H\aA����dZdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
	ddlZn#e
$rddlZYnwxYwddlZddlmZdZejdkreZd�ZneZd�Zeed	��sd
e_dgZdZdZd
Zd
Zd
ZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'e'Z(dZ)d
Z*d
Z+d
Z,dZ-dZ.d
Z/d
Z0dZ1dZ2dZ3dZ4dZ5dZ6dZ7dZ8ej9e7��Z:ej9e8��Z;	ddl<Z<dZ=dZ>d�Z?Gd�d e@��ZAGd!�d"eA��ZBGd#�d$e@��ZCGd%�d&e@��ZDGd'�d(e@��ZEd6d)�ZFd*�ZGGd+�d,e@��ZHGd-�d.e@��ZIGd/�d0eI��ZJGd1�d2e@��ZKGd3�d4eK��ZLGd5�de@��ZMdS)7zAllan Saddi <allan@saddi.com>z
$Revision$�N)�	get_errnoTic�,�|�d��S)N�latin-1)�decode��ss �7/usr/lib/python3/dist-packages/flup/server/fcgi_base.py�<lambda>r
3s��!�(�(�9�-�-��c��|S�N�rs r	r
r
6s��!�r�SHUT_WR��BaseFCGIServer��������	�
��FCGI_MAX_CONNS�
FCGI_MAX_REQS�FCGI_MPXS_CONNSz!BBHHBxz!HB5xz!LB3xz!B7xz
/tmp/fcgi.logc���t|krdS	ttd��}|�t	j��dd��d|�d���|���dS#YdSxYw)N�ar���zfcgi: �
)�DEBUG�open�DEBUGLOG�write�time�ctime�close)�level�msg�fs   r	�_debugr-rsu���5�=�=��F�	��X�s�#�#�A�
�G�G�d�j�l�l�1�R�4�&8�&8�&8�#�#�#�>�?�?�?�
�G�G�I�I�I�I�I��	��D�D���s�AA.�.A3c�R�eZdZdZd�Zd�Zd�Zdd�Zdd�Zdd
�Z	d�Z
d�ZeZd
�Z
dS)�InputStreamz�
    File-like object representing FastCGI input streams (FCGI_STDIN and
    FCGI_DATA). Supports the minimum methods required by WSGI spec.
    c�|�||_|jj|_d|_g|_d|_d|_d|_dS)NrrF)	�_conn�server�inputStreamShrinkThreshold�_shrinkThreshold�_buf�_bufList�_pos�_avail�_eof)�self�conns  r	�__init__zInputStream.__init__�s?����
�!%�� F�����	���
���	������	�	�	rc��|j|jkrB|j|jd�|_|xj|jzc_d|_|jdksJ�dSdS)z6Gets rid of already read data (since we can't rewind).Nr)r7r4r5r8�r:s r	�
_shrinkBufferzInputStream._shrinkBuffer�sb���9��-�-�-��	�$�)�*�*�-�D�I��K�K�4�9�$�K�K��D�I��;�!�#�#�#�#�.�-�
$�#rc�8�|j���dS)z(Waits for more data to become available.N)r1�
process_inputr>s r	�_waitForDatazInputStream._waitForData�s���
� � �"�"�"�"�"r���c��|j|jkr	|jrdS	|dks|j|jz
|kr$|jr|j}n |����>|j|z}	|jr/|xjd�|j��z
c_g|_|j|j|�}||_|���|S)NrTr)r7r8r9rBr6r5�joinr?)r:�n�newPos�rs    r	�readzInputStream.read�s����9���#�#��	�#��3�
	��1�u�u���t�y�0�A�5�5��9��!�[�F���%�%�'�'�'����Q�����=�	��I�I����$�-�0�0�0�I�I��D�M��I�d�i��&�'����	��������rNc��|j|jkr	|jrdS	|jr/|xjd�|j��z
c_g|_|j�d|j��}|dkrQ|jr|j}nH|�+t|j��||jzkr|j|z}n|�����|dz}	|j|j|�}||_|�	��|S)NrT�
rr)
r7r8r9r6r5rE�find�lenrBr?)r:�length�irGrHs     r	�readlinezInputStream.readline�s���9���#�#��	�#��3�	��}�
#��	�	�S�X�X�d�m�4�4�4�	�	� "��
��	���u�d�i�0�0�A��1�u�u��9�
�!�[�F���)�c�$�)�n�n����@R�.R�.R�!%��V�!3����%�%�'�'�'���Q�����I�d�i��&�'����	��������rrc���d}g}|���}|rN|�|��|t|��z
}d|cxkr|krnnn|���}|�N|S)Nr)rP�appendrM)r:�sizehint�total�lines�lines     r	�	readlineszInputStream.readlines�s��������}�}�����	#��L�L������S��Y�Y��E��8�$�$�$�$�u�$�$�$�$�$���=�=�?�?�D��	#��rc��|Sr
rr>s r	�__iter__zInputStream.__iter__�s���rc�@�|���}|st�|Sr
)rP�
StopIteration)r:rHs  r	�__next__zInputStream.__next__�s"���M�M�O�O���	 ����rc��|s	d|_dS|j�|��|xjt	|��z
c_dS�NT)r9r6rRr8rM�r:�datas  r	�add_datazInputStream.add_data�sE���	%��D�I�I�I��M� � ��&�&�&��K�K�3�t�9�9�$�K�K�K�Kr�rCr
�r)�__name__�
__module__�__qualname__�__doc__r<r?rBrIrPrWrYr\�nextrarrr	r/r/}s������������$�$�$�#�#�#�����4����>
�
�
�
��������D�%�%�%�%�%rr/c�J��eZdZdZ�fd�Zd�Zd	�fd�	Zd
�fd�	Z�fd�Z�xZ	S)�MultiplexedInputStreamz�
    A version of InputStream meant to be used with MultiplexedConnections.
    Assumes the MultiplexedConnection (the producer) and the Request
    (the consumer) are running in different threads.
    c���tt|���|��tj��}tj|��|_dSr
)�superrjr<�	threading�RLock�	Condition�_lock)r:r;�lock�	__class__s   �r	r<zMultiplexedInputStream.__init__�sI���
�$�d�+�+�4�4�T�:�:�:��� � ���(��.�.��
�
�
rc�8�|j���dSr
)rp�waitr>s r	rBz#MultiplexedInputStream._waitForDatas���
�������rrCc���|j���	tt|���|��|j���S#|j���wxYwr
)rp�acquirerlrjrI�release)r:rFrrs  �r	rIzMultiplexedInputStream.readsi����
������	!��/��6�6�;�;�A�>�>��J��� � � � ��D�J��� � � � �����'A�A8Nc���|j���	tt|���|��|j���S#|j���wxYwr
)rprvrlrjrPrw)r:rNrrs  �r	rPzMultiplexedInputStream.readlinesi����
������	!��/��6�6�?�?��G�G��J��� � � � ��D�J��� � � � ���rxc�,��|j���	tt|���|��|j���|j���dS#|j���wxYwr
)rprvrlrjra�notifyrw)r:r`rrs  �r	razMultiplexedInputStream.add_datas�����
������	!��(�$�/�/�8�8��>�>�>��J�������J��� � � � � ��D�J��� � � � ���s�AA8�8Brbr
)
rdrerfrgr<rBrIrPra�
__classcell__�rrs@r	rjrj�s����������
/�/�/�/�/����!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!rrjc�8�eZdZdZd
d�Zd�Zd�Zd�Zd�Zd�Z	d	S)�OutputStreamz�
    FastCGI output stream (FCGI_STDOUT/FCGI_STDERR). By default, calls to
    write() or writelines() immediately result in Records being sent back
    to the server. Buffering should be done in a higher level!
    Fc�h�||_||_||_||_g|_d|_d|_dS�NF)r1�_req�_type�	_bufferedr6�dataWritten�closed)r:r;�req�type�buffereds     r	r<zOutputStream.__init__#s8����
���	���
�!�����
� �������rc�:�t|��}|r�t||jjjt
z
��}t
|j|jj��}||_	|d|�|_
|j�|��||d�}||z}|��dSdSr
)
rM�minr�r2�maxwrite�FCGI_HEADER_LEN�Recordr��	requestId�
contentLength�contentDatar1�writeRecord)r:r`rN�toWrite�recs     r	�_writezOutputStream._write,s����T�����		��&�$�)�"2�";�o�"M�N�N�G����T�Y�%8�9�9�C� '�C��"�8�G�8�n�C�O��J�"�"�3�'�'�'�����>�D��g��F��		�		�		�		�		rc��|jrJ�|sdSd|_|jr|j�|��dS|�|��dSr^)r�r�r�r6rRr�r_s  r	r&zOutputStream.write9sc���;�����	��F�����>�	��M� � ��&�&�&�&�&��K�K������rc�L�|jrJ�|D]}|�|���dSr
)r�r&�r:rUrVs   r	�
writelineszOutputStream.writelinesFs>���;�����	�	�D��J�J�t�����	�	rc��|jr8d�|j��}g|_|�|��dSdS)Nr)r�rEr6r�r_s  r	�flushzOutputStream.flushLsH���>�	��8�8�D�M�*�*�D��D�M��K�K�������	�	rc���|js]|jrX|���t|j|jj��}|j�|��d|_dSdSdS)z/Sends end-of-stream notification, if necessary.TN)	r�r�r�r�r�r�r�r1r��r:r�s  r	r)zOutputStream.closeTsn���{�	�t�/�	��J�J�L�L�L����T�Y�%8�9�9�C��J�"�"�3�'�'�'��D�K�K�K�		�	�	�	rN)F)
rdrerfrgr<r�r&r�r�r)rrr	rrs}��������
��������������������rrc�*�eZdZdZd�Zd�Zd�Zd�ZdS)�TeeOutputStreamzq
    Simple wrapper around two or more output file-like objects that copies
    written data to all streams.
    c��||_dSr
)�_streamList)r:�
streamLists  r	r<zTeeOutputStream.__init__as��%����rc�D�|jD]}|�|���dSr
)r�r&)r:r`r,s   r	r&zTeeOutputStream.writeds/���!�	�	�A�
�G�G�D�M�M�M�M�	�	rc�:�|D]}|�|���dSr
�r&r�s   r	r�zTeeOutputStream.writelinesh�0���	�	�D��J�J�t�����	�	rc�B�|jD]}|����dSr
)r�r�)r:r,s  r	r�zTeeOutputStream.flushls-���!�	�	�A�
�G�G�I�I�I�I�	�	rN)rdrerfrgr<r&r�r�rrr	r�r�\sZ��������&�&�&�����������rr�c�*�eZdZdZd�Zd�Zd�Zd�ZdS)�
StdoutWrapperzN
    Wrapper for sys.stdout so we know if data has actually been written.
    c�"�||_d|_dSr�)�_filer�)r:�stdouts  r	r<zStdoutWrapper.__init__ts����
� ����rc�L�|rd|_|j�|��dSr^)r�r�r&r_s  r	r&zStdoutWrapper.writexs.���	$�#�D���
��������rc�:�|D]}|�|���dSr
r�r�s   r	r�zStdoutWrapper.writelines}r�rc�,�t|j|��Sr
)�getattrr�)r:�names  r	�__getattr__zStdoutWrapper.__getattr__�s���t�z�4�(�(�(rN)rdrerfrgr<r&r�r�rrr	r�r�psZ��������!�!�!����
���)�)�)�)�)rr�c���tjd|||dz���d}|dzr/tjd|||dz���ddz}|dz
}n|dz
}tjd|||dz���d}|dzr/tjd|||dz���ddz}|dz
}n|dz
}||||z�}||z
}||||z�}||z
}|||ffS)zv
    Decodes a name/value pair.

    The number of bytes decoded as well as the name/value pair
    are returned.
    �brr��!Lri���)�struct�unpack)r�pos�
nameLength�valueLengthr��values      r	�decode_pairr��s!����s�A�c�#�a�%�i�L�1�1�!�4�J��C����]�4��3�s�1�u�9��6�6�q�9�J�F�
��q�����q����-��Q�s�3�q�5�y�\�2�2�1�5�K��S����m�D�!�C��A��I�,�7�7��:�Z�G���q�����q����S��Z��
� �D��:��C�
�c�#�k�/�!�"�E��;��C��$����rc�*�t|��}|dkrtjd|��}ntjd|dz��}t|��}|dkr|tjd|��z
}n|tjd|dz��z
}||z|zS)zI
    Encodes a name/value pair.

    The encoded string is returned.
    r�r�r�l)rMr��pack)r�r�r�rr�s     r	�encode_pairr��s����T���J��C����K��Z�(�(����K��j�:�5�6�6���e�*�*�K��S���	�V�[��k�
*�
*�*���	�V�[��{�Z�7�
8�
8�8���t�8�e��rc�b�eZdZdZeefd�Zd�Zee��Zd�Z	d�Z
ee
��Z
d�ZdS)r�zD
    A FastCGI Record.

    Used for encoding/decoding records.
    c�d�t|_||_||_d|_d|_d|_dS)Nrr)�FCGI_VERSION_1�versionr�r�r��
paddingLengthr�)r:r�r�s   r	r<zRecord.__init__�s5��%�����	�"�������������rc�b�g}d}|r�	|�|��}nI#tj$r7}|jtjkrtj|ggg��Yd}~�Y�d}~wwxYw|sn0|�|��t|��}||z
}||z}|��d�|��|fS)z�
        Attempts to receive length bytes from a socket, blocking if necessary.
        (Socket may be blocking or non-blocking.)
        rNr)	�recv�socket�error�errno�EAGAIN�selectrRrMrE)�sockrN�dataList�recvLenr`�e�dataLens       r	�_recvallzRecord._recvall�s���
�����	�
��y�y��(�(�����<�
�
�
��7�e�l�*�*��M�4�&�"�b�1�1�1��H�H�H�H������
�����
���O�O�D�!�!�!��$�i�i�G��w��G��g��F��	��x�x��!�!�7�*�*s��A$�,A�A�A$c�Z�	|�|t��\}}n#t�xYw|tkrt�tjt
|��\|_|_|_|_	|_
tdd|���|j|j|j	fz��|j	rC	|�||j	��\|_
}n#t�xYw||j	krt�|j
r*	|�||j
��dS#t�xYwdS)z'Read and decode a Record from a socket.Trz<read: fd = %d, type = %d, requestId = %d, contentLength = %dN)r�r��EOFErrorr�r��FCGI_Headerr�r�r�r�r�r-�filenor�)r:r��headerrNs    r	rIzRecord.read�sF��	�!�]�]�4��A�A�N�F�F�F��	��N�����O�#�#��N�,2�=��f�+M�+M�	)���d�i����1C��(��Q�!2�"�k�k�m�m�T�Y���"�0�2�!2�3�3�3�
��	�
�+/�=�=��9=�9K�,M�,M�(�� �&�&��
��������*�*�*�����	�
��
�
�d�D�$6�7�7�7�7�7��
������		�	s �!�	*�8#C�	C%�D�	D(c��t|��}|rs	|�|��}nI#tj$r7}|jtjkrt
jg|gg��Yd}~�Y�d}~wwxYw||d�}||z}|�qdSdS)zY
        Writes data to a socket and does not return until all the data is sent.
        N)rM�sendr�r�r�r�r�)r�r`rN�sentr�s     r	�_sendallzRecord._sendall�s����T�����
	�
��y�y��������<�
�
�
��7�e�l�*�*��M�"�t�f�b�1�1�1��H�H�H�H������
��������;�D��d�N�F��
	�
	�
	�
	�
	s�)�A/�,A*�)A*�*A/c���|jdz|_tdd|���|j|j|jfz��t
jt|j	|j|j|j|j��}|�
||��|jr|�
||j��|jr |�
|d|jz��dSdS)z&Encode and write a Record to a socket.rTrz=write: fd = %d, type = %d, requestId = %d, contentLength = %d�N)r�r�r-r�r�r�r�r�r�r�r�r�)r:r�r�s   r	r&zRecord.writes���"�0�0�1�4����Q�!2�"�k�k�m�m�T�Y���"�0�2�!2�3�3�3�
��[�$�,��	�!�^�T�-?�!�/�1�1��	
�
�
�d�F�#�#�#���	2��M�M�$�� 0�1�1�1���	<��M�M�$���(:� :�;�;�;�;�;�	<�	<rN)rdrerfrg�FCGI_UNKNOWN_TYPE�FCGI_NULL_REQUEST_IDr<r��staticmethodrIr�r&rrr	r�r��s���������
.�9M�����+�+�+�.�|�H�%�%�H� � � �D��� �|�H�%�%�H�<�<�<�<�<rr�c�0�eZdZdZd�Zd�Zdefd�Zd�ZdS)�Requesta8
    Represents a single FastCGI request.

    These objects are passed to your handler and is the main interface
    between your handler and the fcgi module. The methods should not
    be called by your handler. However, server, params, stdin, stdout,
    stderr, and data are free for your handler's use.
    c���||_|j|_i|_||��|_t	||t
��|_t	||td���|_||��|_	dS)NT)r�)
r1r2�params�stdinr�FCGI_STDOUTr��FCGI_STDERR�stderrr`)r:r;�inputStreamClasss   r	r<zRequest.__init__*sl����
��k������%�%�d�+�+��
�"�4��{�;�;���"�4��{�T�J�J�J���$�$�T�*�*��	�	�	rc��	|j�|��\}}n�#tj��}t	j|���|j�t|�	��d����|j�
��|jjs|j�
|��td}}YnxYwtdd||fz��	|���|�||��dS#t$j
$r!}|jt&jkr�Yd}~dSd}~wwxYw)z<Runs the handler, flushes the streams, and ends the request.)�filezutf-8rTrz#protocolStatus = %d, appStatus = %dN)r2�handler�io�StringIO�	traceback�	print_excr�r&�bytes�getvaluer�r�r�r��FCGI_REQUEST_COMPLETEr-�_flush�_endr�r��EPIPE)r:�protocolStatus�	appStatus�outputr�s     r	�runzRequest.run4sR��
	A�(,��(;�(;�D�(A�(A�%�N�I�I��	A��[�]�]�F���V�,�,�,�,��K���e�F�O�O�$5�$5�w�?�?�@�@�@��K�������;�*�
(���!�!�$�'�'�'�(=�q�I�N�N�N�����Q� E�,�i�8�!9�:�:�:�	��K�K�M�M�M��I�I�i��0�0�0�0�0���|�	�	�	��w�%�+�%�%��&�%�%�%�%�%�����	���s"� �B,C�'*D�E�"D>�>Erc�>�|j�|||��dSr
)r1�end_request�r:r�r�s   r	r�zRequest._endLs"���
���t�Y��?�?�?�?�?rc�j�|j���|j���dSr
)r�r)r�r>s r	r�zRequest._flushOs0�����������������rN)	rdrerfrgr<r�r�r�r�rrr	r�r�!sk��������+�+�+����0�/D�@�@�@�@�����rr�c�*�eZdZdZd�Zdefd�Zd�ZdS)�
CGIRequestz4A normal CGI request disguised as a FastCGI request.c�`�d|_t|_d|_d|_||_t
tj��|_	tjj|_ttjj��|_tjj|_t!j��|_dS)NrrF)r��FCGI_RESPONDER�role�flags�abortedr2�dict�os�environr��sysr��bufferr�r�r�r��BytesIOr`)r:r2s  r	r<zCGIRequest.__init__Uss�����"��	���
��������2�:�&�&����Y�%��
�#�C�J�$5�6�6����j�'����J�L�L��	�	�	rrc�.�tj|��dSr
)r	�exitr�s   r	r�zCGIRequest._endcs���������rc��dSr
rr>s r	r�zCGIRequest._flushfs���rN)rdrerfrgr<r�r�r�rrr	rrSsT������>�>�!�!�!��/D�����
�
�
�
�
rrc�v�eZdZdZdZeZd�Zd�Zd�Z	d�Z
d�Zded	fd
�Z
d�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�ZdS)�
Connectionz�
    A Connection with the web server.

    Each Connection is associated with a single socket (which is
    connected to the web server) and is responsible for handling all
    the FastCGI message processing for that socket.
    Fc�>�||_||_||_i|_dSr
)�_sock�_addrr2�	_requests)r:r��addrr2s    r	r<zConnection.__init__us$����
���
��������rc�$�	|j�tj��n#YdSxYw		t	j|jggg��\}}}|r|j�d��sn�>n#YnxYw|j���dS)zClose the Connection's socket.NTi)r�shutdownr�rr�r�r))r:rH�wr�s    r	�_cleanupSocketzConnection._cleanupSocket}s���	��J�����/�/�/�/��	��F�F����	�
� �-����b�"�=�=���1�a����
���� 5� 5���
���	��D�����
�������s�$'�,�?A0�0A4c�4�d|_|jru	|���nX#ttf$rYnLtjtjf$r(}t|��tj	krYd}~n�d}~wwxYw|j�u|�
��dS)z&Begin processing data from the socket.TN)�
_keepGoingrAr��KeyboardInterruptr�r�r�rr��EBADFr)r:r�s  r	r�zConnection.run�s�������o�	�
��"�"�$�$�$�$���/�0�
�
�
����L�&�,�/�
�
�
��Q�<�<�5�;�.�.��E�E�E�E������
�����o�	�	
�������s �%�A:�A:�A5�4A5�5A:c��|jrB	tj|jgggd��\}}}n#t$rt�wxYw|rn|j�B|jsdSt��}|�|j��|jtkr|�	|��dS|jtkr|�|��dS|jtkr|�
|��dS|jtkr|�|��dS|jt kr|�|��dS|jt$kr|�|��dS|jt*kr|�|��dSdS)z?Attempt to read a single Record from the socket and process it.g�?N)rr�r�
ValueErrorr�r�rIr��FCGI_GET_VALUES�_do_get_values�FCGI_BEGIN_REQUEST�_do_begin_request�FCGI_ABORT_REQUEST�_do_abort_request�FCGI_PARAMS�
_do_params�
FCGI_STDIN�	_do_stdin�	FCGI_DATA�_do_datar�r��_do_unknown_type)r:rHrr�r�s     r	rAzConnection.process_input�s����o�	�
� �-����b�"�c�B�B���1�a�a���
�
�
���
�����K�%��o�	���	��F��h�h�����������8��&�&�����$�$�$�$�$�
�X�+�
+�
+��"�"�3�'�'�'�'�'�
�X�+�
+�
+��"�"�3�'�'�'�'�'�
�X��
$�
$��O�O�C� � � � � �
�X��
#�
#��N�N�3������
�X��
"�
"��M�M�#������
�]�2�
2�
2��!�!�#�&�&�&�&�&�
�Ds�!+�=c�:�|�|j��dS)z/
        Write a Record to the socket.
        N)r&rr�s  r	r�zConnection.writeRecord�s��	�	�	�$�*�����rrTc�t�tt|j��}tjt
||��|_t|_|�	|��|r
|j
|j=tdd|jz��|jtzs$|j
s|���d|_dSdSdS)a

        End a Request.

        Called by Request objects. An FCGI_END_REQUEST Record is
        sent to the web server. If the web server no longer requires
        the connection, the socket is closed, thereby ending this
        Connection (run() returns).
        Trzend_request: flags = %dFN)r��FCGI_END_REQUESTr�r�r��FCGI_EndRequestBodyr��FCGI_EndRequestBody_LENr�r�rr-r�FCGI_KEEP_CONNrr)r:r�r�r��remover�s      r	r�zConnection.end_request�s����%�s�}�5�5�� �+�&9�9�&4�6�6���3�����������	.���s�}�-��Q� 9�C�I� E�F�F�F��	�N�*�	$�D�N�	$����!�!�!�#�D�O�O�O�	$�	$�	$�	$rc��tt��}d}||jkrrt|j|��\}\}}|jj�|��}|�+|xjt|t|����z
c_||jk�rt|j��|_|�|��dS)z6Handle an FCGI_GET_VALUES request from the web server.rN)r��FCGI_GET_VALUES_RESULTr�r�r�r2�
capability�getr��strrMr�)r:�inrec�outrecr�r�r��caps       r	r!zConnection._do_get_values�s����.�/�/�����E�'�'�'�!,�U�->��!D�!D��C��$���+�(�,�,�T�2�2�C����"�"�k�$��C���&A�&A�A�"�"�	�E�'�'�'� #�6�#5�6�6������� � � � � rc�H�tjt|j��\}}|j�||j��}|j||c|_|_|_	d|_
|js'|jr |�
|dtd���dS||j|j<dS)z1Handle an FCGI_BEGIN_REQUEST from the web server.Fr)r3N)r�r��FCGI_BeginRequestBodyr�r2�
request_class�_inputStreamClassr�rrr�_multiplexedrr��FCGI_CANT_MPX_CONN)r:r9rrr�s     r	r#zConnection._do_begin_request�s����m�$9�5�;L�M�M���e��k�'�'��d�.D�E�E��-2�_�d�E�*��
�s�x������� �	2�T�^�	2����S�!�%7���F�F�F�F�F�.1�D�N�5�?�+�+�+rc�Z�|j�|j��}|�	d|_dSdS)z{
        Handle an FCGI_ABORT_REQUEST from the web server.

        We just mark a flag in the associated Request.
        NT)rr7r�r�r:r9r�s   r	r%zConnection._do_abort_request�s2���n� � ���1�1���?��C�K�K�K��?rc�.�|���dS)zRun the request.N)r��r:r�s  r	�_start_requestzConnection._start_requests��	���	�	�	�	�	rc�:�|j�|j��}|�y|jr[d}||jkrLt	|j|��\}\}}t
|��|jt
|��<||jk�JdSdS|�|��dSdS)zw
        Handle an FCGI_PARAMS Record.

        If the last FCGI_PARAMS Record is received, start the request.
        Nr)	rr7r�r�r�r��	force_strr�rF)r:r9r�r�r�r�s      r	r'zConnection._do_params
s����n� � ���1�1���?��"�
)����E�/�/�/�)4�U�5F��)L�)L�&�C��$��2;�E�2B�2B�C�J�y����/��E�/�/�/�/�/�/�/��#�#�C�(�(�(�(�(��?rc��|j�|j��}|�!|j�|j��dSdS)zHandle the FCGI_STDIN stream.N)rr7r�r�rar�rCs   r	r)zConnection._do_stdinsD���n� � ���1�1���?��I���u�0�1�1�1�1�1��?rc��|j�|j��}|�!|j�|j��dSdS)zHandle the FCGI_DATA stream.N)rr7r�r`rar�rCs   r	r+zConnection._do_data sD���n� � ���1�1���?��H���e�/�0�0�0�0�0��?rc���tt��}tjt|j��|_t|_|�	t��dS)z4Handle an unknown request type. Respond accordingly.N)r�r�r�r��FCGI_UnknownTypeBodyr�r��FCGI_UnknownTypeBody_LENr�r�r�)r:r9r:s   r	r,zConnection._do_unknown_type&sI���)�*�*��#�[�)=�u�z�J�J���7�����������rN)rdrerfrgr@r/r?r<rr�rAr�r�r�r!r#r%rFr'r)r+r,rrr	rrjs
���������L�#�����
�
�
�
�
�
�#�#�#�J���*+�#8��$�$�$�$�2!�!�!�2�2�2�������
)�)�)� 2�2�2�1�1�1�����rrc���eZdZdZdZeZ�fd�Z�fd�Zd�Z	de
df�fd�	Z�fd�Z�fd	�Z
d
�Z�fd�Z�fd�Z�fd
�Z�xZS)�MultiplexedConnectionz[
    A version of Connection capable of handling multiple requests
    simultaneously.
    Tc���tt|���|||��tj��}tj|��|_dSr
)rlrOr<rmrnrorp)r:r�rr2rqrrs     �r	r<zMultiplexedConnection.__init__5sM���
�#�T�*�*�3�3�D�$��G�G�G��� � ���(��.�.��
�
�
rc���|j���|jr |j���|j� |j���tt|�����dSr
)rprvrrtrwrlrOr)r:rrs �r	rz$MultiplexedConnection._cleanupSocket?sv����
�������n�	��J�O�O�����n�	��
������
�#�T�*�*�9�9�;�;�;�;�;rc���|j���	|�|j��|j���dS#|j���wxYwr
)rprvr&rrwr�s  r	r�z!MultiplexedConnection.writeRecordHse��	
�
������	!��I�I�d�j�!�!�!��J��� � � � � ��D�J��� � � � ���s�A�A+rc�2��|j���	tt|���||||��|j���|j���dS#|j���wxYwr
)rprvrlrOr�r{rw)r:r�r�r�r3rrs     �r	r�z!MultiplexedConnection.end_requestRs�����
������	!��'��.�.�:�:�3�	�;I�;A�
C�
C�
C�
�J�������J��� � � � � ��D�J��� � � � ���s�AA;�;Bc���|j���	tt|���|��|j���dS#|j���wxYwr
)rprvrlrOr#rw�r:r9rrs  �r	r#z'MultiplexedConnection._do_begin_request]�o����
������	!��'��.�.�@�@��G�G�G��J��� � � � � ��D�J��� � � � �����(A�A:c���|j���	tt|���|��|j���dS#|j���wxYwr
)rprvrlrOr%rwrUs  �r	r%z'MultiplexedConnection._do_abort_requestdrVrWc�:�tj|jd��dS)Nr)�thread�start_new_threadr�rEs  r	rFz$MultiplexedConnection._start_requestks�������,�,�,�,�,rc���|j���	tt|���|��|j���dS#|j���wxYwr
)rprvrlrOr'rwrUs  �r	r'z MultiplexedConnection._do_paramsnso����
������	!��'��.�.�9�9�%�@�@�@��J��� � � � � ��D�J��� � � � ���rWc���|j���	tt|���|��|j���dS#|j���wxYwr
)rprvrlrOr)rwrUs  �r	r)zMultiplexedConnection._do_stdinuso����
������	!��'��.�.�8�8��?�?�?��J��� � � � � ��D�J��� � � � ���rWc���|j���	tt|���|��|j���dS#|j���wxYwr
)rprvrlrOr+rwrUs  �r	r+zMultiplexedConnection._do_data|so����
������	!��'��.�.�7�7��>�>�>��J��� � � � � ��D�J��� � � � ���rW)rdrerfrgr@rjr?r<rr�r�r�r#r%rFr'r)r+r|r}s@r	rOrO-s+����������L�.��/�/�/�/�/�<�<�<�<�<�!�!�!�*+�#8��	!�	!�	!�	!�	!�	!�!�!�!�!�!�!�!�!�!�!�-�-�-�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!�!rrOc	�X�eZdZeZeZdZdZddddddde	fdf	d�Z
d�Zd�Zd	�Z
d
�Zd�ZdS)ri ipNTFc��|�i}||_||_||_||_||_|	|_|
|_||_||_tj
��|_tr|	ddl
}|�|j��d}n#t $rd}YnwxYw|}
|rt"|_|
dz}
nt&|_t(|t*|
t,|rdpdi|_dSt&|_t(dt*dt,di|_dS)a�
        bindAddress, if present, must either be a string or a 2-tuple. If
        present, run() will open its own listening socket. You would use
        this if you wanted to run your application as an 'external' FastCGI
        app. (i.e. the webserver would no longer be responsible for starting
        your app) If a string, it will be interpreted as a filename and a UNIX
        socket will be opened. If a tuple, the first element, a string,
        is the interface name/IP to bind to, and the second element (an int)
        is the port number.

        If binding to a UNIX socket, umask may be set to specify what
        the umask is to be changed to before the socket is created in the
        filesystem. After the socket is created, the previous umask is
        restored.
        
        Set multiplexed to True if you want to handle multiple requests
        per connection. Some FastCGI backends (namely mod_fastcgi) don't
        multiplex requests at all, so by default this is off (which saves
        on thread creation/locking overhead). If threads aren't available,
        this keyword is ignored; it's not possible to multiplex requests
        at all.
        Nr�drr)�applicationr�
multithreaded�multiprocess�debug�roles�forceCGI�_bindAddress�_umaskrZ�
allocate_lock�_appLock�thread_available�resource�	getrlimit�
RLIMIT_NOFILE�ImportErrorrO�_connectionClassrrrrr6)r:rbrrcrd�bindAddress�umask�multiplexedrerfrgrm�maxConns�maxReqss              r	r<zBaseFCGIServer.__init__�s2��6�?��G�&������*���(�����
���
� ��
�'�������,�.�.��
��	�
�����$�-�-�h�.D�E�E�a�H�����
�
�
�����
�����G��
3�(=��%��1����(2��%����w���!2��!7�a��D�O�O�O�%/�D�!����q���	�D�O�O�Os�$$B	�	B�Bc�*�|j��d}tjttjtj��}	|���nJ#tj$r8}|jtj	krd}n|jtj
kr�Yd}~nd}~wwxYw|rL|jsEtj
�dd������d��r=|�|��}|���t'jd���nld}t+|j��t,urutjtjtj��}	tj|j��n#t2$rYnwxYw|j�tj|j��}n�t+|j��t8usJ�t;|j��dksJ�tjtjtj��}|�tjtj d��|�!|j��|�"tj#��|�tj|��|S)	NTF�FCGI_FORCE_CGI�N�Yrrr)$rhr��fromfd�FCGI_LISTENSOCK_FILENO�AF_INET�SOCK_STREAM�getpeernamer�r��ENOTSOCK�ENOTCONNrgrrr7�upper�
startswith�cgirequest_classr�r	r
r�r8�AF_UNIX�unlink�OSErrorrirs�tuplerM�
setsockopt�
SOL_SOCKET�SO_REUSEADDR�bind�listen�	SOMAXCONN)r:�isFCGIr�r�r��oldUmasks      r	�_setupSocketzBaseFCGIServer._setupSocket�sC����$��F��=�!7���!'�!3�5�5�D�
�� � �"�"�"�"���<�
�
�
��7�e�n�,�,�"�F�F��W���.�.�����������
�����
�T�]�
��z�~�~�.��4�4�:�:�<�<�G�G��L�L�
��+�+�D�1�1�����	�	�	���������H��D�%�&�&�#�-�-��}�V�^�V�5G�H�H����I�d�/�0�0�0�0�������D������;�*�!�x���4�4�H���D�-�.�.�%�7�7�7�7��4�,�-�-��2�2�2�2��}�V�^�V�5G�H�H������ 1�6�3F��J�J�J��I�I�d�'�(�(�(��K�K��(�)�)�)��#����"�"�"��s)�A�B�.B�B�.F�
F�Fc�.�|���dS)zCloses the main socket.N)r))r:r�s  r	rzBaseFCGIServer._cleanupSocket
s���
�
�����rc�����	�
��j|jvr	tdfS�j}|�|j��d|d<�j|d<|j��j}n ttj�jf��}||d<t�t��o
to|j|d<t�t��p|j|d<t�t��|d	<|�d
d��dvrd
|d<nd|d<|�|��g�g�d�	����	fd��
d���
fd�	}|js|j���		|�||���		�	D]}|r�
|����s�
d��t+�	d��r�	���n*#t+�	d��r�	���wwxYwn2#t.j$r }|jt2jkr�Yd}~nd}~wwxYw|js|j���n&#|js|j���wwxYwt8dfS)zSpecial handler for WSGI.r)rrzwsgi.versionz
wsgi.inputN�wsgi.errorszwsgi.multithreadzwsgi.multiprocessz
wsgi.run_once�HTTPS�off)�on�1�httpszwsgi.url_scheme�httpc���t|��tus
Jd����s
Jd����s�x\}}�dd�<d}|D]!\}}|���dkrd}n�"|sO�
�M	t�
��dkr1|�dtt|����f��n#YnxYwd|zd	z}|D]B}||d
�d��dz|d�d��zd	zz
}�C|d	z
}�	j�|���	j�|���	j�	��dS)
Nzwrite() argument must be byteszwrite() before start_response()Fzcontent-lengthTrzContent-LengthsStatus: s
r�asciis: )
r�r��lowerrMrRr8�encoder�r&r�)r`�status�responseHeaders�foundr�r�r�headers_sent�headers_setr��results       ����r	r&z%BaseFCGIServer.handler.<locals>.write2s������:�:��&�&�&�(H�&�&�&��A�A� A�A�A�A��
$�<G�G�'���,�q�q�q�/���$3���L�F�5��|�|�~�~�)9�9�9� $����:����!3���v�;�;�!�+�+�+�2�2�4D�47��D�	�	�N�N�4D�E�E�E����������&�(�7�2��-�a�a�F�����)�)�'�2�2�U�:�V�A�Y�=M�=M�g�=V�=V�V�Y`�`�`�A�A��W����
� � ��#�#�#��J���T�"�"�"��J�������s
�'AB,�,B0c���|r>	�r0|d|d���|d���	d}n#d}wxYw�r
Jd���t|ttf��s
Jd���t|t��r|�d��}t|��dks
Jd���t
|dd	���s
Jd
���t|��tus
Jd���	|D]K\}}t|��tus
Jd
|z���t|��tus
Jd|z����L||g�dd�<�S)NrrrzHeaders already set!zStatus must be text or bytesrrz$Status must be at least 4 charactersrz#Status must begin with 3-digit codezHeaders must be a listTz!Header name "%s" must be a stringz%Value of header "%s" must be a string)
�with_traceback�
isinstancer��	text_typer�rM�intr��listr8)r��response_headers�exc_infor��valr�r�r&s     ���r	�start_responsez.BaseFCGIServer.handler.<locals>.start_responseMs�����
?�$�#�S�)�h�q�k�(�1�+�6�6�E�E�h�q�k�R�R�R�S� $�H�H��t�H�O�O�O�O�&�>�>�(>�>�>�>��f�u�i�&8�9�9�Y�Y�;Y�Y�Y�Y��&�)�,�,�
2����y�1�1���v�;�;�!�#�#�#�%K�#�#�#��v�b�q�b�z�?�?�I�I�$I�I�I�I��(�)�)�T�1�1�1�3K�1�1�1�
\� 0�\�\�H�D����:�:��,�,�,�.Q�TX�.X�,�,�,���9�9��+�+�+�-T�W[�-[�+�+�+�+�$�&6�7�K����N��Ls�2;�?rr)r
)rrf�FCGI_UNKNOWN_ROLEr��updaterr�rhr�r�r	r�rrlrcrdr7�_sanitizeEnvrkrvrb�hasattrr)r�r�r�r�rwr�)r:r�rr�r�r`r�r�r�r�r&s `     @@@@r	r�zBaseFCGIServer.handlers���������8�4�:�%�%�$�a�'�'��*�����t�|�$�$�$�"'���� #�	������$��Z�F�F�$�c�j�#�*�%=�>�>�F�!'��
��*4�S�*�*E�*E�&E�'N�&6�'N�;?�;M�	�"�#�'1�#�z�'B�'B�(9�'+�'8�	�#�$�#-�c�:�#>�#>��� ��;�;�w��&�&�+�5�5�)0�G�%�&�&�)/�G�%�&����'�"�"�"�������	�	�	�	�	�	�	�	�6	�	�	�	�	�	�	�	�4�!�	$��M�!�!�#�#�#�	(�

��)�)�'�>�B�B��'� &�(�(���(�!�E�$�K�K�K��'�#���c�
�
�
��v�w�/�/�'����������v�w�/�/�'��������'�������<�
�
�
��7�e�k�)�)��*�)�)�)�)�����
�����%�
(��
�%�%�'�'�'����%�
(��
�%�%�'�'�'�'�
(����%�a�'�'sH�G�&F*�%G�*'G�G�H(�H�$G?�:H(�?H�H(�(#Ic	��d|vrd|d<d}d|vr|d�dd��}d|vs|ds|�|d|d<nd|d<d	|vs|d	s&|�t|��dkr|d|d	<nd|d	<d
D]G\}}||vr>|d�t|jj�d|�d
�d����|||<�HdS)z7Ensure certain values are present, if required by WSGI.�SCRIPT_NAME�N�REQUEST_URI�?r�	PATH_INFOr�QUERY_STRING))�REQUEST_METHOD�GET)�SERVER_NAME�	localhost)�SERVER_PORT�80)�SERVER_PROTOCOLzHTTP/1.0r�z: missing FastCGI param z required by WSGI!
�utf)�splitrMr&�	bytearrayrrrd)r:r�reqUrir��defaults     r	r�zBaseFCGIServer._sanitizeEnv~s>����'�'�%'�G�M�"����G�#�#��]�+�1�1�#�q�9�9�F��g�%�%�W�[�-A�%��!�'-�a�y���$�$�')���$���(�(���0G�(��!�c�&�k�k�A�o�o�*0��)���'�'�*,���'�>�	(�	(�L�D���7�"�"��
�&�,�,�Y�.2�n�.E�.E�.E�t�t�t�8M�NS�.U�.U�V�V�V�!(���
��	(�	(rc��|jrZddl}|j�d|�tj�����d��z��dSd}|j�d|z��dS)zt
        Called by Request if an exception occurs within the handler. May and
        should be overridden.
        rNsContent-Type: text/html

�utf8s�<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>Unhandled Exception</title>
</head><body>
<h1>Unhandled Exception</h1>
<p>An unhandled exception was thrown by the application.</p>
</body></html>
)re�cgitbr�r&�htmlr	r�r�)r:r�r��	errorpages    r	r�zBaseFCGIServer.error�s���
�:�	(��L�L�L��J���?�"�Z�Z�����7�7�>�>�v�F�F�G�
H�
H�
H�
H�
H��I�
�J���?�&�'�
(�
(�
(�
(�
(r)rdrerfr�r>rr�r�r3rr<r�rr�r�r�rrr	rr�s��������M�!��
�H�
"/��,0�#�%�!��5��N�#4��	F�F�F�F�P2�2�2�h���k(�k(�k(�Z(�(�(�@(�(�(�(�(rrc)N�
__author__�__version__r	r�signalr�r�r�r�r�r��_threadrZrprm�flup.serverrrl�
hexversionr8r�rH�unicoder�r�__all__r|r�r�r"r$r/r&r(r�r�r*r r5r��FCGI_MAXTYPEr�r2r�FCGI_AUTHORIZER�FCGI_FILTERr�rA�FCGI_OVERLOADEDr�rrrr�r=r0rL�calcsizer1rMr'r#r%r-�objectr/rjrr�r�r�r�r�r�rrrOrrrr	�<module>r�s9��6-�
���
�
�
�
�	�	�	�	�
�
�
�
�
�
�
�
�	�	�	�	�
�
�
�
�
�
�
�
���������������������M�M�M�M�M���������!�!�!�!�!�!����>�Z����I�-�-�I�I��I���I��w�v�y�!�!���F�N��
����������������
�
�����
�	������� ��������������������!���
�#����������)�&�/�*=�>�>��*�6�?�+?�@�@����K�K�K�
�E��H�	�	�	�t%�t%�t%�t%�t%�&�t%�t%�t%�l(!�(!�(!�(!�(!�[�(!�(!�(!�T=�=�=�=�=�6�=�=�=�~�����f����()�)�)�)�)�F�)�)�)�( � � � �8���(k<�k<�k<�k<�k<�V�k<�k<�k<�Z0�0�0�0�0�f�0�0�0�d
�
�
�
�
��
�
�
�.A�A�A�A�A��A�A�A�FT!�T!�T!�T!�T!�J�T!�T!�T!�ln(�n(�n(�n(�n(�V�n(�n(�n(�n(�n(s�/�	;�;

Youez - 2016 - github.com/yon3zu
LinuXploit