Ñò
¯ÉòXc           @   sR  d Z  d i g  Z e  D]' Z e d e e ƒ e j e e ƒ q [ ƒ d Z d Z d Z	 d d k
 Z
 e
 i d	 ƒ d d
 k Td d
 k Td d
 k Td d
 k Td d
 k Td d
 k Td 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 d d k l Z d „  Z d „  Z d „  Z d S(   i   i    t    s   -.i   s+   The Incredible Kontent Extraction AutomatorsË  
%prog [options] <file_with_account_list>
%prog [options] <host> <user> <password>
%prog [options]

Reads a white-space separated list of account details ('user password host')
from the provided filename, one account per line or alternatively, for single
accounts takes the arguments 'user password host' directly and verifies the
cPanel access details among other things.

Full documentation: https://confluence.endurance.com/display/HGS/MigrationsTransferIkea

Example of the 'file_with_account_list' file:
    somehost.com bob l4m3passW0RD
    somehost2.net nomnom44 noneshallpass
    
Running the tool:
    %prog -c somehost.com bob l4m3passW0RD
    (runs pre-transfer checks to verify login info and show account stats)
    
    %prog -b list
    (iterates through accounts in the file 'list', verifies information, gets
    account stats and generates backups)
    
    %prog -bd somehost.com bob l4m3passW0RD
    (creates, and downloads backup from source server)
iÿÿÿÿNi-   (   t   *(   t   gethostname(   t   OptionGroup(   t   OptionParser(   t   urlparse(   t   cPanel(   t   WHMc          C   sG  t  t d d t ƒ}  |  i d d d d d d d	 t d
 d ƒ|  i d d d d d d d	 t d
 d ƒ|  i d d d d d d d	 t d
 d ƒ|  i d d d d d d d	 t d
 d ƒ|  i d d d d d d d	 t d
 d ƒ|  i d d d d d d d	 t d
 d ƒ|  i d  d d d d! d	 t d
 d" ƒt |  d# ƒ } | i d$ d% d& d' d( d) d d* d	 d+ d
 d, ƒ| i d- d. d& d' d( d/ d d0 d	 d1 d
 d2 ƒ| i d3 d d d d4 d	 t d
 d5 ƒ| i d6 d d d d7 d	 t d
 d8 ƒ| i d9 d: d d d d; d	 t d
 d< ƒ| i d= d> d& d? d( d@ d dA d	 d  d
 dB ƒ|  i | ƒ |  S(C   Nt   versions   %prog s   -cs   --pre-checkt   actiont
   store_truet   destt   precheckt   defaultt   helps)   run pre-transfer check for the account(s)s   -ls   --listt   lists0   list available cPanel backups for the account(s)s   -ss
   --skiphomet   skiphomes.   Upload a cpanel-exclude.conf to the account(s)s   -bs   --backupt   backups,   generate cPanel backup(s) for the account(s)s   -ds
   --downloadt   downloadsa   download the most recently generated cPanel backup(s) for the accounts into the current directorys   -rs	   --restoret   restores(   restores the downloaded cPanel backup(s)s	   --cleanupt   cleanupsD   Removes the backup file generated by the script after downloading its   Additional optionss   -ts	   --threadst   typet   intt   metavart   THREADSt   threadsi   s“   sets the number of concurrent threads to use for verifying login details (too many will cause problems, stick with the default) [default: %default]s   -ws   --waitt   WAITTIMEt   waittimei   sl   sets the wait time between each cPanel login attempt that ikea makes. IN SECONDS [default: %default seconds]s   --no-collisiont   nocollisions(   skip checking for domain name collisionss   --no-sslt   nossls5   don't use SSL-secured connections [default: %default]s   --check-ftps   -ft   ftpcheckso   Enable checking for FTP access. USE ONLY WHEN YOU HAVE DIRECT ACCESS TO THE CPANEL ACCOUNTS [Default: %default]s   --bind-addresss   -it   stringt   BINDIPt   bindips\   Bind the outgoing calls to the specified IP address. [default: the server's main IP address](   R   t   USAGEt   __version__t
   add_optiont   FalseR   t   Nonet   add_option_group(   t   parsert   group(    (    s&   /root/bin/ikeamodules/ikea/__init__.pyt   optionHandlerC   sJ    ''(.c          C   sõ  g  }  d  } x+ | d j o t d ƒ } |  i | ƒ q Wd  } d  } g  } x¢|  D]š} | d  d j o Pn | d  d j o7 | d i d ƒ GHt | d i d ƒ d ƒ GH| GHqS | d	  d
 j o | d	 } qS | d	  d j o[ | oP | oI t i d t i d G| G| G| d	 GH| i t | | | d	 ƒ ƒ PqíqS | d  d j o | i d ƒ d } qS | d  d j or | og | o` t i d t i d G| G| G| i d ƒ d GH| i t | | | i d ƒ d ƒ ƒ d  } qíqS qS W| S(   Nt   dones   > i   s   Your Primary Domain With Us: : i   s   Old Hosting Account IP: : t   :i    i   s   The username to that site: : s   The password to that site: : s   [+] t   Addingi   s   The username tos   : : i   s   The password to(	   R&   t	   raw_inputt   appendt   splitR   t   bcolt   OKGREENt   ENDCR   (   t
   user_inputt   entryt   oldhostt   usert   acctst   line(    (    s&   /root/bin/ikeamodules/ikea/__init__.pyt   getInputy   s@      	'	0&c       	      sv  t  i d t  i t GHt ƒ  }  |  i ƒ  \ ‰ } ˆ i o( t i ‰  ‡ ‡  f d †  } | t _ n g  } t | ƒ d j o¢ t	 i
 i | d ƒ oW t | d ƒ } xt | D]8 } | i t | d | d | d ˆ i ˆ i ƒ ƒ q« Wq-t  i d t  i d | d d GHt i d ƒ nt | ƒ d	 j o6 | i t | d | d | d ˆ i ˆ i ƒ ƒ nÆ |  i ƒ  t i d ƒ t  i d
 t  i d GHt  i d
 t  i d GHd GHt  i d
 t  i d GHt  i d
 t  i d GHt ƒ  } t | ƒ d j o t ˆ _ n% t  i d t  i d GHt i d ƒ t i d t	 i ƒ  t i ƒ p( t  i d t  i d GHt i d ƒ n ˆ i oR ˆ i oG ˆ i  o< ˆ i! o1 ˆ i" o& ˆ i# o |  i ƒ  t i d ƒ n t$ | ˆ i% ˆ i& ƒ ˆ i ot' | ƒ } | oë ˆ i  oà ˆ i# oÕ ˆ i oÊ d t  i d
 t  i d GHt( d ƒ } t | ƒ d j o$ t  i d t  i GHt i d ƒ n d | j o t ˆ _! n d | j o t ˆ _  n d | j o t ˆ _# n d | j o t ˆ _" qïqón ˆ i o t) | ƒ n ˆ i  o t* | ˆ i! ƒ n ˆ i# o  t+ | ˆ i, ˆ i! ˆ i" ƒ n ˆ i" o t- | ƒ n t. ƒ  d  S(   Ns   [$] c             s)   ˆ |  | Ž  } | i  ˆ  i d f ƒ | S(   Ni    (   t   bindR!   (   t   at   kt   sock(   t   optionst   true_socket(    s&   /root/bin/ikeamodules/ikea/__init__.pyt   bound_socket¢   s    i   i    i   s   [!] s
   The file 's   ' does not exist.i   s   [*] sY   Enter the server IP, account username, account password, separate by spaces on each line.s   Example:s   	127.0.0.1 bob p4ssw0rds@   Or, alternatively, copy/paste the transfer form from the ticket.s(   Enter 'done' on its own line to proceed:sR   No valid accounts data provided, nothing to check. Use --help for more informations
   ^/home\d?/s&   IKEA must be run in a /home partition!s   
sŠ   Checks completed. Start backup/download process? Enter the typical backup/download options to processed ('s','b','d','r'). ctrl-c to exit:s   > i   s9   String length is too large to make any sense. Aborting...t   st   bt   dt   r(/   R1   R2   R3   t   TITLER*   t
   parse_argsR!   t   sockett   lent   ost   patht   isfilet	   parseFileR/   R   R   R   t   FAILt   syst   exitt
   print_helpt   OKBLUER:   t   Truet   checkt   WARNINGt   ret   searcht   getcwdt   IR   R   R   R   R   R   t   loginInfoCheckerR   R   t   preCheckR.   t   listBackupst   createBackupst   downloadBackupsR   t   restoreBackupst
   closePorts(   R(   t   argsRA   R8   t   uphlistR9   t   successt	   userinput(    (   R@   R?   s&   /root/bin/ikeamodules/ikea/__init__.pyt   main›   s€    	
	 :#6
	,

(


 
(   i   i    i    i    (    t   VERSIONt   joint   _[1]t   xR   R   t   strR#   RF   R"   RH   t   setdefaulttimeoutt   pretransferR   R   R   t   posttransfert   helperst   os.pathRJ   RV   t   readlineR   t   optparseR   R   R   R   R   R*   R:   Re   (    (    (    s&   /root/bin/ikeamodules/ikea/__init__.pyt   <module>   s.   H





	6	"