Esempio n. 1
0
 def run(self):
     while(1==1):
         #pipein,pipeout=os.pipe()
         p = subprocess.Popen("%s %s %s" % (self.global_config_hash['OSCOUNT_SCRIPT'],GlobalConfigHandleKernel.remote_universal_bus,GlobalConfigHandleKernel.remote_universal_ip),
                                             shell=True,
                                             close_fds=True,
                                             stdin=open("/dev/null", 'r'),
                                             #stdout=pipein,
                                             stdout=subprocess.PIPE,
                                             stderr=open("/dev/null", 'w'))
         #os.close(pipein)
         wait_time=0
         while(wait_time < 30):
             poll_status=p.poll()
             if(poll_status is not None):
                 break
             else:
                 time.sleep(1)
                 wait_time=wait_time + 1
                 continue
         poll_status=p.poll()
         if(poll_status is None):
             p.kill()
             SpecialOperationThread.unversal_write_log(self.config_log_fd,"Here gets the oscount not finished\n")
             time.sleep(int(self.global_config_hash['OSCOUNT_SLEEP']))
             continue
         if(p.returncode !=0):
             SpecialOperationThread.unversal_write_log(self.config_log_fd,"Here gets the oscount returncode !=0 maybe failed\n")
         else:
             for count_data in p.stdout:
                 GlobalConfigHandleKernel.global_oscount_data['oscount']=count_data.strip()
                 break
             #os.close(pipeout)
         time.sleep(int(self.global_config_hash['OSCOUNT_SLEEP']))
Esempio n. 2
0
def create_connect_socket(config_log_fd, global_config_hash):
    if (GlobalConfigHandleKernel.remote_universal_ip is None):
        time.sleep(1)
        return "error"
    clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    if (clientsocket < 0):
        SpecialOperationThread.unversal_write_log(
            config_log_fd,
            "Create clientsocket failed in local_sms_queue thread\n")
        return "error"
    clientsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    clientsocket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
    clientsocket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
    try:
        clientsocket.settimeout(10)
        clientsocket.connect((GlobalConfigHandleKernel.remote_universal_ip,
                              int(global_config_hash['SERVER_PORT'])))
        clientsocket.settimeout(None)
    except:
        clientsocket.close()
        SpecialOperationThread.unversal_write_log(
            config_log_fd,
            "Connect failed to universal remote ip:port %s:%s in local_sms_queue thread\n"
            % (GlobalConfigHandleKernel.remote_universal_ip,
               global_config_hash['SERVER_PORT']))
        return "error"
    return clientsocket
Esempio n. 3
0
 def run(self):
     connections = {}
     addressall = {}
     while True:
         try:
             while True:
                 events = GlobalConfigHandleKernel.global_autountar_epollfd.poll(
                     int(self.global_config_hash['LISTEN_FD']))
                 for fileno, event in events:
                     if (event & select.EPOLLIN):
                         if (fileno >=
                                 int(self.global_config_hash['LISTEN_FD']) -
                                 2):
                             SpecialOperationThread.unversal_write_log(
                                 self.untar_log_fd,
                                 "Auto server fd mounted to maximum,exit\n")
                             clear_autotar_tok(fileno)
                             #exit(1) modified as following:
                             continue
                         data_tmp = ""
                         while True:
                             try:
                                 data_tmp = GlobalConfigHandleKernel.global_autountar_epoll_handle_conn[
                                     fileno].recv(
                                         int(self.global_config_hash[
                                             'BUF_SIZE']))
                                 if (data_tmp is not None
                                         and len(data_tmp) > 0
                                         and len(data_tmp) <= int(
                                             self.global_config_hash[
                                                 'BUF_SIZE'])):
                                     if (data_tmp.strip() ==
                                             "TaskServerAuto exit"):
                                         clear_autotar_tok(fileno)
                                         break
                                     GlobalConfigHandleKernel.global_autountar_epoll_handle_openresult[
                                         fileno].write(data_tmp)
                                     GlobalConfigHandleKernel.global_autountar_epoll_handle_openresult[
                                         fileno].flush()
                                     break
                                 elif (len(data_tmp) <= 0 or len(data_tmp) >
                                       int(self.
                                           global_config_hash['BUF_SIZE'])):
                                     clear_autotar_tok(fileno)
                                     break
                             except socket.error, msg:
                                 if (msg.errno == errno.EAGAIN
                                         or msg.errno == errno.EWOULDBLOCK
                                         or msg.errno == errno.EINTR):
                                     continue
                                 else:
                                     clear_autotar_tok(fileno)
                                     break
                             except:
                                 if (1 < 0):
                                     pass
                                 else:
                                     clear_autotar_tok(fileno)
                                     break
Esempio n. 4
0
def open_log_first(global_config_hash,config_log_fd):
    global combine_log_handle
    try:
        combine_log_handle=open(global_config_hash['WEB_LOG_DIR'] + "/" + today_time_date + "-act-combine.log","a")
        if(combine_log_handle is None):
            print "Error to open combine web log file %s:%s" % (global_config_hashtable['WEB_LOG_DIR'],today_time_date)
            SpecialOperationThread.unversal_write_log(config_log_fd,"Error to open combine web log file %s:%s\n" % (global_config_hashtable['WEB_LOG_DIR'],today_time_date))
            return -1
    except:
        return -2
    return 0
Esempio n. 5
0
def check_logname_update(global_config_hash,config_log_fd,l_date):
    global combine_log_handle
    #new_time_date=str(datetime.datetime.now()).split()[0]
    new_time_date=l_date
    if(new_time_date!=today_time_date):
        try:
            combine_log_handle.close()
            combine_log_handle=open(global_config_hash['WEB_LOG_DIR'] + "/" + new_time_date + "-act-combine.log","a")
            if(combine_log_handle is None):
                SpecialOperationThread.unversal_write_log(config_log_fd,"Error to open combine web log file %s:%s\n" % (global_config_hashtable['WEB_LOG_DIR'],new_time_date))
                print "Error to open combine web log file %s:%s" % (global_config_hashtable['WEB_LOG_DIR'],new_time_date)
                return -1
        except:
            return -2
    return 0
Esempio n. 6
0
 def run(self):
     first_o_result=open_log_first(self.global_config_hash,self.config_log_fd)
     if(first_o_result < 0):
         if(first_o_result == -2):
             SpecialOperationThread.unversal_write_log(config_log_fd,"Error to open combine web log file %s:%s\n" % (global_config_hashtable['WEB_LOG_DIR'],"onfirst"))
         return "error"
     while(1==1):
         #The following 3 lines is deleted on 2012-08-23
         #if(self.web_queue.empty()):
         #    usleep(10000)
         #    continue
         #logname_s_result=check_logname_update(self.global_config_hash,self.config_log_fd)
         #if(logname_s_result < 0):
         #    if(logname_s_result == -2):
         #        SpecialOperationThread.unversal_write_log(config_log_fd,"Error to open combine web log file %s:%s\n" % (global_config_hashtable['WEB_LOG_DIR'],"onfirst"))
         #    return "error"
         (log_string,l_date,l_code)=self.web_queue.get()
         logname_s_result=check_logname_update(self.global_config_hash,self.config_log_fd,l_date)
         if(logname_s_result < 0):
             if(logname_s_result == -2):
                 SpecialOperationThread.unversal_write_log(config_log_fd,"Error to open combine web log file %s:%s\n" % (global_config_hashtable['WEB_LOG_DIR'],"onfirst"))
             self.web_queue.task_done()
             return "error"
         if(combine_log_handle is None and log_string is not None):
             self.config_log_fd_web.write(l_code + " " + log_string + "\n")
             self.config_log_fd_web.flush()
             self.web_queue.task_done()
             continue
         if(log_string is not None):
             try:
                 combine_log_handle.write(l_code + " " + log_string + "\n")
                 combine_log_handle.flush()
             except IOError,ioe:
                 print "Write web log string error %s and exactly error %s ..\n" % (log_string,ioe.args)
                 self.config_log_fd_web.write(l_code + " " + log_string +"\n")
                 self.config_log_fd_web.flush()
                 self.web_queue.task_done()
                 GlobalConfigHandleKernel.global_ksms_temp_queue.put(["ksms Write web action log failed,hostname:[%s]" % GlobalConfigHandleKernel.global_hostname,"127.0.0.1"])
                 continue
             except Exception,ioe:
                 print "Write web log string error %s and exactly error %s ..\n" % (log_string,ioe.args)
                 self.config_log_fd_web.write(l_code + " " + log_string +"\n")
                 self.config_log_fd_web.flush()
                 self.web_queue.task_done()
                 GlobalConfigHandleKernel.global_ksms_temp_queue.put(["ksms Write web action log failed,hostname:[%s]" % GlobalConfigHandleKernel.global_hostname,"127.0.0.1"])
                 continue
             except:
