%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3.6/site-packages/pyzor/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3.6/site-packages/pyzor/__pycache__/server.cpython-36.pyc

3

�2�^�=�
@s"dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
ZyddlZWne
k
r|ddlZYnXddlZddlZddlZddlZejjj�dd�ZGdd�dej�ZGdd�de�ZGd	d
�d
eje�ZGdd�de�ZGd
d�deje�ZGdd�dej �Z!dS)a�Networked spam-signature detection server.

The server receives the request in the form of a RFC5321 message, and
responds with another RFC5321 message.  Neither of these messages has a
body - all of the data is encapsulated in the headers.

The response headers will always include a "Code" header, which is a
HTTP-style response code, and a "Diag" header, which is a human-readable
message explaining the response code (typically this will be "OK").

Both the request and response headers always include a "PV" header, which
indicates the protocol version that is being used (in a major.minor format).
Both the requestion and response headers also always include a "Thread",
which uniquely identifies the request (this is a requirement of using UDP).
Responses to requests may arrive in any order, but the "Thread" header of
a response will always match the "Thread" header of the appropriate request.

Authenticated requests must also have "User", "Time" (timestamp), and "Sig"
(signature) headers.
�NcGsHxBy||�Stk
r>}z|jdtjkr.�WYdd}~XqXqWdS)z*restart a system call interrupted by EINTRrN)�OSError�args�errnoZEINTR)�funcr�e�r�/usr/lib/python3.6/server.py�_eintr_retry/sr	c@sBeZdZdZdZdZddd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dS)�Serverz_The pyzord server.  Handles incoming UDP connections in a single
    thread and single process.i �NcCsd|dkrtjt_ntjt_tjd�|_tjd�|_||_	t
|j	dd�|_||_||_
i|_i|_|j�||_|jjd|�tjj||tdd�y|jjtjtjd�Wn6ttjfk
r�}z|jjd	|�WYdd}~XnX|j�|j�tjtj|j �tjtj!|j"�dS)
N�:rZpyzordzpyzord-usageZhandles_one_stepFzListening on %s)Zbind_and_activatez%Unable to set IPV6_V6ONLY to false %s)#�socketZAF_INET6r
Zaddress_familyZAF_INET�loggingZ	getLogger�log�	usage_log�database�getattr�one_step�	passwd_fn�	access_fn�accounts�acl�load_config�	forwarder�debug�SocketServer�	UDPServer�__init__�RequestHandlerZ
setsockoptZIPPROTO_IPV6ZIPV6_V6ONLY�AttributeError�errorZserver_bindZserver_activate�signal�SIGUSR1�reload_handler�SIGTERM�shutdown_handler)�self�addressrrrrrrrrr?s0
 zServer.__init__cCs(tjj|j�|_tjj|j|j�|_dS)z>Reads the configuration files and loads the accounts and ACLs.N)�pyzor�configZload_passwd_filerrZload_access_filerr)r&rrrraszServer.load_configcOs&|jjd�tj|jd�}|j�dS)zsHandler for the SIGTERM signal. This should be used to kill the
        daemon and ensure proper clean-up.
        z SIGTERM received. Shutting down.)�targetN)r�info�	threading�Thread�shutdown�start)r&r�kwargs�trrrr%fszServer.shutdown_handlercOs&|jjd�tj|jd�}|j�dS)zgHandler for the SIGUSR1 signal. This should be used to reload
        the configuration files.
        z*SIGUSR1 received. Reloading configuration.)r*N)rr+r,r-rr/)r&rr0r1rrrr#nszServer.reload_handlercCs|jjd|dd�dS)Nz'Error while processing request from: %sT)�exc_info)rr )r&�request�client_addressrrr�handle_errorvszServer.handle_error)N)�__name__�
__module__�__qualname__�__doc__Zmax_packet_sizeZtime_diff_allowancerrr%r#r5rrrrr
9s
!r
c@s4eZdZdZd
dd�Zddd�Zdd	�Zd
d�ZdS)�
PreForkServerz�The same as Server, but prefork itself when starting the self, by
    forking a number of child-processes.

    The parent process will then wait for all his child process to complete.
    �cCs"d|_tj|||||�||_dS)zvThe same as Server.__init__ but requires a list of databases
        instead of a single database connection.
        N)�pidsr
