2017-11-17 14:47:22 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from tornado.websocket import WebSocketHandler
|
2017-11-27 17:16:35 +00:00
|
|
|
from util import parse_anchor_from_message
|
2017-11-17 14:47:22 +00:00
|
|
|
|
2017-11-27 17:47:33 +00:00
|
|
|
# from buttons import fsm
|
|
|
|
from sql_injection_fsm import fsm
|
2017-12-02 14:19:05 +00:00
|
|
|
import event_handler_connector
|
2017-11-17 14:47:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ZMQWebSocketHandler(WebSocketHandler):
|
2017-11-27 17:16:35 +00:00
|
|
|
def __init__(self, application, request, **kwargs):
|
2017-11-17 14:47:22 +00:00
|
|
|
super().__init__(application, request, **kwargs)
|
|
|
|
|
|
|
|
def open(self, *args, **kwargs):
|
|
|
|
def zmq_callback(msg_parts):
|
|
|
|
anchor, data = msg_parts
|
|
|
|
logging.debug('Received on pull socket: {}'.format(data.decode()))
|
|
|
|
self.write_message(data.decode())
|
|
|
|
|
2017-12-02 14:19:05 +00:00
|
|
|
event_handler_connector.register_callback(zmq_callback)
|
2017-11-17 14:47:22 +00:00
|
|
|
|
|
|
|
def on_message(self, message):
|
|
|
|
logging.debug('Received on WebSocket: {}'.format(message))
|
2017-11-27 17:45:58 +00:00
|
|
|
fsm.trigger(parse_anchor_from_message(message), message=message)
|
2017-11-17 14:47:22 +00:00
|
|
|
|
2017-11-27 17:16:35 +00:00
|
|
|
def send_message(self, message: str, anchor: str = None):
|
2017-12-02 14:19:05 +00:00
|
|
|
event_handler_connector.send_message(message, anchor)
|
2017-11-17 14:47:22 +00:00
|
|
|
|
|
|
|
def on_close(self):
|
2017-11-27 17:16:35 +00:00
|
|
|
pass
|
2017-11-17 14:47:22 +00:00
|
|
|
|
|
|
|
# much secure, very cors, wow
|
|
|
|
def check_origin(self, origin):
|
|
|
|
return True
|
|
|
|
|