Ejemplo n.º 1
0
def get_item(name, paid):
    if (paid):
        token = 'paid_item_%s' % name
    else:
        token = 'item_%s' % name
    cacheditem = memcache.get(token)
    if cacheditem is None:
        if (paid):
            itemlookup = FreebieItem.gql("WHERE freebie_name = :1", name).get()
        else:
            itemlookup = FreebieItem.gql("WHERE freebie_name = :1 and cost = 0", name).get()
        if itemlookup is None:
            #could not find item to look up its deliverer.  return an error
            return None
        else:
            item = {
                   "name":name,
                   "version":itemlookup.freebie_version, 
                   "giver":itemlookup.freebie_giver, 
                   "givers":itemlookup.givers, 
                   "designer_key":itemlookup.designer_key, 
                   "designer_cut":itemlookup.designer_cut, 
                   "baseprice":itemlookup.baseprice
                   }
            memcache.set(token, yaml.safe_dump(item))
    else:
        #pull the item's details out of the yaml'd dict
        item = yaml.safe_load(cacheditem)
    return item
Ejemplo n.º 2
0
def get_item(name, paid):
    if (paid):
        token = 'paid_item_%s' % name
    else:
        token = 'item_%s' % name
    cacheditem = memcache.get(token)
    if cacheditem is None:
        if (paid):
            itemlookup = FreebieItem.gql("WHERE freebie_name = :1", name).get()
        else:
            itemlookup = FreebieItem.gql(
                "WHERE freebie_name = :1 and cost = 0", name).get()
        if itemlookup is None:
            #could not find item to look up its deliverer.  return an error
            return None
        else:
            item = {
                "name": name,
                "version": itemlookup.freebie_version,
                "giver": itemlookup.freebie_giver,
                "givers": itemlookup.givers,
                "designer_key": itemlookup.designer_key,
                "designer_cut": itemlookup.designer_cut,
                "baseprice": itemlookup.baseprice
            }
            memcache.set(token, yaml.safe_dump(item))
    else:
        #pull the item's details out of the yaml'd dict
        item = yaml.safe_load(cacheditem)
    return item
Ejemplo n.º 3
0
    def get(self):
        message = '''<h1>List of Freebie items</h1>
<p>This lists all item currently in the distribution system as of %s.</p>
<table class="sortable" border=\"1\">''' % datetime.datetime.utcnow().isoformat(' ')
        message += '<tr><th>Row</th><th>Owner</th><th>Giver ID</th><th>Name</th><th>Version</th><th>Update Date</th><th>Distributor Location</th><th>Texture Key</th><th>Texture Server</th><th>Texture Updatetime</th></tr><br />\n'
        query = FreebieItem.gql("")
        content =[]
        for record in query:
            owner = record.freebie_owner
            if (owner == None):
                owner = '***Not assigned***'
            if (record.freebie_texture_update == None):
                i = -1
            else:
                i = record.freebie_texture_update
            content += ['<td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%d</td>\n' % (owner, record.freebie_giver, record.freebie_name, record.freebie_version, record.freebie_timedate, record.freebie_location, record.freebie_texture_key, record.freebie_texture_serverkey, i)]



        content = sorted(content)

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

        message += "</table>"
        self.response.out.write((head % 'Freebie Items List') + message + end)
Ejemplo n.º 4
0
    def post(self):
        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 self.request.headers["X-SecondLife-Owner-Key"] in model.adminkeys:
            self.error(403)
        else:
            done_str = self.request.get("done")
            serverkey = self.request.headers["X-SecondLife-Object-Key"]
            logging.info("Finalizing texture update from texture server %s" % (serverkey))
            if not done_str:
                logging.info("Done not confirmed, something is seriously wrong")
                self.error(402)
            else:
                starttime = int(done_str)
                t = int(time.time())
                ts = "%d" % t
                logging.info("Cleaning all textures for server %s with timestamp below %d" % (serverkey, starttime))

                query = FreebieItem.gql("WHERE freebie_texture_serverkey = :1", serverkey)
                for record in query:
                    if record.freebie_texture_update < starttime:
                        logging.info("Cleaned info for %s" % record.freebie_name)
                        record.freebie_texture_serverkey = ""
                        record.freebie_texture_update = -1
                        record.freebie_texture_key = ""
                        record.put()

                logging.info("Version info stored: %s" % ts)
                model.GenericStorage_Store("TextureTime", ts)
                self.response.out.write("Version updated: %s" % ts)
