c013a389fe
- Added is_valid_directory function to validate directory paths, ensuring they do not contain control characters and are within a specified length. - Introduced quote_shell_arg to safely quote shell arguments, preventing command injection. - Created build_cd_command to generate a command for changing directories in a shell. - Enhanced the LoginHandler to utilize a login rate limiter, preventing brute-force attacks by tracking failed login attempts. - Implemented an EncodingCache to optimize encoding detection for SSH connections. - Updated the UI to include an input field for specifying an initial directory upon login, with appropriate validation and hints. - Added a quickbar in the terminal interface for easy access to copy and paste functionality. - Introduced a toast notification system to provide feedback on copy actions. - Refactored connection storage to encrypt passwords at rest, improving security. - Updated various templates and styles to accommodate new features and improve user experience.
82 lines
2.6 KiB
Python
82 lines
2.6 KiB
Python
import logging
|
|
import tornado.web
|
|
import tornado.ioloop
|
|
|
|
from tornado.options import options
|
|
from webssh import handler
|
|
from webssh.handler import (
|
|
ConnectionHandler, ConnectionsHandler, IndexHandler, LoginHandler,
|
|
LogoutHandler, WsockHandler, NotFoundHandler
|
|
)
|
|
from webssh.settings import (
|
|
get_app_settings, get_host_keys_settings, get_policy_setting,
|
|
get_ssl_context, get_server_settings, check_encoding_setting
|
|
)
|
|
|
|
|
|
def make_handlers(loop, options):
|
|
host_keys_settings = get_host_keys_settings(options)
|
|
policy = get_policy_setting(options, host_keys_settings)
|
|
|
|
handlers = [
|
|
(r'/login', LoginHandler),
|
|
(r'/logout', LogoutHandler),
|
|
(r'/connections', ConnectionsHandler),
|
|
(r'/connections/([a-f0-9]{24})', ConnectionHandler),
|
|
(r'/', IndexHandler, dict(loop=loop, policy=policy,
|
|
host_keys_settings=host_keys_settings)),
|
|
(r'/ws', WsockHandler, dict(loop=loop))
|
|
]
|
|
return handlers
|
|
|
|
|
|
def make_app(handlers, settings):
|
|
settings.update(default_handler_class=NotFoundHandler)
|
|
return tornado.web.Application(handlers, **settings)
|
|
|
|
|
|
def app_listen(app, port, address, server_settings):
|
|
app.listen(port, address, **server_settings)
|
|
if not server_settings.get('ssl_options'):
|
|
server_type = 'http'
|
|
else:
|
|
server_type = 'https'
|
|
handler.redirecting = True if options.redirect else False
|
|
logging.info(
|
|
'Listening on {}:{} ({})'.format(address, port, server_type)
|
|
)
|
|
|
|
|
|
def check_trusted_downstream(options, server_settings):
|
|
if not options.xheaders:
|
|
return
|
|
|
|
if server_settings.get('trusted_downstream'):
|
|
return
|
|
|
|
logging.warning(
|
|
'xheaders is enabled without --tdstream, so any client can spoof '
|
|
'X-Forwarded-For and impersonate another address. Set '
|
|
'--tdstream=<proxy ip> when running behind a reverse proxy, or '
|
|
'--xheaders=False when clients connect directly.'
|
|
)
|
|
|
|
|
|
def main():
|
|
options.parse_command_line()
|
|
check_encoding_setting(options.encoding)
|
|
loop = tornado.ioloop.IOLoop.current()
|
|
app = make_app(make_handlers(loop, options), get_app_settings(options))
|
|
ssl_ctx = get_ssl_context(options)
|
|
server_settings = get_server_settings(options)
|
|
check_trusted_downstream(options, server_settings)
|
|
app_listen(app, options.port, options.address, server_settings)
|
|
if ssl_ctx:
|
|
server_settings.update(ssl_options=ssl_ctx)
|
|
app_listen(app, options.sslport, options.ssladdress, server_settings)
|
|
loop.start()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|