Ñò
Ÿd°Xc           @   sÍ   d  d k  Z  d  d k Z 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	 l
 Z
 l Z l Z l Z d  d k l Z e d „ Z d	 „  Z d
 „  Z d „  Z d S(   iÿÿÿÿN(   t   bcol(   t	   calcWidth(   t   getCols(   t   strftime(   t   Requestt   urlopent   URLErrort	   HTTPError(   t   quotec      	   C   sÌ  t  ƒ  } d } Ht i d i | d ƒ t i GHt | d d d ƒ } d i | d ƒ d	 i | d ƒ d
 i | d ƒ GHt i d ƒ } g  } x8|  D]0} y+ | i	 d d o | i	 d d } n Wn t
 j
 o d- } n Xd- } g  }	 | i pÐ t | ƒ d t i | i d t i t i d | i d t i }
 t |
 ƒ t | i d |
 ƒ ƒ } t i d t i } t | ƒ t | i d | ƒ ƒ } |
 i | d | ƒ | i | d | ƒ GHq” n t | ƒ d t i | i d t i t i d | i d t i }
 t |
 ƒ t | i d |
 ƒ ƒ } t i d | i d t i ƒ p€ t i d | i d t i ƒ p` t i d | i d t i ƒ p@ t i d | i d t i ƒ p  t i d | i d t i ƒ oe t i d t i } t | ƒ t | i d | ƒ ƒ } |
 i | d | ƒ | i | d | ƒ GHn | o‚ t | | ƒ } | ph t i d t i } t | ƒ t | i d | ƒ ƒ } |
 i | d | ƒ | i | d | ƒ GHq” q½n | i ƒ  oÊt i d t i } t i ƒ  } d } t } | d } xŒ| p„t i ƒ  } | | } | | j oŽ| t i d d ƒ } | i ƒ  ot | i	 ƒ d j oö | i	 d d  d! j oI | i	 d d | j p- t i d" | i	 d d t i } t } qXq\| i	 d d  d# j o1 t } t i d$ | i	 d d d t i } q\| i	 d d  d% j o0 | d 7} t i d& t | ƒ d t i } q\q·q»| d j o t i d' t i } t } q»| d 7} t i d( t | ƒ d t i } n t | ƒ t | i d | ƒ ƒ } | d j o d) t  | d ƒ } n d* | } t | ƒ t | i d | ƒ ƒ } |
 i | d | ƒ | i | d | ƒ | i | d | ƒ d+ Gt! i" i# ƒ  t i$ d ƒ qWHn | p | i d, o t% | | ƒ n | d 7} q” Wd- S(.   s*   Loop through accounts and generate backupsi   s   ___Backup creationt   _i    i<   i   s   #  Primary Domain (username)i    t   Statuss   Time i   s   \x1B\[[^A-Za-z]*[A-Za-z]t   files   . t   primarydomains    (t   )t    s$   Bad cPanel login details, skipping..s   hostgator.com$t   hostnames   hostgator.com.tr$s   hostgator.in$s   webhostsunucusu.com$s   websitedns.in$sE   Hostgator server detected. Are you sure you are using the right tool?s3   Failed to create cpbackup-exclude.conf. Skipping...s&   Request sent, waiting for it to take..i   i
   i   t   statust   completes
   Complete: t
   inprogresss    Process started and verified.. (t   timeouts2   Backup timed out server-side, will check again.. (sS   Failed getting list of backups from the server, backup may still have been started.s9   Unable to get list of backups, will check again.. (retry s   %02dm %02ds s   %02ds s   t   movedcpbackupN(&   R   R    t   HEADERt   ljustt   ENDCR   t   rjustt   ret   compilet   backupst
   IndexErrort   Nonet   cpanelt   strt   infot   FAILt   usernamet   lent   subt   OKGREENt   searcht   It   WARNINGt   skiphomet   startBackupt   timet   Falset   randomt   randintt   getBackupListt   Truet   OKBLUEt   divmodt   syst   stdoutt   flusht   sleept	   undoshome(   t   acctst   shomet   columnst   countt   colst   aansit   wgetst   acctt   mostrecentoldbackupt
   checkagaint   c1t   a1t   c2t   a2t   testt	   starttimet	   failcountt   donet   ttct   curtimet   tdifft   startedt   c3t   a3(    (    s$   /root/bin/ikeamodules/ikea/backup.pyt   createBackups   sž    	4 
F""+F" "/"+
 
#+
.

&"
"Cc         C   s  t  ƒ  } t | d d ƒ } t i d ƒ } h g  d 6g  d 6g  d 6h  d 6g  d 6} | d i |  i ƒ t |  i d ƒ d	 j o |  i d | d |  i <n |  i p(| d i d
 t	 i
 |  i d |  i t	 i d t	 i |  i t	 i ƒ t	 i d |  i d t	 i } t	 i
 |  i d t	 i d | } t | ƒ d | } t | ƒ t | i d | ƒ ƒ }	 t	 i d t	 i }
 t |
 ƒ t | i d |
 ƒ ƒ } | i | d |	 ƒ |
 i | d	 | ƒ GHd St	 i d |  i d t	 i } t	 i
 |  i d t	 i d | } t i d |  i d t i ƒ p€ t i d |  i d t i ƒ p` t i d |  i d t i ƒ p@ t i d |  i d t i ƒ p  t i d |  i d t i ƒ o› t | ƒ d | } t | ƒ t | i d | ƒ ƒ }	 t	 i d t	 i }
 t |
 ƒ t | i d |
 ƒ ƒ } | i | d |	 ƒ |
 i | d	 | ƒ GHn t |  ƒ ot | ƒ d | } t | ƒ t | i d | ƒ ƒ }	 t	 i d t	 i }
 t |
 ƒ t | i d |
 ƒ ƒ } | i | d |	 ƒ |
 i | d	 | ƒ GH|  i d o d |  i } n d |  i } | d  |  i 7} | d! d" 7} t | ƒ } | i d# |  i ƒ t | ƒ t |  _ d	 St | ƒ d | } t | ƒ t | i d | ƒ ƒ }	 t	 i d$ t	 i }
 t |
 ƒ t | i d |
 ƒ ƒ } | i | d |	 ƒ |
 i | d	 | ƒ GHd Sd  S(%   Ni    iD   s   \x1B\[[^A-Za-z]*[A-Za-z]t   toobigt   nospacet   noaccesst   domainst   usersi   s   U/P: s    / s	    Server: t   (R   R   t    s   . R   s=   Unable to access the cPanel account with the provided detailsi    s   hostgator.com$R   s   hostgator.com.tr$s   hostgator.in$s   webhostsunucusu.com$s   websitedns.in$sE   Hostgator server detected. Are you sure you are using the right tool?s!   -> Uploaded cpbackup-exclude.conft   ssls   https://%s:2083/s   https://%s:2082/s\   xml-api/cpanel?cpanel_xmlapi_user=%s&cpanel_xmlapi_apiversion=2&cpanel_xmlapi_module=FilemansK   &cpanel_xmlapi_func=savefile&dir=&filename=cpbackup-exclude.conf&content=%st   *t   Authorizations6   It appears that placing a cpbackup-exclude.conf failed(   R   R   R   R   t   appendR"   R#   R    R   R    R   t   passwordR   R(   t   serverR!   R   R$   R   R%   R&   R'   t	   skipcheckR1   R   t
   add_headert
   authheaderR   R0   R)   (   R?   R;   R:   R<   R=   t   checkst   usert   domainRB   RC   RD   RE   t   urlt   req(    (    s$   /root/bin/ikeamodules/ikea/backup.pyR)   ~   sf    	


J#""+# ""/""+
	""+c         C   s:  y|  i  d o d |  i } n d |  i } | d d } t | ƒ } | i d |  i ƒ t | ƒ } x± | D]© } | i ƒ  p qo qo | i ƒ  d j o| d t d	 ƒ |  i  d
 <yF |  i d |  i  d
 ƒ } | d } x | D] } | d d }	 qà WWn d SX|	 o d Sd Sqo qo WWn t	 j
 o
 }
 d SXd S(   NRX   s   https://%s:2083s   https://%s:2082s   /download?file=%ss   cpbackup-exclude.confRZ   RY   s   cpbackup-exclude.conf.baks   %m%d%H%MR   t   datat   resulti    i   (
   R    R]   R   R_   R`   R   t   stripR   t   moveFileR   (   R?   t   baseurlRd   Re   t   ft   lineRf   t   dresultt   piecet   successt   e(    (    s$   /root/bin/ikeamodules/ikea/backup.pyR^   À   s8     
 c         C   s  t  ƒ  } t | d d ƒ } t i d ƒ } h g  d 6g  d 6g  d 6h  d 6g  d 6} | d i |  i ƒ t |  i d ƒ d	 j o |  i d | d |  i <n |  i p(| d i d
 t	 i
 |  i d |  i t	 i d t	 i |  i t	 i ƒ t	 i d |  i d t	 i } t	 i
 |  i d t	 i d | } t | ƒ d | } t | ƒ t | i d | ƒ ƒ }	 t	 i d t	 i }
 t |
 ƒ t | i d |
 ƒ ƒ } | i | d |	 ƒ |
 i | d	 | ƒ GHd  St	 i d |  i d t	 i } t	 i
 |  i d t	 i d | } t i d |  i d t i ƒ p€ t i d |  i d t i ƒ p` t i d |  i d t i ƒ p@ t i d |  i d t i ƒ p  t i d |  i d t i ƒ o› t | ƒ d | } t | ƒ t | i d | ƒ ƒ }	 t	 i d t	 i }
 t |
 ƒ t | i d |
 ƒ ƒ } | i | d |	 ƒ |
 i | d	 | ƒ GHn |  i o3|  i d ƒ t | ƒ d | } t | ƒ t | i d | ƒ ƒ }	 t	 i d t	 i }
 t |
 ƒ t | i d |
 ƒ ƒ } | i | d |	 ƒ |
 i | d	 | ƒ GH|  i d o} |  i |  i d d ƒ t	 i d t	 i }
 t |
 ƒ t | i d |
 ƒ ƒ } | i | d |	 ƒ |
 i | d	 | ƒ GHd  Sn d  S(    Ni    iD   s   \x1B\[[^A-Za-z]*[A-Za-z]RQ   RR   RS   RT   RU   i   s   U/P: s    / s	    Server: RV   R   R   RW   s   . R   s=   Unable to access the cPanel account with the provided detailsi    s   hostgator.com$R   s   hostgator.com.tr$s   hostgator.in$s   webhostsunucusu.com$s   websitedns.in$sE   Hostgator server detected. Are you sure you are using the right tool?s   cpbackup-exclude.confs$   -> Removed the cpbackup-exclude.confR   s*   -> Restored original cpbackup-exclude.conf(   R   R   R   R   R[   R"   R#   R    R   R    R   R\   R   R(   R]   R!   R   R$   R   R%   R&   R'   R)   t
   removeFileR1   Ri   (   R?   R;   R:   R<   R=   Ra   Rb   Rc   RB   RC   RD   RE   (    (    s$   /root/bin/ikeamodules/ikea/backup.pyR7   å   sT    	


J#""+# ""/
""+"+(   R   R3   R+   R-   t   helpersR    R   R   R   t   urllib2R   R   R   R   t   urllibR   R,   RP   R)   R^   R7   (    (    (    s$   /root/bin/ikeamodules/ikea/backup.pyt   <module>   s   "h	B	%