
    Iil	                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	Z	ddl
mZ ddlZddlmZ dd	lmZ  e	j"                  d
      Zej'                  e	j(                         d Zej,                  j/                  d      s ej0                  d        eddd      Zej5                   e	j6                  d             ej9                  e        e       Z e       Z eeddge      Zd Z y)u%   Módulo de segurança da aplicação.    )Limiter)get_remote_address)LoginManager)
JWTManagerN)RotatingFileHandler)	timedeltasend_discord_audit_logsecurityc                 &    t        dd ddd        | S )NzAlerta de uso excessivo	RateLimitu-   Limite de requisições atingido (rate limit))actionuser_idobject_typedetails
ip_addressr	   responses    4/srv/www/ollama/chat-ollama/src/security/__init__.pyrate_limit_exceeded_callbackr      s     (? O    logszlogs/security.logi   
   )maxBytesbackupCountz)%(asctime)s - %(levelname)s - %(message)sz200 per dayz50 per hour)key_funcdefault_limits	on_breachc                    t        j                  dd      | j                  d<   t        d      | j                  d<   t        d      | j                  d<   t        j                  |        d	t        _        d
t        _        dt        _        t        j                  |        t        j                  |        d| j                  d<   d| j                  d<   d| j                  d<   t        d      | j                  d<   | j                  d        }y)u,   Inicializa as configurações de segurança.JWT_SECRET_KEYzyour-secret-key   )hoursJWT_ACCESS_TOKEN_EXPIRES   )daysJWT_REFRESH_TOKEN_EXPIRESz
auth.loginu1   Por favor, faça login para acessar esta página.infoTSESSION_COOKIE_SECURESESSION_COOKIE_HTTPONLYLaxSESSION_COOKIE_SAMESITEPERMANENT_SESSION_LIFETIMEc                 ~    d| j                   d<   d| j                   d<   d| j                   d<   d| j                   d<   | S )	NnosniffzX-Content-Type-Options
SAMEORIGINzX-Frame-Optionsz1; mode=blockzX-XSS-Protectionz#max-age=31536000; includeSubDomainszStrict-Transport-Security)headersr   s    r   add_security_headersz+init_security.<locals>.add_security_headersC   sK    5>12.:*+/>+,8]45r   N)osgetenvconfigr   login_managerinit_app
login_viewlogin_messagelogin_message_categoryjwtlimiterafter_request)appr1   s     r   init_securityr>   0   s    #%99-=?P#QCJJ -6Q-?CJJ)*.7R.@CJJ*+3+M"UM+1M(LLS*.CJJ&',0CJJ(),1CJJ()/8q/ACJJ+, r   )!__doc__flask_limiterr   flask_limiter.utilr   flask_loginr   flask_jwt_extendedr   logginglogging.handlersr   r2   datetimer   src.discord.discord_webhookr
   	getLoggersecurity_loggersetLevelINFOr   pathexistsmakedirssecurity_handlersetFormatter	Formatter
addHandlerr5   r:   r;   r>    r   r   <module>rT      s    + ! 1 $ )  0 	  >#'##J/    & 
ww~~fBKK& 
   /g///    + ,l
!=1*r   