def post(self): if lindenip.inrange(os.environ["REMOTE_ADDR"]) != "Production": self.error(403) elif self.request.headers["X-SecondLife-Shard"] != "Production": logging.warning("Attempt while on beta grid %s" % (self.request.headers["X-SecondLife-Shard"])) self.response.set_status(305) else: av = self.request.headers["X-SecondLife-Owner-Key"] objectkey = self.request.headers["X-SecondLife-Object-Key"] sim_id = self.request.headers["X-SecondLife-Region"] logging.info("Bought items request from %s in sim %s" % (av, sim_id)) # if paid_items == '': # paid_items = '0' # if tags == '': # tags = 'all' # tags = tags.split('|') body = self.request.body # Use a query parameter to keep track of the last key of the last # batch, to know where to start the next batch. last_key_str = self.request.get("start") last_version_str = self.request.get("last_version") last_version = int(last_version_str) current_version = int(model.GenericStorage_GetOrPutDefault("TextureTime", "0")) # normal work mode, lets do check and send texture result = "" logging.info( "Versions different (DB:%s,Vendor:%s) Starting to send update..." % (current_version, last_version_str) ) if not last_key_str: last_key = 0 result = "version\n%s\n" % current_version logging.info("no last_key, send from start") else: last_key = int(last_key_str) result = "continue\n%s\n" % current_version logging.info("last_key was: %s" % last_key_str) query = Purchases.all() query.filter("item_reciver =", av) entities = query.fetch(21, last_key) count = 0 more = False for texture in entities: count = count + 1 if count < 21: logging.info("%s:%d" % (texture.freebie_name, texture.freebie_texture_update)) result = result + texture.freebie_name + "\n" + texture.freebie_texture_key + "\n" else: last_key = last_key + 20 result = result + ("startwith\n%d" % (last_key)) more = True logging.info("More texture availabe, request next time from %d" % (last_key)) if more == False: logging.info("Sending finished now") result = result + "end\n" self.response.out.write(result)
def post(self): if lindenip.inrange(os.environ['REMOTE_ADDR']) != 'Production': self.error(403) elif self.request.headers['X-SecondLife-Shard'] != 'Production': logging.warning("Attempt while on beta grid %s" % (self.request.headers['X-SecondLife-Shard'])) self.response.set_status(305) else: av=self.request.headers['X-SecondLife-Owner-Key'] objectkey=self.request.headers['X-SecondLife-Object-Key'] sim_id = self.request.headers['X-SecondLife-Region'] logging.info('Bought items request from %s in sim %s' % (av, sim_id)) #if paid_items == '': # paid_items = '0' #if tags == '': # tags = 'all' #tags = tags.split('|') body = self.request.body # Use a query parameter to keep track of the last key of the last # batch, to know where to start the next batch. last_key_str = self.request.get('start') last_version_str = self.request.get('last_version') last_version = int(last_version_str) current_version = int(model.GenericStorage_GetOrPutDefault('TextureTime', '0')) # normal work mode, lets do check and send texture result ='' logging.info ('Versions different (DB:%s,Vendor:%s) Starting to send update...' % (current_version, last_version_str)) if not last_key_str: last_key = 0 result ='version\n%s\n' % current_version logging.info ('no last_key, send from start') else: last_key=int(last_key_str) result ='continue\n%s\n' % current_version logging.info ('last_key was: %s' % last_key_str) query = Purchases.all() query.filter('item_reciver =', av) entities = query.fetch(21,last_key) count = 0 more = False for texture in entities: count = count + 1 if count < 21: logging.info('%s:%d' % (texture.freebie_name,texture.freebie_texture_update)) result=result + texture.freebie_name +"\n"+texture.freebie_texture_key+"\n" else: last_key=last_key+20 result=result + ("startwith\n%d" % (last_key)) more = True logging.info ('More texture availabe, request next time from %d' % (last_key)) if more == False: logging.info ('Sending finished now') result = result + "end\n" self.response.out.write(result)
def post(self): #check linden IP and allowed avs` if lindenip.inrange(os.environ['REMOTE_ADDR']) != 'Production': self.error(403) elif self.request.headers['X-SecondLife-Shard'] != 'Production': logging.warning("Attempt while on beta grid %s" % (self.request.headers['X-SecondLife-Shard'])) self.response.set_status(305) elif not distributors.Contributor_authorized( self.request.headers['X-SecondLife-Owner-Key']): logging.info( "Illegal attempt to request a list from %s, box %s located in %s at %s" % (self.request.headers['X-SecondLife-Owner-Name'], self.request.headers['X-SecondLife-Object-Name'], self.request.headers['X-SecondLife-Region'], self.request.headers['X-SecondLife-Local-Position'])) self.error(403) elif not db.WRITE_CAPABILITY.is_enabled(): self.response.set_status(503) self.response.headders['Retry-After'] = 120 logging.info( "Told that the db was down for maintenance to %s, box %s located in %s at %s" % (self.request.headers['X-SecondLife-Owner-Name'], self.request.headers['X-SecondLife-Object-Name'], self.request.headers['X-SecondLife-Region'], self.request.headers['X-SecondLife-Local-Position'])) self.response.out.write('Currently down for maintenance') else: #populate a dictionary with what we've been given in post #should be newline-delimited, token=value lines = self.request.body.split('\n') params = {} for line in lines: params[line.split('=')[0]] = line.split('=')[1] try: rcpt = str(params['rcpt']) query = Purchases.all() query.filter('item_reciver =', rcpt) items = [] for item in query: items = items + [item.item] result = "%s\n%s" % (rcpt, "\n".join(set(items))) logging.info('Sent paid items list for %s' % rcpt) self.response.out.write(result) except KeyError: logging.error( 'Key error for paid resender list vendor %s, queue entry: %s|%s %s' % (self.request.headers['X-SecondLife-Object-Key'], rcpt, lines, sys.exc_info())) self.error(403)
def post(self): #check linden IP and allowed avs` if lindenip.inrange(os.environ['REMOTE_ADDR']) != 'Production': self.error(403) elif self.request.headers['X-SecondLife-Shard'] != 'Production': logging.warning("Attempt while on beta grid %s" % (self.request.headers['X-SecondLife-Shard'])) self.response.set_status(305) elif not distributors.Contributor_authorized(self.request.headers['X-SecondLife-Owner-Key']): logging.info("Illegal attempt to request a list from %s, box %s located in %s at %s" % (self.request.headers['X-SecondLife-Owner-Name'], self.request.headers['X-SecondLife-Object-Name'], self.request.headers['X-SecondLife-Region'], self.request.headers['X-SecondLife-Local-Position'])) self.error(403) elif not db.WRITE_CAPABILITY.is_enabled(): self.response.set_status(503) self.response.headders['Retry-After'] = 120 logging.info("Told that the db was down for maintenance to %s, box %s located in %s at %s" % (self.request.headers['X-SecondLife-Owner-Name'], self.request.headers['X-SecondLife-Object-Name'], self.request.headers['X-SecondLife-Region'], self.request.headers['X-SecondLife-Local-Position'])) self.response.out.write('Currently down for maintenance') else: #populate a dictionary with what we've been given in post #should be newline-delimited, token=value lines = self.request.body.split('\n') params = {} for line in lines: params[line.split('=')[0]] = line.split('=')[1] try: rcpt = str(params['rcpt']) query = Purchases.all() query.filter('item_reciver =', rcpt) items = [] for item in query: items= items + [item.item] result = "%s\n%s" % (rcpt, "\n".join(set(items))) logging.info ('Sent paid items list for %s' % rcpt) self.response.out.write(result) except KeyError: logging.error('Key error for paid resender list vendor %s, queue entry: %s|%s %s' % (self.request.headers['X-SecondLife-Object-Key'], rcpt, lines, sys.exc_info())) self.error(403)
def post(self): #check linden IP and allowed avs if lindenip.inrange(os.environ['REMOTE_ADDR']) != 'Production': self.error(403) elif self.request.headers['X-SecondLife-Shard'] != 'Production': logging.warning("Attempt while on beta grid %s" % (self.request.headers['X-SecondLife-Shard'])) self.response.set_status(305) elif not distributors.Contributor_authorized(self.request.headers['X-SecondLife-Owner-Key']): logging.info("Illegal attempt to request redeliver from %s, box %s located in %s at %s" % (self.request.headers['X-SecondLife-Owner-Name'], self.request.headers['X-SecondLife-Object-Name'], self.request.headers['X-SecondLife-Region'], self.request.headers['X-SecondLife-Local-Position'])) self.error(403) #don't need this for redelivery # elif not db.WRITE_CAPABILITY.is_enabled(): # self.response.set_status(503) # self.response.headders['Retry-After'] = 120 # logging.info("Told that the db was down for maintenance to %s, box %s located in %s at %s" % (self.request.headers['X-SecondLife-Owner-Name'], self.request.headers['X-SecondLife-Object-Name'], self.request.headers['X-SecondLife-Region'], self.request.headers['X-SecondLife-Local-Position'])) # self.response.out.write('Currently down for maintenance') else: #populate a dictionary with what we've been given in post #should be newline-delimited, token=value lines = self.request.body.split('\n') params = {} for line in lines: params[line.split('=')[0]] = line.split('=')[1] try: rcpt = str(params['rcpt']) item_name = params['objname'] query = Purchases.all(keys_only=True) query.filter('item_reciver =', rcpt) query.filter('item =', item_name) if query.count(1): self.response.out.write(tools.httpin_delivery(self, rcpt, item_name, "")) # token = 'paid_item_%s' % item_name # cacheditem = memcache.get(token) # if cacheditem is None: # paiditem = FreebieItem.gql("WHERE freebie_name = :1", item_name).get() # if paiditem is None: # #could not find item to look up its deliverer. return an error # logging.error('Error, Paid item %s not found yet was found before. Requested by %s using %s.' % (item_name, self.request.headers['X-SecondLife-Owner-Name'], self.request.headers['X-SecondLife-Object-Name'])) # self.error(503) # return # else: # item = {"name":paiditem.freebie_name, "version":paiditem.freebie_version, "giver":paiditem.freebie_giver, "givers":paiditem.givers, "giver":paiditem.freebie_giver, "baseprice":paiditem.baseprice} # memcache.set(token, yaml.safe_dump(item)) # else: # #pull the item's details out of the yaml'd dict # item = yaml.safe_load(cacheditem) # name_version = "%s - %s" % (item_name, item['version']) # if item['givers'] == []: # logging.error('Error, Paid item %s does not have http urls.' % (name)) # self.error(503) # return # urls = item['givers'] # #need to add a way to rotate the urls # url_token = 'url_%s' % item_name # url_num = memcache.incr(url_token, initial_value=0) # url_num = url_num % ((len(urls)/2)) # # count_token = 'item_count_%s' % item_name # memcache.incr(count_token, initial_value=0) # #need to send itme here # result = urlfetch.fetch(urls[url_num*2-1], method="POST", payload="%s|%s" % (name_version, rcpt) , headers={}, deadline = 10) # if result.content == "sent": # self.response.out.write('sent|%s|%s' % (rcpt, name_version))#do we need all of this? # else: # url_num = memcache.incr(url_token, initial_value=0) # url_num = url_num % ((len(urls)/2)) # #need to send itme here # result = urlfetch.fetch(urls[url_num*2-1], method="POST", payload="%s|%s" % (name_version, rcpt) , headers={}, deadline = 10) # if result.content == "sent": # self.response.out.write('sent|%s|%s' % (rcpt, name_version))#do we need all of this? # else: # logging.error('Error, Paid item %s did not get sent. Status %s Message from vendor: %s' % (name_version, result.status_code, result.content)) # self.error(503) else: logging.error('Error, %s has no record of paid item %s yet redelvier requested it.' % (rcpt, item_name)) self.error(404) except KeyError: logging.error('Key error for paid redeliver vendor %s, queue entry: %s|%s %s' % (self.request.headers['X-SecondLife-Object-Key'], rcpt, item_name, sys.exc_info())) self.error(403)
def post(self): #check linden IP and allowed avs if lindenip.inrange(os.environ['REMOTE_ADDR']) != 'Production': self.error(403) elif self.request.headers['X-SecondLife-Shard'] != 'Production': logging.warning("Attempt while on beta grid %s" % (self.request.headers['X-SecondLife-Shard'])) self.response.set_status(305) elif not distributors.Contributor_authorized( self.request.headers['X-SecondLife-Owner-Key']): logging.info( "Illegal attempt to request redeliver from %s, box %s located in %s at %s" % (self.request.headers['X-SecondLife-Owner-Name'], self.request.headers['X-SecondLife-Object-Name'], self.request.headers['X-SecondLife-Region'], self.request.headers['X-SecondLife-Local-Position'])) self.error(403) #don't need this for redelivery # elif not db.WRITE_CAPABILITY.is_enabled(): # self.response.set_status(503) # self.response.headders['Retry-After'] = 120 # logging.info("Told that the db was down for maintenance to %s, box %s located in %s at %s" % (self.request.headers['X-SecondLife-Owner-Name'], self.request.headers['X-SecondLife-Object-Name'], self.request.headers['X-SecondLife-Region'], self.request.headers['X-SecondLife-Local-Position'])) # self.response.out.write('Currently down for maintenance') else: #populate a dictionary with what we've been given in post #should be newline-delimited, token=value lines = self.request.body.split('\n') params = {} for line in lines: params[line.split('=')[0]] = line.split('=')[1] try: rcpt = str(params['rcpt']) item_name = params['objname'] query = Purchases.all(keys_only=True) query.filter('item_reciver =', rcpt) query.filter('item =', item_name) if query.count(1): self.response.out.write( tools.httpin_delivery(self, rcpt, item_name, "")) # token = 'paid_item_%s' % item_name # cacheditem = memcache.get(token) # if cacheditem is None: # paiditem = FreebieItem.gql("WHERE freebie_name = :1", item_name).get() # if paiditem is None: # #could not find item to look up its deliverer. return an error # logging.error('Error, Paid item %s not found yet was found before. Requested by %s using %s.' % (item_name, self.request.headers['X-SecondLife-Owner-Name'], self.request.headers['X-SecondLife-Object-Name'])) # self.error(503) # return # else: # item = {"name":paiditem.freebie_name, "version":paiditem.freebie_version, "giver":paiditem.freebie_giver, "givers":paiditem.givers, "giver":paiditem.freebie_giver, "baseprice":paiditem.baseprice} # memcache.set(token, yaml.safe_dump(item)) # else: # #pull the item's details out of the yaml'd dict # item = yaml.safe_load(cacheditem) # name_version = "%s - %s" % (item_name, item['version']) # if item['givers'] == []: # logging.error('Error, Paid item %s does not have http urls.' % (name)) # self.error(503) # return # urls = item['givers'] # #need to add a way to rotate the urls # url_token = 'url_%s' % item_name # url_num = memcache.incr(url_token, initial_value=0) # url_num = url_num % ((len(urls)/2)) # # count_token = 'item_count_%s' % item_name # memcache.incr(count_token, initial_value=0) # #need to send itme here # result = urlfetch.fetch(urls[url_num*2-1], method="POST", payload="%s|%s" % (name_version, rcpt) , headers={}, deadline = 10) # if result.content == "sent": # self.response.out.write('sent|%s|%s' % (rcpt, name_version))#do we need all of this? # else: # url_num = memcache.incr(url_token, initial_value=0) # url_num = url_num % ((len(urls)/2)) # #need to send itme here # result = urlfetch.fetch(urls[url_num*2-1], method="POST", payload="%s|%s" % (name_version, rcpt) , headers={}, deadline = 10) # if result.content == "sent": # self.response.out.write('sent|%s|%s' % (rcpt, name_version))#do we need all of this? # else: # logging.error('Error, Paid item %s did not get sent. Status %s Message from vendor: %s' % (name_version, result.status_code, result.content)) # self.error(503) else: logging.error( 'Error, %s has no record of paid item %s yet redelvier requested it.' % (rcpt, item_name)) self.error(404) except KeyError: logging.error( 'Key error for paid redeliver vendor %s, queue entry: %s|%s %s' % (self.request.headers['X-SecondLife-Object-Key'], rcpt, item_name, sys.exc_info())) self.error(403)