Esempio n. 7
0
def create_connect_socket(untar_log_fd,global_config_hash,t_ip):
    clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    if(clientsocket < 0):
        SpecialOperationThread.unversal_write_log(untar_log_fd,"Create clientsocket failed in client_sync_server thread\n") 
        return "error"
    clientsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    clientsocket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
    clientsocket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
    try:
        clientsocket.settimeout(10)
        clientsocket.connect((t_ip,int(global_config_hash['SERVER_PORT'])))
        clientsocket.settimeout(None)
    except:
        clientsocket.close()
        SpecialOperationThread.unversal_write_log(untar_log_fd,"Connect failed to universal remote ip:port %s:%s in client_sync_server thread\n" % (t_ip,global_config_hash['SERVER_PORT'])) 
        return "error"
    return clientsocket
Esempio n. 8
0
def create_connect_socket(config_log_fd,global_config_hash):
    if(GlobalConfigHandleKernel.remote_universal_ip is None):
        time.sleep(1)
        return "error"
    clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    if(clientsocket < 0):
        SpecialOperationThread.unversal_write_log(config_log_fd,"Create clientsocket failed in local_sms_queue thread\n") 
        return "error"
    clientsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    clientsocket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
    clientsocket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
    try:
        clientsocket.settimeout(10)
        clientsocket.connect((GlobalConfigHandleKernel.remote_universal_ip,int(global_config_hash['SERVER_PORT'])))
        clientsocket.settimeout(None)
    except:
        clientsocket.close()
        SpecialOperationThread.unversal_write_log(config_log_fd,"Connect failed to universal remote ip:port %s:%s in local_sms_queue thread\n" % (GlobalConfigHandleKernel.remote_universal_ip,global_config_hash['SERVER_PORT'])) 
        return "error"
    return clientsocket
Esempio n. 9
0
 def run(self):
     while (1 == 1):
         #pipein,pipeout=os.pipe()
         p = subprocess.Popen(
             "%s %s %s" % (self.global_config_hash['OSCOUNT_SCRIPT'],
                           GlobalConfigHandleKernel.remote_universal_bus,
                           GlobalConfigHandleKernel.remote_universal_ip),
             shell=True,
             close_fds=True,
             stdin=open("/dev/null", 'r'),
             #stdout=pipein,
             stdout=subprocess.PIPE,
             stderr=open("/dev/null", 'w'))
         #os.close(pipein)
         wait_time = 0
         while (wait_time < 30):
             poll_status = p.poll()
             if (poll_status is not None):
                 break
             else:
                 time.sleep(1)
                 wait_time = wait_time + 1
                 continue
         poll_status = p.poll()
         if (poll_status is None):
             p.kill()
             SpecialOperationThread.unversal_write_log(
                 self.config_log_fd, "Here gets the oscount not finished\n")
             time.sleep(int(self.global_config_hash['OSCOUNT_SLEEP']))
             continue
         if (p.returncode != 0):
             SpecialOperationThread.unversal_write_log(
                 self.config_log_fd,
                 "Here gets the oscount returncode !=0 maybe failed\n")
         else:
             for count_data in p.stdout:
                 GlobalConfigHandleKernel.global_oscount_data[
                     'oscount'] = count_data.strip()
                 break
             #os.close(pipeout)
         time.sleep(int(self.global_config_hash['OSCOUNT_SLEEP']))
Esempio n. 10
0
 def run(self):
     connections={}
     addressall={}
     while True:
         try:
             while True:
                 events = GlobalConfigHandleKernel.global_autountar_epollfd.poll(int(self.global_config_hash['LISTEN_FD']))
                 for fileno, event in events:
                     if(event & select.EPOLLIN):
                         if(fileno >= int(self.global_config_hash['LISTEN_FD'])-2):
                             SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Auto server fd mounted to maximum,exit\n")
                             clear_autotar_tok(fileno)
                             #exit(1) modified as following:
                             continue
                         data_tmp=""
                         while True:
                             try:
                                 data_tmp=GlobalConfigHandleKernel.global_autountar_epoll_handle_conn[fileno].recv(int(self.global_config_hash['BUF_SIZE']))
                                 if(data_tmp is not None and len(data_tmp) >0 and len(data_tmp) <= int(self.global_config_hash['BUF_SIZE'])):
                                     if(data_tmp.strip() == "TaskServerAuto exit"):
                                         clear_autotar_tok(fileno)
                                         break
                                     GlobalConfigHandleKernel.global_autountar_epoll_handle_openresult[fileno].write(data_tmp)
                                     GlobalConfigHandleKernel.global_autountar_epoll_handle_openresult[fileno].flush()
                                     break
                                 elif(len(data_tmp) <= 0 or len(data_tmp) > int(self.global_config_hash['BUF_SIZE'])):
                                     clear_autotar_tok(fileno)
                                     break
                             except socket.error,msg:
                                 if(msg.errno == errno.EAGAIN or msg.errno == errno.EWOULDBLOCK or msg.errno==errno.EINTR):
                                     continue
                                 else:
                                     clear_autotar_tok(fileno)
                                     break
                             except:
                                 if(1<0):
                                     pass
                                 else:
                                     clear_autotar_tok(fileno)
                                     break
Esempio n. 11
0
def create_connect_socket(untar_log_fd, global_config_hash, t_ip):
    clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    if (clientsocket < 0):
        SpecialOperationThread.unversal_write_log(
            untar_log_fd,
            "Create clientsocket failed in client_sync_server thread\n")
        return "error"
    clientsocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    clientsocket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
    clientsocket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
    try:
        clientsocket.settimeout(10)
        clientsocket.connect((t_ip, int(global_config_hash['SERVER_PORT'])))
        clientsocket.settimeout(None)
    except:
        clientsocket.close()
        SpecialOperationThread.unversal_write_log(
            untar_log_fd,
            "Connect failed to universal remote ip:port %s:%s in client_sync_server thread\n"
            % (t_ip, global_config_hash['SERVER_PORT']))
        return "error"
    return clientsocket
Esempio n. 12
0
 def run(self):
     clientsocket=None
     while(1==1):
         clientsocket=create_connect_socket(self.config_log_fd,self.global_config_hash)
         if(str(clientsocket) == "error"):
             time.sleep(1)
             continue
         else:
             break
     create_tok=0
     while(1==1):
         abc_sms=GlobalConfigHandleKernel.local_sms_queue.get()
         if(abc_sms is None or len(abc_sms.strip()) < 6):
             continue
         abc_sms=abc_sms.strip().replace("lsms","ksms")
         while(1==1):
             if(create_tok==1):
                 create_tok=0
                 while(1==1):
                     clientsocket=create_connect_socket(self.config_log_fd,self.global_config_hash)
                     if(str(clientsocket) == "error"):
                         time.sleep(1)
                         continue
                     else:
                         break
             try:
                 infds,outfds,errfds=select.select([],[clientsocket.fileno()],[],int(self.global_config_hash['CONNECT_TIMEOUT']))
                 if(len(outfds) !=0):
                     clientsocket.send(abc_sms +"\r\n")
                 else:
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(self.config_log_fd,"Send failed to universal remote ip %s in local_sms_queue thread\n" % GlobalConfigHandleKernel.remote_universal_ip) 
                     time.sleep(1)
                     create_tok=1
                     continue
                 infds,outfds,errfds=select.select([clientsocket.fileno()],[],[],int(self.global_config_hash['CONNECT_TIMEOUT']))
                 recv_tmp_data=None
                 if(len(infds) !=0):
                     recv_tmp_data=clientsocket.recv(1024)
                 else:
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(self.config_log_fd,"Recv failed to universal remote ip %s in local_sms_queue thread\n" % GlobalConfigHandleKernel.remote_universal_ip) 
                     time.sleep(1)
                     create_tok=1
                     continue
                 if(recv_tmp_data.strip() != "ok"):
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(self.config_log_fd,"Notok failed to universal remote ip %s in local_sms_queue thread\n" % GlobalConfigHandleKernel.remote_universal_ip) 
                     time.sleep(1)
                     create_tok=1
                     continue
             except:
                 clientsocket.close()
                 time.sleep(1)
                 create_tok=1
                 continue
             break
         continue
     clientsocket.close()
