def post(self): av = self.request.get('av') data = AvData.get_or_insert(key_name="Data:" + av) query = AvTokenValue.gql("WHERE av = :1", av) if query.count(1) > 0: for record in query: if record.value != "leasher,00000000-0000-0000-0000-000000000000": setattr(data, record.token, record.value) data.put() for record in query: record.delete() name = Av.get_by_key_name("Av:" + av) if name is None: namequery = Av.gql("WHERE id = :1", av) count = namequery.count() if count == 0: #doesn't exist. save logging.error("key %s has no record in Av. While converting", av) elif count == 1: #already exists. just update the name avname = namequery.get() if avname: Av(key_name="Av:" + av, id=av, name=avname.name).put() avname.delete() else: #there's more than one record. delete them all and just save one #this should never happen logging.error("key %s had more than one record in Av.", av) avname = "" for record in namequery: avname = record.name record.delete() Av(key_name="Av:" + av, id=av, name=avname)
def post(self): av = self.request.get('av') data = AvData.get_or_insert(key_name="Data:"+av) query = AvTokenValue.gql("WHERE av = :1", av) if query.count(1) > 0: for record in query: if record.value != "leasher,00000000-0000-0000-0000-000000000000": setattr(data, record.token, record.value) data.put() for record in query: record.delete() name = Av.get_by_key_name("Av:"+av) if name is None: namequery = Av.gql("WHERE id = :1", av) count = namequery.count() if count == 0:#doesn't exist. save logging.error("key %s has no record in Av. While converting", av) elif count == 1:#already exists. just update the name avname = namequery.get() if avname: Av(key_name="Av:"+av, id = av, name = avname.name).put() avname.delete() else:#there's more than one record. delete them all and just save one #this should never happen logging.error("key %s had more than one record in Av.", av) avname = "" for record in namequery: avname = record.name record.delete() Av(key_name="Av:"+av, id = av, name = avname)
def get(self): #check linden 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'] record = AvTokenValue.gql("WHERE av = :1 AND token = 'owner'", av).get() if record is not None: owner = record.value.split(",")[0] logging.warning('Remote disabled for %s' % self.request.headers['X-SecondLife-Owner-Name']) self.response.out.write("remoteoff|%s" % owner) else: self.response.out.write("remoteoff|%s" % av) logging.warning('Remote disabled for selfowned %s' % self.request.headers['X-SecondLife-Owner-Name'])
def get(self): #check linden 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'] record = AvTokenValue.gql("WHERE av = :1 AND token = 'owner'", av).get() if record is not None: owner = record.value.split(",")[0] logging.warning( 'Remote disabled for %s' % self.request.headers['X-SecondLife-Owner-Name']) self.response.out.write("remoteoff|%s" % owner) else: self.response.out.write("remoteoff|%s" % av) logging.warning( 'Remote disabled for selfowned %s' % self.request.headers['X-SecondLife-Owner-Name'])
def get(self): self.response.headers['Content-Type'] = 'text/plain' av = "2cad26af-c9b8-49c3-b2cd-2f6e2d808022" query = AvTokenValue.gql("WHERE av = :1", av) for record in query: self.response.out.write('%s=%s\n' % (record.token, record.value))
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)