r�_prefork)r&r'rrrZpreforkrrrr�szPreForkServer.__init__��?cCs�g}xTt|j�D]F}t|j�}tj�}|sL|�|_tj||d�tjd�q|j	|�qW||_
x|j
D]}ttj|d�qhWdS)z=Fork the current process and wait for all children to finish.)�
poll_intervalrN)
�ranger=�nextr�os�forkr
�
serve_forever�_exit�appendr<r	�waitpid)r&r?r<Zdummyr�pidrrrrD�s
zPreForkServer.serve_forevercCs:x |jp
fD]}tj|tj�qW|jdkr6tj|�dS)zpIf this is the parent process send the TERM signal to all children,
        else call the super method.
        N)r<rB�killr!r$r
r.)r&rHrrrr.�s
zPreForkServer.shutdowncCs:x |jp
fD]}tj|tj�qW|jdkr6tj|�dS)zpIf this is the parent process send the USR1 signal to all children,
        else call the super method.
        N)r<rBrIr!r"r
r)r&rHrrrr�s
zPreForkServer.load_configN)r;)r>)r6r7r8r9rrDr.rrrrrr:{s


	r:c@seZdZdZdS)�ThreadingServerz�A threaded version of the pyzord server.  Each connection is served
    in a new thread.  This may not be suitable for all database types.N)r6r7r8r9rrrrrJ�srJc@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
�BoundedThreadingServerz^Same as ThreadingServer but this also accepts a limited number of
    concurrent threads.
    NcCs&tj||||||d�tj|�|_dS)N)r)rJrr,Z	Semaphore�	semaphore)r&r'rrrZmax_threads�forwarding_serverrrrr�szBoundedThreadingServer.__init__cCs|jj�tj|||�dS)N)rL�acquirerJ�process_request)r&r3r4rrrrO�s
z&BoundedThreadingServer.process_requestcCstj|||�|jj�dS)N)rJ�process_request_threadrL�release)r&r3r4rrrrP�sz-BoundedThreadingServer.process_request_thread)N)r6r7r8r9rrOrPrrrrrK�s
rKc@seZdZdZddd�ZdS)�
ProcessServerz�A multi-processing version of the pyzord server.  Each connection is
    served in a new process. This may not be suitable for all database types.
    �(NcCs |t_tj||||||d�dS)N)r)rR�max_childrenr
r)r&r'rrrrTrMrrrr�szProcessServer.__init__)rSN)r6r7r8r9rrrrrrR�srRc@sjeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdeee	e
ed�Z
dS)rzHandle a single pyzord request.cOs$tjj�|_tjj|f|�|�dS)N)�email�messageZMessage�responser�DatagramRequestHandlerr)r&rr0rrrr�szRequestHandler.__init__cCs�d|jd<d|jd<dtj|jd<y|j�W�nBtk
rf}z|jdd|�WYd	d	}~X�ntjk
r�}z|jd
d|�WYd	d	}~Xn�tjk
r�}z|jdd
|�WYd	d	}~Xn�tjk
r�}z|jdd|�WYd	d	}~Xnztj	k
�r0}z|jdd|�WYd	d	}~XnFt
k
�rt}z(|jdd|�|jjj
tj��WYd	d	}~XnX|jjjd|jj��|jj|jj�jd��d	S)z7Handle a pyzord operation, cleanly handling any errors.Z200�CodeZOK�Diagz%s�PVi�zNot implemented: %sNi�zVersion Not Supported: %si�zBad request: %si�z!Unauthorized: Signature Error: %si�z
Forbidden: %si�zInternal Server Error: %szSending: %r�utf8)rWr(�
proto_version�_really_handle�NotImplementedErrorr5�UnsupportedVersionError�
ProtocolError�SignatureError�AuthorizationError�	Exception�serverrr �	traceback�
format_excrZ	as_stringZwfile�write�encode)r&rrrr�handle�s(

"    $zRequestHandler.handlec Cs�|jjjd|j�tj|jj�jdd�d�}|d|j	d<|dpHt
j}|t
jkr�yt
jj
||jj|�Wntk
r�t
jd��YnXd|kr�t
jd��y&tt|d��tt
j�kr�t
j��Wn2tk
r�|jjjd	|d�t
jd
��YnX|d}||jj|k�rt
jd��|jjjd
||jd�y|j|}Wntk
�rbtd��YnX|jd�}|�r�|�r�|||�|jjjd||jd|||j	d�dS)z(handle() without the exception handling.zReceived: %rs

�
r-ZUserz
Unknown user.r[z)Protocol Version not specified in requestzInvalid PV: %szInvalid Protocol VersionZOpz0User is not authorized to request the operation.zGot a %s command from %srz'Requested operation is not implemented.z	Op-Digestz%s,%s,%s,%r,%srYN) rerrZpacketrUZmessage_from_bytesZrfile�read�replacerWr(Zanonymous_userZaccountZverify_signaturer�KeyErrorrbra�int�floatr]r`�
ValueError�warnrrcr4�
dispatchesr_Zget_allrr+)r&r3�userZopcode�dispatch�digestsrrrr^�sF



zRequestHandler._really_handlecCs6|jjjd||�|jjdd|�|jjd|�dS)z,Create an appropriate response for an error.z%s: %srYz%drZN)rerr rWZreplace_header)r&�coderVrrrr5/szRequestHandler.handle_errorcCs6|jjjd|d�dtj|jd<dd|jd<dS)zkHandle the 'pong' command.

        This command returns maxint for report counts and 0 whitelist.
        zRequest pong for %srz%d�CountzWL-CountN)rerr�sys�maxsizerW)r&rvrrr�handle_pong5szRequestHandler.handle_pongcCsn|d}y|jj|}Wn tk
r8tjjj�}YnX|jjjd|�d|j	|j
d<d|j|j
d<dS)zpHandle the 'check' command.

        This command returns the spam/ham counts for the specified digest.
        rzRequest to check digest %sz%drxzWL-CountN)rerrnr(�engines�common�Recordrr�r_countrW�wl_count)r&rv�digest�recordrrr�handle_check>szRequestHandler.handle_checkcCs�|jjjd|�|jjr(|jjj|�nTxR|D]J}y|jj|}Wn tk
rbtjj	j
�}YnX|j�||jj|<q.W|jjr�x|D]}|jjj
|�q�WdS)zwHandle the 'report' command in a single step.

        This command increases the spam count for the specified digests.zRequest to report digests %sN)rerrrr�reportrnr(r|r}r~Zr_incrementr�queue_forward_request)r&rvr�r�rrr�
handle_reportLs

zRequestHandler.handle_reportcCs�|jjjd|�|jjr(|jjj|�nTxR|D]J}y|jj|}Wn tk
rbtjj	j
�}YnX|j�||jj|<q.W|jjr�x|D]}|jjj
|d�q�WdS)zyHandle the 'whitelist' command in a single step.

        This command increases the ham count for the specified digests.zRequest to whitelist digests %sTN)rerrrr�	whitelistrnr(r|r}r~Zwl_incrementrr�)r&rvr�r�rrr�handle_whitelist_s

zRequestHandler.handle_whitelistcCs�|d}y|jj|}Wn tk
r8tjjj�}YnX|jjjd|�dd�}d||j	�|j
d<d||j�|j
d<d||j�|j
d<d||j
�|j
d	<d|j|j
d
<d|j|j
d<dS)
z�Handle the 'info' command.

        This command returns diagnostic data about a digest (timestamps for
        when the digest was first/last seen as spam/ham, and spam/ham
        counts).
        rz'Request for information about digest %scSs|sdStj|j��S)zoConvert a datetime object to a POSIX timestamp.

            If the object is None, then return 0.
            r)�timeZmktimeZ	timetuple)Ztime_objrrr�time_output�sz/RequestHandler.handle_info.<locals>.time_outputz%dZEnteredZUpdatedz
WL-Enteredz
WL-UpdatedrxzWL-CountN)rerrnr(r|r}r~rrZ	r_enteredrWZ	r_updatedZ
wl_enteredZ
wl_updatedrr�)r&rvr�r�r�rrr�handle_infors
	zRequestHandler.handle_infoN)ZpingZpongr+Zcheckr�r�)r6r7r8r9rrjr^r5r{r�r�r�r�rsrrrrr�s >	 r)"r9rBryr�rr
r!rr,rfZ
email.messagerUr�ImportErrorZsocketserverZpyzor.configr(Z
pyzor.accountZpyzor.engines.commonZpyzor.hacks.py26ZhacksZpy26Zhack_allr	rr
r:ZThreadingMixInrJrKZForkingMixInrRrXrrrrr�<module>s4
B2

Zerion Mini Shell 1.0