Esempio n. 13
0
 def run(self):
     while (1 == 1):
         [task_pre,
          task_addr] = GlobalConfigHandleKernel.global_untar_iptask.get()
         if (task_pre is None or task_addr is None):
             SpecialOperationThread.unversal_write_log(
                 self.untar_log_fd, "Here gets the setuntar error : None\n")
             continue
         task_line = task_pre.split()
         if (task_line is None or (len(task_line) != 5)
                 or task_line[0].strip() != "setuntar"):
             #here send alarms
             GlobalConfigHandleKernel.local_sms_queue.put(
                 "lsms " + str(GlobalConfigHandleKernel.global_my_ip) +
                 " Here gets the setuntar error")
             SpecialOperationThread.unversal_write_log(
                 self.untar_log_fd,
                 "Here gets the setuntar error : %s\n" % task_pre)
             continue
         for dip in task_line[2].strip().split(","):
             clientsocket = None
             client_try_time = 0
             while (1 == 1):
                 clientsocket = create_connect_socket(
                     self.untar_log_fd, self.global_config_hash, dip)
                 if (str(clientsocket) == "error"):
                     time.sleep(1)
                     client_try_time = client_try_time + 1
                     if (client_try_time >= 3):
                         break
                     continue
                 else:
                     break
             if (client_try_time >= 3):
                 GlobalConfigHandleKernel.local_sms_queue.put(
                     "lsms " + str(GlobalConfigHandleKernel.global_my_ip) +
                     " Here cannot connect to " + dip)
                 #here send alarms
                 continue
             try:
                 if ("/" not in task_line[1].strip()):
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Wrong filename failed to ip %s:%s in client_sync_server thread\n"
                         % (dip, task_line[1].strip()))
                     #here send alarms
                     GlobalConfigHandleKernel.local_sms_queue.put(
                         "lsms " +
                         str(GlobalConfigHandleKernel.global_my_ip) +
                         " Wrong filename of setuntar " +
                         task_line[1].strip())
                     continue
                 r_filename = (task_line[1].strip()
                               )[task_line[1].strip().rindex("/"):]
                 infds, outfds, errfds = select.select(
                     [], [clientsocket.fileno()], [],
                     int(self.global_config_hash['CONNECT_TIMEOUT']))
                 if (len(outfds) != 0):
                     ten_access = int(
                         stat.S_IMODE(
                             os.stat(task_line[1].strip()).st_mode))
                     eight_1 = ten_access / 64
                     eight_2 = (ten_access - 64 * eight_1) / 8
                     eight_3 = (ten_access - 64 * eight_1 - 8 * eight_2)
                     eight_access = str(eight_1) + str(eight_2) + str(
                         eight_3)
                     if (task_line[3].strip() == "0"):
                         clientsocket.send(
                             "kernel " + getpass.getuser() + " /" +
                             r_filename + " " +
                             str(os.stat(task_line[1].strip())[6]) +
                             " stand " + task_line[4].strip() + " " +
                             eight_access + "\r\n")
                     else:
                         clientsocket.send(
                             "kernel " + getpass.getuser() + " /" +
                             r_filename + " " +
                             str(os.stat(task_line[1].strip())[6]) +
                             " standu " + task_line[4].strip() + " " +
                             eight_access + "\r\n")
                 else:
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Send sync failed to ip %s:%s in client_sync_server thread\n"
                         % (dip, task_line[1].strip()))
                     #here send alarms
                     GlobalConfigHandleKernel.local_sms_queue.put(
                         "lsms " +
                         str(GlobalConfigHandleKernel.global_my_ip) +
                         " Send sync untar from %s:%s failed " %
                         (dip, task_line[1].strip()))
                     continue
                 infds, outfds, errfds = select.select(
                     [clientsocket.fileno()], [], [],
                     int(self.global_config_hash['CONNECT_TIMEOUT']))
                 recv_tmp_data = None
                 if (len(infds) != 0):
                     recv_tmp_data = clientsocket.recv(1024)
                 else:
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Recv1 failed from ip %s:%s in client_sync_server thread\n"
                         % (dip, task_line[1].strip()))
                     #here send alarms
                     GlobalConfigHandleKernel.local_sms_queue.put(
                         "lsms " +
                         str(GlobalConfigHandleKernel.global_my_ip) +
                         " Recv sync untar from %s:%s failed " %
                         (dip, task_line[1].strip()))
                     continue
                 if (recv_tmp_data.strip() != "ok"):
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Recv1 ok failed from ip %s:%s in client_sync_server thread\n"
                         % (dip, task_line[1].strip()))
                     #here send alarms
                     GlobalConfigHandleKernel.local_sms_queue.put(
                         "lsms " +
                         str(GlobalConfigHandleKernel.global_my_ip) +
                         " Recv sync untar from %s:%s failed " %
                         (dip, task_line[1].strip()))
                     continue
                 infds, outfds, errfds = select.select(
                     [], [clientsocket.fileno()], [],
                     int(self.global_config_hash['CONNECT_TIMEOUT']))
                 if (len(outfds) == 0):
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Send check failed to ip %s:%s in client_sync_server thread\n"
                         % (dip, task_line[1].strip()))
                     #here send alarms
                     GlobalConfigHandleKernel.local_sms_queue.put(
                         "lsms " +
                         str(GlobalConfigHandleKernel.global_my_ip) +
                         " Send sync untar from %s:%s failed " %
                         (dip, task_line[1].strip()))
                     continue
                 file_tmp_handle = None
                 try:
                     file_tmp_handle = open(task_line[1].strip(), "rb")
                 except:
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Open file failed to ip %s:%s in client_sync_server thread\n"
                         % (dip, task_line[1].strip()))
                     #here send alarms
                     GlobalConfigHandleKernel.local_sms_queue.put(
                         "lsms " +
                         str(GlobalConfigHandleKernel.global_my_ip) +
                         " Open sync untar from %s:%s failed " %
                         (dip, task_line[1].strip()))
                     continue
                 full_tok = 0
                 while (True):
                     kk_tmp_read = file_tmp_handle.read(4096)
                     if (not kk_tmp_read):
                         full_tok = 1
                         break
                     try:
                         clientsocket.send(kk_tmp_read)
                     except:
                         clientsocket.close()
                         SpecialOperationThread.unversal_write_log(
                             self.untar_log_fd,
                             "Send file failed to ip %s:%s in client_sync_server thread\n"
                             % (dip, task_line[1].strip()))
                         #here send alarms
                         GlobalConfigHandleKernel.local_sms_queue.put(
                             "lsms " +
                             str(GlobalConfigHandleKernel.global_my_ip) +
                             " Send file sync untar from %s:%s failed " %
                             (dip, task_line[1].strip()))
                         break
                 file_tmp_handle.close()
                 if (full_tok == 0):
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Send full_tok==0 to ip %s:%s in client_sync_server thread\n"
                         % (dip, task_line[1].strip()))
                     continue
                 infds, outfds, errfds = select.select(
                     [clientsocket.fileno()], [], [],
                     int(self.global_config_hash['CONNECT_TIMEOUT']))
                 recv_tmp_data = None
                 if (len(infds) == 0):
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Recv2 failed from ip %s %s in client_sync_server thread\n"
                         % (dip, (task_line[1].strip())))
                     #here send alarms
                     GlobalConfigHandleKernel.local_sms_queue.put(
                         "lsms " +
                         str(GlobalConfigHandleKernel.global_my_ip) +
                         " Recv2 sync untar from %s:%s failed " %
                         (dip, task_line[1].strip()))
                     continue
                 if (task_line[3].strip() == "0"):
                     try:
                         clientsocket.recv(1024)
                     except:
                         pass
                 else:
                     file_tmp_open_md5 = hashlib.md5(task_line[1].strip() +
                                                     dip).hexdigest()
                     try:
                         result_tmp_open = open(
                             self.global_config_hash['UNTAR_EXEC_RESULT'] +
                             "/" + file_tmp_open_md5 + ".res", "wb")
                     except:
                         clientsocket.close()
                         SpecialOperationThread.unversal_write_log(
                             self.untar_log_fd,
                             "Recv3 failed from ip %s:%s in client_sync_server thread\n"
                             % (dip, task_line[1].strip()))
                         #here send alarms
                         GlobalConfigHandleKernel.local_sms_queue.put(
                             "lsms " +
                             str(GlobalConfigHandleKernel.global_my_ip) +
                             " Recv3 sync untar from %s:%s failed " %
                             (dip, task_line[1].strip()))
                         continue
                     try:
                         abc_tmp = clientsocket.recv(4096)
                         while (abc_tmp and len(abc_tmp) != 0):
                             result_tmp_open.write(abc_tmp)
                             result_tmp_open.flush()
                             abc_tmp = clientsocket.recv(4096)
                     except:
                         clientsocket.close()
                         continue
                     finally:
                         result_tmp_open.close()
                 clientsocket.close()
             except:
                 pass
             continue
