Ñò
ubSc        
   @   s{   d  d k  Z  d  d k Z d  d k l Z d  d k l Z d  d k l Z d  d k l Z d  d k	 Z
 d d d „  ƒ  YZ d S(	   iÿÿÿÿN(   t   encodestring(   t   urlparse(   t	   xmlToDict(   t
   itemgettert   cPanelc           B   s\   e  Z d  Z d d „ Z d e e d „ Z d d „ Z d d „ Z d d „ Z	 d d „ Z
 RS(	   s\   Class which handles functions and methods and holds information for a single cPanel account.i#  c         C   s’  | |  _  | |  _ | |  _ | |  _ t |  _ t |  _ g  |  _ d  |  _	 d  |  _
 t |  _ h  |  _ d |  i d <d  |  i d <d  |  i d <d  |  i d <d  |  i d <d  |  i d <d  |  i d <d  |  i d	 <d  |  i d <d |  i d
 <t |  i d <d |  i d <| |  i d <g  |  i d <g  |  _ | p# d | d t | d ƒ |  _ n d | d t | ƒ |  _ t d | | f ƒ d  } d | |  _ d  S(   Ns   ???t   primarydomaint	   diskusaget	   disklimitt   diskusageperct   diskspaceunitst	   numaddonst   dbst	   numemailst   hostnamet   resellert    t   movedcpbackupt   sslt   domainss   http://t   :i   s   https://s   %s:%siÿÿÿÿs   Basic %s(   t   servert   usernamet   passwordt   ftpcheckt   Falset   ftpt   cpanelt   backupst   Nonet
   backupfilet   dledfilet   skiphomet   infot   errorst   strt   baseurlR    t
   authheader(   t   selfR   R   R   t   usesslR   t   portt   base64string(    (    s&   /root/bin/ikeamodules/cPanel/cPanel.pyt   __init__   s>    												#c      *   C   s>  g  |  _  | d  j o |  i } n t |  _ t |  _ y´ d |  i d } | d | 7} t i | ƒ } | i	 d |  i
 ƒ t i | ƒ } d  } | i ƒ  } y' d  } t | ƒ d } t |  i d <Wn$ t |  i d <|  i  i d ƒ n XWn t i j
 o	 }	 n X| oºy|  i } | d | 7} | d	 7} t i | ƒ } | i	 d |  i
 ƒ t i | ƒ } d  } | i ƒ  } y d  } t | ƒ d
 } Wn |  i  i d ƒ d  } n X| oTy:x3| D]+}
 |
 d d d j o |
 d d |  i d <q½|
 d d d j o |
 d d |  i d <q½|
 d d d j o |
 d d |  i d <q½|
 d d d j oX |
 d d |  i d <|
 d d |  i d <|
 d d |  i d <|
 d d |  i d <q½|
 d d d j o |
 d d |  i d <q½q½WWqt j
 o qXn |  i d } t i | ƒ } | i	 d |  i
 ƒ t i | ƒ } d  } | i ƒ  } y d  } t | ƒ d
 } Wn$ d |  i d  <|  i  i d! ƒ n X| om yF x? | D]7 }
 |
 d" d |  i d  <|  i d# i |
 d" d ƒ q©WWqt j
 o d |  i d  <qXn |  i d  i d$ ƒ o d |  i d  <n |  i } | d% | 7} | d& 7} t i | ƒ } | i	 d |  i
 ƒ t i | ƒ } d  } | i ƒ  } yG d  } t | ƒ d
 } x* | D]" }
 |  i d# i |
 d' d ƒ q¸WWn> t j
 o n- t i i i j
 o |  i  i d( ƒ n X|  i } | d) | 7} | d* 7} t i | ƒ } | i	 d |  i
 ƒ t i | ƒ } d  } | i ƒ  } yG d  } t | ƒ d
 } x* | D]" }
 |  i d# i |
 d' d ƒ q¤WWn> t j
 o n- t i i i j
 o |  i  i d+ ƒ n XWn¨ t i j
 o™ }	 t |	 d, ƒ o! |  i  i d- t |	 i ƒ ƒ qÁt |	 d. ƒ oO |	 i d/ j o |  i  i d0 ƒ q³|	 i d1 j o |  i  i d2 ƒ q³‚  qÁqÅXt |  _ n | on |  i od y+ t i |  i |  i |  i  ƒ } t |  _ Wq:t i! j
 o# }	 |  i  i d3 t |	 ƒ ƒ q:Xn d  S(4   Ns   https://s   :2087s   /xml-api/acctcounts?user=%st   Authorizationt   resultR   s2   WHM: failed to parse reseller account information.sM   /xml-api/cpanel?user=%s&cpanel_xmlapi_module=StatsBar&cpanel_xmlapi_func=stats^   &display=diskusage|addondomains|sqldatabases|hostname|emailaccounts&cpanel_xmlapi_apiversion=2t   datasY   cPanel: failed to fetch account information from server, server returned garbage XML datat   namei    t   sqldatabasest   _countR   t   addondomainsR
   t   emailaccountsR   R   t   _maxR   t   unitsR	   t   percentR   R   t   valuesm   /xml-api/cpanel?cpanel_xmlapi_apiversion=2&cpanel_xmlapi_module=DomainLookup&cpanel_xmlapi_func=getmaindomains   ???R   sH   cPanel: failed to check primary domain, server returned garbage XML datat   main_domainR   s   Remote executions2   /xml-api/cpanel?user=%s&cpanel_xmlapi_apiversion=2sE   &cpanel_xmlapi_module=AddonDomain&cpanel_xmlapi_func=listaddondomainst   domainsR   cPanel: failed fetching addon domain information, server returned garbage XML datas1   /xml-api/cpanel?user=%s&cpanel_xmlapi_module=Parks@   &cpanel_xmlapi_func=listparkeddomains&cpanel_xmlapi_apiversion=2sS   cPanel: failed fetching parked domain information, server returned garbage XML datat   reasons   cPanel: t   codei‘  s(   cPanel: Invalid username and/or passwordi“  s>   cPanel: Could not access cPanel due to a '403 Forbidden' errors   FTP: ("   R!   R   R   R   R   R   R   t   urllib2t   Requestt
   add_headerR$   t   urlopent   readR   t   TrueR    t   appendt   URLErrorR#   t   KeyErrort
   startswitht   xmlt   parserst   expatt
   ExpatErrort   hasattrR"   R8   R9   R   t   ftplibt   FTPR   t
   all_errors(   R%   t   accountR   R   t   urlt   reqt   handleR,   t   dresultt   et   piece(    (    s&   /root/bin/ikeamodules/cPanel/cPanel.pyt   refreshInfo@   s   				

 !	 $		
 $	
 $	!#c   
      C   s   | d  j o |  i } n yn g  } d  } |  i } | d | 7} | d 7} t i | ƒ } | i d |  i ƒ t i | ƒ } | 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 o² y— t | ƒ } x[ | d D]O }	 | i h |	 d d d 6|	 d d d 6|	 d d d 6|	 d d d 6ƒ q`W| i d t d ƒ d t ƒ | |  _ t SWqüt j
 o t SXn t Sd  S(   NsO   /xml-api/cpanel?user=%s&cpanel_xmlapi_apiversion=2&cpanel_xmlapi_module=Backupss#   &cpanel_xmlapi_func=listfullbackupsR*   R8   s   cPanel: R9   i‘  s(   cPanel: Invalid username and/or passwordi“  s>   cPanel: Could not access cPanel due to a '403 Forbidden' errorR,   t   filei    t	   localtimet   statust   timet   keyt   reverse(   R   R   R#   R:   R;   R<   R$   R=   R>   RA   RH   R!   R@   R"   R8   R9   R?   R   R   t   sortR   R   RB   R   (
   R%   RL   R   R,   RM   RN   RO   RQ   R+   RR   (    (    s&   /root/bin/ikeamodules/cPanel/cPanel.pyt   getBackupListÜ   sD    	
!	
 M	
c         C   sˆ   | d  j o |  i } n |  i } | d | 7} | d 7} t i | ƒ } | i d |  i ƒ t i | ƒ } | i ƒ  } t	 | ƒ } | S(   NsO   /xml-api/cpanel?user=%s&cpanel_xmlapi_apiversion=1&cpanel_xmlapi_module=Filemans   &cpanel_xmlapi_func=fullbackupR*   (
   R   R   R#   R:   R;   R<   R$   R=   R>   R   (   R%   RL   RM   RN   RO   R,   (    (    s&   /root/bin/ikeamodules/cPanel/cPanel.pyt   startBackup  s    	
c         C   sŒ   | d  j o |  i } n |  i } | d | 7} | d | 7} t i | ƒ } | i d |  i ƒ t i | ƒ } | i ƒ  } t	 | ƒ } | S(   Ns]   /xml-api/cpanel?cpanel_xmlapi_user=%s&cpanel_xmlapi_apiversion=2&cpanel_xmlapi_module=FilemansV   &cpanel_xmlapi_func=fileop&op=unlink&sourcefiles=%s&doubledecode=0&metadata=&destfile=R*   (
   R   R   R#   R:   R;   R<   R$   R=   R>   R   (   R%   t   myfileRL   RM   RN   RO   R,   (    (    s&   /root/bin/ikeamodules/cPanel/cPanel.pyt
   removeFile  s    	c         C   sš   | d  j o |  i } n |  i } | d | 7} | d | 7} | d | 7} t i | ƒ } | i d |  i ƒ t i | ƒ } | i ƒ  } t	 | ƒ } | S(   Ns]   /xml-api/cpanel?cpanel_xmlapi_user=%s&cpanel_xmlapi_apiversion=2&cpanel_xmlapi_module=Filemans1   &cpanel_xmlapi_func=fileop&op=move&sourcefiles=%ss   &destfiles=%sR*   (
   R   R   R#   R:   R;   R<   R$   R=   R>   R   (   R%   R]   t   myfile2RL   RM   RN   RO   R,   (    (    s&   /root/bin/ikeamodules/cPanel/cPanel.pyt   moveFile!  s    	N(   t   __name__t
   __module__t   __doc__R)   R   R?   RS   R[   R\   R^   R`   (    (    (    s&   /root/bin/ikeamodules/cPanel/cPanel.pyR      s   )œ*(    (   R:   RI   t   base64R    R   t   helpersR   t   operatorR   t   xml.parsers.expatRD   R   (    (    (    s&   /root/bin/ikeamodules/cPanel/cPanel.pyt   <module>   s   