2018-01-24 14:10:59 +00:00
|
|
|
from tornado.ioloop import IOLoop
|
|
|
|
from tornado.web import Application
|
2018-01-25 15:48:48 +00:00
|
|
|
from terminado import TermSocket, UniqueTermManager
|
2018-01-24 14:10:59 +00:00
|
|
|
|
2018-01-24 15:26:01 +00:00
|
|
|
from config import TERMINADO_PORT, TERMINADO_WD
|
2018-01-29 17:36:29 +00:00
|
|
|
from config.logs import logging
|
|
|
|
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
|
|
|
|
self.application = Application(
|
|
|
|
[(
|
|
|
|
url,
|
|
|
|
TerminadoMiniServer.CORSTermSocket,
|
|
|
|
{'term_manager': UniqueTermManager(shell_command=shellcmd,
|
|
|
|
term_settings={'cwd': workdir})}
|
|
|
|
)]
|
|
|
|
)
|
|
|
|
|
|
|
|
class CORSTermSocket(TermSocket):
|
|
|
|
def check_origin(self, origin):
|
|
|
|
return True
|
|
|
|
|
|
|
|
def listen(self):
|
|
|
|
self.application.listen(self.port)
|
|
|
|
IOLoop.instance().start()
|
|
|
|
|
2018-01-24 14:10:59 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2018-01-29 17:36:29 +00:00
|
|
|
log.info('Terminado Mini Server listening on {}'.format(TERMINADO_PORT))
|
2018-01-25 15:48:48 +00:00
|
|
|
TerminadoMiniServer('/terminal', TERMINADO_PORT, TERMINADO_WD, ['bash']).listen()
|