Esempio n. 14
0
 def run(self):
     clientsocket = None
     while (1 == 1):
         clientsocket = create_connect_socket(self.untar_log_fd,
                                              self.global_config_hash)
         if (str(clientsocket) == "error"):
             time.sleep(1)
             continue
         else:
             break
     create_tok = 0
     while (1 == 1):
         while (1 == 1):
             time.sleep(int(self.global_config_hash['CLIENT_UNTAR_SLEEP']))
             if (create_tok == 1):
                 create_tok = 0
                 while (1 == 1):
                     clientsocket = create_connect_socket(
                         self.untar_log_fd, self.global_config_hash)
                     if (str(clientsocket) == "error"):
                         time.sleep(1)
                         continue
                     else:
                         break
             try:
                 infds, outfds, errfds = select.select(
                     [], [clientsocket.fileno()], [],
                     int(self.global_config_hash['CONNECT_TIMEOUT']))
                 if (len(outfds) != 0):
                     GlobalConfigHandleKernel.global_my_ip = clientsocket.getsockname(
                     )[0]
                     clientsocket.send("autocoming " +
                                       clientsocket.getsockname()[0] +
                                       "\r\n")
                 else:
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Send auto failed to universal remote ip %s in client_tar_server thread\n"
                         % GlobalConfigHandleKernel.remote_universal_ip)
                     create_tok = 1
                     continue
                 infds, outfds, errfds = select.select(
                     [clientsocket.fileno()], [], [],
                     int(self.global_config_hash['CONNECT_TIMEOUT']))
                 recv_tmp_data = None
                 if (len(infds) != 0):
                     recv_tmp_data = clientsocket.recv(1024)
                 else:
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Recv1 failed from universal remote ip %s in client_tar_server thread\n"
                         % GlobalConfigHandleKernel.remote_universal_ip)
                     create_tok = 1
                     continue
                 if (recv_tmp_data.strip() == "No"):
                     clientsocket.close()
                     create_tok = 1
                     continue
                 recv_2_all = recv_tmp_data.strip().split()
                 if (len(recv_2_all) != 4 or ("/" not in recv_2_all[0])
                         or ("/" not in recv_2_all[3])
                         or (".." in recv_2_all[0])
                         or (".." in recv_2_all[3])):
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Not3 failed from universal remote ip %s in client_tar_server thread\n"
                         % GlobalConfigHandleKernel.remote_universal_ip)
                     create_tok = 1
                     continue
                 infds, outfds, errfds = select.select(
                     [], [clientsocket.fileno()], [],
                     int(self.global_config_hash['CONNECT_TIMEOUT']))
                 if (len(outfds) != 0):
                     clientsocket.send("ok\r\n")
                 else:
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Send ok failed to universal remote ip %s in client_tar_server thread\n"
                         % GlobalConfigHandleKernel.remote_universal_ip)
                     create_tok = 1
                     continue
                 #here recv data
                 tmp_recv_size = 0
                 tmp_recv_tmpdata = None
                 file_suf = (recv_2_all[0].strip()
                             )[recv_2_all[0].strip().rindex("/"):]
                 file_suf = recv_2_all[3].strip() + file_suf
                 trans_result = tar_client_translate_path(file_suf)
                 if (trans_result is None):
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Recv file path None to universal remote ip %s in client_tar_server thread\n"
                         % GlobalConfigHandleKernel.remote_universal_ip)
                     create_tok = 1
                     continue
                 [file_suf_new, file_suf_dir] = trans_result
                 if (file_suf_new is None or file_suf_dir is None):
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Recv file path None to universal remote ip %s in client_tar_server thread\n"
                         % GlobalConfigHandleKernel.remote_universal_ip)
                     create_tok = 1
                     continue
                 try:
                     if (not os.path.isdir(file_suf_dir)):
                         os.makedirs(file_suf_dir, 0755)
                     f_recv_file = open(file_suf_new, "wb")
                 except:
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Recv open file None to universal remote ip %s:%s in client_tar_server thread\n"
                         % (GlobalConfigHandleKernel.remote_universal_ip,
                            file_suf_new))
                     create_tok = 1
                     continue
                 infds, outfds, errfds = select.select(
                     [clientsocket.fileno()], [], [],
                     int(self.global_config_hash['CONNECT_TIMEOUT']))
                 if (len(infds) == 0):
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Recv2 timeout from universal remote ip %s in client_tar_server thread\n"
                         % GlobalConfigHandleKernel.remote_universal_ip)
                     create_tok = 1
                     continue
                 recv_full_tok = 0
                 while (long(tmp_recv_size) < long(recv_2_all[1])):
                     try:
                         tmp_recv_tmpdata = clientsocket.recv(
                             int(self.global_config_hash['BUF_SIZE']))
                         tmp_recv_size = long(tmp_recv_size) + long(
                             len(tmp_recv_tmpdata))
                         f_recv_file.write(tmp_recv_tmpdata)
                         f_recv_file.flush()
                         if (long(tmp_recv_size) == long(recv_2_all[1])):
                             SpecialOperationThread.unversal_write_log(
                                 self.untar_log_fd,
                                 "Recv3 full from universal remote ip %s in client_tar_server thread\n"
                                 % GlobalConfigHandleKernel.
                                 remote_universal_ip)
                             recv_full_tok = 1
                             break
                     except:
                         clientsocket.close()
                         SpecialOperationThread.unversal_write_log(
                             self.untar_log_fd,
                             "Recv data failed from universal remote ip %s in client_tar_server thread\n"
                             % GlobalConfigHandleKernel.remote_universal_ip)
                         create_tok = 1
                         break
                 f_recv_file.close()
                 if (recv_full_tok != 1):
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Recv3 empty from universal remote ip %s in client_tar_server thread\n"
                         % GlobalConfigHandleKernel.remote_universal_ip)
                 if (recv_2_all[2].strip() == "1" and recv_full_tok == 1):
                     GlobalConfigHandleKernel.task_data_queue.put([
                         "utar", file_suf_new,
                         clientsocket.fileno(), clientsocket, "close"
                     ])
                     clientsocket = None
                 else:
                     try:
                         clientsocket.send("Finished\r\n")
                     except:
                         pass
                     clientsocket.close()
                 create_tok = 1
                 continue
             except:
                 clientsocket.close()
                 create_tok = 1
                 continue
             continue
         continue
     clientsocket.close()
