예제 #1
0
    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.Distributor_authorized(self.request.headers['X-SecondLife-Owner-Key']):
            logging.warning("Illegal attempt to request an item 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:
                name = params['objname']
                item = tools.get_item(name, True)
                if item is None:
                    #could not find item to look up its deliverer.  return an error
                    logging.error('Error, Paid item %s not found. Requested by %s using %s.' % (name, self.request.headers['X-SecondLife-Owner-Name'], self.request.headers['X-SecondLife-Object-Name']))
                    self.error(403)
                    return
                name_version = "%s - %s" % (name, item['version'])
                rcpt = str(params['rcpt'])
                paid = int(params['paid'])
                baseprice = int(item['baseprice'])
                if paid >= baseprice:
                    pass
                else:
                    token = 'Distributor_%s' % self.request.headers['X-SecondLife-Owner-Key']
                    cacheditem = memcache.get(token)
                    if cacheditem is None:
                        dist = Distributor.gql("WHERE avkey = :1", self.request.headers['X-SecondLife-Owner-Key']).get()
                        dist_info = {"max_discount":dist.max_discount, "commission":dist.commission}
                        memcache.set(token, yaml.safe_dump(dist_info))
                    else:
                        #pull the item's details out of the yaml'd dict
                        dist_info = yaml.safe_load(cacheditem)
                    disprice = baseprice * (100-dist_info['max_discount'])/100.0
                    if paid < disprice:
                        if paid < (disprice - 50):
                            logging.error('Rejecting request: Wrong price by %s, vendor %s located in %s at %s. Item:%s Item Price:%s Price Paid:%s Max Discount:%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'],
                               name,
                               baseprice,
                               paid,
                               dist_info['max_discount']
                               ))
                            self.error(403)
                            self.response.out.write('Wrong amount Item:%s Item Price:%s Price Paid:%s Max Discount:%s%%' % 
                              (name,
                               baseprice,
                               paid,
                               dist_info['max_discount']
                               ))
                            return
                        else:
                            logging.warning('Under Paid Item accepting: Wrong price by %s, vendor %s located in %s at %s. Item:%s Item Price:%s Price Paid:%s Max Discount:%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'],
                               name,
                               baseprice,
                               paid,
                               ))
                            
                    
                #need to record record here
                record = Purchases(purchaser = rcpt, item = name, seller = self.request.headers['X-SecondLife-Owner-Key'], item_reciver = 'request', loc = '%s %s' % (self.request.headers['X-SecondLife-Region'], self.request.headers['X-SecondLife-Local-Position']), vender_name = self.request.headers['X-SecondLife-Object-Name'], amount_paid = paid)
                record.put()
                #have the vendor transfer the money
                self.response.out.write('pay|%s|%s|%s|%s|%s' % (moneyRcpt, paid, rcpt, name, record.key().id()))#do we need all of this?
            except KeyError:
                logging.error('Key error for paid Post vendor  %s, queue entry: %s|%s   %s' % (item['giver'], rcpt, name_version, sys.exc_info()))
                self.error(403)
예제 #2
0
    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.Distributor_authorized(
                self.request.headers['X-SecondLife-Owner-Key']):
            logging.warning(
                "Illegal attempt to request an item 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:
                name = params['objname']
                item = tools.get_item(name, True)
                if item is None:
                    #could not find item to look up its deliverer.  return an error
                    logging.error(
                        'Error, Paid item %s not found. Requested by %s using %s.'
                        %
                        (name, self.request.headers['X-SecondLife-Owner-Name'],
                         self.request.headers['X-SecondLife-Object-Name']))
                    self.error(403)
                    return
                name_version = "%s - %s" % (name, item['version'])
                rcpt = str(params['rcpt'])
                paid = int(params['paid'])
                baseprice = int(item['baseprice'])
                if paid >= baseprice:
                    pass
                else:
                    token = 'Distributor_%s' % self.request.headers[
                        'X-SecondLife-Owner-Key']
                    cacheditem = memcache.get(token)
                    if cacheditem is None:
                        dist = Distributor.gql(
                            "WHERE avkey = :1", self.request.
                            headers['X-SecondLife-Owner-Key']).get()
                        dist_info = {
                            "max_discount": dist.max_discount,
                            "commission": dist.commission
                        }
                        memcache.set(token, yaml.safe_dump(dist_info))
                    else:
                        #pull the item's details out of the yaml'd dict
                        dist_info = yaml.safe_load(cacheditem)
                    disprice = baseprice * (100 -
                                            dist_info['max_discount']) / 100.0
                    if paid < disprice:
                        if paid < (disprice - 50):
                            logging.error(
                                'Rejecting request: Wrong price by %s, vendor %s located in %s at %s. Item:%s Item Price:%s Price Paid:%s Max Discount:%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'], name,
                                 baseprice, paid, dist_info['max_discount']))
                            self.error(403)
                            self.response.out.write(
                                'Wrong amount Item:%s Item Price:%s Price Paid:%s Max Discount:%s%%'
                                % (name, baseprice, paid,
                                   dist_info['max_discount']))
                            return
                        else:
                            logging.warning(
                                'Under Paid Item accepting: Wrong price by %s, vendor %s located in %s at %s. Item:%s Item Price:%s Price Paid:%s Max Discount:%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'],
                                    name,
                                    baseprice,
                                    paid,
                                ))

                #need to record record here
                record = Purchases(
                    purchaser=rcpt,
                    item=name,
                    seller=self.request.headers['X-SecondLife-Owner-Key'],
                    item_reciver='request',
                    loc='%s %s' %
                    (self.request.headers['X-SecondLife-Region'],
                     self.request.headers['X-SecondLife-Local-Position']),
                    vender_name=self.request.
                    headers['X-SecondLife-Object-Name'],
                    amount_paid=paid)
                record.put()
                #have the vendor transfer the money
                self.response.out.write(
                    'pay|%s|%s|%s|%s|%s' %
                    (moneyRcpt, paid, rcpt, name,
                     record.key().id()))  #do we need all of this?
            except KeyError:
                logging.error(
                    'Key error for paid Post vendor  %s, queue entry: %s|%s   %s'
                    % (item['giver'], rcpt, name_version, sys.exc_info()))
                self.error(403)
예제 #3
0
    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.Distributor_authorized(self.request.headers['X-SecondLife-Owner-Key']):
#            logging.info("Illegal attempt to request an item 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:
                name = params['objname']
                item = tools.get_item(name, True)
                if item is None:
                    #could not find item to look up its deliverer.  return an error
                    logging.error('Error, Paid item %s not found. Requested by %s using %s.' % (name, self.request.headers['X-SecondLife-Owner-Name'], self.request.headers['X-SecondLife-Object-Name']))
                    self.error(403)
                    return
                name_version = "%s - %s" % (name, item['version'])
                rcpt = self.request.headers['X-SecondLife-Owner-Key']
                paid = int(params['paid'])
                baseprice = int(item['baseprice'])
                if paid >= baseprice:
                    pass
                else:

                            logging.error('Rejecting request: Wrong price by %s, gift vendor %s located in %s at %s. Item:%s Item Price:%s Price Paid:%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'],
                               name,
                               baseprice,
                               paid
                               ))
                            self.error(403)
                            return  
                #need to record record here
                record = Purchases(purchaser = rcpt, item = name, seller = self.request.headers['X-SecondLife-Owner-Key'], item_reciver = 'gift request', loc = '%s %s' % (self.request.headers['X-SecondLife-Region'], self.request.headers['X-SecondLife-Local-Position']), vender_name = self.request.headers['X-SecondLife-Object-Name'], amount_paid = paid)
                record.put()
                #have the vendor transfer the money
                self.response.out.write('pay|%s|%s|%s|%s|%s' % (moneyRcpt, paid, rcpt, name, record.key().id()))#do we need all of this?
            except KeyError:
                logging.error('Key error for paid Post gift vendor  %s, queue entry: %s|%s   %s' % (item['giver'], rcpt, name_version, sys.exc_info()))
                self.error(403)
예제 #4
0
    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.Distributor_authorized(self.request.headers['X-SecondLife-Owner-Key']):
#            logging.info("Illegal attempt to request an item 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:
                name = params['objname']
                item = tools.get_item(name, True)
                if item is None:
                    #could not find item to look up its deliverer.  return an error
                    logging.error(
                        'Error, Paid item %s not found. Requested by %s using %s.'
                        %
                        (name, self.request.headers['X-SecondLife-Owner-Name'],
                         self.request.headers['X-SecondLife-Object-Name']))
                    self.error(403)
                    return
                name_version = "%s - %s" % (name, item['version'])
                rcpt = self.request.headers['X-SecondLife-Owner-Key']
                paid = int(params['paid'])
                baseprice = int(item['baseprice'])
                if paid >= baseprice:
                    pass
                else:

                    logging.error(
                        'Rejecting request: Wrong price by %s, gift vendor %s located in %s at %s. Item:%s Item Price:%s Price Paid:%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'],
                           name, baseprice, paid))
                    self.error(403)
                    return
                #need to record record here
                record = Purchases(
                    purchaser=rcpt,
                    item=name,
                    seller=self.request.headers['X-SecondLife-Owner-Key'],
                    item_reciver='gift request',
                    loc='%s %s' %
                    (self.request.headers['X-SecondLife-Region'],
                     self.request.headers['X-SecondLife-Local-Position']),
                    vender_name=self.request.
                    headers['X-SecondLife-Object-Name'],
                    amount_paid=paid)
                record.put()
                #have the vendor transfer the money
                self.response.out.write(
                    'pay|%s|%s|%s|%s|%s' %
                    (moneyRcpt, paid, rcpt, name,
                     record.key().id()))  #do we need all of this?
            except KeyError:
                logging.error(
                    'Key error for paid Post gift vendor  %s, queue entry: %s|%s   %s'
                    % (item['giver'], rcpt, name_version, sys.exc_info()))
                self.error(403)