https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/trac/web/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/trac/web/__pycache__/auth.cpython-310.pyc
o

�k�`7H�@s<ddlmZmZddlmZmZddlmZmZddl	Z	ddl
Z
ddlZddlZ
ddlZ
ddlmZmZmZddlTddlmZmZddlmZmZdd	lmZmZdd
lmZddlm Z ddl!m"Z"dd
l#m$Z$ddl%m&Z&m'Z'Gdd�de(�Z)Gdd�de*ed�Z+Gdd�de+�Z,Gdd�de,�Z-Gdd�de,�Z.dS)�)�ABCMeta�abstractmethod)�	b64decode�	b64encode)�md5�sha1N)�
BoolOption�	IntOption�Option)�*)�IAuthenticator�IRequestHandler)�Chrome�INavigationContributor)�hex_entropy�md5crypt)�crypt)�	threading)�time_now)�tag)�_�tag_c@s�eZdZdZeeee�dZe	dddd�Z
e	dddd�Zedd	d
d�Z
eddd
d�Zeddd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)S)*�LoginModulea�User authentication manager.

    This component implements user authentication based on HTTP
    authentication provided by the web-server, combined with cookies
    for communicating the login information across the whole site.

    This mechanism expects that the web-server is setup so that a
    request to the path '/login' requires authentication (such as
    Basic or Digest). The login name is then stored in the database
    and associated with a unique key that gets passed back to the user
    agent using the 'trac_auth' cookie. This cookie is used to
    identify the user in subsequent requests to non-protected
    resources.
    F�trac�
check_auth_ip�falsezQWhether the IP address of the user should be checked for
         authentication.�ignore_auth_casez6Whether login names should be converted to lower case.�auth_cookie_domain�z�Auth cookie domain attribute.

        The auth cookie can be shared among multiple subdomains
        by setting the value to the domain. (//since 1.2//)
        �auth_cookie_lifetimeraLLifetime of the authentication cookie, in seconds.

        This value determines how long the browser will cache
        authentication information, and therefore, after how much
        inactivity a user will have to log in again. The value
        of 0 makes the cookie expire at the end of the browsing
        session.
        �auth_cookie_pathz�Path for the authentication cookie. Set this to the common
        base path of several Trac instances if you want them to share
        the cookie.
        cCsHd}|jr	|j}nd|jvr|�||jd�}|sdS|jr"|��}|S)N�	trac_auth)�remote_user�incookie�_get_name_for_cookie�ignore_case�lower)�self�req�authname�r*�//usr/lib/python3/dist-packages/trac/web/auth.py�authenticateZs
�zLoginModule.authenticatecCsdS)N�loginr*�r'r(r*r*r+�get_active_navigation_itemlsz&LoginModule.get_active_navigation_itemccs��|jr<ddtdt|j��||j�d�fVddtjt�tj	t
d�ddd�tjd	d
|jd��|j
��ddd
d�fVdSddtjt
d�|j
��d�fVdS)N�metanavr-zlogged in as %(user)s��user�logout�Logout�submit)�name�type�hidden�__FORM_TOKEN)r7r6�value�postztrac-logout)�action�method�id�class_�Login)�href)�is_authenticatedrr�env�
authorinfor)r�form�div�buttonr�input�
form_tokenrAr3�ar-r.r*r*r+�get_navigation_itemsos0������
�
�
�z LoginModule.get_navigation_itemscCst�d|j�S)Nz/(login|logout)/?$)�re�match�	path_infor.r*r*r+�
match_request�szLoginModule.match_requestcCs<|j�d�r|�|�n|j�d�r|�|�|�|�dS)Nz/loginz/logout)rN�
startswith�	_do_login�
_do_logout�_redirect_backr.r*r*r+�process_request�s

zLoginModule.process_requestcCs�|jstjtd�td�|j�d�dd�}ttd|d���|j}|jr'|�	�}|j
d|fvr7ttd	|j
d
���|jj�B}|dt
t��df�d
}|j�d�}|d
urb|�||�}||kr`|jnd
}|d
urvt�}|d|||jt
t��f�Wd
�n1s�wY||_
||jd<|jr�|j|jdd<|jp�|jp�d|jdd<|jjr�d|jdd<d|jdd<|jdkr�|j|jdd<d
Sd
S)a�Log the remote user in.

        This function expects to be called when the remote user name
        is available. The user name is inserted into the `auth_cookie`
        table and a cookie identifying the user on subsequent requests
        is sent back to the client.

        If the Authenticator was created with `ignore_case` set to
        true, then the authentication name passed from the web server
        in req.remote_user will be converted to lower case before
        being used. This is to avoid problems on installations
        authenticating against Windows which is not case sensitive
        regarding user names and domain names
        zinstallation documentationzConfiguring Authentication�TracInstallz#ConfiguringAuthentication)�titlerAzKAuthentication information not available. Please refer to the %(inst_doc)s.)�inst_doc�	anonymouszAlready logged in as %(user)s.r1z'DELETE FROM auth_cookie WHERE time < %si/
