MMCT TEAM
Server IP : 111.118.215.189  /  Your IP : 216.73.216.126
Web Server : Apache
System : Linux md-in-83.webhostbox.net 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User : a1673wkz ( 2475)
PHP Version : 8.2.25
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /usr/lib/python2.7/site-packages/pyzor/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : //usr/lib/python2.7/site-packages/pyzor/server.pyc
�
YF�Tc@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
ZyddlZWne
k
r�ddlZnXddlZddlZddlZddlZejjj�d�Zdejfd��YZdefd��YZdejefd	��YZd
efd��YZdejefd
��YZdej fd��YZ!dS(s�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.
i����NcGsQxJtrLy||�SWqtk
rH}|jdtjkrI�qIqXqWdS(s*restart a system call interrupted by EINTRiN(tTruetOSErrortargsterrnotEINTR(tfuncRte((s0/usr/lib/python2.7/site-packages/pyzor/server.pyt_eintr_retry/s	tServercBsJeZdZdZdZdd�Zd�Zd�Zd�Z	d�Z
RS(	s_The pyzord server.  Handles incoming UDP connections in a single
    thread and single process.i i�cCsld|dkrtjt_ntjt_tjd�|_tjd�|_||_	t
|j	dt�|_||_
||_i|_i|_|j�||_|jjd|�tjj||tdt�y |jjtjtjd�Wn/ttjfk
r'}|jjd|�nX|j�|j�tjtj |j!�tjtj"|j#�dS(	Nt:itpyzordspyzord-usagethandles_one_stepsListening on %stbind_and_activates%Unable to set IPV6_V6ONLY to false %s($tsockettAF_INET6Rtaddress_familytAF_INETtloggingt	getLoggertlogt	usage_logtdatabasetgetattrtFalsetone_stept	passwd_fnt	access_fntaccountstacltload_configt	forwardertdebugtSocketServert	UDPServert__init__tRequestHandlert
setsockopttIPPROTO_IPV6tIPV6_V6ONLYtAttributeErrorterrortserver_bindtserver_activatetsignaltSIGUSR1treload_handlertSIGTERMtshutdown_handler(tselftaddressRRRRR((s0/usr/lib/python2.7/site-packages/pyzor/server.pyR"?s0					
	 

cCs:tjj|j�|_tjj|j|j�|_dS(s>Reads the configuration files and loads the accounts and ACLs.N(tpyzortconfigtload_passwd_fileRRtload_access_fileRR(R0((s0/usr/lib/python2.7/site-packages/pyzor/server.pyRascOs3|jjd�tjd|j�}|j�dS(ssHandler for the SIGTERM signal. This should be used to kill the
        daemon and ensure proper clean-up.
        s SIGTERM received. Shutting down.ttargetN(Rtinfot	threadingtThreadtshutdowntstart(R0Rtkwargstt((s0/usr/lib/python2.7/site-packages/pyzor/server.pyR/fscOs3|jjd�tjd|j�}|j�dS(sgHandler for the SIGUSR1 signal. This should be used to reload
        the configuration files.
        s*SIGUSR1 received. Reloading configuration.R6N(RR7R8R9RR;(R0RR<R=((s0/usr/lib/python2.7/site-packages/pyzor/server.pyR-nscCs|jjd|dt�dS(Ns'Error while processing request from: %stexc_info(RR(R(R0trequesttclient_address((s0/usr/lib/python2.7/site-packages/pyzor/server.pythandle_errorvsN(t__name__t
__module__t__doc__tmax_packet_sizettime_diff_allowancetNoneR"RR/R-RA(((s0/usr/lib/python2.7/site-packages/pyzor/server.pyR9s!			t
PreForkServercBs8eZdZdd�Zdd�Zd�Zd�ZRS(s�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.
    icCs/d|_tj|||||�||_dS(svThe same as Server.__init__ but requires a list of databases
        instead of a single database connection.
        N(RGtpidsRR"t_prefork(R0R1RRRtprefork((s0/usr/lib/python2.7/site-packages/pyzor/server.pyR"�s	g�?cCs�g}xtt|j�D]c}|jj�}tj�}|sl|�|_tj|d|�tjd�q|j	|�qW||_
x$|j
D]}ttj|d�q�WdS(s=Fork the current process and wait for all children to finish.t
poll_intervaliN(
txrangeRJRtnexttostforkRt
serve_forevert_exittappendRIRtwaitpid(R0RLRItdummyRtpid((s0/usr/lib/python2.7/site-packages/pyzor/server.pyRQ�s	cCsPx*|jpdD]}tj|tj�qW|jdkrLtj|�ndS(spIf this is the parent process send the TERM signal to all children,
        else call the super method.
        N((RIROtkillR+R.RGRR:(R0RV((s0/usr/lib/python2.7/site-packages/pyzor/server.pyR:�scCsPx*|jpdD]}tj|tj�qW|jdkrLtj|�ndS(spIf this is the parent process send the USR1 signal to all children,
        else call the super method.
        N((RIRORWR+R,RGRR(R0RV((s0/usr/lib/python2.7/site-packages/pyzor/server.pyR�s(RBRCRDR"RQR:R(((s0/usr/lib/python2.7/site-packages/pyzor/server.pyRH{s
		tThreadingServercBseZdZRS(s�A threaded version of the pyzord server.  Each connection is served
    in a new thread.  This may not be suitable for all database types.(RBRCRD(((s0/usr/lib/python2.7/site-packages/pyzor/server.pyRX�stBoundedThreadingServercBs,eZdZdd�Zd�Zd�ZRS(s^Same as ThreadingServer but this also accepts a limited number of
    concurrent threads.
    cCs5tj|||||d|�tj|�|_dS(NR(RXR"R8t	Semaphoret	semaphore(R0R1RRRtmax_threadstforwarding_server((s0/usr/lib/python2.7/site-packages/pyzor/server.pyR"�scCs$|jj�tj|||�dS(N(R[tacquireRXtprocess_request(R0R?R@((s0/usr/lib/python2.7/site-packages/pyzor/server.pyR_�s
cCs$tj|||�|jj�dS(N(RXtprocess_request_threadR[trelease(R0R?R@((s0/usr/lib/python2.7/site-packages/pyzor/server.pyR`�sN(RBRCRDRGR"R_R`(((s0/usr/lib/python2.7/site-packages/pyzor/server.pyRY�s	t
ProcessServercBseZdZddd�ZRS(s�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.
    i(cCs,|t_tj|||||d|�dS(NR(Rbtmax_childrenRR"(R0R1RRRRcR]((s0/usr/lib/python2.7/site-packages/pyzor/server.pyR"�s	N(RBRCRDRGR"(((s0/usr/lib/python2.7/site-packages/pyzor/server.pyRb�sR#cBs�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zidd
6ed6ed6ed
6e	d6e
d6Z
RS(sHandle a single pyzord request.cOs,tjj�|_tjj|||�dS(N(temailtmessagetMessagetresponseR tDatagramRequestHandlerR"(R0RR<((s0/usr/lib/python2.7/site-packages/pyzor/server.pyR"�scCs�d|jd<d|jd<dtj|jd<y|j�Wn
tk
re}|jdd|�n�tjk
r�}|jd	d
|�n�tjk
r�}|jdd|�n�tjk
r�}|jd
d|�nitj	k
r	}|jdd|�n@t
k
rH}|jdd|�|jjj
tj��nX|jjjd|jj��|jj|jj�jd��dS(s7Handle a pyzord operation, cleanly handling any errors.t200tCodetOKtDiags%stPVi�sNot implemented: %si�sVersion Not Supported: %si�sBad request: %si�s!Unauthorized: Signature Error: %si�s
Forbidden: %si�sInternal Server Error: %ssSending: %rtutf8N(RgR2t
proto_versiont_really_handletNotImplementedErrorRAtUnsupportedVersionErrort
ProtocolErrortSignatureErrortAuthorizationErrort	ExceptiontserverRR(t	tracebackt
format_excRt	as_stringtwfiletwritetencode(R0R((s0/usr/lib/python2.7/site-packages/pyzor/server.pythandle�s(

c
Cs0|jjjd|j�tj|jj�jdd�d�}|d|j	d<|dpbt
j}|t
jkr�y!t
jj
||jj|�Wq�tk
r�t
jd��q�Xnd|kr�t
jd��ny8tt|d��tt
j�krt
j��nWn:tk
rM|jjjd	|d�t
jd
��nX|d}||jj|kr�t
jd��n|jjjd
||jd�y|j|}Wntk
r�td��nX|jd�}|r�|r�|||�n|jjjd||jd|||j	d�dS(s(handle() without the exception handling.sReceived: %rs

s
R9tUsers
Unknown user.Rms)Protocol Version not specified in requestsInvalid PV: %ssInvalid Protocol VersiontOps0User is not authorized to request the operation.sGot a %s command from %sis'Requested operation is not implemented.s	Op-Digests%s,%s,%s,%r,%sRjN( RwRRtpacketRdtmessage_from_bytestrfiletreadtreplaceRgR2tanonymous_usertaccounttverify_signatureRtKeyErrorRtRstinttfloatRoRrt
ValueErrortwarnRRuR@t
dispatchesRqtget_allRR7(R0R?tusertopcodetdispatchtdigests((s0/usr/lib/python2.7/site-packages/pyzor/server.pyRp�sF"
%


cCsG|jjjd||�|jjdd|�|jjd|�dS(s,Create an appropriate response for an error.s%s: %sRjs%dRlN(RwRR(Rgtreplace_header(R0tcodeRe((s0/usr/lib/python2.7/site-packages/pyzor/server.pyRA/scCs?|jjjd|d�dtj|jd<d|jd<dS(skHandle the 'pong' command.

        This command returns maxint for report counts and 0 whitelist.
        sRequest pong for %sis%dtCountsWL-CountNt0(RwRRtsystmaxintRg(R0R�((s0/usr/lib/python2.7/site-packages/pyzor/server.pythandle_pong5scCs�|d}y|jj|}Wn#tk
rCtjjj�}nX|jjjd|�d|j	|j
d<d|j|j
d<dS(spHandle the 'check' command.

        This command returns the spam/ham counts for the specified digest.
        isRequest to check digest %ss%dR�sWL-CountN(RwRR�R2tenginestcommontRecordRRtr_countRgtwl_count(R0R�tdigesttrecord((s0/usr/lib/python2.7/site-packages/pyzor/server.pythandle_check>s

cCs�|jjjd|�|jjr8|jjj|�nexb|D]Z}y|jj|}Wn#tk
r~tjj	j
�}nX|j�||jj|<q?W|jjr�x$|D]}|jjj
|�q�WndS(swHandle the 'report' command in a single step.

        This command increases the spam count for the specified digests.sRequest to report digests %sN(RwRRRRtreportR�R2R�R�R�tr_incrementRtqueue_forward_request(R0R�R�R�((s0/usr/lib/python2.7/site-packages/pyzor/server.pyt
handle_reportLs



cCs�|jjjd|�|jjr8|jjj|�nexb|D]Z}y|jj|}Wn#tk
r~tjj	j
�}nX|j�||jj|<q?W|jjr�x'|D]}|jjj
|t�q�WndS(syHandle the 'whitelist' command in a single step.

        This command increases the ham count for the specified digests.sRequest to whitelist digests %sN(RwRRRRt	whitelistR�R2R�R�R�twl_incrementRR�R(R0R�R�R�((s0/usr/lib/python2.7/site-packages/pyzor/server.pythandle_whitelist_s



cCs�|d}y|jj|}Wn#tk
rCtjjj�}nX|jjjd|�d�}d||j	�|j
d<d||j�|j
d<d||j�|j
d<d||j
�|j
d<d|j|j
d	<d|j|j
d
<dS(s�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).
        is'Request for information about digest %scSs|s
dStj|j��S(soConvert a datetime object to a POSIX timestamp.

            If the object is None, then return 0.
            i(ttimetmktimet	timetuple(ttime_obj((s0/usr/lib/python2.7/site-packages/pyzor/server.pyttime_output�ss%dtEnteredtUpdateds
WL-Entereds
WL-UpdatedR�sWL-CountN(RwRR�R2R�R�R�RRt	r_enteredRgt	r_updatedt
wl_enteredt
wl_updatedR�R�(R0R�R�R�R�((s0/usr/lib/python2.7/site-packages/pyzor/server.pythandle_infors

		tpingtpongR7tcheckR�R�N(RBRCRDR"R~RpRAR�R�R�R�R�RGR�(((s0/usr/lib/python2.7/site-packages/pyzor/server.pyR#�s"			>							("RDROR�R�RR
R+RR8Rxt
email.messageRdR tImportErrortsocketservertpyzor.configR2t
pyzor.accounttpyzor.engines.commontpyzor.hacks.py26thackstpy26thack_allRR!RRHtThreadingMixInRXRYtForkingMixInRbRhR#(((s0/usr/lib/python2.7/site-packages/pyzor/server.pyt<module>s4
	
B2

MMCT - 2023