Esempio n. 1
0
 def get(self):
   import time
   t2 = time.time()
   do = self.request.get('do')
   if (do == 'delete_requests'):
     db.delete(ValidationRequest.all(keys_only=True).fetch(200))
     return self.redirect('/validator')
   
   elif do == 'delete_quotas':
     db.delete(DemoClient.all(keys_only=True).fetch(200))
     return self.redirect('/validator')
   
   service_users = ServiceUser.all().fetch(100)
   validation_requests = ValidationRequest.all().fetch(100)
   t = time.time()
   for service_user in service_users:
     service_user.api_key = service_user.key().name()
   
   for validation_request in validation_requests:
     validation_request.access_key = validation_request.key().name()  
   now = time.time()
   logging.debug('LOG1%f' %(now - t))
   logging.debug('LOG2%f' %(now - t2))
   context = {
     'service_users':service_users,
     'validation_requests':validation_requests,
   }
   return self.render_response('validator.html', context)
Esempio n. 2
0
 def post(self):
   method = self.request.get("method")
   if (method == "new_service_user"):
     name = self.request.get('name')
     existing = ServiceUser.all(keys_only=True).filter('name = ',name).get()
     if (existing is not None):
       return self.response.out.write('already exists')
     else:
       ServiceUser(name=name, key_name=tropo.generate_key()).put()
       return self.redirect('/validator')
   else:
     return self.response.out.write('no type')
Esempio n. 3
0
    def get(self):
      target = self.request.get('target')
      api_key = self.request.get('api_key')
      secret = self.request.get('secret')
      intro = self.request.get('intro')
      if (not target) or (not api_key):
        return self.response.out.write('target and service key is required params.')

      method = re.match('(\\w+):', target)
      if (method is None):
        return self.response.out.write('target '+target+' not valid')
      
      ds_user_entry = ServiceUser.get_by_key_name(api_key)
      if (not ds_user_entry):
        return self.response.out.write('api key ' + api_key + ' does not exist')
      
      
      method = method.group(1)
      access_key = tropo.generate_key()
      if (method == 'tel' or 'sip'):
        if not secret:
          secret = tropo.generate_secret() 
        if not intro:
          intro = "Hello! Your secret code is :"
        context = {
          'to':target,
          'secret':secret,
          'intro':intro,
          'access_key':access_key
        }
        http_rpc = tropo.tropo_run_script(context, async=True)
        ds_rpc = db.create_rpc()
        ValidationRequest(
          target = target,
          api_key = api_key,
          key_name = access_key,
          secret = int(secret)
        ).put(rpc=ds_rpc)
        resp = json.dumps({'access_key':access_key,'secret':secret})
        http_rpc.wait()
        ds_rpc.wait()
        return self.response.out.write(resp)
      return self.response.out.write('method not supported.')