def main(): mc = pylibmc.Client(["127.0.0.1"], binary=True, behaviors={"tcp_nodelay": True, "ketama": True}) while True: head = mc.get('queue_head') tail = mc.get('queue_tail') if mc.get('queue_head') < mc.get('queue_tail') or mc.get(str(head)) is not None: #there is something in the queue item = mc.get(str(head)) #this item needs to be uploaded item = str(item) item = item.split(',') data_to_be_sent = {}; #for i in range(0,len(item)): # syslog.syslog("AALU: item["+str(i)+"] = "+ item[i]) data_to_be_sent['i'] = item[0] data_to_be_sent['t'] = item[1] data_to_be_sent['d'] = item[2] #+","+item[3]+","+item[4]+","+item[5] # logging.info('Item 1 %s' % item[0]) # logging.info('Item 2 %s' % item[1]) # logging.info('Item 3 %s' % item[2]) if item[1] == 'MKP': data_to_be_sent['d'] = item[2] +","+item[3]+","+item[4]+","+item[5] thread = get.get('http://ec2-54-93-162-141.eu-central-1.compute.amazonaws.com:8080/server','',data_to_be_sent); # thread = get.get('http://0.0.0.0:8888/server','',data_to_be_sent); syslog.syslog("AALU: in loop.py for MKP: %s,%s" %(str(time.time()),data_to_be_sent['d'])) thread.start(); thread.join(); #add if else based on the application for which data is being uploaded. elif item[1] == 'IVR': data_to_be_sent['d'] = item[2] # thread = uploader.file_uploader('http://128.122.140.120:8888/ivr_server', '', data_to_be_sent['d']) thread = uploader.file_uploader('http://ec2-54-93-162-141.eu-central-1.compute.amazonaws.com:8080/ivr_server', '', data_to_be_sent['d']) syslog.syslog("AALU: in loop.py for IVR: %s,%s" %(str(time.time()),data_to_be_sent['d'])) thread.start() thread.join() elif item[1] == 'SEN': data_to_be_sent['d'] = item[2] thread = uploader.file_uploader('http://ec2-54-93-162-141.eu-central-1.compute.amazonaws.com:8080/random_server', '', data_to_be_sent['d']) syslog.syslog("AALU: in loop.py for SEN: %s,%s" %(str(time.time()),data_to_be_sent['d'])) thread.start(); thread.join() if head < tail: mc.incr('queue_head') #else there is no need to increase the head location mc.delete(str(head)) else: #the queue seems to be empty so do nothing. #wait for a half a second and then ho out to the while again doNothing();
def POST(self): syslog.syslog("AALU: In get_handler") data = web.input(myfile={}) #syslog.syslog("AALU: Data " + str(data)) #RUN: change the directory here based on machine filedir = '/home/talal/FilesToBeUploadedAWS' if 'myfile' in data: filepath=data.myfile.filename.replace('\\','/') # replaces the windows-style slashes with linux ones. filename=filepath.split('/')[-1] # splits the and chooses the last part (the filename with extension) syslog.syslog("AALU: filename = %s" %filename) fout = open(filedir +'/'+ filename,'w') # creates the file where the uploaded file should be stored #syslog.syslog("AALU: in if") fout.write(data.myfile.file.read()) # writes the uploaded file to the newly created file. fout.close() # closes the file, upload complete. syslog.syslog("AALU: get handler: %s,%s" %(str(time.time()),filename)) if '10.8.0.10' in filename: syslog.syslog("AALU: in if 10.8.0.10") thread = uploader.file_uploader('http://10.8.0.6:8081/nexmo_get', '', filedir + '/' + filename) thread.start() elif '10.8.0.6' in filename: syslog.syslog("AALU: in if 10.8.0.6") thread = uploader.file_uploader('http://10.8.0.10:8081/nexmo_get', '', filedir + '/' + filename) thread.start()
def POST(self): syslog.syslog("AALU: In Upload POST") data = web.input(myfile={}) syslog.syslog("AALU: Data " + str(data)) filedir = '/home/cted-server/FilesToBeUploadedAWS' if 'myfile' in data: filepath=data.myfile.filename.replace('\\','/') # replaces the windows-style slashes with linux ones. filename=filepath.split('/')[-1] # splits the and chooses the last part (the filename with extension) syslog.syslog("AALU: File Path " + filedir + '/' + filename) fout = open(filedir +'/'+ filename,'w') # creates the file where the uploaded file should be stored fout.write(data.myfile.file.read()) # writes the uploaded file to the newly created file. fout.close() # closes the file, upload complete. # thread = uploader.file_uploader('http://128.122.140.120:8888/ivr_server', '', filedir + '/' + filename) thread = uploader.file_uploader('http://ec2-54-93-162-141.eu-central-1.compute.amazonaws.com:8080/ivr_server', '', filedir + '/' + filename) thread.start()
def main(): new_time = datetime.datetime.now() now = new_time #RUN: change the ip to mention the source filename = "SEN:10.8.0.10:"+str(now) + ".txt" random_text = ("Random text is going into this goddamn file and its so deep" + "\n") * 2000 #RUN: foldername needs to be changed based on the machine usage. file_path = '/home/openbts/UploadFolder/' + filename.replace(" ", "") with open(file_path, "w+") as file_to_send: file_to_send.write(random_text) file_to_send.close() syslog.syslog("RAPID: Random file:%s at time:%s" %(filename.replace(" ",""),str(time.time()))) #RUN: change the ip and port below based on what is your local server thread = uploader.file_uploader('http://10.0.0.1:8080/upload', '', file_path) thread.start() thread.join()
def GET(self): user_data = web.input() global random if user_data['do'] == 'search': #search on aws for a random file uploaded by someone else. For example if you are calling this from rapidcell you can search with my openvpn IP to try and find a file i have uploaded result = ""; if user_data['key'] in random: #is not None: #send a non-empty string to the user_data['ip'] for i in range(0,min(len(random[user_data['key']]),5)): result = result+","+random[user_data['key']][i] #send result variable back. data_to_be_sent = {}; data_to_be_sent['result'] = result data_to_be_sent['ip'] = user_data['ip'] #this is the openvpn ip coming with the request data_to_be_sent['id'] = user_data['id'] thread = get.get('http://128.122.140.120:8080/search_handler','',data_to_be_sent); #node_name coming in each request is the ip of the handler thread.start(); elif user_data['do'] == 'get': syslog.syslog("BALU: sending file back %s,%s" %(str(time.time()),user_data['key'])) filedir = '/home/ec2-user/random' # change this to the directory you want to store the file in. filename = user_data['key'] thread = uploader.file_uploader('http://128.122.140.120:8080/get_handler', '', filedir + '/' + filename) thread.start()