Exemplo n.º 1
0
def client_send_data(cmd,dest,port):
    send_data = crypt.strong_encrypt(SECRET_KEY,cmd)
    addr = (dest,port)
    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    # s.setblocking(0)
    s.connect(addr)
    s.send(send_data)
    recv_data = s.recv(1024000)
    recv_data = crypt.strong_decrypt(SECRET_KEY,str(recv_data))
    s.close()
    return recv_data
Exemplo n.º 2
0
    def dataReceived(self, data):
        try:
            data = crypt.strong_decrypt(SECRET_KEY,str(data))
            print data
            data = literal_eval(data)
	    print data
            if data.get('salt') == 1:
                result = self.factory.call_saltstack(data)
                result = crypt.strong_encrypt(SECRET_KEY,str(result))
                self.transport.write(result)
            else:
                pass
        except Exception, e:
            print e
Exemplo n.º 3
0
    def connectionMade(self):
        """
        #第一次连接时需要做的事情
        """
        ip = self.transport.getPeer().host
        if not ip in server['allow']:
            """
            禁IP
            """
            not_allow = 'The IP (%s) not allow' % ip
            logger.error(not_allow)
            msg = crypt.strong_encrypt(SECRET_KEY,not_allow)
            self.transport.write(msg)
	    self.transport.loseConnection()
Exemplo n.º 4
0
def client_send_data(cmd,dest,port):
    send_data = crypt.strong_encrypt(SECRET_KEY,cmd)
    addr = (dest,port)
    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    s.connect(addr)
    recv_data = ''
    s.send(send_data)
    try:
        while 1:
            data = s.recv(1024)
            recv_data += data
            s.setblocking(0)
            time.sleep(0.1)
    except Exception:
        pass
    recv_data = crypt.strong_decrypt(SECRET_KEY,str(recv_data))
    s.close()
    return recv_data
Exemplo n.º 5
0
    def thread_send_result(self,result):
        result = crypt.strong_encrypt(SECRET_KEY,str(result))
#        if len(result) > 65535:
#            result = crypt.strong_encrypt(SECRET_KEY,'''{'error':'result data too long!'}''')
        self.transport.write(result)