def getCredDecryptData(ers,x): if x == 1 : # Encryption is on i=0 for b in ers: if b.pwd is not None and len(b.pwd) > 0 : d = decrypt(b.pwd,string.capitalize(b.sname)) ers[i].pwd = d i+=1 return ers
def open(self, *args): clients.append(self) logging.info('Client %s connected. Number of clients: %d' % (str(self.request.remote_ip), clients.__len__())) token = self.get_argument('token') channel, timestamp = crypt.decrypt(token).split('|') diff = abs(int(time.time()) - int(timestamp)) # token is valid only for 24 hours if diff < 86400: self.channel = channel logging.info('Client authenticated. Channel name: %s' % self.channel) self.listen() tornado.ioloop.IOLoop.instance().add_timeout(datetime.timedelta(minutes=1), self.heartbeat) else: logging.warning('Invalid token: %s' % token) self.close()
def logic(data): dec_data = decrypt(data) data = json.loads(dec_data) if "cmd" in data: send_data = get_iphostname() cmd = data['cmd'] timeout = data.get("timeout", def_timeout) command = Command(cmd) recode, output, error = command.run(int(timeout)) if not recode: print recode # 如国命令执行成功 send_data['result'] = output else: print recode # 如国命令执行失败 send_data['result'] = error send_data['cmd'] = cmd enc_data = json.dumps(send_data) return encrypt(enc_data) else: return encrypt("input error")
workdir = os.path.dirname(os.path.realpath(__file__)) sys.path.insert(0, workdir + "/../") from utils.crypt import encrypt,decrypt # 三个参数,一个是处理内容,一个是发送次数,三十超时时间 HOST = '127.0.0.1' PORT = 9200 CNT = int(sys.argv[2]) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) data = {} data['cmd'] = sys.argv[1] data['timeout'] = sys.argv[3] data = json.dumps(data) enc_data = encrypt(data) send_data = "%010d%s"%(len(enc_data), enc_data) for i in xrange(CNT): s.send(send_data) for i in xrange(CNT): but_int = s.recv(10) data_size=int(but_int) buf = decrypt(s.recv(data_size)) ret = json.loads(buf) print ret['result']