2018-01-24 14:10:59 +00:00
|
|
|
from tornado.ioloop import IOLoop
|
|
|
|
from tornado.web import Application
|
2018-03-02 17:01:00 +00:00
|
|
|
from terminado import TermSocket, SingleTermManager
|
2018-01-24 14:10:59 +00:00
|
|
|
|
2018-02-09 08:58:47 +00:00
|
|
|
from tfw.config import tfwenv
|
2018-01-31 14:50:52 +00:00
|
|
|
from tfw.config.logs import logging
|
2018-03-25 14:06:59 +00:00
|
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
2018-01-24 14:10:59 +00:00
|
|
|
|
|
|
|
|
2018-01-25 15:48:48 +00:00
|
|
|
class TerminadoMiniServer:
|
|
|
|
def __init__(self, url, port, workdir, shellcmd):
|
|
|
|
self.port = port
|
2018-03-06 13:28:36 +00:00
|
|
|
self._term_manager = SingleTermManager(shell_command=shellcmd,
|
|
|
|
term_settings={'cwd': workdir})
|
2018-01-25 15:48:48 +00:00
|
|
|
self.application = Application(
|
|
|
|
[(
|
|
|
|
url,
|
2018-03-06 15:15:04 +00:00
|
|
|
TerminadoMiniServer.ResetterTermSocket,
|
2018-03-06 13:28:36 +00:00
|
|
|
{'term_manager': self._term_manager}
|
2018-01-25 15:48:48 +00:00
|
|
|
)]
|
|
|
|
)
|
|
|
|
|
2018-03-06 13:28:36 +00:00
|
|
|
@property
|
|
|
|
def term_manager(self):
|
|
|
|
return self._term_manager
|
|
|
|
|
2018-03-02 16:05:01 +00:00
|
|
|
@property
|
|
|
|
def pty(self):
|
|
|
|
return self.term_manager.terminal.ptyproc
|
|
|
|
|
2018-03-06 15:15:04 +00:00
|
|
|
class ResetterTermSocket(TermSocket):
|
2018-01-25 15:48:48 +00:00
|
|
|
def check_origin(self, origin):
|
|
|
|
return True
|
|
|
|
|
2018-03-06 15:15:04 +00:00
|
|
|
def on_close(self):
|
|
|
|
self.term_manager.terminal = None
|
|
|
|
self.term_manager.get_terminal()
|
|
|
|
|
2018-01-25 15:48:48 +00:00
|
|
|
def listen(self):
|
|
|
|
self.application.listen(self.port)
|
|
|
|
|
2018-01-24 14:10:59 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2018-03-25 14:06:59 +00:00
|
|
|
LOG.info('Terminado Mini Server listening on {}'.format(tfwenv.TERMINADO_PORT))
|
2018-02-09 08:58:47 +00:00
|
|
|
TerminadoMiniServer('/terminal', tfwenv.TERMINADO_PORT, tfwenv.TERMINADO_WD, ['bash']).listen()
|
2018-03-03 13:47:55 +00:00
|
|
|
IOLoop.instance().start()
|