
oTc           @   sP   d  d l  Z  d  d l Z d  d l m Z d d d  Z d d  Z d   Z d S(   iN(   t   httpauthc      	   C   s  d t  j j k rt j t  j j d  } | d  k rL t  j d d   n  | se t j t j } n  t	 |   r y> |    }  t
 |  t  s t d  n  |  j | d d   } Wqt k
 r |  | d  } qXn1 t
 |  t  s t d  n  |  j | d d   } t j | | d t  j j d | d | rE| d t  j _ t S| j d  sc| j d	  rt j d
 t  j j d  n  t t  j _ n  t S(   Nt   authorizationi  s   Bad Requests)   Authentication users must be a dictionaryt   usernamet   methodt   encryptt   realmt   passwords/   Attempt to login with wrong credentials from %ss   Remote-Addr(   t   cherrypyt   requestt   headersR    t   parseAuthorizationt   Nonet	   HTTPErrort   DIGEST_AUTH_ENCODERSt   MD5t   callablet
   isinstancet   dictt
   ValueErrort   gett	   TypeErrort   checkResponseR   t   logint   Truet   loggingt   infot   False(   t   usersR   R   t   ahR   (    (    s%   /var/www/SABnzbd/cherrypy/lib/auth.pyt
   check_auth   s4    		c         C   sB   t  | |  r d  St j |   t j j d <t j d d   d  S(   Ns   www-authenticatei  s.   You are not authorized to access that resource(   R   R    t	   basicAuthR   t   responseR	   R   (   R   R   R   (    (    s%   /var/www/SABnzbd/cherrypy/lib/auth.pyt
   basic_auth2   s    c         C   sE   t  | d |  r d  St j |   t j j d <t j d d   d  S(   NR   s   www-authenticatei  s.   You are not authorized to access that resource(   R   R    t
   digestAuthR   R   R	   R   (   R   R   (    (    s%   /var/www/SABnzbd/cherrypy/lib/auth.pyt   digest_authB   s    (   R   R   t   cherrypy.libR    R   R   R    R"   (    (    (    s%   /var/www/SABnzbd/cherrypy/lib/auth.pyt   <module>   s
   ,