
ubSc           @   sb   d  d k  l  Z  d  d k l Z d  d k Z d  d k l Z d  d k Z d e  f d     YZ d S(   i(   t   cPanel(   t   encodestringN(   t	   xmlToDictt   WHMc           B   s   e  Z d  Z d d e d d  Z d   Z d   Z d   Z d d d	 d
 d d
 d d d d d d d d d d
 d  Z	 d   Z
 RS(   s;   
    Class object for a WHM account, root or reseller.
    t    i&  c      	   C   sv   t  i |  | | | d | d | t |  _ | o d | d | |  _ n( t d | | f  d  } d | |  _ d  S(   Nt   sslt   ports   WHM t   :s   %s:%sis   Basic %s(   R    t   __init__t   Falset   whmt
   authheaderR   (   t   selft   servert   usernamet   passwordt   hashR   R   t   base64string(    (    s#   /root/bin/ikeamodules/cPanel/WHM.pyR      s    "	c         C   s  t  |  _ yZ |  i } | d 7} t i |  } | i d |  i  t i |  } d  } | i	   } Wn t i
 j
 o } t | d  o! |  i i d t | i   qt | d  oO | i d j o |  i i d  q	| i d j o |  i i d	  q	  qn Xt |  _ |  i S(
   Ns   /xml-api/myprivst   Authorizationt   reasons   WHM: t   codei  s%   WHM: Invalid username and/or passwordi  s8   WHM: Could not access WHM due to a '403 Forbidden' error(   R	   R
   t   baseurlt   urllib2t   Requestt
   add_headerR   t   urlopent   Nonet   readt   URLErrort   hasattrt   errorst   appendt   strR   R   t   True(   R   t   urlt   reqt   handlet   datat   e(    (    s#   /root/bin/ikeamodules/cPanel/WHM.pyt	   checkInfo    s(    		
!	c         C   s9  g  } yX |  i  } | d | 7} t i |  } | i d |  i  t i |  } | i   } Wn t i j
 o } t | d  o | i	 d t
 | i   q t | d  oI | i d j o | i	 d  q | i d j o | i	 d	  q   q n Xy t |  } Wn | i	 d
  n X| d d | f S(   s   
        Returns a tuple of the XML representation of the accountsummary data for
        the requested account and any errors encountered.
        s   /xml-api/accountsummary?user=%sR   R   s   WHM: R   i  s   WHM: Invalid access detailsi  s8   WHM: Could not access WHM due to a '403 Forbidden' errorsV   WHM: failed to fetch account information from server, server returned garbage XML datat   accti    (   R   R   R   R   R   R   R   R   R   R   R    R   R   R   (   R   t   accountR   R"   R#   R$   R%   R&   (    (    s#   /root/bin/ikeamodules/cPanel/WHM.pyt
   getSummary9   s,    	c         C   ss   |  i  } | d | 7} | d 7} | GHt i |  } | i d |  i  t i |  } | i   } t |  } | S(   NsO   /xml-api/cpanel?user=%s&cpanel_xmlapi_apiversion=2&cpanel_xmlapi_module=Backupss#   &cpanel_xmlapi_func=listfullbackupsR   (   R   R   R   R   R   R   R   R   (   R   R)   R"   R#   R$   R%   (    (    s#   /root/bin/ikeamodules/cPanel/WHM.pyt   test   s    	
i   i  t   defaulti    i   t   x3t   Englisht	   unlimitedc         C   s   |  i  } | d | | | | | f 7} | d | | |
 | | f 7} | d | | | | f 7} | d | | f 7} | GHt i |  } | i d |  i  t i |  } | i   } t |  } | S(   Ns<   /xml-api/addpkg?name=%s&featurelist=%s&quota=%d&ip=%d&cgi=%ds4   &frontpage=%d&cpmod=%s&maxftp=%s&maxsql=%s&maxpop=%ss+   &maxlst=%s&maxsub=%s&maxpark=%s&maxaddon=%ss   &hasshell=%d&bwlimit=%sR   (   R   R   R   R   R   R   R   R   (   R   t   namet   quotat   bwlimitt   featurelistt   ipt   cgit	   frontpaget   cpmodt   languaget   maxftpt   maxsqlt   maxpopt   maxlstt   maxsubt   maxparkt   maxaddont   hasshellR"   R#   R$   R%   (    (    s#   /root/bin/ikeamodules/cPanel/WHM.pyt
   addPackage   s    	c         C   so   |  i  } | d | | f 7} | GHt i |  } | i d |  i  t i |  } | i   } t |  } | S(   Ns%   /xml-api/changepackage?user=%s&pkg=%sR   (   R   R   R   R   R   R   R   R   (   R   R)   t   packageR"   R#   R$   R%   (    (    s#   /root/bin/ikeamodules/cPanel/WHM.pyt
   setPackage   s    	N(   t   __name__t
   __module__t   __doc__R   R!   R   R'   R*   R+   RA   RC   (    (    (    s#   /root/bin/ikeamodules/cPanel/WHM.pyR      s   			(	   R    t   base64R   R   t   helpersR   t   xml.parsers.expatt   xmlR   (    (    (    s#   /root/bin/ikeamodules/cPanel/WHM.pyt   <module>   s
   