# Oxypanel
# File: views/webscoket.py
# Desc: the websocket request handler

from flask import request

import config
from app import app, websocket, redis_client
from util.data import get_websocket
from util.log import logger
from util.web.user import get_current_user

# More internal router than view
@websocket.route('/websocket')
def websocket_request(ws):
    with app.request_context(ws.environ):
        # Check user
        user = get_current_user()
        if not user: return ws.send('INVALID_USER')
        # Check request key
        request_key = request.args.get('key', None)
        if not request_key: return ws.send('INVALID_REQUEST_KEY')

        request_data = redis_client.hgetall(
            '{0}{1}'.format(config.REDIS['WEBSOCKET_REQUEST_PREFIX'], request_key)
        )

        if int(request_data['user_id']) != user.id:
            logger.warning('Invalid user_id ({0}) w/valid websocket request: {1}'.format(user.id, request_key))
            return ws.send('INVALID_USER')

    # Looks like everything's OK, lets load the websocket in question
    module_name, websocket_name = request_data['websocket'].split('/')
    websocket_class = get_websocket(module_name, websocket_name)
    if websocket_class is None:
        logger.critical('Websocket class not found: {}'.format(websocket_class))
        return ws.send('INVALID_WEBSOCKET')

    # Start the websocket!
    websocket_class(request_data['websocket_data'], ws)

@@ -70,16 +70,29 @@
 andler%0A%0A
+import json%0A%0A
 from fla
@@ -749,18 +749,17 @@
 ig.REDIS
-%5B'
+_
 WEBSOCKE
@@ -764,24 +764,14 @@
 KET_
-REQUEST_
 PREFIX
-'%5D
 , re
@@ -792,16 +792,92 @@
      )%0A%0A
+        if not request_data:%0A            return ws.send('INVALID_REQUEST')%0A%0A
         
@@ -1009,16 +1009,33 @@
 .format(
+%0A                
 user.id,
@@ -1047,16 +1047,29 @@
 est_key)
+%0A            
 )%0A      
@@ -1501,30 +1501,32 @@
 et!%0A    
-websocket_clas
+data = json.load
 s(reques
@@ -1549,14 +1549,40 @@
 t_data'%5D
+)%0A    websocket_class(data
 , ws)%0A

Use correct config attributes, pre-json loads data