Esempio n. 15
0
 def run(self):
     while(1==1):
         [task_pre,task_addr]=GlobalConfigHandleKernel.global_untar_iptask.get()
         if(task_pre is None or task_addr is None):
             SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Here gets the setuntar error : None\n")
             continue
         task_line=task_pre.split()
         if(task_line is None or (len(task_line)!=5) or task_line[0].strip()!="setuntar"):
             #here send alarms
             GlobalConfigHandleKernel.local_sms_queue.put("lsms " + str(GlobalConfigHandleKernel.global_my_ip) + " Here gets the setuntar error")
             SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Here gets the setuntar error : %s\n" % task_pre)
             continue
         for dip in task_line[2].strip().split(","):
             clientsocket=None
             client_try_time=0
             while(1==1):
                 clientsocket=create_connect_socket(self.untar_log_fd,self.global_config_hash,dip)
                 if(str(clientsocket) == "error"):
                     time.sleep(1)
                     client_try_time=client_try_time + 1
                     if(client_try_time >=3):
                         break
                     continue
                 else:
                     break
             if(client_try_time >=3):
                 GlobalConfigHandleKernel.local_sms_queue.put("lsms " + str(GlobalConfigHandleKernel.global_my_ip) + " Here cannot connect to " + dip)
                 #here send alarms
                 continue
             try:
                 if("/" not in task_line[1].strip()):
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Wrong filename failed to ip %s:%s in client_sync_server thread\n" % (dip,task_line[1].strip()))
                     #here send alarms
                     GlobalConfigHandleKernel.local_sms_queue.put("lsms " + str(GlobalConfigHandleKernel.global_my_ip) + " Wrong filename of setuntar " + task_line[1].strip())
                     continue
                 r_filename=(task_line[1].strip())[task_line[1].strip().rindex("/"):]
                 infds,outfds,errfds=select.select([],[clientsocket.fileno()],[],int(self.global_config_hash['CONNECT_TIMEOUT']))
                 if(len(outfds) !=0):
                     ten_access=int(stat.S_IMODE(os.stat(task_line[1].strip()).st_mode))
                     eight_1=ten_access/64
                     eight_2=(ten_access-64*eight_1)/8
                     eight_3=(ten_access-64*eight_1-8*eight_2)
                     eight_access=str(eight_1) + str(eight_2) + str(eight_3)
                     if(task_line[3].strip() == "0"):
                         clientsocket.send("kernel " +getpass.getuser() + " /" +r_filename + " " +str(os.stat(task_line[1].strip())[6]) + " stand " +task_line[4].strip()+ " "+eight_access+"\r\n")
                     else:
                         clientsocket.send("kernel " +getpass.getuser() + " /" +r_filename + " " +str(os.stat(task_line[1].strip())[6]) + " standu " +task_line[4].strip()+ " "+eight_access+"\r\n")
                 else:
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Send sync failed to ip %s:%s in client_sync_server thread\n" % (dip,task_line[1].strip()))
                     #here send alarms
                     GlobalConfigHandleKernel.local_sms_queue.put("lsms " + str(GlobalConfigHandleKernel.global_my_ip) + " Send sync untar from %s:%s failed " % (dip,task_line[1].strip()))
                     continue
                 infds,outfds,errfds=select.select([clientsocket.fileno()],[],[],int(self.global_config_hash['CONNECT_TIMEOUT']))
                 recv_tmp_data=None
                 if(len(infds) !=0):
                     recv_tmp_data=clientsocket.recv(1024)
                 else:
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Recv1 failed from ip %s:%s in client_sync_server thread\n" % (dip,task_line[1].strip()))
                     #here send alarms
                     GlobalConfigHandleKernel.local_sms_queue.put("lsms " + str(GlobalConfigHandleKernel.global_my_ip) + " Recv sync untar from %s:%s failed " % (dip,task_line[1].strip()))
                     continue
                 if(recv_tmp_data.strip() != "ok"):
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Recv1 ok failed from ip %s:%s in client_sync_server thread\n" % (dip,task_line[1].strip()))
                     #here send alarms
                     GlobalConfigHandleKernel.local_sms_queue.put("lsms " + str(GlobalConfigHandleKernel.global_my_ip) + " Recv sync untar from %s:%s failed " % (dip,task_line[1].strip()))
                     continue
                 infds,outfds,errfds=select.select([],[clientsocket.fileno()],[],int(self.global_config_hash['CONNECT_TIMEOUT']))
                 if(len(outfds) ==0):
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Send check failed to ip %s:%s in client_sync_server thread\n" % (dip,task_line[1].strip()))
                     #here send alarms
                     GlobalConfigHandleKernel.local_sms_queue.put("lsms " + str(GlobalConfigHandleKernel.global_my_ip) + " Send sync untar from %s:%s failed " % (dip,task_line[1].strip()))
                     continue
                 file_tmp_handle=None
                 try:
                     file_tmp_handle=open(task_line[1].strip(),"rb")
                 except:
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Open file failed to ip %s:%s in client_sync_server thread\n" % (dip,task_line[1].strip()))
                     #here send alarms
                     GlobalConfigHandleKernel.local_sms_queue.put("lsms " + str(GlobalConfigHandleKernel.global_my_ip) + " Open sync untar from %s:%s failed " % (dip,task_line[1].strip()))
                     continue
                 full_tok=0
                 while(True):
                     kk_tmp_read=file_tmp_handle.read(4096)
                     if(not kk_tmp_read):
                         full_tok=1
                         break
                     try:
                         clientsocket.send(kk_tmp_read)
                     except:
                         clientsocket.close()
                         SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Send file failed to ip %s:%s in client_sync_server thread\n" % (dip,task_line[1].strip()))
                         #here send alarms
                         GlobalConfigHandleKernel.local_sms_queue.put("lsms " + str(GlobalConfigHandleKernel.global_my_ip) + " Send file sync untar from %s:%s failed " % (dip,task_line[1].strip()))
                         break
                 file_tmp_handle.close()
                 if(full_tok ==0):
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Send full_tok==0 to ip %s:%s in client_sync_server thread\n" % (dip,task_line[1].strip()))
                     continue
                 infds,outfds,errfds=select.select([clientsocket.fileno()],[],[],int(self.global_config_hash['CONNECT_TIMEOUT']))
                 recv_tmp_data=None
                 if(len(infds) ==0):
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Recv2 failed from ip %s %s in client_sync_server thread\n" % (dip,(task_line[1].strip())))
                     #here send alarms
                     GlobalConfigHandleKernel.local_sms_queue.put("lsms " + str(GlobalConfigHandleKernel.global_my_ip) + " Recv2 sync untar from %s:%s failed " % (dip,task_line[1].strip()))
                     continue
                 if(task_line[3].strip() == "0"):
                     try:
                         clientsocket.recv(1024)
                     except:
                         pass
                 else:
                     file_tmp_open_md5=hashlib.md5(task_line[1].strip() + dip).hexdigest()
                     try:
                         result_tmp_open=open(self.global_config_hash['UNTAR_EXEC_RESULT'] + "/" + file_tmp_open_md5 + ".res","wb")
                     except:
                         clientsocket.close()
                         SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Recv3 failed from ip %s:%s in client_sync_server thread\n" % (dip,task_line[1].strip()))
                         #here send alarms
                         GlobalConfigHandleKernel.local_sms_queue.put("lsms " + str(GlobalConfigHandleKernel.global_my_ip) + " Recv3 sync untar from %s:%s failed " % (dip,task_line[1].strip()))
                         continue
                     try:
                         abc_tmp=clientsocket.recv(4096)
                         while(abc_tmp and len(abc_tmp)!=0):
                             result_tmp_open.write(abc_tmp)
                             result_tmp_open.flush()
                             abc_tmp=clientsocket.recv(4096)
                     except:
                         clientsocket.close()
                         continue
                     finally:
                         result_tmp_open.close()
                 clientsocket.close()
             except:
                 pass
             continue
Esempio n. 16
0
 def run(self):
     while(1==1):
         [task_tok,task_filename,task_id,task_conns,task_option]=GlobalConfigHandleKernel.task_data_queue.get()
         #print(task_tok + task_filename)
         try:
             task_conns.setblocking(0)
         except:
             pass
         if(task_option is None or len(task_option)==0):
             SpecialOperationThread.unversal_write_log(self.config_log_fd,"Here gets the error task line from task_data_queue: %s,%s\n" % (task_tok,task_filename))
             GlobalConfigHandleKernel.task_data_queue.task_done()
             need_close_conns(task_conns,task_option)
             continue
         if(task_filename is None or len(task_filename)==0):
             SpecialOperationThread.unversal_write_log(self.config_log_fd,"Here gets the error task line from task_data_queue: %s,%s\n" % (task_tok,task_filename))
             GlobalConfigHandleKernel.task_data_queue.task_done()
             need_close_conns(task_conns,task_option)
             continue
         if(task_id is None or len(str(task_id))==0):
             SpecialOperationThread.unversal_write_log(self.config_log_fd,"Here gets the error task line from task_data_queue: %s,%s\n" % (task_tok,task_filename))
             GlobalConfigHandleKernel.task_data_queue.task_done()
             need_close_conns(task_conns,task_option)
             continue
         task_data_hash=self.global_config_hash['TASK_QUEUE_SH']
         task_data_hash_real=eval(task_data_hash)
         tmp_task_get=None
         if((task_tok is not None) and (task_tok in task_data_hash_real)):
             tmp_task_get=task_data_hash_real[task_tok]
         else:
             SpecialOperationThread.unversal_write_log(self.config_log_fd,"Here gets the error task line from task_data_queue not in the config hash : %s,%s\n" % (task_tok,task_filename))
             GlobalConfigHandleKernel.task_data_queue.task_done()
             need_close_conns(task_conns,task_option)
             continue
         p=None
         sh_toks=0
         if(len(str(task_filename)) >=4):
             file_suffix_name=""
             if("." in str(task_filename)):
                 file_suffix_name=str(task_filename)[str(task_filename).rindex("."):]
             support_suffix=eval(self.global_config_hash['UNTAR_SUPPORT_EXEC'])
             if(file_suffix_name in support_suffix):
                 sh_toks=1
                 mode=(7*8*8)+(5 *8)+ 5
                 os.chmod(str(task_filename),mode)
                 if(file_suffix_name != ".exe"):
                     try:
                         os.system("sed -i 's/\r//g' %s ;" % str(task_filename))
                     except:
                         pass
                 p = subprocess.Popen("%s" % str(task_filename),
                                             shell=True,
                                             close_fds=True,
                                             stdin=open("/dev/null", 'r'),
                                             stdout=task_id,
                                             stderr=subprocess.STDOUT)
             else:
                 p = subprocess.Popen("%s %s" % (str(tmp_task_get),str(task_filename)),
                                             shell=True,
                                             close_fds=True,
                                             stdin=open("/dev/null", 'r'),
                                             stdout=task_id,
                                             stderr=subprocess.STDOUT)
         else:
             p = subprocess.Popen("%s %s" % (str(tmp_task_get),str(task_filename)),
                                             shell=True,
                                             close_fds=True,
                                             stdin=open("/dev/null", 'r'),
                                             stdout=task_id,
                                             stderr=subprocess.STDOUT)
         wait_time=0
         while(wait_time < int(self.global_config_hash['TASK_TIMEOUT'])):
             poll_status=p.poll()
             if(poll_status is not None):
                 break
             else:
                 time.sleep(1)
                 wait_time=wait_time + 1
                 continue
         poll_status=p.poll()
         if(poll_status is None):
             p.kill()
             SpecialOperationThread.unversal_write_log(self.config_log_fd,"Here gets the task not finished for : %s,%s\n" % (task_tok,task_filename))
             GlobalConfigHandleKernel.task_data_queue.task_done()
             need_close_conns(task_conns,task_option)
             continue
         if(p.returncode !=0):
             SpecialOperationThread.unversal_write_log(self.config_log_fd,"Here gets the task returncode !=0 maybe failed : %s,%s\n" % (task_tok,task_filename))
         else:
             SpecialOperationThread.unversal_write_log(self.config_log_fd,"Here gets the task successfully : %s,%s\n" % (task_tok,task_filename))
             try:
                 if(os_toks == 0):
                     os.unlink(task_filename)
             except:
                 pass
         GlobalConfigHandleKernel.task_data_queue.task_done()
         need_close_conns(task_conns,task_option)
         continue
