Пример #1
0
 def post(self):
     #check linden IP  and allowed avs
     logging.info('Alarm URL')
     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:
         logging.warning(
             "Illegal attempt to set alarm URL 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:
         alarmurl = self.request.body
         alarm = AppSettings(key_name="alarmurl", value=alarmurl)
         alarm.put()
         memcache.set('alarmurl', alarmurl)
         logging.info('Alarm URL set to %s' % alarmurl)
         self.response.out.write('Added')
Пример #2
0
 def post(self):
     #check linden IP  and allowed avs
     logging.info('Disperse URL')
     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:
         logging.warning("Illegal attempt to set disperse URL 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:
         disperseurl = self.request.body
         disperse = AppSettings(key_name="disperseurl", value=disperseurl)
         disperse.put()
         memcache.set('disperseurl', disperseurl)
         logging.info('Disperse URL set to %s' % disperseurl)
         self.response.out.write('Added')
Пример #3
0
def AlarmUrl():
    theurl = memcache.get('alarmurl')
    if theurl is None:
        alarm = AppSettings.get_by_key_name("alarmurl")
        if alarm is None:
            return ''
        else:
            memcache.set('alarmurl', alarm.value)
            return alarm.value
    else:
        return theurl
Пример #4
0
def AlarmUrl():
    theurl=memcache.get('alarmurl')
    if theurl is None:
        alarm = AppSettings.get_by_key_name("alarmurl")
        if alarm is None:
            return ''
        else:
            memcache.set('alarmurl', alarm.value)
            return alarm.value
    else:
        return theurl
Пример #5
0
def DisperseurlUrl():
    theurl=memcache.get('disperseurl')
    if theurl is None:
        disperse = AppSettings.get_by_key_name("disperseurl")
        if disperse is None:
            return ''
        else:
            memcache.set('disperseurl', disperse.value)
            return disperse.value
    else:
        return theurl
Пример #6
0
def DisperseurlUrl():
    theurl = memcache.get('disperseurl')
    if theurl is None:
        disperse = AppSettings.get_by_key_name("disperseurl")
        if disperse is None:
            return ''
        else:
            memcache.set('disperseurl', disperse.value)
            return disperse.value
    else:
        return theurl
Пример #7
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')
Пример #8
0
from google.appengine.api import urlfetch
from google.appengine.api import memcache
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

import relations

relationtypes = ['owns', 'secowns'
                 ]  #valid relation types.  For the sake of consistency
#let's keep only active verbs in this list

from model import AppSettings
import model

sharedpass = AppSettings.get_or_insert("sharedpass",
                                       value="sharedpassword").value
cmdurl = AppSettings.get_or_insert("cmdurl",
                                   value="http://yourcmdapp.appspot.com").value


def AlarmUrl():
    theurl = memcache.get('alarmurl')
    if theurl is None:
        alarm = AppSettings.get_by_key_name("alarmurl")
        if alarm is None:
            return ''
        else:
            memcache.set('alarmurl', alarm.value)
            return alarm.value
    else:
        return theurl
Пример #9
0
from google.appengine.api import urlfetch
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from model import AvTokenValue, AppSettings
import lindenip
import logging
import os
import relations



g_owner = "owner" #token for owner
g_secowner= "secowners" #tokes for secowner

sharedpass = AppSettings.get_or_insert("sharedpass", value="sharedpassword").value
cmdurl = AppSettings.get_or_insert("cmdurl", value="http://yourcmdapp.appspot.com").value


class MainPage(webapp.RequestHandler):
    def delete(self):
        if lindenip.inrange(os.environ['REMOTE_ADDR']) != 'Production':#only allow access from sl
            self.error(403)
        elif self.request.headers['X-SecondLife-Shard'] != 'Production':
            logging.warning("Attempt while on beta grid %s" % (self.request.headers['X-SecondLife-Shard']))
            self.response.set_status(305)
        else:
            av = self.request.headers['X-SecondLife-Owner-Key']#get owner av key
            avname = self.request.headers['X-SecondLife-Owner-Name']#get owner av name
            subbie = self.request.path.split("/")[-1] #get key of sub from path
            if avname != "(Loading...)":
Пример #10
0
from model import Purchases, AppSettings, Distributor, Dispersals
import cgi
import distributors
import lindenip
import logging
import model
import os
import sys
import tools
import wsgiref.handlers
import yaml




moneyRcpt = AppSettings.get_or_insert("moneyRcpt", value="00000000-0000-0000-0000-000000000000").value
dispersalMsgs = {"seller":"commission from vendors", "designer":"designer cut", "maintainer":"maintainer stipend"}



def DisperseurlUrl():
    theurl=memcache.get('disperseurl')
    if theurl is None:
        disperse = AppSettings.get_by_key_name("disperseurl")
        if disperse is None:
            return ''
        else:
            memcache.set('disperseurl', disperse.value)
            return disperse.value
    else:
        return theurl
Пример #11
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')
Пример #12
0
from google.appengine.api.datastore import _ToDatastoreError
from google.appengine.ext import db, webapp
from google.appengine.runtime import DeadlineExceededError
from model import Purchases, AppSettings, Distributor, Dispersals
import cgi
import distributors
import lindenip
import logging
import model
import os
import sys
import tools
import wsgiref.handlers
import yaml

moneyRcpt = AppSettings.get_or_insert(
    "moneyRcpt", value="00000000-0000-0000-0000-000000000000").value
dispersalMsgs = {
    "seller": "commission from vendors",
    "designer": "designer cut",
    "maintainer": "maintainer stipend"
}


def DisperseurlUrl():
    theurl = memcache.get('disperseurl')
    if theurl is None:
        disperse = AppSettings.get_by_key_name("disperseurl")
        if disperse is None:
            return ''
        else:
            memcache.set('disperseurl', disperse.value)