ó
b=0Yc           @   s5  d  Z  d „  Z d d l Z d d l Z d d l Z d d l m Z d d l m	 Z	 m
 Z
 d d l m Z d d l m Z d Z d	 Z d
 Z d Z e j d e j e ƒ ƒ Z i d d 6d d 6d d 6d d 6d d 6d d 6Z e d „ Z e d „ Z e d „ Z d e d „ Z d d e d „ Z d e d „ Z d S(   t   DirectAdminc           C   s"   t  j j d ƒ p! t  j j d ƒ S(   Ns"   /usr/local/directadmin/directadmins(   /usr/local/directadmin/custombuild/build(   t   ost   patht   isfile(    (    (    sF   /usr/lib/python2.7/site-packages/clcommon/cpapi/plugins/directadmin.pyt   detect   s    iÿÿÿÿN(   t   load(   t   NoDBAccessDatat   CpApiTypeError(   t   _dblogin_cplogin_pairs(   t   ClPwds&   /usr/local/directadmin/conf/mysql.confs!   /usr/local/directadmin/data/userss	   user.confs/   /usr/local/directadmin/data/admin/reseller.lists
   .+/(.+)/%st   domaint   dnst   packaget   emailt   mailt   languaget   localet   namet   cplogint   resellerc         C   sˆ   t  ƒ  } y, t |  ƒ } | d | d <| d | d <WnL t k
 r` } t d t | ƒ ƒ ‚ n$ t k
 rƒ t d |  f ƒ ‚ n X| S(   Nt   usert   logint   passwdt   passs0   Can not open file with data to database access; s-   Can not get database access data from file %s(   t   dictt
   loadconfigt   IOErrorR   t   strt   KeyError(   t
   _conf_patht   accesst
   login_datat   err(    (    sF   /usr/lib/python2.7/site-packages/clcommon/cpapi/plugins/directadmin.pyt	   db_access%   s    	c         C   so   g  t  j  t j j |  d t ƒ ƒ D] } t j | ƒ ^ q" } g  | D] } | rD | j d ƒ ^ qD } t | ƒ S(   Nt   *i   (	   t   globR   R   t   joint	   USER_CONFt   USER_PATTERNt   matcht   groupt   tuple(   t   _pathR   t
   match_listR'   t
   users_list(    (    sF   /usr/lib/python2.7/site-packages/clcommon/cpapi/plugins/directadmin.pyt   cpusers3   s    =(c         C   s8   t  |  ƒ } t t j | j ƒ  ƒ } | j ƒ  t | ƒ S(   N(   t   opent   mapR   t   stript	   readlinest   closeR)   (   t   _resellers_patht   streamt   resellers_list(    (    sF   /usr/lib/python2.7/site-packages/clcommon/cpapi/plugins/directadmin.pyt	   resellers9   s    
c         C   s"   t  ƒ  } t d |  d | ƒ } | S(   Nt   cplogin_lstR   (   R!   R   (   R7   t   with_system_usersR   t   data(    (    sF   /usr/lib/python2.7/site-packages/clcommon/cpapi/plugins/directadmin.pyt   dblogin_cplogin_pairs@   s    	c         C   s  t  ƒ  } t |  t t f ƒ r* |  g } n¼ t |  t  t f ƒ rN t |  ƒ } n˜ |  d  k rÂ g  t j t j	 j
 | d t ƒ ƒ D] } t j | ƒ ^ q| } g  | D] } | rž | j d ƒ ^ qž } n$ t d d d d d t |  ƒ j ƒ ‚ t ƒ  } t t ƒ }	 x€ |	 D]x }
 t t j	 j
 t j	 j
 | |
 j ƒ  d ƒ ƒ ƒ } | j t g  | D] } | | k rH| |
 f ^ qHƒ ƒ | j ƒ  qWxŒ | D]„ }  t t j	 j
 | |  d	 ƒ ƒ } | j |  ƒ | d
 <t g  | D] } | j t j | ƒ ƒ ^ qÆƒ } | | k r…| j | ƒ q…q…W| S(   NR"   i   t   funcnamet   cpinfot   supportettypess   str|unicode|list|tuplet   received_types
   users.lists	   user.confR   (   t   listt
   isinstanceR   t   unicodeR)   t   NoneR#   t   iglobR   R   R$   R%   R&   R'   R(   R   t   typet   __name__R   R.   t   RESELLERS_LISTR0   t   updateR2   R   t   gett   USERCONF_PARAM_MAPt   append(   t   cpusert   keylsR*   t   returnedt   cpusers_listR   R+   R'   t   user_reseller_mapt   reseller_list_streamt   reseller_logint   reseller_cpuser_listt	   user_namet   cpuser_datat   keyt   cpuser_data_lst(    (    sF   /usr/lib/python2.7/site-packages/clcommon/cpapi/plugins/directadmin.pyR<   F   s0    	=+	0"1c         C   sê   g  } t  ƒ  } | j ƒ  } t |  t t f ƒ ry d t f d „  ƒ  Y} i  } x* |  D] \ } } | | | ƒ | | <qS Wn  xj | D]b } | d | d }	 t j j |	 ƒ r€ t j j	 | | j
 ƒ }
 |
 | k râ | j |
 ƒ qâ q€ q€ W| S(   s  
    Detects and returns list of folders contained the home dirs of users of the DirectAdmin

    :param str|None _sysusers: for testing
    :param str|None _path: for testing
    :return: list of folders, which are parent of home dirs of users of the panel
    t   pwc           B   s   e  Z d  „  Z RS(   c         S   s   | |  _  | |  _ d  S(   N(   t   pw_namet   pw_dir(   t   selfR   t   dir(    (    sF   /usr/lib/python2.7/site-packages/clcommon/cpapi/plugins/directadmin.pyt   __init__v   s    	(   RE   t
   __module__R\   (    (    (    sF   /usr/lib/python2.7/site-packages/clcommon/cpapi/plugins/directadmin.pyRW   u   s   t   /s
   /user.conf(   R	   t   get_user_dictR@   R?   R)   t   objectR   R   t   existst   dirnameRY   RJ   (   t	   _sysusersR*   t   homedirst   clpwdt
   users_dictRW   R   R[   RS   t	   conf_filet   homedir(    (    sF   /usr/lib/python2.7/site-packages/clcommon/cpapi/plugins/directadmin.pyRd   e   s    		(   R   R   R   s   resellerR   s   locale(   t
   __cpname__R   R   R#   t   ret   clcommon.clconfparsR   R   t   clcommon.cpapi.cpapiexceptionsR   R   t    clcommon.cpapi.plugins.universalR   t   clcommonR	   t
   DA_DB_CONFt   DA_USERS_PATHR%   RF   t   compilet   escapeR&   RI   R!   R-   R6   RB   t   FalseR:   R<   Rd   (    (    (    sF   /usr/lib/python2.7/site-packages/clcommon/cpapi/plugins/directadmin.pyt   <module>   s6   	
