def wechat_auth(): if request.method == 'GET': token = 'dengruchao' data = request.args signature = data.get('signature', '') timestamp = data.get('timestamp', '') nonce = data.get('nonce', '') echostr = data.get('echostr', '') list1 = [token, timestamp, nonce] list1.sort() sha1 = hashlib.sha1() map(sha1.update, list1) hashcode = sha1.hexdigest() if hashcode == signature: response = make_response(echostr) response.content_type = 'text' return response else: return 'Hello World' else: recv = request.stream.read() xml_recv = ET.fromstring(recv) fromUserName = xml_recv.find('FromUserName').text reply = Reply(fromUserName) return reply.dispatch(recv)
def exposed_delete_block(self, id): if id in self.block_id: self.block_id.remove(id) os.remove(id) return Reply.reply() else: return Reply.error('Block not found')
def exposed_get_block(self, file_name): if file_name in self.block_id: read_file = open(file_name, 'rb') data = read_file.read() read_file.close() return Reply.reply(data) else: return Reply.error('File not found')
def run(self): import sys from reply import Reply try: logging.info("%s: Starting reply" % (time.strftime("%d%b%Y,%H:%M")) ) rep = Reply() rep.run() except SystemExit: logging.error("%s: Gateway SIGTERM, exiting" % time.strftime("%d%b%Y,%H:%M")) sys.exit(0)
def post(self): # parse message message = xmpp.Message(self.request.POST) raw_text = message.body account = message.sender.split('/')[0].lower() # find active user of this account uid = twig_db.getActiveUser(account) r = Reply() isPreCmd, precmd = command.isIdCommand( raw_text ) if isPreCmd: cmd_id, raw_text = precmd r.h( cmd_id ) isCmd, data = command.parseText( raw_text ) if isCmd: # is command cmd, params = data command.dispatchCommand(account, cmd, params, r) if len( r.dump() ) > 0: message.reply( r.dump() ) else: # is text if uid: command.dispatchCommand(account, 'send', data, r) message.reply( r.dump() ) else: r.l( "!no active user found") message.reply( r.dump() )
def brute_force(body,controlList): md5 = json.loads(body)["md5"] i = 0 found = False pw = "" while not found and i< max: if (controlList[md5] == 1): return Reply(md5,"","Worker aborted") pw = force(i, 0, "", md5,controlList) i += 1 found = pw != "" return Reply(md5, pw, None)
def get_banner(self): """Waits for the SMTP banner at the beginning of the connection. :returns: |Reply| object populated with the response. """ banner = Reply(command='[BANNER]') banner.enhanced_status_code = False self.reply_queue.append(banner) self._flush_pipeline() return banner
def setUp(self): self.reply = Reply('test-api-key') self.request = helpers.RawRequest() self.sanitizer = helpers.Sanitizer() # Create people for each in resources.people: res = self.request.createPeople(each) self.sanitizer.getId(res)
def __init__(self): self.reply = Reply('V6z-Vb-AGcAqfqxZxds3mQ2') self.basePath = self.reply.basePath self.version = self.reply.version self.headers = self.reply.headers self.session = requests.Session() self.session.headers.update(self.headers)
def helo(self, helo_as): """Sends the HELO command with identifier string and waits for the reply. :param helo_as: HELO identifier string, usually an FQDN. :returns: |Reply| object populated with the response. """ helo = Reply(command='HELO') helo.enhanced_status_code = False self.reply_queue.append(helo) command = 'HELO '+helo_as self.io.send_command(command) self._flush_pipeline() return helo
def read_file(path, file_name): name_conn = rpyc.connect(name_node_IP, 5000, config={'allow_public_attrs': True}) name_node = name_conn.root block_locations = [] name_reply = name_node.read_file(path, block_locations) #block_locations = name_reply print(block_locations) if name_reply is 0: print("File could not be located") return for i in range(len(block_locations)): node_IPs = block_locations[i].split(",") name = block_locations[i][0] node_IPs = block_locations[i][1].split('{') node_IPs = node_IPs.split('}')[0] node_IPs = node_IPs.split(',') send_blocks.append([block_locations[i].replace("/", "!@!"), node_IPs]) fetched_bytes = BytesIO() fetched_bytes.write(name_reply) fetched_bytes.flush() fetched_bytes.seek(0) #temp = block_locations.split(',') receive_blocks = [] i = 0 ''' for i in range(0, len(block_locations), 2): receive_blocks.append([block_locations[i]]) node_IPs = block_locations[i+1].split('{')[1] node_IPs = node_IPs.split('}')[0] node_IPs = node_IPs.split(',') receive_blocks[i][0].append(node_IPs) ''' for block in receive_blocks: data_conn = rpyc.connect(block, 5000, config={'allow_public_attrs': True}) data_node = data_conn.root data_reply = Reply.Load(data_node.get_block(block)) fetched_bytes = BytesIO() fetched_bytes.write(data_reply.result) fetched_bytes.flush() fetched_bytes.seek(0) if not data_reply.error: with open(file_name, 'ab+') as dest: shutil.copyfileobj(fetched_bytes, dest, blocksize)
def reply_rm_if_can(user_id, id): can_admin = None r = Reply.mc_get(id) if r: po = Po.mc_get(r.rid) if po: can_admin = r.can_admin(user_id) or po.can_admin(user_id) if can_admin: r.rm() mc_feed_tuple.delete(po.id) return can_admin
def delete_block(block_name): conn = rpyc.connect(data_node_IP, 5000, config={'allow_public_attrs': True}) data_node = conn.root.BlockStore() reply = Reply.Load(data_node.delete_block(block_name)) if reply.is_err(): print('Could not delete block ', block_name) print(reply.err) else: return
def handle_text_message(event): recv_message = Reply.controller(event.message.text) # message from user reply_message = TextSendMessage(text="不明なエラー") if recv_message["type"] == Reply.TYPE_TEXT: reply_message = TextSendMessage(text=recv_message["message"]) elif recv_message["type"] == Reply.TYPE_CAROUSEL: reply_message = recv_message["message"] line_bot_api.reply_message( event.reply_token, reply_message )
def ehlo(self, ehlo_as): """Sends the EHLO command with identifier string and waits for the reply. When this method returns, the ``self.extensions`` object will also be populated with the SMTP extensions the server supports. :param ehlo_as: EHLO identifier string, usually an FQDN. :returns: |Reply| object populated with the response. """ ehlo = Reply(command='EHLO') ehlo.enhanced_status_code = False self.reply_queue.append(ehlo) command = 'EHLO '+ehlo_as self.io.send_command(command) self._flush_pipeline() if ehlo.code == '250': self.extensions.reset() ehlo.message = self.extensions.parse_string(ehlo.message) return ehlo
def exposed_put_block(self, file_name, data, replica_node_ids): print('new file name', file_name) if file_name in self.block_id: return Reply.error('File name already exists') else: try: with open(file_name, 'wb') as f: f.write(data) except: self.block_id.remove(id) return Reply.error('Error saving block') self.save_block(file_name) # send out replicas replica_node_ids.pop(0) if len(replica_node_ids) > 0: done = 1 tries = 0 print("Sending replica to ", replica_node_ids[0]) while done == 1: c = rpyc.connect(replica_node_ids[0], 5000) next_node = c.root.BlockStore() reply = Reply.Load(next_node.put_block(file_name, data, replica_node_ids)) print(reply.status) if reply.status == 0: print("replica sent!") done = 0 else: print("node busy trying again") # wait 5 seconds and try again time.sleep(5) tries += 1 if tries > 4: # after 4 tries give up print("could not send block replica") break return Reply.reply()
def make_file(bucket_name, file_name, to_path): s3 = boto3.resource( 's3' ) #, aws_access_key_id=ACCESS_ID, aws_secret_access_key=ACCESS_KEY) s3data = s3.Object(bucket_name=bucket_name, key=file_name).get() file_size = s3data['ContentLength'] print(file_size) name_conn = rpyc.connect(name_node_IP, 5000, config={'allow_public_attrs': True}) name_node = name_conn.root name_reply = name_node.make_file(file_size, to_path) print(file_size) print(name_reply) #block_locations = name_reply.result block_locations = name_reply send_blocks = [] #j = 1 #with open(file_path, 'rb+') as input: # block = [] # bytes = input.read() for i in range(0, len(block_locations), 2): node_IPs = block_locations[i + 1].split('{')[1] node_IPs = node_IPs.split('}')[0] node_IPs = node_IPs.split(',') send_blocks.append([block_locations[i].replace("/", "!@!"), node_IPs]) i = 0 try: for chunk in iter(lambda: s3data['Body'].read(block_size), b''): block_id = send_blocks[i][0] print(send_blocks[i][1][0]) data_conn = rpyc.connect(send_blocks[i][1][0], 5000, config={'allow_public_attrs': True}) data_node = data_conn.root #print("Now inserting: ", block_id) data_reply = Reply.Load( data_node.put_block(block_id, chunk, send_blocks[i][1])) print(data_reply.status) i += 1 except: pass
def get(self): raw = self.request.get("raw") cmd = self.request.get("cmd") params = self.request.get("params") if params is None: params = '' self.response.write(FORM) account = "*****@*****.**" r = Reply() if raw is not None and len(raw)>0: # find active user of this account uid = twig_db.getActiveUser(account) isPreCmd, precmd = command.isIdCommand( raw ) if isPreCmd: cmd_id, raw = precmd r.h( cmd_id ) isCmd, data = command.parseText( raw ) if isCmd: # is command cmd, params = data command.dispatchCommand(account, cmd, params, r) if len( r.dump() ) ==0: r.l("(blank reply)") else: # is text if uid: command.dispatchCommand(account, 'send', data, r) else: r.l("!no active account found") else: if cmd is not None and len(cmd)>0: command.dispatchCommand( account, cmd, params, r ) reply = r.dump() if len(reply)>0: self.response.write( (""" <h1>Result</h1> value:<br /><textarea readonly="true" rows="20" cols="50">%s</textarea> """ % reply))
def call_api(body,controlList): url = "http://md5cracker.org/api/api.cracker.php?r=1140&database=md5cracker.org&hash=" md5 = json.loads(body)["md5"] url += md5 req = Request(url) pw = "" err = None try: res = urlopen(req) text = res.read().decode("utf-8") pw = json.loads(text)["result"] except HTTPError as e: err = e return Reply(md5, pw, err)
def send_block(file_name): # conn = rpyc.connect(data_node_IP, 5000, config={'allow_public_attrs': True}) conn = rpyc.connect(node_IPs[0], 5000, config={'allow_public_attrs': True}) print("Connecting with server...") data_node = conn.root.BlockStore() file_blocks = create_blocks(file_name) i = 1 for block in file_blocks: block_id = 'MobyBlock' + str(i) print("Now inserting: ", block_id) reply = Reply.Load(data_node.put_block(block_id, block, node_IPs)) print(reply.status) if reply.is_err(): print('Could not insert block', block_id) print(reply.err) break i += 1
async def on_message(message): if message.author == bot.user: return # if message.attachments: # for a in message.attachments: # filepath = "{0}/{1}".format(TEMP_FILE_PATH, a.filename) # await a.save(fp=filepath) # if matchPic.JudgeMatching(filepath): # # 雑 # message.content += "破壊" # os.remove(filepath) reaction = Reply.React(message.content) if reaction is None: return print("{0} {1} {2}:{3} {4}".format(message.content, message.author, message.guild, message.channel, message.created_at)) if type(reaction) is str: await message.channel.send(reaction) else: await message.channel.send(file=reaction.File())
def get_blocks(block_name, new_file_name): conn = rpyc.connect(data_node_IP, 5000, config={'allow_public_attrs': True}) data_node = conn.root.BlockStore() print("Connecting with server...") reply = Reply.Load(data_node.get_block(block_name)) if reply.is_err(): print('Could not get block ', block_name) print(reply.err) fetched_bytes = BytesIO() fetched_bytes.write(reply.result) fetched_bytes.flush() fetched_bytes.seek(0) print('Fetched: ', len(fetched_bytes.getbuffer())) print("Saving to: ", new_file_name) with open(new_file_name, 'wb') as dest: shutil.copyfileobj(fetched_bytes, dest, block_size) dest.close()
def log_num_reply(): num = Reply.raw_sql('select count(1) from reply').fetchone()[0] log_history_new(Reply, LOG_HISTORY_CID_REPLY, num)
"""This is a dummy version of server_main. Only ran locally, and does not support reminders""" from reply import Reply from credentials import Credentials from callybot_database import CallybotDB import logg import sys sys.stdout = logg.Logger(sys.stdout, open('dummylog.txt', 'a')) # Writes to file and console credential = Credentials() db_credentials = credential.db_info db = CallybotDB(db_credentials[0], db_credentials[1], db_credentials[2], db_credentials[3]) replier = Reply(credential.access_token, db) joachim_jahr_id = "1550995208259075" while True: inn = input("Input message: ") data = {'entry': [{'messaging': [{'message': {'text': inn}}]}]} print(replier.arbitrate(joachim_jahr_id, data))
def redirect(self): # methinks this is probably a vuln right here :I location = "https://{host}{path}".format(host = self.headers['host'], path = self.path) return Reply.text(308, '', headers=dict(location=location))
def __init__(self, trigger: Union[Message, InlineQuery]): Reply.__init__(self, trigger, None, None, "html")
def __init__(self, trigger: Union[Message, InlineQuery]): if not isinstance(trigger, Message): raise ValueError Reply.__init__(self, trigger, None, None, "markdown")
def replies(self): return Reply.objects(receivers__contains=self).order_by('-created_at')
def replies(self): replies = Reply.objects(topic=self) replies = [r.replyConvert() for r in replies] return replies
def reply_user_id_list(self): reply_id_list = self.reply_id_list_reversed(42, 0) user_id_list = [i.user_id for i in Reply.mc_get_list(reply_id_list)] return set(user_id_list) - self.zsite_id_list()
def redirect(self): # methinks this is probably a vuln right here :I location = "https://{host}{path}".format(host=self.headers['host'], path=self.path) return Reply.text(308, '', headers=dict(location=location))
def create_reply(self, message, parent): reply = Reply(message, self, datetime.now(), parent) parent.replies.append(reply) return reply