Esempio n. 17
0
 def run(self):
     clientsocket = None
     while (1 == 1):
         clientsocket = create_connect_socket(self.config_log_fd,
                                              self.global_config_hash)
         if (str(clientsocket) == "error"):
             time.sleep(1)
             continue
         else:
             break
     create_tok = 0
     while (1 == 1):
         abc_sms = GlobalConfigHandleKernel.local_sms_queue.get()
         if (abc_sms is None or len(abc_sms.strip()) < 6):
             continue
         abc_sms = abc_sms.strip().replace("lsms", "ksms")
         while (1 == 1):
             if (create_tok == 1):
                 create_tok = 0
                 while (1 == 1):
                     clientsocket = create_connect_socket(
                         self.config_log_fd, self.global_config_hash)
                     if (str(clientsocket) == "error"):
                         time.sleep(1)
                         continue
                     else:
                         break
             try:
                 infds, outfds, errfds = select.select(
                     [], [clientsocket.fileno()], [],
                     int(self.global_config_hash['CONNECT_TIMEOUT']))
                 if (len(outfds) != 0):
                     clientsocket.send(abc_sms + "\r\n")
                 else:
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(
                         self.config_log_fd,
                         "Send failed to universal remote ip %s in local_sms_queue thread\n"
                         % GlobalConfigHandleKernel.remote_universal_ip)
                     time.sleep(1)
                     create_tok = 1
                     continue
                 infds, outfds, errfds = select.select(
                     [clientsocket.fileno()], [], [],
                     int(self.global_config_hash['CONNECT_TIMEOUT']))
                 recv_tmp_data = None
                 if (len(infds) != 0):
                     recv_tmp_data = clientsocket.recv(1024)
                 else:
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(
                         self.config_log_fd,
                         "Recv failed to universal remote ip %s in local_sms_queue thread\n"
                         % GlobalConfigHandleKernel.remote_universal_ip)
                     time.sleep(1)
                     create_tok = 1
                     continue
                 if (recv_tmp_data.strip() != "ok"):
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(
                         self.config_log_fd,
                         "Notok failed to universal remote ip %s in local_sms_queue thread\n"
                         % GlobalConfigHandleKernel.remote_universal_ip)
                     time.sleep(1)
                     create_tok = 1
                     continue
             except:
                 clientsocket.close()
                 time.sleep(1)
                 create_tok = 1
                 continue
             break
         continue
     clientsocket.close()
Esempio n. 18
0
                 break
         except socket.error,msg:
             if(msg.errno == errno.EAGAIN or msg.errno == errno.EWOULDBLOCK or msg.errno==errno.EINTR):
                 continue
             else:
                 clear_autotar_tok(fileno)
                 break
         except:
             if(1<0):
                 pass
             else:
                 clear_autotar_tok(fileno)
                 break
 elif(event & select.EPOLLOUT):
     if(fileno >= int(self.global_config_hash['LISTEN_FD'])-2):
         SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Auto server fd mounted to maximum,exit\n")
         exit(1)
     if(GlobalConfigHandleKernel.global_autountar_epoll_handle_full.get(fileno) is not None):
         continue
     data_tmp=""
     data_tmp=GlobalConfigHandleKernel.global_autountar_epoll_handle_openfile[fileno].read(int(self.global_config_hash['BUF_SIZE']))
     #if(data_tmp is None):
     if(data_tmp is None or data_tmp ==""):
         GlobalConfigHandleKernel.global_autountar_epoll_handle_full[fileno]="full"
         SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Auto server openfile read fully\n")
         continue
     while True:
         try:
             send_size=0
             while(send_size < len(data_tmp)):
                 data_tmp=data_tmp[send_size:]
Esempio n. 19
0
 def run(self):
     while (1 == 1):
         [task_pre, task_con,
          task_id] = GlobalConfigHandleKernel.global_autountar_iptask.get()
         if (task_pre is None or task_con is None or task_id is None):
             SpecialOperationThread.unversal_write_log(
                 self.untar_log_fd, "Here gets the autotar error : None\n")
             continue
         task_line = task_pre.split()
         if (task_line is None
                 or (len(task_line) != 5 and len(task_line) != 2)):
             send_common_result_to_client(task_con, "Error\r\n")
             need_close_conns(task_con, "close")
             SpecialOperationThread.unversal_write_log(
                 self.untar_log_fd,
                 "Here gets the autotar error : %s\n" % task_pre)
             continue
         if (len(task_line) == 2 and task_line[0].strip() == "delcoming"):
             for d_ip in task_line[1].strip().split(","):
                 if (d_ip in GlobalConfigHandleKernel.global_tar_all_hash):
                     if (len(GlobalConfigHandleKernel.
                             global_tar_all_hash[d_ip]) != 0):
                         del (GlobalConfigHandleKernel.
                              global_tar_all_hash[d_ip][0])
             send_common_result_to_client(task_con, "OK\r\n")
             need_close_conns(task_con, "close")
         elif (len(task_line) == 2
               and task_line[0].strip() == "cleancoming"):
             for d_ip in task_line[1].strip().split(","):
                 if (d_ip in GlobalConfigHandleKernel.global_tar_all_hash):
                     GlobalConfigHandleKernel.global_tar_all_hash[d_ip] = []
             send_common_result_to_client(task_con, "OK\r\n")
             need_close_conns(task_con, "close")
         elif (len(task_line) == 2
               and task_line[0].strip() == "removecoming"):
             for d_ip in task_line[1].strip().split(","):
                 if (d_ip in GlobalConfigHandleKernel.global_tar_all_hash):
                     del (
                         GlobalConfigHandleKernel.global_tar_all_hash[d_ip])
             send_common_result_to_client(task_con, "OK\r\n")
             need_close_conns(task_con, "close")
         elif (len(task_line) == 2
               and task_line[0].strip() == "autocoming"):
             if (task_line[1].strip()
                     in GlobalConfigHandleKernel.global_tar_all_hash
                     and len(GlobalConfigHandleKernel.global_tar_all_hash[
                         task_line[1].strip()]) != 0):
                 send_rs = send_common_result_to_client(
                     task_con,
                     (GlobalConfigHandleKernel.global_tar_all_hash[
                         task_line[1].strip()][0]).replace("$", " ") +
                     "\r\n")
                 if (send_rs == "error"):
                     need_close_conns(task_con, "close")
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Here sends name and size of the autotar step 2 error : %s\n"
                         % GlobalConfigHandleKernel.global_tar_all_hash[
                             task_line[1].strip()][0])
                     continue
                 try:
                     recv_len = None
                     infds, outfds, errfds = select.select(
                         [task_id], [], [],
                         int(self.global_config_hash['CONNECT_TIMEOUT']))
                     if (len(infds) != 0):
                         recv_len = task_con.recv(1024)
                 except:
                     need_close_conns(task_con, "close")
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Here recv ok of the autotar step 3 except : %s\n"
                         % GlobalConfigHandleKernel.global_tar_all_hash[
                             task_line[1].strip()][0])
                     continue
                 if (recv_len is None or recv_len.strip() != "ok"
                         or len(recv_len) >= 1023 or len(recv_len) <= 0):
                     need_close_conns(task_con, "close")
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Here recv ok of the autotar step 3 error : %s\n" %
                         GlobalConfigHandleKernel.global_tar_all_hash[
                             task_line[1].strip()][0])
                     continue
                 #here open files
                 try:
                     file_tmp_open_name = (
                         GlobalConfigHandleKernel.global_tar_all_hash[
                             task_line[1].strip()][0]).split("$")[0]
                     file_tmp_open_md5 = hashlib.md5(
                         file_tmp_open_name +
                         task_line[1].strip()).hexdigest()
                     file_tmp_open = open(file_tmp_open_name, "rb")
                     result_tmp_open = open(
                         self.global_config_hash['UNTAR_EXEC_RESULT'] +
                         "/" + file_tmp_open_md5 + ".res", "wb")
                 except:
                     need_close_conns(task_con, "close")
                     SpecialOperationThread.unversal_write_log(
                         self.untar_log_fd,
                         "Here open file of the autotar step 4 failed  : %s\n"
                         % GlobalConfigHandleKernel.global_tar_all_hash[
                             task_line[1].strip()][0])
                     continue
                 try:
                     task_con.setblocking(0)
                 except:
                     pass
                 del (GlobalConfigHandleKernel.global_tar_all_hash[
                     task_line[1].strip()][0])
                 GlobalConfigHandleKernel.global_autountar_epoll_handle_openfile[
                     task_id] = file_tmp_open
                 GlobalConfigHandleKernel.global_autountar_epoll_handle_openresult[
                     task_id] = result_tmp_open
                 GlobalConfigHandleKernel.global_autountar_epoll_handle_conn[
                     task_id] = task_con
                 GlobalConfigHandleKernel.global_autountar_epollfd.register(
                     task_id, select.EPOLLIN | select.EPOLLOUT)
                 #here need to delete hash for ip
                 continue
             else:
                 send_common_result_to_client(task_con, "No\r\n")
                 need_close_conns(task_con, "close")
         elif (len(task_line) == 5 and task_line[0].strip() == "autountar"):
             if (not os.path.isfile(task_line[1].strip())):
                 send_common_result_to_client(task_con, "Error\r\n")
                 need_close_conns(task_con, "close")
                 continue
             for d_ip in task_line[2].strip().split(","):
                 if (d_ip.strip()
                         in GlobalConfigHandleKernel.global_tar_all_hash):
                     GlobalConfigHandleKernel.global_tar_all_hash[
                         d_ip].append(
                             task_line[1].strip() + "$" +
                             str(os.stat(task_line[1].strip())[6]) + "$" +
                             task_line[3].strip() + "$" +
                             task_line[4].strip())
                 else:
                     GlobalConfigHandleKernel.global_tar_all_hash[d_ip] = [
                         task_line[1].strip() + "$" +
                         str(os.stat(task_line[1].strip())[6]) + "$" +
                         task_line[3].strip() + "$" + task_line[4].strip()
                     ]
             send_common_result_to_client(task_con, "OK\r\n")
             need_close_conns(task_con, "close")
         else:
             send_common_result_to_client(task_con, "Error\r\n")
             need_close_conns(task_con, "close")
         continue
