コード例 #1
0
 def POST(self):
   try:
     self.request()
   except web.Unauthorized:
     data = web.input()
     imsi = str(data.imsi)
     params = {'imsi': imsi}
     params['mac'] = WebCommonBase.compute_mac(params, self.key)
     #web.log.debug("%s?%s" % ("%s/reauth" % web.fb_config.api_url, "&".join(["%s=%s" % (k,urllib.quote(v)) for k,v in params.items()])))
     requests.post("%s/reauth" % web.fb_config.api_url, params, verify=False) # XXX THIS IS INSECURE!!!
     self.request()
コード例 #2
0
    def xmpp_request(self, module, params):
      try:
          params['mac'] = WebCommonBase.compute_mac(params, self.key)
          request_url = "%s/%s" % (self.config.api_url, module)
          web.log.debug("Making request to %s with args %s" % (request_url, params))
          r = requests.post(request_url, data=params, verify=False) # XXX THIS IS INSECURE!!!
      except Exception as e:
          web.log.error("FB API server error %s" % e)
          raise web.InternalError(str(e))
      web.log.debug("Response: %s, %d" % (r, r.status_code))
      if r.status_code == 401:
          web.log.debug("FB XMPP server auth error for user")
          raise web.Unauthorized()
      elif r.status_code == 500:
          web.log.error("FB XMPP server internal error %s" % r.text)
          raise web.InternalError(r.text)
      elif r.status_code == 400:
          web.log.error("FB XMPP server bad request error %s" % r.text)
          raise web.BadRequest()

      return r
コード例 #3
0
    def POST(self):
        data = web.input()
        web.log.debug("Incoming XMPP messsage %s" % data)
        self.verify(data, fields=["sender_id", "sender_name", "body"])

        sender_id = str(data.sender_id)
        sender_name = str(data.sender_name)
        body = str(data.body)
        imsi = str(data.imsi)

        accounts = web.db.select([self.config.t_users, self.config.t_base_stations], \
            where="imsi=$imsi " + \
              "AND %s.base_station = %s.id" % (self.config.t_users, self.config.t_base_stations), \
            vars={"imsi": imsi})
        account = accounts[0]
        if account:
          web.log.info("Sending incoming message to base station: from=%s, body=%s, to=%s, base_station=%s, url=%s" % \
              (sender_id, body, imsi, account.base_station, account.callback_url))
          params = {'imsi': account.imsi, 'sender_id': sender_id, 'sender_name': sender_name, 'body': body}
          params['mac'] = WebCommonBase.compute_mac(params, self.key)
          r = requests.post(account.callback_url, params, verify=False) # XXX THIS IS INSECURE!!!
          raise web.Accepted()
        raise web.Unauthorized()
コード例 #4
0
 def _verify_channel(self, data):
   return WebCommonBase._verify_channel(self, data)