コード例 #1
0
ファイル: relation.py プロジェクト: raj441977/collarcmds
 def delete(self):
     if (self.request.headers['sharedpass'] == sharedpass):
         queryparams = self.request.query_string.split("/")
         logging.debug('query:%s' % (self.request.query_string))
         try:
             type = queryparams[0]
             obj = queryparams[1]
             subj = queryparams[2]
             mode = self.request.path.split("/")[-1]
         except(IndexError):
             type = self.request.path.split("/")[-1]
             obj = self.request.path.split("/")[-2]
             subj = self.request.path.split("/")[-3]
             mode = self.request.path.split("/")[-4]
             logging.info('Using old method')
         logging.debug('DELETE MODE:%s OBJ:%s SUBJ:%s TYPE:%s' % (mode, obj, subj, type))
         if mode == "type":
             relations.del_by_obj_type(obj, type)
         elif mode == "obj":
             relations.del_by_obj(obj)
         elif mode == "all":
             relations.delete(subj, type, obj)
         elif type == "safety":
             logging.debug('TRYING SAFETY DELETE')
             result = relations.del_by_obj_subj(obj, subj)
             self.response.out.write(result)
         self.response.set_status(202)
     else:
         self.error(403)
         logging.error('wrong shared password expecting %s received %s ip address' % (sharedpass,self.request.headers['sharedpass'],os.environ['REMOTE_ADDR']))
コード例 #2
0
ファイル: removesub.py プロジェクト: lkalif/collardata
    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)
コード例 #3
0
ファイル: removesub.py プロジェクト: raj441977/collardata
    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)