Ejemplo n.º 5
0
    def get(self):
        message = '''<h1>List of Freebie items</h1>
<p>This lists all item currently in the distribution system as of %s.</p>
<table class="sortable" border=\"1\">''' % datetime.datetime.utcnow(
        ).isoformat(' ')
        message += '<tr><th>Row</th><th>Owner</th><th>Giver ID</th><th>Name</th><th>Version</th><th>Update Date</th><th>Distributor Location</th><th>Texture Key</th><th>Texture Server</th><th>Texture Updatetime</th></tr><br />\n'
        query = FreebieItem.gql("")
        content = []
        for record in query:
            owner = record.freebie_owner
            if (owner == None):
                owner = '***Not assigned***'
            if (record.freebie_texture_update == None):
                i = -1
            else:
                i = record.freebie_texture_update
            content += [
                '<td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%d</td>\n'
                % (owner, record.freebie_giver, record.freebie_name,
                   record.freebie_version, record.freebie_timedate,
                   record.freebie_location, record.freebie_texture_key,
                   record.freebie_texture_serverkey, i)
            ]

        content = sorted(content)

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

        message += "</table>"
        self.response.out.write((head % 'Freebie Items List') + message + end)
Ejemplo n.º 6
0
    def post(self):
        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 self.request.headers['X-SecondLife-Owner-Key'] in model.adminkeys:
            self.error(403)
        else:
            done_str = self.request.get('done')
            serverkey= self.request.headers['X-SecondLife-Object-Key']
            logging.info('Finalizing texture update from texture server %s' % (serverkey))
            if not done_str:
                logging.info ('Done not confirmed, something is seriously wrong')
                self.error(402)
            else:
                starttime=int(done_str)
                t=int(time.time())
                ts="%d" % t
                logging.info ('Cleaning all textures for server %s with timestamp below %d' % (serverkey, starttime))

                query = FreebieItem.gql("WHERE freebie_texture_serverkey = :1", serverkey)
                for record in query:
                    if record.freebie_texture_update < starttime:
                        logging.info ('Cleaned info for %s' % record.freebie_name)
                        record.freebie_texture_serverkey = ''
                        record.freebie_texture_update = -1
                        record.freebie_texture_key = ''
                        record.put()

                logging.info ('Version info stored: %s' % ts)
                model.GenericStorage_Store('TextureTime', ts)
                self.response.out.write('Version updated: %s' % ts)
