Spaces:
Paused
Paused
| import tornado.ioloop | |
| import tornado.web | |
| import paramiko | |
| from webssh.handler import IndexHandler, WsockHandler | |
| from tornado.options import define, options | |
| # Define application options | |
| define('address', default='0.0.0.0', help='Bind address') | |
| define('port', default=7860, help='Port to listen on') | |
| define('xsrf', default=False, help='Enable XSRF protection') | |
| define('debug', default=True, help='Enable debug mode') | |
| define('maxconn', default=4, help='Maximum number of connections') | |
| define('policy', default='autoadd', help='SSH host key policy') | |
| define('sslport', default=443, help='SSL port for redirect') | |
| define('timeout', default=30, help='SSH connection timeout') | |
| define('encoding', default='utf-8', help='Default encoding') | |
| define('delay', default=10, help='Delay before recycling worker') | |
| define('xheaders', default=False, help='Support X-Real-Ip and X-Forwarded-For headers') | |
| define('fbidhttp', default=False, help='Forbid public plain HTTP requests') | |
| # New handler for your custom page | |
| class MyPageHandler(tornado.web.RequestHandler): | |
| def get(self): | |
| self.render('mypage.html') # Render the new page template | |
| def make_app(): | |
| loop = tornado.ioloop.IOLoop.current() | |
| # Set SSH host key policy | |
| policy = paramiko.AutoAddPolicy() if options.policy == 'autoadd' else paramiko.RejectPolicy() | |
| # Define host keys settings | |
| host_keys_settings = { | |
| 'system_host_keys': paramiko.util.load_host_keys('/app/ssh/ssh_known_hosts'), | |
| 'host_keys': paramiko.HostKeys(), | |
| 'host_keys_filename': None | |
| } | |
| # Create Tornado application | |
| return tornado.web.Application( | |
| [ | |
| (r'/', IndexHandler, dict(loop=loop, policy=policy, host_keys_settings=host_keys_settings)), | |
| (r'/ws', WsockHandler, dict(loop=loop)), | |
| (r'/mypage', MyPageHandler), # Route for your new page | |
| ], | |
| xsrf_cookies=options.xsrf, | |
| debug=options.debug, | |
| template_path='/app/WebSSH/templates', # Correct template directory | |
| ) | |
| if __name__ == '__main__': | |
| # Parse command-line options | |
| tornado.options.parse_command_line() | |
| # Create and start the application | |
| app = make_app() | |
| app.listen(options.port, address=options.address) | |
| print(f"WebSSH server running on {options.address}:{options.port}") | |
| tornado.ioloop.IOLoop.current().start() | |