Ñò
ubSc           @   sÔ   d  d k  Z  d  d k Z d  d k Z d  d k l Z d  d k l Z d e i f d „  ƒ  YZ d d d „  ƒ  YZ	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d e d „ Z d „  Z d „  Z d S(   iÿÿÿÿN(   t   exists(   t   callt   tickerc           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   s,   t  i i |  ƒ | |  _ t  i ƒ  |  _ d  S(   N(   t	   threadingt   Threadt   __init__t   msgt   Eventt   event(   t   selfR   (    (    s%   /root/bin/ikeamodules/ikea/helpers.pyR      s    	c         C   s   |  i  ƒ  d  S(   N(   t   start(   R	   (    (    s%   /root/bin/ikeamodules/ikea/helpers.pyt	   __enter__   s    c         C   s   |  i  i ƒ  |  i ƒ  d  S(   N(   R   t   sett   join(   R	   (    (    s%   /root/bin/ikeamodules/ikea/helpers.pyt   __exit__   s    c         C   s\   t  i i |  i ƒ xB |  i i ƒ  p1 t  i i d ƒ t  i i ƒ  |  i i d ƒ q Wd  S(   Nt   .i   (   t   syst   stdoutt   writeR   R   t   isSett   flusht   wait(   R	   (    (    s%   /root/bin/ikeamodules/ikea/helpers.pyt   run    s     (   t   __name__t
   __module__R   R   R   R   (    (    (    s%   /root/bin/ikeamodules/ikea/helpers.pyR      s   			t   bcolc           B   s5   e  Z d  Z d Z d Z d Z d Z d Z d „  Z RS(   s   [95ms   [94ms   [92ms   [93ms   [91ms   [0mc         C   s:   d |  _  d |  _ d |  _ d |  _ d |  _ d |  _ d  S(   Nt    (   t   HEADERt   OKBLUEt   OKGREENt   WARNINGt   FAILt   ENDC(   R	   (    (    s%   /root/bin/ikeamodules/ikea/helpers.pyt   disable0   s    					(	   R   R   R   R   R   R   R   R    R!   (    (    (    s%   /root/bin/ikeamodules/ikea/helpers.pyR   (   s   c      	   C   s%  t  |  d ƒ i ƒ  } g  } d } yÞ x× | D]Ï } | d } | d d j o® | i ƒ  i ƒ  } t | ƒ d j o qú t | ƒ d j  oL t i d t i d t | ƒ d t i | i ƒ  t i d	 t i GHqú | i	 | d | d | d
 g ƒ q+ q+ WWn t i
 d t i d GHt SX| S(   sÚ   Quickly and dirtily 'parse' cPanel login details from a file and return it as a list.
    Each line should contain the following: server hostname/IP, cPanel username, cPanel password
    ie. 127.0.0.1 bob changeme
    t   ri    i   t   #i   s   [!] s*   Warning, incomplete login details on line s   , "s   ", skipping entryi   s@   Failed to parse cPanel access information from the provided file(   t   opent	   readlinest   stript   splitt   lenR   R   R    t   strt   appendR   t   False(   t   filenamet   linest   listt   lt   linet   info(    (    s%   /root/bin/ikeamodules/ikea/helpers.pyt	   parseFile9   s$     
L.c         G   s„   |  d } g  } x+ | D]# } | i  t t | | ƒ ƒ ƒ q Wd } x | D] } | | 7} qK W| |  j o | d c d 8<n | S(   Ng      Y@i    i   (   R*   t   intt   round(   t   columnst   argst   perct   colst   argt   totalt   col(    (    s%   /root/bin/ikeamodules/ikea/helpers.pyt	   calcWidthR   s    
 ! c          C   sA   t  i d d ƒ i ƒ  i ƒ  \ }  } t |  ƒ t | ƒ }  } | S(   Ns	   stty sizeR"   (   t   ost   popent   readR'   R3   (   t   rowsR5   (    (    s%   /root/bin/ikeamodules/ikea/helpers.pyt   getCols_   s    $c         C   sf   x_ t  d d ƒ D]N } | i d d ƒ \ } } |  i ƒ  i ƒ  | i ƒ  i ƒ  j o | i ƒ  Sq Wt S(   Ns   /etc/userdomainsR"   t   :i   (   R$   R'   R&   t   lowerR+   (   t   domainR0   t   ldomaint   luser(    (    s%   /root/bin/ikeamodules/ikea/helpers.pyt   domainExistse   s     %c         C   s    t  i i d |  ƒ o t St S(   Ns   /var/cpanel/users/(   R=   t   patht   isfilet   TrueR+   (   t   user(    (    s%   /root/bin/ikeamodules/ikea/helpers.pyt
   userExistsl   s    c          C   sl   d }  t  |  ƒ p t d g d h d d 6ƒn t |  d ƒ } | i ƒ  i d d ƒ i ƒ  }  d	 |  } | S(
   Ns   /root/.accesshashs&   /usr/local/cpanel/bin/realmkaccesshasht   envt   roott   REMOTE_USERR"   s   
R   s	   WHM root:(   R    R   R$   R?   t   replacet   rstrip(   t   hasht   ft   auth(    (    s%   /root/bin/ikeamodules/ikea/helpers.pyt   readHashq   s    
c         C   sY  t  |  d ƒ d j o$ Hd GHx |  d D] } | GHq( Wn t  |  d ƒ d j o2 Hd GHx) |  d D] } t i | t i GHqc Wn t  |  d ƒ d j o2 Hd GHx) |  d D] } t i | t i GHq¬ Wn t  |  d ƒ d j oü t } y× xÐ |  d i ƒ  D]¾ \ } } x¯ t d	 d
 ƒ D]ž } | i d d ƒ \ } } | i ƒ  i	 ƒ  } xk | D]c }	 |	 i ƒ  i	 ƒ  | j oD | p Hd GHt
 } n t i | d | d | i ƒ  t i GHqQqQWqWqþ WWqàt j
 o d GHqàXn t  |  d ƒ d j o^ t }
 xU |  d D]E } t d | ƒ o. |
 p Hd GHt
 }
 n t i | t i GHqqWn d  S(   Nt   noaccessi   sK   The login details for the following cPanel accounts appear to be incorrect:t   toobigsF   The following accounts are too big to reliably back up through cPanel:t   nospacesF   The following accounts are at or too close to their disk space quotas:t   domainss   /etc/userdomainsR"   RB   sJ   Domain name collisions! The following domains already exist on the server:s    (s   ), owned by sJ   Skipping domain name collision checking as /etc/userdomains does not existt   userss   /var/cpanel/users/s5   The following usernames already exists on the server:(   R(   R   R   R    R+   t	   iteritemsR$   R'   R&   RC   RJ   R   t   IOErrorR    (   t   checkst   entryRK   t   collidet   ut   dR0   RE   RF   t   mdomaint   ucollide(    (    s%   /root/bin/ikeamodules/ikea/helpers.pyt   checkSummaryz   s`          
= 
c         C   s   d  S(   N(    (   t   stringt   colort   sl(    (    s%   /root/bin/ikeamodules/ikea/helpers.pyt   echoª   s    c           C   s¿  t  i ƒ  d j ot d d d d d d d d d	 d
 d d d g ƒ t d d d d d d d d
 d	 d d d d g ƒ t d d d d d d d d d	 d
 d d d g ƒ t d d d d d d d d
 d	 d d d d g ƒ t d d d d d d d d d	 d
 d d d g ƒ t d d d d d d d d
 d	 d d d d g ƒ t d d d d d d d d d	 d
 d d d g ƒ t d d d d d d d d
 d	 d d d d g ƒ d  St i d t i d GHd  Sd  S(   Ni    s   /sbin/iptabless   -It   INPUTs   -pt   tcps   -ms   --dports
   1024:65535s   --sportt   2082s   -jt   ACCEPTt   OUTPUTt   udpt   2083s   [!] s8   Not running as root... Unable to open ports on my own :((   R=   t   geteuidR   R   R   R    (    (    (    s%   /root/bin/ikeamodules/ikea/helpers.pyt	   openPorts­   s    11111111c           C   s£  t  i ƒ  d j oŒt d d d d d d d d d	 d
 d d d g ƒ t d d d d d d d d
 d	 d d d d g ƒ t d d d d d d d d d	 d
 d d d g ƒ t d d d d d d d d
 d	 d d d d g ƒ t d d d d d d d d d	 d
 d d d g ƒ t d d d d d d d d
 d	 d d d d g ƒ t d d d d d d d d d	 d
 d d d g ƒ t d d d d d d d d
 d	 d d d d g ƒ n d  S(   Ni    s   /sbin/iptabless   -DRi   s   -pRj   s   -ms   --dports
   1024:65535s   --sportRk   s   -jRl   Rm   Rn   Ro   (   R=   Rp   R   (    (    (    s%   /root/bin/ikeamodules/ikea/helpers.pyt
   closePortsÉ   s    11111115(    (   R=   R   R   t   os.pathR    t
   subprocessR   R   R   R   R2   R<   RA   RG   RL   RU   Rd   t   NoneR+   Rh   Rq   Rr   (    (    (    s%   /root/bin/ikeamodules/ikea/helpers.pyt   <module>   s    								0	