Ejemplo n.º 7
0
    def get(self):
        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.Contributor_authorized(
                self.request.headers['X-SecondLife-Owner-Key']):
            logging.warning(
                "Illegal attempt to check for 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)
        else:
            # get the deliveries where giverkey = key provided (this way we can
            # still have multiple givers)
            giverkey = self.request.headers['X-SecondLife-Object-Key']
            givername = self.request.headers['X-SecondLife-Object-Name']

            # true or false.  if true, then remove items from db on returning them
            pop = cgi.escape(self.request.get('pop'))

            avname = self.request.headers['X-SecondLife-Owner-Name']
            logging.info('%s (%s) from %s checked' %
                         (givername, giverkey, avname))

            # to enable/disable the update routine fast, only need to update old records
            if (False):
                timestring = datetime.datetime.utcnow()
                location = '%s @ %s' % (
                    self.request.headers['X-SecondLife-Region'],
                    self.request.headers['X-SecondLife-Local-Position'])

                query = FreebieItem.gql("WHERE freebie_giver = :1", giverkey)
                for record in query:
                    record.freebie_owner = avname
                    record.freebie_timedate = timestring
                    record.freebie_location = location
                    record.put()
                    logging.info('Updated %s from %s' %
                                 (record.freebie_name, avname))

            #deliveries = FreebieDelivery.gql("WHERE giverkey = :1", giverkey)
            token = "deliveries_%s" % giverkey
            deliveries = memcache.get(token)
            if deliveries is not None:
                response = ""
                #take the list of lists and format it
                #write each out in form <objname>|receiverkey, one per line
                out = '\n'.join(['|'.join(x) for x in deliveries])
                self.response.out.write(out)
                logging.info('%s got delivery string\n%s' % (givername, out))
                memcache.delete(token)
            else:
                self.response.out.write('')
Ejemplo n.º 8
0
 def get(self):
     logging.info('CRON UpdateCount')
     query = FreebieItem.all().fetch(1000)
     for record in query:
         count_token = 'item_count_%s' % record.freebie_name
         count = memcache.get(count_token)
         if count is not None:
             if int(count) > 1:
                 db.run_in_transaction(UpdateRecord, record.key(), count_token)
                 logging.info('CRON: Count info for %s  updated with %s new requests' % (record.freebie_name, count))
     logging.info('CRON UpdateCount: Finished')
Ejemplo n.º 9
0
 def get(self):
     logging.info('CRON UpdateCount')
     query = FreebieItem.all().fetch(1000)
     for record in query:
         count_token = 'item_count_%s' % record.freebie_name
         count = memcache.get(count_token)
         if count is not None:
             if int(count) > 1:
                 db.run_in_transaction(UpdateRecord, record.key(),
                                       count_token)
                 logging.info(
                     'CRON: Count info for %s  updated with %s new requests'
                     % (record.freebie_name, count))
     logging.info('CRON UpdateCount: Finished')
Ejemplo n.º 10
0
    def post(self):
        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 self.request.headers['X-SecondLife-Owner-Key'] in model.adminkeys:
            self.error(403)
        else:
            self.response.headers['Content-Type'] = 'text/plain'
            name = self.request.headers['X-SecondLife-Owner-Name']
            serverkey =self.request.headers['X-SecondLife-Object-Key']
            logging.info('Receiving price info from texture server %s' % (serverkey))
            lines = self.request.body.split('\n')

            for line in lines:
                params = {}
                if line != "":
                    item = line.split('~')[0]

                    t=int(time.time())
                    ts="%d" % t

                    record = FreebieItem.gql('WHERE freebie_name = :1', item).get()
                    if record is None:
                        logging.info("Item %s not in freebielist, skipping price info %s" % (item ,line))
                    else:
                        numParms = line.count('~')
                        if numParms > 0:
                            baseprice = line.split('~')[1]
                            record.baseprice = int(baseprice)
                            if numParms > 2:
                                designer = line.split('~')[2]
                                designer_cut = line.split('~')[3]
                                record.designer_key = designer
                                record.designer_cut = int(designer_cut)
                            record.freebie_texture_update= t
                            record.put()
                            logging.info("Price updated for %s with %s form server %s at %d" % (item,line,serverkey,t))
                            token = 'item_%s' % record.freebie_name
                            token2 = 'paid_item_%s' % record.freebie_name
                            memcache.delete(token)
                            memcache.set(token2, yaml.safe_dump({"name":record.freebie_name, "version":record.freebie_version, "giver":record.freebie_giver, "givers":record.givers, "designer_key":record.designer_key, "designer_cut":record.designer_cut, "baseprice":record.baseprice}))
                        else:
                            logging.info("No info for item %s skipping" % (item))
#            model.GenericStorage_Store('TextureTime', ts)
            self.response.out.write('saved')
Ejemplo n.º 11
0
    def get(self):
        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.Contributor_authorized(self.request.headers['X-SecondLife-Owner-Key']):
            logging.warning("Illegal attempt to check for 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)
        else:
            # get the deliveries where giverkey = key provided (this way we can
            # still have multiple givers)
            giverkey = self.request.headers['X-SecondLife-Object-Key']
            givername = self.request.headers['X-SecondLife-Object-Name']
            
            # true or false.  if true, then remove items from db on returning them
            pop = cgi.escape(self.request.get('pop'))
            
            avname = self.request.headers['X-SecondLife-Owner-Name']
            logging.info('%s (%s) from %s checked' % (givername, giverkey, avname))

# to enable/disable the update routine fast, only need to update old records
            if (False):
                timestring = datetime.datetime.utcnow()
                location = '%s @ %s' % (self.request.headers['X-SecondLife-Region'], self.request.headers['X-SecondLife-Local-Position'])

                query = FreebieItem.gql("WHERE freebie_giver = :1", giverkey)
                for record in query:
                    record.freebie_owner = avname
                    record.freebie_timedate = timestring
                    record.freebie_location = location
                    record.put()
                    logging.info('Updated %s from %s' % (record.freebie_name, avname))

            #deliveries = FreebieDelivery.gql("WHERE giverkey = :1", giverkey)
            token = "deliveries_%s" % giverkey
            deliveries = memcache.get(token)
            if deliveries is not None:
                response = ""
                #take the list of lists and format it
                #write each out in form <objname>|receiverkey, one per line
                out = '\n'.join(['|'.join(x) for x in deliveries])
                self.response.out.write(out)
                logging.info('%s got delivery string\n%s' % (givername, out))
                memcache.delete(token)
            else:
                self.response.out.write('')
Ejemplo n.º 12
0
    def post(self):
        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 self.request.headers["X-SecondLife-Owner-Key"] in model.adminkeys:
            self.error(403)
        else:
            self.response.headers["Content-Type"] = "text/plain"
            name = self.request.headers["X-SecondLife-Owner-Name"]
            serverkey = self.request.headers["X-SecondLife-Object-Key"]
            logging.info("Receiving textures from texture server %s" % (serverkey))
            lines = unicode(self.request.body).split("\n")

            for line in lines:
                params = {}
                if line != "":
                    params["item"] = line.split("=")[0]
                    params["texture"] = line.split("=")[1]
                    item = params["item"].split("~")[0]
                    texture = params["texture"]
                    if params["item"].find("~") != -1:
                        tags = params["item"].split("~", 1)[1].split("~")
                    else:
                        tags = list()
                    t = int(time.time())
                    ts = "%d" % t

                    record = FreebieItem.gql("WHERE freebie_name = :1", item).get()
                    if record is None:
                        logging.info("Item %s not in freebielist, skipping texture %s" % (item, texture))
                    else:
                        record.freebie_texture_key = texture
                        record.freebie_texture_serverkey = serverkey
                        record.freebie_texture_update = t
                        record.tags = tags
                        record.put()
                        logging.info(
                            "Texture updated for %s with %s form server %s at %d" % (item, texture, serverkey, t)
                        )
            #            model.GenericStorage_Store('TextureTime', ts)
            self.response.out.write("saved")
Ejemplo n.º 13
0
    def post(self):
        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 self.request.headers['X-SecondLife-Owner-Key'] in model.adminkeys:
            self.error(403)
        else:
            self.response.headers['Content-Type'] = 'text/plain'
            name = self.request.headers['X-SecondLife-Owner-Name']
            serverkey = self.request.headers['X-SecondLife-Object-Key']
            logging.info('Receiving textures from texture server %s' % (serverkey))
            lines = unicode(self.request.body).split('\n')

            for line in lines:
                params = {}
                if line != "":
                    params['item'] = line.split('=')[0]
                    params['texture'] = line.split('=')[1]
                    item = params['item'].split('~')[0]
                    texture = params['texture']
                    if params['item'].find('~')!= -1:
                        tags = params['item'].split('~',1)[1].split('~')
                    else:
                        tags = list()
                    t=int(time.time())
                    ts="%d" % t

                    record = FreebieItem.gql('WHERE freebie_name = :1', item).get()
                    if record is None:
                        logging.info("Item %s not in freebielist, skipping texture %s" % (item ,texture))
                    else:
                        record.freebie_texture_key = texture
                        record.freebie_texture_serverkey = serverkey
                        record.freebie_texture_update= t
                        record.tags = tags
                        record.put()
                        logging.info("Texture updated for %s with %s form server %s at %d" % (item,texture,serverkey,t))
#            model.GenericStorage_Store('TextureTime', ts)
            self.response.out.write('saved')
Ejemplo n.º 14
0
def remove_item_url(name, deliver):
    item = FreebieItem.gql("WHERE freebie_name = :1", name).get()
    if item is None:
        #could not find item to look up its deliverer.  return an error
        logging.info("Removing %s deliver from %s but item is not found." % (deliver, name)) #return None
    else:
        logging.info("Removing %s deliver from %s" % (deliver, name))
        item.givers.remove(deliver)
        item.put()
        token = 'item_%s' % name
        token2 = 'paid_item_%s' % name
        data = yaml.safe_dump({
                               "name":name,
                               "version":item.freebie_version, 
                               "giver":item.freebie_giver, 
                               "givers":item.givers, 
                               "designer_key":item.designer_key, 
                               "designer_cut":item.designer_cut, 
                               "baseprice":item.baseprice
                               })
        if item.baseprice == 0:
            memcache.set(token, data)
        memcache.set(token2, data)
Ejemplo n.º 15
0
def remove_item_url(name, deliver):
    item = FreebieItem.gql("WHERE freebie_name = :1", name).get()
    if item is None:
        #could not find item to look up its deliverer.  return an error
        logging.info("Removing %s deliver from %s but item is not found." %
                     (deliver, name))  #return None
    else:
        logging.info("Removing %s deliver from %s" % (deliver, name))
        item.givers.remove(deliver)
        item.put()
        token = 'item_%s' % name
        token2 = 'paid_item_%s' % name
        data = yaml.safe_dump({
            "name": name,
            "version": item.freebie_version,
            "giver": item.freebie_giver,
            "givers": item.givers,
            "designer_key": item.designer_key,
            "designer_cut": item.designer_cut,
            "baseprice": item.baseprice
        })
        if item.baseprice == 0:
            memcache.set(token, data)
        memcache.set(token2, data)
Ejemplo n.º 16
0
    def post(self):
        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 self.request.headers["X-SecondLife-Owner-Key"] in model.adminkeys:
            self.error(403)
        else:
            self.response.headers["Content-Type"] = "text/plain"
            name = self.request.headers["X-SecondLife-Owner-Name"]
            serverkey = self.request.headers["X-SecondLife-Object-Key"]
            logging.info("Receiving price info from texture server %s" % (serverkey))
            lines = self.request.body.split("\n")

            for line in lines:
                params = {}
                if line != "":
                    item = line.split("~")[0]

                    t = int(time.time())
                    ts = "%d" % t

                    record = FreebieItem.gql("WHERE freebie_name = :1", item).get()
                    if record is None:
                        logging.info("Item %s not in freebielist, skipping price info %s" % (item, line))
                    else:
                        numParms = line.count("~")
                        if numParms > 0:
                            baseprice = line.split("~")[1]
                            record.baseprice = int(baseprice)
                            if numParms > 2:
                                designer = line.split("~")[2]
                                designer_cut = line.split("~")[3]
                                record.designer_key = designer
                                record.designer_cut = int(designer_cut)
                            record.freebie_texture_update = t
                            record.put()
                            logging.info(
                                "Price updated for %s with %s form server %s at %d" % (item, line, serverkey, t)
                            )
                            token = "item_%s" % record.freebie_name
                            token2 = "paid_item_%s" % record.freebie_name
                            memcache.delete(token)
                            memcache.set(
                                token2,
                                yaml.safe_dump(
                                    {
                                        "name": record.freebie_name,
                                        "version": record.freebie_version,
                                        "giver": record.freebie_giver,
                                        "givers": record.givers,
                                        "designer_key": record.designer_key,
                                        "designer_cut": record.designer_cut,
                                        "baseprice": record.baseprice,
                                    }
                                ),
                            )
                        else:
                            logging.info("No info for item %s skipping" % (item))
            #            model.GenericStorage_Store('TextureTime', ts)
            self.response.out.write("saved")
Ejemplo n.º 17
0
    def post(self):
        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']
#            if not distributors.Distributor_authorized(av): #Really needs to be changed??? function needs to be changed to distributors.authorized_designer as soon as the database for that is fully functioning
#                self.error(402)
#            else:
                objectkey=self.request.headers['X-SecondLife-Object-Key']
                sim_id = self.request.headers['X-SecondLife-Region']
                logging.info('Gift Texture request from %s in sim %s' % (objectkey, sim_id))
                body = self.request.body
                # Use a query parameter to keep track of the last key of the last
                # batch, to know where to start the next batch.
                last_key_str = self.request.get('start')
                last_version_str = self.request.get('last_version')
                last_version = int(last_version_str)
                current_version = int(model.GenericStorage_GetOrPutDefault('TextureTime', '0'))
                if current_version < 0:
                    # system updating at the moment
                    logging.info ('System in update mode, inform the client')
                    self.response.out.write('Updating')
                else:
                    # normal work mode, lets do check and send texture
                    result =''
                    if not last_version_str:
                        # no last time given so we can use the stored time
                        last_version_str = '0'
                        last_version = 0
                        logging.info ('no last_version, send update')
                    else:
                        last_version = int(last_version_str)
                        logging.info ('last_version (%s)' % last_version_str)
                    if current_version == last_version:
                        logging.info ('Versions are identic, no action needed')
                        self.response.out.write('CURRENT')
                    else:
                        logging.info ('Versions different (DB:%s,Vendor:%s) Starting to send update...' % (current_version, last_version_str))
                        if not last_key_str:
                            last_key = 0
                            result ='version\n%s\n' % current_version
                            logging.info ('no last_key, send from start')
                        else:
                            last_key=int(last_key_str)
                            result ='continue\n%s\n' % current_version
                            logging.info ('last_key was: %s' % last_key_str)
                        query = FreebieItem.all()
                        query.filter('freebie_texture_update >', 0)
                        entities = query.fetch(21,last_key)
                        count = 0
                        more = False
                        for texture in entities:
                            count = count + 1
                            if count < 21:
                                logging.info('%s:%d' % (texture.freebie_name,texture.freebie_texture_update))
                                result=result + texture.freebie_name +"\n"+texture.freebie_texture_key+"\n"
                                result=result + "%s\n" % texture.baseprice
                            else:
                                last_key=last_key+20
                                result=result + ("startwith\n%d" % (last_key))
                                more = True
                                logging.info ('More texture availabe, request next time from %d' % (last_key))
                        if more == False:
                            logging.info ('Sending finished now')
                            result = result + "end\n"
                        self.response.out.write(result)
Ejemplo n.º 18
0
 def post(self):
     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"]
         #            if not distributors.Distributor_authorized(av): #Really needs to be changed??? function needs to be changed to distributors.authorized_designer as soon as the database for that is fully functioning
         #                self.error(402)
         #            else:
         objectkey = self.request.headers["X-SecondLife-Object-Key"]
         sim_id = self.request.headers["X-SecondLife-Region"]
         logging.info("Gift Texture request from %s in sim %s" % (objectkey, sim_id))
         body = self.request.body
         # Use a query parameter to keep track of the last key of the last
         # batch, to know where to start the next batch.
         last_key_str = self.request.get("start")
         last_version_str = self.request.get("last_version")
         last_version = int(last_version_str)
         current_version = int(model.GenericStorage_GetOrPutDefault("TextureTime", "0"))
         if current_version < 0:
             # system updating at the moment
             logging.info("System in update mode, inform the client")
             self.response.out.write("Updating")
         else:
             # normal work mode, lets do check and send texture
             result = ""
             if not last_version_str:
                 # no last time given so we can use the stored time
                 last_version_str = "0"
                 last_version = 0
                 logging.info("no last_version, send update")
             else:
                 last_version = int(last_version_str)
                 logging.info("last_version (%s)" % last_version_str)
             if current_version == last_version:
                 logging.info("Versions are identic, no action needed")
                 self.response.out.write("CURRENT")
             else:
                 logging.info(
                     "Versions different (DB:%s,Vendor:%s) Starting to send update..."
                     % (current_version, last_version_str)
                 )
                 if not last_key_str:
                     last_key = 0
                     result = "version\n%s\n" % current_version
                     logging.info("no last_key, send from start")
                 else:
                     last_key = int(last_key_str)
                     result = "continue\n%s\n" % current_version
                     logging.info("last_key was: %s" % last_key_str)
                 query = FreebieItem.all()
                 query.filter("freebie_texture_update >", 0)
                 entities = query.fetch(21, last_key)
                 count = 0
                 more = False
                 for texture in entities:
                     count = count + 1
                     if count < 21:
                         logging.info("%s:%d" % (texture.freebie_name, texture.freebie_texture_update))
                         result = result + texture.freebie_name + "\n" + texture.freebie_texture_key + "\n"
                         result = result + "%s\n" % texture.baseprice
                     else:
                         last_key = last_key + 20
                         result = result + ("startwith\n%d" % (last_key))
                         more = True
                         logging.info("More texture availabe, request next time from %d" % (last_key))
                 if more == False:
                     logging.info("Sending finished now")
                     result = result + "end\n"
                 self.response.out.write(result)
Ejemplo n.º 19
0
    def get(self):
        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.Contributor_authorized(
                self.request.headers['X-SecondLife-Owner-Key']):
            logging.warning(
                "Illegal attempt to update 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)
        else:
            self.response.headers['Content-Type'] = 'text/plain'
            name = cgi.escape(self.request.get('object'))
            version = cgi.escape(self.request.get('version'))
            giverkey = self.request.headers['X-SecondLife-Object-Key']
            avname = self.request.headers['X-SecondLife-Owner-Name']
            location = '%s @ %s' % (
                self.request.headers['X-SecondLife-Region'],
                self.request.headers['X-SecondLife-Local-Position'])
            timestring = datetime.datetime.utcnow()
            url = cgi.escape(self.request.get('url', default_value='None'))
            if url == 'None':
                giverurl = []
            else:
                giverurl = [unicode(giverkey)]
                deliv_box = Deliver.get_or_insert("Deliv:%s" % giverkey,
                                                  timedate=0,
                                                  url='None')
                update_dist = False
                if url != deliv_box.url:
                    update_dist = True
                elif timestring - deliv_box.timedate > datetime.timedelta(
                        0, 60):
                    update_dist = True
                if update_dist:
                    deliv_box.url = url
                    deliv_box.timedate = timestring
                    deliv_box.owner = avname
                    deliv_box.location = location
                    deliv_box.put()

            # If no version provided, set a default
            version = version or 'NOVERSION'
            #look for an existing item with that name
            items = FreebieItem.gql("WHERE freebie_name = :1", name)
            item = items.get()
            if (item == None):
                newitem = FreebieItem(freebie_name=name,
                                      freebie_version=version,
                                      freebie_giver=giverkey,
                                      givers=giverurl,
                                      freebie_owner=avname,
                                      freebie_timedate=timestring,
                                      freebie_location=location)
                newitem.put()
                item = newitem
            # Version check removed because 3.7x and onwards does not include
            # version numbers in object names. So this means that it's
            # possible to downgrade and switch to delivering an older version. -Nan

            # TODO: Instead of having items identified only by name and
            # version, allow them to be identified by name and UUID.  This will
            # allow us to have unversioned items that are still delivered by
            # multiple dist boxes, because we can tell if a box is out of sync
            # by the item's UUID.
            else:
                item.givers = []
                logging.info("Clearing box list for item %s" % name)

                # will be 'NOVERSION' for 3.7x collars
                item.freebie_version = version

                item.freebie_giver = giverkey
                if giverurl != []:
                    if giverkey in item.givers:
                        #item.givers[item.givers.index(giverkey)+1] = url
                        logging.info("Box in list")
                    else:
                        item.givers[:0] = giverurl
                        logging.info("Adding box")
                elif giverkey in item.givers:
                    index = item.givers.index(giverkey)
                    item.givers[index:index] = []
                    logging.warning("Removing box")
                item.freebie_owner = avname
                item.freebie_timedate = timestring
                item.freebie_location = location
                item.put()
            #update item in memcache
            token = 'item_%s' % name
            token2 = 'paid_item_%s' % name
            data = yaml.safe_dump({
                "name": name,
                "version": item.freebie_version,
                "giver": item.freebie_giver,
                "givers": item.givers,
                "designer_key": item.designer_key,
                "designer_cut": item.designer_cut,
                "baseprice": item.baseprice
            })
            if item.baseprice == 0:
                memcache.set(token, data)
            memcache.set(token2, data)
            self.response.out.write('saved')
            logging.info('saved item %s version %s by %s with urls %s' %
                         (name, item.freebie_version, avname, item.givers))
Ejemplo n.º 20
0
    def get(self):
        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.Contributor_authorized(self.request.headers['X-SecondLife-Owner-Key']):
            logging.warning("Illegal attempt to update 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)
        else:
            self.response.headers['Content-Type'] = 'text/plain'
            name = cgi.escape(self.request.get('object'))
            version = cgi.escape(self.request.get('version'))
            giverkey = self.request.headers['X-SecondLife-Object-Key']
            avname = self.request.headers['X-SecondLife-Owner-Name']
            location = '%s @ %s' % (self.request.headers['X-SecondLife-Region'], self.request.headers['X-SecondLife-Local-Position'])
            timestring = datetime.datetime.utcnow()
            url = cgi.escape(self.request.get('url', default_value='None'))
            if url == 'None':
                giverurl = []
            else:
                giverurl = [unicode(giverkey)]
                deliv_box = Deliver.get_or_insert("Deliv:%s" % giverkey, timedate=0, url='None')
                update_dist = False
                if url != deliv_box.url:
                    update_dist = True
                elif timestring - deliv_box.timedate > datetime.timedelta(0, 60):
                    update_dist = True
                if update_dist:
                    deliv_box.url = url
                    deliv_box.timedate = timestring
                    deliv_box.owner = avname
                    deliv_box.location = location
                    deliv_box.put()

            # If no version provided, set a default
            version = version or 'NOVERSION'
            #look for an existing item with that name
            items = FreebieItem.gql("WHERE freebie_name = :1", name)
            item = items.get()
            if (item == None):
                newitem = FreebieItem(freebie_name = name, freebie_version = version, freebie_giver = giverkey, givers = giverurl, freebie_owner = avname, freebie_timedate = timestring, freebie_location = location)
                newitem.put()
                item = newitem
             # Version check removed because 3.7x and onwards does not include
             # version numbers in object names. So this means that it's
             # possible to downgrade and switch to delivering an older version. -Nan
            
            # TODO: Instead of having items identified only by name and
            # version, allow them to be identified by name and UUID.  This will
            # allow us to have unversioned items that are still delivered by
            # multiple dist boxes, because we can tell if a box is out of sync
            # by the item's UUID.
            else:
                item.givers = []
                logging.info("Clearing box list for item %s" % name)
                
                # will be 'NOVERSION' for 3.7x collars
                item.freebie_version = version 
                
                item.freebie_giver = giverkey
                if giverurl != []:
                    if giverkey in item.givers:
                        #item.givers[item.givers.index(giverkey)+1] = url
                        logging.info("Box in list")
                    else:
                        item.givers[:0] = giverurl
                        logging.info("Adding box")
                elif giverkey in item.givers:
                    index = item.givers.index(giverkey)
                    item.givers[index:index] = []
                    logging.warning("Removing box")
                item.freebie_owner = avname
                item.freebie_timedate = timestring
                item.freebie_location = location
                item.put()
            #update item in memcache
            token = 'item_%s' % name
            token2 = 'paid_item_%s' % name
            data = yaml.safe_dump({
                                   "name":name,
                                   "version":item.freebie_version, 
                                   "giver":item.freebie_giver, 
                                   "givers":item.givers, 
                                   "designer_key":item.designer_key, 
                                   "designer_cut":item.designer_cut, 
                                   "baseprice":item.baseprice
                                   })
            if item.baseprice == 0:
                memcache.set(token, data)
            memcache.set(token2, data)
            self.response.out.write('saved')
            logging.info('saved item %s version %s by %s with urls %s' % (name, item.freebie_version, avname, item.givers))