Nr!z�
                    INSERT INTO auth_cookie (cookie, name, ipnr, time)
                         VALUES (%s, %s, %s, %s)
                   �domain�/�pathT�secure�httponlyr�expires)r"rrJrrA�wiki�	TracErrorrr%r&r)rC�db_transaction�intrr#�get�_cookie_to_namer:r�remote_addr�	outcookierr �	base_path�secure_cookiesr)r'r(rWr"�db�cookier!r6r*r*r+rQ�sd

����
�����
��
�zLoginModule._do_logincCs�|jdks|js
dSd|jvr|j�d|jdjf�n	|j�d|jf�|�|�|jd�	d�}|rFt
�d|�s?|�|�}|�
|�dSdS)	zoLog the user out.

        Simply deletes the corresponding record from the auth_cookie
        table.
        �POSTNr!z'DELETE FROM auth_cookie WHERE cookie=%sz%DELETE FROM auth_cookie WHERE name=%sr0zlogout.redirectz	https?:|/)r=rBr#rCrar:r)�_expire_cookie�configrcrLrMrA�redirect)r'r(�custom_redirectr*r*r+rR�s 
��

�zLoginModule._do_logoutcCspd|jd<|jr|j|jdd<|jp|jpd|jdd<d|jdd<|jjr/d|jdd	<d|jdd
<dS)zyInstruct the user agent to drop the auth cookie by setting
        the "expires" property to a date in the past.
        rr!rYrZr[i���r^Tr\r]N)rfrr rgrCrhr.r*r*r+rl�s
��zLoginModule._expire_cookiecCsD|jrd}|j|jf}nd}|jf}|j�||�D]\}|SdS)Nz8SELECT name FROM auth_cookie WHERE cookie=%s AND ipnr=%sz,SELECT name FROM auth_cookie WHERE cookie=%s)�check_ipr:rerC�db_query)r'r(rj�sql�argsr6r*r*r+rd�s�zLoginModule._cookie_to_namecCs"|�||�}|dur|�|�|S�N)rdrl)r'r(rjr6r*r*r+r$�s
z LoginModule._get_name_for_cookiec
Cs�|�|�}|rf|�d�s%tj�|j�dd�\}}tj�|||dddf�}|j�d�}|jd|�}|j|d�}|�d�}||�d�d�}	|	|ksR|	�|d�rf|	�d�||j	�d�krf|�
||	�|�
|���dS)z0Redirect the user back to the URL she came from.)zhttp://zhttps://N��:rZ)�_refererrP�urllib�parse�urlparse�base_url�
urlunparse�find�rstriprNrn�abs_href)
r'r(�referer�scheme�host�pos�base_scheme�
base_noscheme�base_noscheme_norm�referer_noschemer*r*r+rSs(

�
��zLoginModule._redirect_backcCs|j�d�p
|�d�S)Nr��Referer)rsrc�
get_headerr.r*r*r+rwszLoginModule._refererN)�__name__�
__module__�__qualname__�__doc__�
implementsrrr
�is_valid_default_handlerrrpr%r
rr	rr r,r/rKrOrTrQrRrlrdr$rSrwr*r*r*r+r&s>����
�	=	rc@seZdZedd��ZdS)�HTTPAuthenticationcCsdSrtr*)r'�environ�start_responser*r*r+�do_auth#szHTTPAuthentication.do_authN)r�r�r�rr�r*r*r*r+r�!sr�)�	metaclassc@seZdZdd�Zdd�ZdS)�PasswordFileAuthenticationcCs.||_t�|�j|_|�|j�t��|_dSrt)	�filename�os�stat�st_mtime�mtime�loadr�Lock�_lock)r'r�r*r*r+�__init__)sz#PasswordFileAuthentication.__init__cCsf|j�&t�|j�j}||jkr!||_|�|j�Wd�dSWd�dS1s,wYdSrt)r�r�r�r�r�r�r�)r'r�r*r*r+�check_reload/s
�"�z'PasswordFileAuthentication.check_reloadN)r�r�r�r�r�r*r*r*r+r�(sr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�BasicAuthenticationcCs"||_t|_i|_t�||�dSrt)�realmr�hashr�r�)r'�htpasswdr�r*r*r+r�9�zBasicAuthentication.__init__c
Cs�i|_t|dd��V}|D]K}|�d�d��}|sqz
|�d�dd�\}}Wnty;td||ftjd�Yqwd	|vsH|�d
�sH|j	rN||j|<qtd|tjd�qWd�n1sbwY|jikrvtd|tjd�dSdS)
N�utf-8��encoding�#rrvruz(Warning: invalid password line in %s: %s��file�$�{SHA}znWarning: cannot parse password for user "%s" without the "crypt" module. Install the passlib package from PyPIz Warning: found no users in file:)
r��open�split�strip�
ValueError�print�sys�stderrrPr)r'r��fd�line�u�hr*r*r+r�@s<�������

��zBasicAuthentication.loadcCs�|��|j�|�}|durdS|�d�r)ttt|�d�����d�|dd�kSd|vr9|�	||dd��|kS|dd��
d�dd�\}}d|d}t|||�|kS)	NFr�r��ascii�r�ru�)r�r�rcrP�strrr�encode�digestrr�r)r'r2�password�the_hash�magic�saltr*r*r+�testYs
�
�zBasicAuthentication.testc	Cs�|�d�}|r,|�d�r,tt|dd��d��d�}t|�dkr,|\}}|�||�r,|Sdd|jfd	g}|d
|�}|d�dS)N�HTTP_AUTHORIZATION�Basic�r�rvru�WWW-AuthenticatezBasic realm="%s"�zContent-Length�0�401 Unauthorized�)rcrPr�rr��lenr�r�)	r'r�r��header�authr2r��headers�writer*r*r+r�js
�
zBasicAuthentication.do_authN)r�r�r�r�r�r�r�r*r*r*r+r�7s
r�c@s>eZdZdZdZdd�Zdd�Zdd�Zdd
d�Zdd
�Z	dS)�DigestAuthenticationzEA simple HTTP digest authentication implementation
    (:rfc:`2617`).�dcCs"g|_||_i|_t�||�dSrt)�
active_noncesr�r�r�r�)r'�htdigestr�r*r*r+r�r�zDigestAuthentication.__init__c
Cs�i|_t|dd��F}|D];}|�d�d��}|sqz|�d�dd�\}}}Wnty<td||ftjd	�Yqw||jkrG||j|<qWd�n1sRwY|jikrgtd
|jtjd	�dSdS)zxLoad account information from apache style htdigest files,
        only users from the specified realm are used
        r�r�r�rrvN�z&Warning: invalid digest line in %s: %sr�z!Warning: found no users in realm:)	r�r�r�r�r�r�r�r�r�)r'r�r�r�r��r�a1r*r*r+r��s4���

���


��zDigestAuthentication.loadcCs\i}tj�|�D]#}|�dd�\}}|ddkr'|ddkr'|dd�||<q|||<q|S)N�=r�r�"���)rx�request�parse_http_listr�)r'�
authorization�valuesr:�n�vr*r*r+�parse_auth_header�s
z&DigestAuthentication.parse_auth_headerrcCsdt�}|j�|�t|j�|jkr|j|jd�|_dd|j||ffdg}|d|�}|d�dS)zdSend a digest challange to the browser. Record used nonces
        to avoid replay attacks.
        Nr�z5Digest realm="%s", nonce="%s", qop="auth", stale="%s"r�r�r�)rr��appendr��
MAX_NONCESr�)r'r�r��stale�noncer�r�r*r*r+�send_auth_request�s
���
z&DigestAuthentication.send_auth_requestcCs0|�d�}|r|�d�s|�||�dS|�|dd��}gd�}|D]}||vr2|�||�dSq#|��|d|jvrF|�||�dSdd�}|j|d}||d|d	g�}	|||d
|d|d|d
|	g�}
|d|
kr{|�||�dS|d
|jvr�|j||dd�dS|j�|d
�|dS)Nr��Digest�)�usernamer�r��uri�response�nc�cnoncer�cSstd�dd�|D�����S)N�:css�|]}|�d�VqdS)r�N)r�)�.0r�r*r*r+�	<genexpr>�s�zADigestAuthentication.do_auth.<locals>.<lambda>.<locals>.<genexpr>)r�join�	hexdigest)�xr*r*r+�<lambda>�sz.DigestAuthentication.do_auth.<locals>.<lambda>�REQUEST_METHODr�r�r�r��qopr��true)r�)rcrPr�r�r�r�r��remove)r'r�r�r�r��
required_keys�key�kdr��a2�correctr*r*r+r��s:
��zDigestAuthentication.do_authN)r)
r�r�r�r�r�r�r�r�r�r�r*r*r*r+r�ys

r�)/�abcrr�base64rr�hashlibrrr�rLr��urllib.parserx�urllib.request�trac.configrr	r
�	trac.core�trac.web.apirr
�trac.web.chromerr�	trac.utilrr�trac.util.compatr�trac.util.concurrencyr�trac.util.datefmtr�trac.util.htmlr�trac.util.translationrr�	Componentr�objectr�r�r�r�r*r*r*r+�<module>s0|B

https://t.me/RX1948 - 2025