Commit 2cccea40 authored by ibuler's avatar ibuler

Add websocket server

parent 9d650ca0
...@@ -6,6 +6,7 @@ import logging ...@@ -6,6 +6,7 @@ import logging
from .config import Config from .config import Config
from .sshd import SSHServer from .sshd import SSHServer
from .ws import WSServer
from .logging import create_logger from .logging import create_logger
...@@ -59,7 +60,7 @@ class Coco: ...@@ -59,7 +60,7 @@ class Coco:
def prepare(self): def prepare(self):
self.sshd = SSHServer(self) self.sshd = SSHServer(self)
pass self.ws = WSServer(self)
def heartbeat(self): def heartbeat(self):
pass pass
...@@ -68,10 +69,6 @@ class Coco: ...@@ -68,10 +69,6 @@ class Coco:
self.prepare() self.prepare()
print(time.ctime()) print(time.ctime())
print('Coco version %s, more see https://www.jumpserver.org' % __version__) print('Coco version %s, more see https://www.jumpserver.org' % __version__)
# Todo: move to websocket server
print('Starting websocket server at %(host)s:%(port)s' % {
'host': self.config['BIND_HOST'], 'port': self.config['WS_PORT']})
print('Quit the server with CONTROL-C.') print('Quit the server with CONTROL-C.')
exit_queue = Queue() exit_queue = Queue()
...@@ -94,7 +91,9 @@ class Coco: ...@@ -94,7 +91,9 @@ class Coco:
thread.start() thread.start()
def run_ws(self): def run_ws(self):
pass thread = threading.Thread(target=self.ws.run, args=())
thread.daemon = True
thread.start()
def shutdown(self): def shutdown(self):
for client in self.clients: for client in self.clients:
......
# coding: utf-8
import tornado.web
import tornado.websocket
import tornado.httpclient
import tornado.ioloop
class MainHandler(tornado.web.RequestHandler):
def get(self, *args, **kwargs):
self.write("Hello world")
class InteractiveHandler(tornado.websocket.WebSocketHandler):
pass
class ProxyHandler(tornado.websocket.WebSocketHandler):
pass
class MonitorHandler(tornado.websocket.WebSocketHandler):
pass
class WSServer:
routers = [
(r'^/$', MainHandler),
(r'/ws/interactive/', MainHandler),
(r'/ws/proxy/(?P<asset_id>[0-9]+)/(?P<system_user_id>[0-9]+)/', MainHandler),
(r'/ws/session/(?P<session_id>[0-9]+)/monitor/', MainHandler),
(r'/ws/session/(?P<session+id>[0-9]+)/join/', MainHandler),
]
def __init__(self, app):
self.app = app
def run(self):
host = self.app.config["BIND_HOST"]
port = self.app.config["WS_PORT"]
print('Starting websocket server at %(host)s:%(port)s' %
{"host": host, "port": port})
ws = tornado.web.Application(self.routers)
ws.listen(port=port, address=host)
tornado.ioloop.IOLoop.current().start()
paramiko>=2.1.2
python-gssapi>=0.6.4
requests>=2.11.1
pyte>=0.5.2
tornado>=4.5.2
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment