Exemplo n.º 1
0
def Distributor_add(av, name):
    record = Distributor.gql('WHERE avkey = :1', av).get()
    if record is None:
        NewDist = Distributor(avkey = av, avname = name)
        NewDist.put()
    token = "dist_auth_%s" % av
    memcache.set(token, True)
Exemplo n.º 2
0
    def get(self):
        message = '''<h1>List of Distributors</h1>
<p>This lists all Distributors currently in the distribution system as of %s.</p>
<table class="sortable" border=\"1\">''' % datetime.datetime.utcnow().isoformat(' ')
        message += '<tr><th>Row</th><th>Distributor</th><th>Key</th></tr><br />\n'
        query = Distributor.gql("")
        dists = []
        for record in query:
            s = '<td>%s</td><td>%s</td>\n' % (record.avname, record.avkey)
            if (s in dists) == False:
                dists += [s]

        for i in range(0,len(dists)):
            message += '<tr><td>%d</td>%s' % (i+1, dists[i])

        message += "</table>"
        self.response.out.write((head % 'Distributor List') + message + end)
Exemplo n.º 3
0
    def get(self):
        message = '''<h1>List of Distributors</h1>
<p>This lists all Distributors currently in the distribution system as of %s.</p>
<table class="sortable" border=\"1\">''' % datetime.datetime.utcnow(
        ).isoformat(' ')
        message += '<tr><th>Row</th><th>Distributor</th><th>Key</th></tr><br />\n'
        query = Distributor.gql("")
        dists = []
        for record in query:
            s = '<td>%s</td><td>%s</td>\n' % (record.avname, record.avkey)
            if (s in dists) == False:
                dists += [s]

        for i in range(0, len(dists)):
            message += '<tr><td>%d</td>%s' % (i + 1, dists[i])

        message += "</table>"
        self.response.out.write((head % 'Distributor List') + message + end)
Exemplo n.º 4
0
def Distributor_authorized(av):
    #True if av is on the authorized distributor list, else False
    token = "dist_auth_%s" % av
    memrecord = memcache.get(token)
    if memrecord is None:
        #dist is not in memcache, check db
        dbrecord = Distributor.gql('WHERE avkey = :1', av).get()
        if dbrecord is None:
            memcache.set(token, False)
            return False
        else:
            memcache.set(token, True)
            return True
    else:
        #dist is in memcache.  check value
        if memrecord:
            return True
        else:
            return False
Exemplo n.º 5
0
 def get(self):
     if 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")
         self.response.out.write('Currently down for maintenance')
     else:
         t=int(time.time()) - 7200;
         logging.info('CRON AccountNewRecords: totaling funds for after %d' % t)
         dispersal = Dispersals()
         commissions_total = 0
         designer_total = 0
         maintainers_total = 0
         total = 0
         maintainers = AppSettings.get_or_insert("maintainers", value="00000000-0000-0000-0000-000000000000|0").value.split("|")
         people_to_pay = []
         query = Purchases.gql("WHERE accounted = :1",  "0")
         for record in query:
             logging.info('CRON: %s|%s' % (record.key().id(), record.seller))
             total += record.amount_paid
             token = 'Distributor_%s' % record.seller
             cacheditem = memcache.get(token)
             if cacheditem is None:
                 dist = Distributor.gql("WHERE avkey = :1", record.seller).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)
             if dist_info['commission'] > 0:
                 commission = record.paid_amount*dist_info['commission']/100
                 commissions_total += commission
                 stoken = '%s_seller' % (record.seller)
                 commission_total = commission + getattr(dispersal, stoken, 0)
                 setattr(dispersal, stoken, commission_total)
                 people_to_pay.append(stoken)
             name = record.item
             item = tools.get_item(name, True)
             if item is None:
                 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']))
             if item['designer_cut'] > 0:
                 cut = record.paid_amount*item['designer_cut']/100
                 designer_total += cut
                 dtoken = '%s_designer' % (item['designer'])
                 cut_total = cut + getattr(dispersal, dtoken, 0)
                 setattr(dispersal, dtoken, cut_total)
                 people_to_pay.append(dtoken)
         for maintainer, amount in zip(maintainers[::2], maintainers[1::2]):
             cut = total*int(amount)/100
             maintainers_total += cut
             mtoken = '%s_maintainer' % (maintainer)
             setattr(dispersal, mtoken, cut)
             people_to_pay.append(mtoken)
         if query.count(1) > 0:
             if total >= (maintainers_total + designer_total + commissions_total):
                 setattr(dispersal, 'commissions_total', commissions_total)
                 setattr(dispersal, 'designers_total', designer_total)
                 setattr(dispersal, 'maintainers_total', maintainers_total)
                 setattr(dispersal, 'dispersal_total', (maintainers_total + designer_total + commissions_total))
                 setattr(dispersal, 'total', total)
                 setattr(dispersal, 'people_to_pay', "\n".join(people_to_pay))
                 dispersal.put()
                 logging.info('CRON AccountNewRecords: saved')
                 #add right url
                 taskqueue.add(url='/paiddist/disperse?id=%s' % (dispersal.key().id()), headers={}, queue_name='Disperse', method='PUT')
                 for record in query:
                     record.accounted = "1"
                     record.put()
             else:
                 logging.error("CRON AccountNewRecords: total dispersal %s is greater than total paid %s" % (maintainers_total + designer_total + commissions_total, total))
                 redirecturl = "not needed?"
                 alarm.SendAlarm('Dispersal', t, True, "total dispersal %s is greater than total paid %s" % (maintainers_total + designer_total + commissions_total, total), redirecturl)
                 self.error(500)
         else:
             logging.info('CRON AccountNewRecords: No records')
         logging.info('CRON AccountNewRecords: Finished')
Exemplo n.º 6
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)
Exemplo n.º 7
0
def Distributor_delete(av, name):
    record = Distributor.gql('WHERE avkey = :1', av).get()
    if record is not None:
        record.delete()
    token = "dist_auth_%s" % av
    memcache.delete(token)
Exemplo n.º 8
0
 def get(self):
     if 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")
         self.response.out.write('Currently down for maintenance')
     else:
         t = int(time.time()) - 7200
         logging.info(
             'CRON AccountNewRecords: totaling funds for after %d' % t)
         dispersal = Dispersals()
         commissions_total = 0
         designer_total = 0
         maintainers_total = 0
         total = 0
         maintainers = AppSettings.get_or_insert(
             "maintainers",
             value="00000000-0000-0000-0000-000000000000|0").value.split(
                 "|")
         people_to_pay = []
         query = Purchases.gql("WHERE accounted = :1", "0")
         for record in query:
             logging.info('CRON: %s|%s' %
                          (record.key().id(), record.seller))
             total += record.amount_paid
             token = 'Distributor_%s' % record.seller
             cacheditem = memcache.get(token)
             if cacheditem is None:
                 dist = Distributor.gql("WHERE avkey = :1",
                                        record.seller).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)
             if dist_info['commission'] > 0:
                 commission = record.paid_amount * dist_info[
                     'commission'] / 100
                 commissions_total += commission
                 stoken = '%s_seller' % (record.seller)
                 commission_total = commission + getattr(
                     dispersal, stoken, 0)
                 setattr(dispersal, stoken, commission_total)
                 people_to_pay.append(stoken)
             name = record.item
             item = tools.get_item(name, True)
             if item is None:
                 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']))
             if item['designer_cut'] > 0:
                 cut = record.paid_amount * item['designer_cut'] / 100
                 designer_total += cut
                 dtoken = '%s_designer' % (item['designer'])
                 cut_total = cut + getattr(dispersal, dtoken, 0)
                 setattr(dispersal, dtoken, cut_total)
                 people_to_pay.append(dtoken)
         for maintainer, amount in zip(maintainers[::2], maintainers[1::2]):
             cut = total * int(amount) / 100
             maintainers_total += cut
             mtoken = '%s_maintainer' % (maintainer)
             setattr(dispersal, mtoken, cut)
             people_to_pay.append(mtoken)
         if query.count(1) > 0:
             if total >= (maintainers_total + designer_total +
                          commissions_total):
                 setattr(dispersal, 'commissions_total', commissions_total)
                 setattr(dispersal, 'designers_total', designer_total)
                 setattr(dispersal, 'maintainers_total', maintainers_total)
                 setattr(dispersal, 'dispersal_total',
                         (maintainers_total + designer_total +
                          commissions_total))
                 setattr(dispersal, 'total', total)
                 setattr(dispersal, 'people_to_pay',
                         "\n".join(people_to_pay))
                 dispersal.put()
                 logging.info('CRON AccountNewRecords: saved')
                 #add right url
                 taskqueue.add(url='/paiddist/disperse?id=%s' %
                               (dispersal.key().id()),
                               headers={},
                               queue_name='Disperse',
                               method='PUT')
                 for record in query:
                     record.accounted = "1"
                     record.put()
             else:
                 logging.error(
                     "CRON AccountNewRecords: total dispersal %s is greater than total paid %s"
                     % (maintainers_total + designer_total +
                        commissions_total, total))
                 redirecturl = "not needed?"
                 alarm.SendAlarm(
                     'Dispersal', t, True,
                     "total dispersal %s is greater than total paid %s" %
                     (maintainers_total + designer_total +
                      commissions_total, total), redirecturl)
                 self.error(500)
         else:
             logging.info('CRON AccountNewRecords: No records')
         logging.info('CRON AccountNewRecords: Finished')
Exemplo n.º 9
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)