代码拉取完成,页面将自动刷新
同步操作将从 Jack/openssh 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
__author__ = 'JackSong'
import logging
import tornado.websocket
from daemon import Bridge
from utils.data import ClientData
from utils.tools import check_ip, check_port
from concurrent.futures import ThreadPoolExecutor
from tornado.gen import coroutine
from utils.tools import PrpcryptInitData
class IndexHandler(tornado.web.RequestHandler):
def get(self):
self.render("index.html")
class WSHandler(tornado.websocket.WebSocketHandler):
executor = ThreadPoolExecutor(4)
clients = dict()
COMMAND = str()
def get_client(self):
return self.clients.get(self._id(), None)
def put_client(self):
bridge = Bridge(self)
self.clients[self._id()] = bridge
def remove_client(self):
bridge = self.get_client()
if bridge:
client = self.clients.pop(self._id(), None)
if client: del client
@staticmethod
def _check_init_param(data):
data = PrpcryptInitData(**data)
return check_ip(data.hostname) and check_port(data.port)
@staticmethod
def _is_init_data(data):
return data.get_type() == 'init'
def _id(self):
return id(self)
def open(self):
self.put_client()
@coroutine
def on_message(self, message):
bridge = self.get_client()
client_data = ClientData(message)
if self._is_init_data(client_data):
if self._check_init_param(client_data.data):
try:
yield self.executor.submit(bridge.open, *(client_data.data,))
logging.info('connection established from: %s' % self._id())
except Exception as e:
self.close()
logging.error('%s' % e.message)
else:
self.remove_client()
logging.info('init param invalid: %s' % client_data.data)
else:
if bridge.status:
command = client_data.data
rest = yield self.executor.submit(bridge.trans_forward, *(command,))
if not rest:
bridge.destroy()
self.close()
def on_close(self):
self.remove_client()
logging.info('client close the connection: %s' % self._id())
def check_origin(self, origin):
return True
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。