Esempio n. 20
0
 def run(self):
     while(1==1):
         [abc_sms,abc_client]=GlobalConfigHandleKernel.global_rrsms_queue.get()
         if(abc_sms is None or len(abc_sms.strip()) < 14 ):
             SpecialOperationThread.unversal_write_log(self.log_fd,"RRSMS wrong: %s [%s]\n" % (abc_sms,abc_client))
             continue
         abc_array=abc_sms.split()
         if(abc_array is None or len(abc_array) != 4):
             SpecialOperationThread.unversal_write_log(self.log_fd,"RRSMS wrong: %s [%s]\n" % (abc_sms,abc_client))
             continue
         abc_msg=abc_array[3].strip()
         abc_msg=abc_msg.replace("'","")
         abc_msg=abc_msg.replace("\"","")
         abc_msg=urllib.unquote(abc_msg)
         if(abc_msg is None or len(abc_msg) < 2):
             SpecialOperationThread.unversal_write_log(self.log_fd,"RRSMS wrong: %s [%s]\n" % (abc_sms,abc_client))
             continue
         #here congervency alarms
         ip_value=""
         ip_f=re.findall(r"([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)",abc_msg)
         if(ip_f is None or len(ip_f) ==0):
             ip_value=""
         else:
             ip_value=":".join(ip_f)
         sub_rep=re.compile("([0-9]+|%)")
         sub_result=sub_rep.sub("",abc_msg)
         sub_md5=hashlib.md5(ip_value + sub_result).hexdigest()
         current_second=long(str(time.time()).split(".")[0])
         if(sub_md5 in GlobalConfigHandleKernel.global_congervency_timer):
             if(current_second - long(GlobalConfigHandleKernel.global_congervency_timer[sub_md5]) >= long(int(self.config_hash['CONGERVENCY_hour']) * 3600)):
                 GlobalConfigHandleKernel.global_congervency_alarm[sub_md5]=1
                 GlobalConfigHandleKernel.global_congervency_timer[sub_md5]=current_second
                 GlobalConfigHandleKernel.global_congervency_content[sub_md5]=abc_msg
             else:
                 if(int(GlobalConfigHandleKernel.global_congervency_alarm[sub_md5]) >= int(self.config_hash['CONGERVENCY_number'])):
                     GlobalConfigHandleKernel.global_congervency_alarm[sub_md5]=GlobalConfigHandleKernel.global_congervency_alarm[sub_md5] + 1
                     SpecialOperationThread.unversal_write_log(self.log_fd,"RRSMS congervency: %s [%s]\n" % (abc_sms,abc_client))
                     continue
                 GlobalConfigHandleKernel.global_congervency_alarm[sub_md5]=GlobalConfigHandleKernel.global_congervency_alarm[sub_md5] + 1
         else:
             GlobalConfigHandleKernel.global_congervency_alarm[sub_md5]=1
             GlobalConfigHandleKernel.global_congervency_timer[sub_md5]=current_second
             GlobalConfigHandleKernel.global_congervency_content[sub_md5]=abc_msg
         #ends
         p_sms = subprocess.Popen("/bin/bash -c \"%s '%s' '%s' '%s'\"" % (self.config_hash['RRSENDSMS_home'],abc_msg,abc_array[2],abc_array[1]),
                                             shell=True,
                                             close_fds=True,
                                             stdin=open("/dev/null", 'r'),
                                             stdout=open("/dev/null", 'w'),
                                             stderr=subprocess.STDOUT)
         poll_counter=0
         poll_ok=0
         while(poll_counter < int(self.config_hash['RRSENDSMS_polltime'])):
             poll_result=p_sms.poll()
             if(poll_result is None):
                 poll_counter = poll_counter + 1
                 time.sleep(1)
                 continue
             else:
                 poll_ok=1
                 break
         if(poll_ok ==0):
             try:
                 p_sms.kill()
                 SpecialOperationThread.unversal_write_log(self.log_fd,"RRSMS send timeout: %s [%s]\n" % (abc_sms,abc_client))
             except:
                 pass
         continue
