ó
-žődc           @   sö   d  d l  Z  d  d l Z d  d l Z d  d l Td  d l Z d  d l Z d  d l m Z d  d l Z d  d l Td  d l	 Z	 d  d l
 Z
 e Z d Z d   Z d   Z d   Z d   Z d	 e	 j e	 j d
  Z d   Z d   Z d   Z e d  d S(   i˙˙˙˙N(   t   *(   t   calls   /home/c         C   sy   |  j  d  } t |  d k ro xQ | D]@ } | j   ra t |  t d d  k ra t } q( q( t } Pq( Wn t } | S(   Nt   .i   i    i   (   t   splitt   lent   isdigitt   intt   ranget   Truet   False(   t   addresst   ip_addrt   it   res(    (    s#   /var/www/Lyra-TL/cgi/global_func.pyt   cfgValidate   s    'c         C   s   d } d } t  |   } | t  |  } | d k rF | j d  } n< | d k rd | j d  } n | d k r | j d  } n  | |  t |  } | S(	   Nt   0000s   </msg>i	   t   0ic   t   00iç  t   000(   R   t   rfindt   str(   t   messaget   lengtht   tailt   length_messaget   kt
   msg_length(    (    s#   /var/www/Lyra-TL/cgi/global_func.pyt   ccm_msg_length(   s    c         C   sF   t  |   } d j | |   } t | d  } t j t | g  } d  S(   Ns   </msg>{0}{1}</msg>s   utf-8(   R   t   formatt   bytest
   subprocessR   t   CGIpath(   R   R   t
   socket_cmdt
   socket_msgt   process1(    (    s#   /var/www/Lyra-TL/cgi/global_func.pyt   send_ccm_msg7   s    c         C   s   d } t  d d t |   d | } d } xB | d k  rp t j j |  rV d } q/ | d } t j d  q/ Wt | d	  } | j   } | j	   | S(
   Ns   ccm_response.txtt   bt   'i    id   ie   i   gš?t   r(
   t   ccm_response_pathR   t   ost   patht   isfilet   timet   sleept   opent   readt   close(   t   uuidt   filenamet   ccm_response_filet   filet   fot   CcmResponse(    (    s#   /var/www/Lyra-TL/cgi/global_func.pyt   get_ccm_responseC   s     	

i   c            s#   d j    f d   t |   D  S(   Nt    c         3   s   |  ] } t  j    Vq d  S(   N(   t   randomt   choice(   t   .0t   _(   t   chars(    s#   /var/www/Lyra-TL/cgi/global_func.pys	   <genexpr>X   s    (   t   joinR   (   t   sizeR<   (    (   R<   s#   /var/www/Lyra-TL/cgi/global_func.pyt   id_generatorW   s    c          C   s   t    }  |  S(   N(   R?   (   t
   command_id(    (    s#   /var/www/Lyra-TL/cgi/global_func.pyt   get_ccm_command_id[   s    	c         C   s7   d } t  d d t |   d | } t j |  d  S(   Ns   ccm_response.txtR$   R%   (   R'   R   R(   t   remove(   R0   R1   R2   (    (    s#   /var/www/Lyra-TL/cgi/global_func.pyt   delete_ccm_response`   s     c         C   s   yb t  j d d g d t } x6 | j   D]( } |  | k r+ d | k r+ d a t Sq+ Wd a t SWn t  j k
 r d a t SXd  S(   Nt   pst   auxt   universal_newlinest   grepi   i    (   R   t   check_outputR   t
   splitlinest   CCMR	   t   CalledProcessError(   t   process_namet   outputt   line(    (    s#   /var/www/Lyra-TL/cgi/global_func.pyt   is_ccm_runningi   s    s   main.py(   t   sockett   sysR+   t   arrayt   loggingR   R   R(   t   globalSettingst   stringR8   t
   DeviceNamet   devicet   response_txt_pathR   R   R#   R6   t   ascii_uppercaset   digitsR?   RA   RC   RO   (    (    (    s#   /var/www/Lyra-TL/cgi/global_func.pyt   <module>   s*   

								