def get(self): #check that we're coming from an LL ip 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'] avname = self.request.headers['X-SecondLife-Owner-Name'] if avname != "(Loading...)": relations.update_av(av, avname) #get all relations for which av is owner or secowner subdict = {} ownersubs = relations.getby_subj_type(av, 'owns') for sub in ownersubs: id = sub.obj_id if id not in subdict: subdict[id] = relations.key2name(id) else: #delete duplicates sub.delete() secownersubs = relations.getby_subj_type(av, 'secowns') for sub in secownersubs: id = sub.obj_id if id not in subdict:#since you can be both an owner and a secowner, ignore those here already in the owner list subdict[id] = relations.key2name(id) out = '' for sub in subdict: out += '%s,%s,' % (sub, subdict[sub]) self.response.out.write(out.rstrip(','))
def post(self): #check that we're coming from an LL ip if not lindenip.inrange(os.environ['REMOTE_ADDR']): self.error(403) elif not self.request.headers['X-SecondLife-Owner-Key'] in model.adminkeys: self.error(403) else: lines = self.request.body.split('\n') params = {} for line in lines: params[line.split('=')[0]] = line.split('=')[1] logging.info('Info receided from SL, now storing %s with key %s' % (params['name'], params['key'])) relations.update_av(params['key'], params['name'])
def post(self): #check that we're coming from an LL ip if not lindenip.inrange(os.environ['REMOTE_ADDR']): self.error(403) elif not self.request.headers[ 'X-SecondLife-Owner-Key'] in model.adminkeys: self.error(403) else: lines = self.request.body.split('\n') params = {} for line in lines: params[line.split('=')[0]] = line.split('=')[1] logging.info('Info receided from SL, now storing %s with key %s' % (params['name'], params['key'])) relations.update_av(params['key'], params['name'])
def get(self): # check that we're coming from an LL ip if not lindenip.inrange(os.environ["REMOTE_ADDR"]): self.error(403) else: av = self.request.headers["X-SecondLife-Owner-Key"] avname = self.request.headers["X-SecondLife-Owner-Name"] if avname != "(Loading...)": relations.update_av(av, avname) # get all relations for which av is owner or secowner subdict = {} suburldict = {} ownersubs = relations.getby_subj_type(av, "owns") for sub in ownersubs: id = sub.obj_id if id not in subdict: subdict[id] = relations.key2name(id) q = Lookup.get_by_key_name("URL:" + id) if q is None: suburldict[id] = "None" else: suburldict[id] = q.ownurl else: # delete duplicates sub.delete() secownersubs = relations.getby_subj_type(av, "secowns") for sub in secownersubs: id = sub.obj_id if ( id not in subdict ): # since you can be both an owner and a secowner, ignore those here already in the owner list subdict[id] = relations.key2name(id) q = Lookup.get_by_key_name("URL:" + id) if q is None: suburldict[id] = "None" else: suburldict[id] = q.securl currenttime = time.time() out = "" subsorted = sorted(subdict.items(), key=itemgetter(1)) for sub in subsorted: # out += '%s,%s,%s,%s,' % (sub[0], sub[1], suburldict[sub[0]], currenttime) # fix for sub restriction we dont send actual urls but only send them on demand out += "%s,%s,%s,%s," % (sub[0], sub[1], "None", 0) memcache.set("Subs:" + av, out) self.response.out.write(out.rstrip(","))
def get(self): #check that we're coming from an LL ip if not lindenip.inrange(os.environ['REMOTE_ADDR']): self.error(403) else: av = self.request.headers['X-SecondLife-Owner-Key'] avname = self.request.headers['X-SecondLife-Owner-Name'] if avname != "(Loading...)": relations.update_av(av, avname) #get all relations for which av is owner or secowner subdict = {} suburldict = {} ownersubs = relations.getby_subj_type(av, 'owns') for sub in ownersubs: id = sub.obj_id if id not in subdict: subdict[id] = relations.key2name(id) q = Lookup.get_by_key_name("URL:"+id) if q is None : suburldict[id] = 'None' else: suburldict[id] = q.ownurl else: #delete duplicates sub.delete() secownersubs = relations.getby_subj_type(av, 'secowns') for sub in secownersubs: id = sub.obj_id if id not in subdict:#since you can be both an owner and a secowner, ignore those here already in the owner list subdict[id] = relations.key2name(id) q = Lookup.get_by_key_name("URL:"+id) if q is None : suburldict[id] = 'None' else: suburldict[id] = q.securl currenttime = time.time() out = '' subsorted = sorted(subdict.items(), key=itemgetter(1)) for sub in subsorted: # out += '%s,%s,%s,%s,' % (sub[0], sub[1], suburldict[sub[0]], currenttime) # fix for sub restriction we dont send actual urls but only send them on demand out += '%s,%s,%s,%s,' % (sub[0], sub[1], "None", 0) memcache.set("Subs:"+av, out) self.response.out.write(out.rstrip(','))
def delete(self): if lindenip.inrange(os.environ['REMOTE_ADDR']) != 'Production':#only allow access from sl 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']#get owner av key avname = self.request.headers['X-SecondLife-Owner-Name']#get owner av name subbie = self.request.path.split("/")[-1] #get key of sub from path if avname != "(Loading...)": relations.update_av(av, avname)#resolve key 2 name for owner logging.info("Remove sub request from %s (%s) for sub (%s)" % (av,avname,subbie)) answer=0 # first check if owner record = AvTokenValue.gql("WHERE av = :1 AND token = :2", subbie, g_owner).get() # request owner record of subbie if record is not None: #found a record for that subbie if av in record.value: # and the av is stil the owner, so remove it ownerlist=record.value.split(",") owner_index=ownerlist.index(av) del ownerlist[owner_index:owner_index+2] if ownerlist == []: #list is emty, so just delete the record record.delete() logging.info("Remove sub request from %s for %s: Primary owner record deleted" % (avname,subbie)) else: #build the new secowner list and save it s="" for x in ownerlist: s += x+"," logging.info(s.rstrip(',')) # update the records value record.value=s.rstrip(',') # and save it record.put() logging.info("Remove sub request from %s for %s: Primary record updated: %s" % (avname,subbie, record.value)) #update the reealtion db relations.delete(av,"owns",subbie) # and prepare the answer for sl answer+=1 #now we do the same for the secowner record = AvTokenValue.gql("WHERE av = :1 AND token = :2", subbie, g_secowner).get() # request owner record of subbie if record is not None: #found a record for that subbie if av in record.value: # and the av is stil the owner, so remove it ownerlist=record.value.split(",") owner_index=ownerlist.index(av) del ownerlist[owner_index:owner_index+2] if ownerlist == []: #list is emty, so just delete the record record.delete() logging.info("Remove sub request from %s for %s: Secower owner record deleted" % (avname,subbie)) else: #build the new secowner list and save it s="" for x in ownerlist: s += x+"," logging.info(s.rstrip(',')) # update the records value record.value=s.rstrip(',') # and save it record.put() logging.info("Remove sub request from %s for %s: Secower record updated: %s" % (avname,subbie, record.value)) #update the reealtion db relations.delete(av,"secowns",subbie) # and prepare the answer for sl answer+=2 # updating relation again due to the bug 716: the relations got not always properly updated, so we need to be sure it happens now if ((answer==0)|(answer==2)): if (relations.delete(av,"owns",subbie)==1): logging.info("Remove sub request from %s for %s: Not in subbies db, but primary owner relation removed" % (avname,subbie)) answer+=1 if ((answer==0)|(answer==1)): if (relations.delete(av,"secowns",subbie)==1): logging.info("Remove sub request from %s for %s: Not in subbies db, but secondary owner relation removed" % (avname,subbie)) answer+=2 # in case the answer is 0, something is wrong and the DBs from cmds and data drifted appart. We send a delete request to cmds, which hopfully fixex it if answer==0: logging.info('Relation not found, sending safety request to cmds') result = urlfetch.fetch(cmdurl + '/relation/?safety/%s/%s' % (subbie, av), method="DELETE", headers={'sharedpass': sharedpass}) if result.status_code == 202: logging.info('Answer from cmds received: %s' % result.content) answer = int(result.content) else: logging.info('Problem with answer from cmds, status %d\n%s' % (result.status_code, result.content)) #answer to sl so we know what happened self.response.headers['Content-Type'] = 'text/plain' self.response.out.write("%d" % answer) self.response.set_status(200)
def delete(self): if lindenip.inrange(os.environ['REMOTE_ADDR'] ) != 'Production': #only allow access from sl 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'] #get owner av key avname = self.request.headers[ 'X-SecondLife-Owner-Name'] #get owner av name subbie = self.request.path.split("/")[ -1] #get key of sub from path if avname != "(Loading...)": relations.update_av(av, avname) #resolve key 2 name for owner logging.info("Remove sub request from %s (%s) for sub (%s)" % (av, avname, subbie)) answer = 0 # first check if owner record = AvTokenValue.gql( "WHERE av = :1 AND token = :2", subbie, g_owner).get() # request owner record of subbie if record is not None: #found a record for that subbie if av in record.value: # and the av is stil the owner, so remove it ownerlist = record.value.split(",") owner_index = ownerlist.index(av) del ownerlist[owner_index:owner_index + 2] if ownerlist == []: #list is emty, so just delete the record record.delete() logging.info( "Remove sub request from %s for %s: Primary owner record deleted" % (avname, subbie)) else: #build the new secowner list and save it s = "" for x in ownerlist: s += x + "," logging.info(s.rstrip(',')) # update the records value record.value = s.rstrip(',') # and save it record.put() logging.info( "Remove sub request from %s for %s: Primary record updated: %s" % (avname, subbie, record.value)) #update the reealtion db relations.delete(av, "owns", subbie) # and prepare the answer for sl answer += 1 #now we do the same for the secowner record = AvTokenValue.gql( "WHERE av = :1 AND token = :2", subbie, g_secowner).get() # request owner record of subbie if record is not None: #found a record for that subbie if av in record.value: # and the av is stil the owner, so remove it ownerlist = record.value.split(",") owner_index = ownerlist.index(av) del ownerlist[owner_index:owner_index + 2] if ownerlist == []: #list is emty, so just delete the record record.delete() logging.info( "Remove sub request from %s for %s: Secower owner record deleted" % (avname, subbie)) else: #build the new secowner list and save it s = "" for x in ownerlist: s += x + "," logging.info(s.rstrip(',')) # update the records value record.value = s.rstrip(',') # and save it record.put() logging.info( "Remove sub request from %s for %s: Secower record updated: %s" % (avname, subbie, record.value)) #update the reealtion db relations.delete(av, "secowns", subbie) # and prepare the answer for sl answer += 2 # updating relation again due to the bug 716: the relations got not always properly updated, so we need to be sure it happens now if ((answer == 0) | (answer == 2)): if (relations.delete(av, "owns", subbie) == 1): logging.info( "Remove sub request from %s for %s: Not in subbies db, but primary owner relation removed" % (avname, subbie)) answer += 1 if ((answer == 0) | (answer == 1)): if (relations.delete(av, "secowns", subbie) == 1): logging.info( "Remove sub request from %s for %s: Not in subbies db, but secondary owner relation removed" % (avname, subbie)) answer += 2 # in case the answer is 0, something is wrong and the DBs from cmds and data drifted appart. We send a delete request to cmds, which hopfully fixex it if answer == 0: logging.info( 'Relation not found, sending safety request to cmds') result = urlfetch.fetch(cmdurl + '/relation/?safety/%s/%s' % (subbie, av), method="DELETE", headers={'sharedpass': sharedpass}) if result.status_code == 202: logging.info('Answer from cmds received: %s' % result.content) answer = int(result.content) else: logging.info( 'Problem with answer from cmds, status %d\n%s' % (result.status_code, result.content)) #answer to sl so we know what happened self.response.headers['Content-Type'] = 'text/plain' self.response.out.write("%d" % answer) self.response.set_status(200)