def get(self): response_dict = {} response_dict['me'] = self.request.url response_dict['version'] = '2.0.0' response_dict['vendor'] = 'e.quinox' response_dict['provides'] = ['heartbeat', 'get_messages', 'post_messages'] response_dict['config'] = {'utc': datetime.utcnow()} self.response.headers['Content-Type'] = 'application/json' self.response.out.write(simplejson.dumps(response_dict))
def send_heartbeat(url, key): json_msg = {} json_msg['method'] = 'heartbeat' json_msg['id'] = 4 params = {} params['kiosk-id'] = DIEID if UPTIME < 60: # under a minute uptimestr = "%.2f seconds" % UPTIME elif UPTIME < 60*60: # under a hour uptimestr = "%.2f minutes" % (UPTIME/(60.0)) elif UPTIME < 60*60*24*3: # under 3 days uptimestr = "%.2f hours" % (UPTIME/(60.0*60.0)) else: # over 3 days uptimestr = "%.2f days" % (UPTIME/(60.0*60.0*24.0)) params['uptime'] = uptimestr params['sw-version'] = '1.0.0' params['time'] = datetime.utcnow() json_msg['params'] = params jsstr = json.dumps(json_msg) hash = MD5.new(jsstr).digest() baseconverter = BaseConverter('0123456789abcdef') sign_16encode = baseconverter.from_decimal(key.sign(hash, "")[0]) #print "encoded: %s" % sign_16encode #print "signature: %d" % key.sign(hash, "")[0] #print "hash: %s" % "".join(["%02x " % ord(x) for x in hash]) headers = {'X-eko-signature': sign_16encode} print jsstr #test decoding x = key.publickey().verify(hash, (baseconverter.to_decimal(sign_16encode),)) req = urllib2.Request(url, jsstr, headers) response = urllib2.urlopen(req) the_page = response.read() print the_page
def get_messages(url, key): json_msg = {} json_msg['method'] = 'get_messages' json_msg['id'] = 4 json_msg['params'] = {'kiosk-id': DIEID} jsstr = json.dumps(json_msg) hash = MD5.new(jsstr).digest() baseconverter = BaseConverter('0123456789abcdef') sign_16encode = baseconverter.from_decimal(key.sign(hash, "")[0]) #print "encoded: %s" % sign_16encode #print "signature: %d" % key.sign(hash, "")[0] #print "hash: %s" % "".join(["%02x " % ord(x) for x in hash]) headers = {'X-eko-signature': sign_16encode} print jsstr #test decoding x = key.publickey().verify(hash, (baseconverter.to_decimal(sign_16encode),)) req = urllib2.Request(url, jsstr, headers) response = urllib2.urlopen(req) the_page = response.read() print the_page
def post(self): """ .. py:func:: post() Dispatches a JSON request to the relavent method in JSONRPCMethods. """ try: method, params, id = self.process() except ValueError, e: self.error(400) # bad request return if method[0] == '_': self.error(403) # access denied return func = getattr(self.methods, method, None) if not func: self.error(404) # file not found return logging.info("This is whats causing trouble %s" % str(params)) self.response.headers['content-type'] = 'application/json' try: result = func(method, id, **params) except: logging.exception("Could not execute rpc %s." % func) self.error(500) return self.response.out.write(simplejson.dumps(result))