Esempio n. 21
0
                 continue
             else:
                 clear_autotar_tok(fileno)
                 break
         except:
             if (1 < 0):
                 pass
             else:
                 clear_autotar_tok(fileno)
                 break
 elif (event & select.EPOLLOUT):
     if (fileno >=
             int(self.global_config_hash['LISTEN_FD']) -
             2):
         SpecialOperationThread.unversal_write_log(
             self.untar_log_fd,
             "Auto server fd mounted to maximum,exit\n")
         exit(1)
     if (GlobalConfigHandleKernel.
             global_autountar_epoll_handle_full.get(
                 fileno) is not None):
         continue
     data_tmp = ""
     data_tmp = GlobalConfigHandleKernel.global_autountar_epoll_handle_openfile[
         fileno].read(
             int(self.global_config_hash['BUF_SIZE']))
     #if(data_tmp is None):
     if (data_tmp is None or data_tmp == ""):
         GlobalConfigHandleKernel.global_autountar_epoll_handle_full[
             fileno] = "full"
         SpecialOperationThread.unversal_write_log(
Esempio n. 22
0
 def run(self):
     while(1==1):
         [task_pre,task_con,task_id]=GlobalConfigHandleKernel.global_autountar_iptask.get()
         if(task_pre is None or task_con is None or task_id is None):
             SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Here gets the autotar error : None\n")
             continue
         task_line=task_pre.split()
         if(task_line is None or (len(task_line)!=5 and len(task_line)!=2)):
             send_common_result_to_client(task_con,"Error\r\n")
             need_close_conns(task_con,"close")
             SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Here gets the autotar error : %s\n" % task_pre)
             continue
         if(len(task_line)==2 and task_line[0].strip()=="delcoming"):
             for d_ip in task_line[1].strip().split(","):
                 if(d_ip in GlobalConfigHandleKernel.global_tar_all_hash):
                     if(len(GlobalConfigHandleKernel.global_tar_all_hash[d_ip])!=0):
                         del(GlobalConfigHandleKernel.global_tar_all_hash[d_ip][0])
             send_common_result_to_client(task_con,"OK\r\n")
             need_close_conns(task_con,"close")
         elif(len(task_line)==2 and task_line[0].strip()=="cleancoming"):
             for d_ip in task_line[1].strip().split(","):
                 if(d_ip in GlobalConfigHandleKernel.global_tar_all_hash):
                     GlobalConfigHandleKernel.global_tar_all_hash[d_ip]=[]
             send_common_result_to_client(task_con,"OK\r\n")
             need_close_conns(task_con,"close")
         elif(len(task_line)==2 and task_line[0].strip()=="removecoming"):
             for d_ip in task_line[1].strip().split(","):
                 if(d_ip in GlobalConfigHandleKernel.global_tar_all_hash):
                     del(GlobalConfigHandleKernel.global_tar_all_hash[d_ip])
             send_common_result_to_client(task_con,"OK\r\n")
             need_close_conns(task_con,"close")
         elif(len(task_line)==2 and task_line[0].strip()=="autocoming"):
             if(task_line[1].strip() in GlobalConfigHandleKernel.global_tar_all_hash and len(GlobalConfigHandleKernel.global_tar_all_hash[task_line[1].strip()])!=0):
                 send_rs=send_common_result_to_client(task_con,(GlobalConfigHandleKernel.global_tar_all_hash[task_line[1].strip()][0]).replace("$"," ") + "\r\n")
                 if(send_rs=="error"):
                     need_close_conns(task_con,"close")
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Here sends name and size of the autotar step 2 error : %s\n" % GlobalConfigHandleKernel.global_tar_all_hash[task_line[1].strip()][0])
                     continue
                 try:
                     recv_len=None
                     infds,outfds,errfds=select.select([task_id],[],[],int(self.global_config_hash['CONNECT_TIMEOUT']))
                     if(len(infds) !=0):
                         recv_len=task_con.recv(1024)
                 except:
                     need_close_conns(task_con,"close")
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Here recv ok of the autotar step 3 except : %s\n" % GlobalConfigHandleKernel.global_tar_all_hash[task_line[1].strip()][0])
                     continue
                 if(recv_len is None or recv_len.strip() != "ok" or len(recv_len)>=1023 or len(recv_len)<=0):
                     need_close_conns(task_con,"close")
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Here recv ok of the autotar step 3 error : %s\n" % GlobalConfigHandleKernel.global_tar_all_hash[task_line[1].strip()][0])
                     continue
                 #here open files
                 try:
                     file_tmp_open_name=(GlobalConfigHandleKernel.global_tar_all_hash[task_line[1].strip()][0]).split("$")[0]
                     file_tmp_open_md5=hashlib.md5(file_tmp_open_name + task_line[1].strip()).hexdigest()
                     file_tmp_open=open(file_tmp_open_name,"rb")
                     result_tmp_open=open(self.global_config_hash['UNTAR_EXEC_RESULT'] + "/" + file_tmp_open_md5 + ".res","wb")
                 except:
                     need_close_conns(task_con,"close")
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Here open file of the autotar step 4 failed  : %s\n" % GlobalConfigHandleKernel.global_tar_all_hash[task_line[1].strip()][0])
                     continue
                 try:
                     task_con.setblocking(0)
                 except:
                     pass
                 del(GlobalConfigHandleKernel.global_tar_all_hash[task_line[1].strip()][0])
                 GlobalConfigHandleKernel.global_autountar_epoll_handle_openfile[task_id]=file_tmp_open
                 GlobalConfigHandleKernel.global_autountar_epoll_handle_openresult[task_id]=result_tmp_open
                 GlobalConfigHandleKernel.global_autountar_epoll_handle_conn[task_id]=task_con
                 GlobalConfigHandleKernel.global_autountar_epollfd.register(task_id,select.EPOLLIN|select.EPOLLOUT)
                 #here need to delete hash for ip
                 continue
             else:
                 send_common_result_to_client(task_con,"No\r\n")
                 need_close_conns(task_con,"close")
         elif(len(task_line)==5 and task_line[0].strip()=="autountar"):
             if(not os.path.isfile(task_line[1].strip())):
                 send_common_result_to_client(task_con,"Error\r\n")
                 need_close_conns(task_con,"close")
                 continue
             for d_ip in task_line[2].strip().split(","):
                 if(d_ip.strip() in GlobalConfigHandleKernel.global_tar_all_hash):
                     GlobalConfigHandleKernel.global_tar_all_hash[d_ip].append(task_line[1].strip() + "$" + str(os.stat(task_line[1].strip())[6])+ "$" + task_line[3].strip() + "$" + task_line[4].strip())
                 else:
                     GlobalConfigHandleKernel.global_tar_all_hash[d_ip]=[task_line[1].strip() + "$" + str(os.stat(task_line[1].strip())[6])+ "$" + task_line[3].strip()+ "$" + task_line[4].strip()]
             send_common_result_to_client(task_con,"OK\r\n")
             need_close_conns(task_con,"close")
         else:
             send_common_result_to_client(task_con,"Error\r\n")
             need_close_conns(task_con,"close")
         continue
Esempio n. 23
0
 def run(self):
     clientsocket=None
     while(1==1):
         clientsocket=create_connect_socket(self.untar_log_fd,self.global_config_hash)
         if(str(clientsocket) == "error"):
             time.sleep(1)
             continue
         else:
             break
     create_tok=0
     while(1==1):
         while(1==1):
             time.sleep(int(self.global_config_hash['CLIENT_UNTAR_SLEEP'])) 
             if(create_tok==1):
                 create_tok=0
                 while(1==1):
                     clientsocket=create_connect_socket(self.untar_log_fd,self.global_config_hash)
                     if(str(clientsocket) == "error"):
                         time.sleep(1)
                         continue
                     else:
                         break
             try:
                 infds,outfds,errfds=select.select([],[clientsocket.fileno()],[],int(self.global_config_hash['CONNECT_TIMEOUT']))
                 if(len(outfds) !=0):
                     GlobalConfigHandleKernel.global_my_ip=clientsocket.getsockname()[0]
                     clientsocket.send("autocoming " + clientsocket.getsockname()[0] +"\r\n")
                 else:
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Send auto failed to universal remote ip %s in client_tar_server thread\n" % GlobalConfigHandleKernel.remote_universal_ip) 
                     create_tok=1
                     continue
                 infds,outfds,errfds=select.select([clientsocket.fileno()],[],[],int(self.global_config_hash['CONNECT_TIMEOUT']))
                 recv_tmp_data=None
                 if(len(infds) !=0):
                     recv_tmp_data=clientsocket.recv(1024)
                 else:
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Recv1 failed from universal remote ip %s in client_tar_server thread\n" % GlobalConfigHandleKernel.remote_universal_ip) 
                     create_tok=1
                     continue
                 if(recv_tmp_data.strip() == "No"):
                     clientsocket.close()
                     create_tok=1
                     continue
                 recv_2_all=recv_tmp_data.strip().split()
                 if(len(recv_2_all)!=4 or ("/" not in recv_2_all[0]) or ("/" not in recv_2_all[3]) or (".." in recv_2_all[0]) or (".." in recv_2_all[3])):
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Not3 failed from universal remote ip %s in client_tar_server thread\n" % GlobalConfigHandleKernel.remote_universal_ip) 
                     create_tok=1
                     continue
                 infds,outfds,errfds=select.select([],[clientsocket.fileno()],[],int(self.global_config_hash['CONNECT_TIMEOUT']))
                 if(len(outfds) !=0):
                     clientsocket.send("ok\r\n")
                 else:
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Send ok failed to universal remote ip %s in client_tar_server thread\n" % GlobalConfigHandleKernel.remote_universal_ip) 
                     create_tok=1
                     continue
                 #here recv data
                 tmp_recv_size=0
                 tmp_recv_tmpdata=None
                 file_suf=(recv_2_all[0].strip())[recv_2_all[0].strip().rindex("/"):]
                 file_suf=recv_2_all[3].strip() + file_suf
                 trans_result=tar_client_translate_path(file_suf)
                 if(trans_result is None):
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Recv file path None to universal remote ip %s in client_tar_server thread\n" % GlobalConfigHandleKernel.remote_universal_ip) 
                     create_tok=1
                     continue
                 [file_suf_new,file_suf_dir]=trans_result
                 if(file_suf_new is None or file_suf_dir is None):
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Recv file path None to universal remote ip %s in client_tar_server thread\n" % GlobalConfigHandleKernel.remote_universal_ip) 
                     create_tok=1
                     continue
                 try:
                     if(not os.path.isdir(file_suf_dir)):
                         os.makedirs(file_suf_dir,0755)
                     f_recv_file=open(file_suf_new,"wb")
                 except:
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Recv open file None to universal remote ip %s:%s in client_tar_server thread\n" % (GlobalConfigHandleKernel.remote_universal_ip,file_suf_new))
                     create_tok=1
                     continue
                 infds,outfds,errfds=select.select([clientsocket.fileno()],[],[],int(self.global_config_hash['CONNECT_TIMEOUT']))
                 if(len(infds)==0):
                     clientsocket.close()
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Recv2 timeout from universal remote ip %s in client_tar_server thread\n" % GlobalConfigHandleKernel.remote_universal_ip) 
                     create_tok=1
                     continue
                 recv_full_tok=0
                 while(long(tmp_recv_size) < long(recv_2_all[1])):
                     try:
                         tmp_recv_tmpdata=clientsocket.recv(int(self.global_config_hash['BUF_SIZE']))
                         tmp_recv_size=long(tmp_recv_size) + long(len(tmp_recv_tmpdata))
                         f_recv_file.write(tmp_recv_tmpdata)
                         f_recv_file.flush()
                         if(long(tmp_recv_size) == long(recv_2_all[1])):
                             SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Recv3 full from universal remote ip %s in client_tar_server thread\n" % GlobalConfigHandleKernel.remote_universal_ip) 
                             recv_full_tok=1
                             break
                     except:
                         clientsocket.close()
                         SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Recv data failed from universal remote ip %s in client_tar_server thread\n" % GlobalConfigHandleKernel.remote_universal_ip) 
                         create_tok=1
                         break
                 f_recv_file.close()
                 if(recv_full_tok !=1):
                     SpecialOperationThread.unversal_write_log(self.untar_log_fd,"Recv3 empty from universal remote ip %s in client_tar_server thread\n" % GlobalConfigHandleKernel.remote_universal_ip) 
                 if(recv_2_all[2].strip()=="1" and recv_full_tok==1):
                     GlobalConfigHandleKernel.task_data_queue.put(["utar",file_suf_new,clientsocket.fileno(),clientsocket,"close"])
                     clientsocket=None
                 else:
                     try:
                         clientsocket.send("Finished\r\n")
                     except:
                         pass
                     clientsocket.close()
                 create_tok=1
                 continue
             except:
                 clientsocket.close()
                 create_tok=1
                 continue
             continue
         continue
     clientsocket.close()