Skip to content

Commit 7110def

Browse files
committed
Added an option for specifying the default character encoding of your ssh servers
1 parent 7cf80e7 commit 7110def

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

webssh/handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,8 @@ def ssh_connect(self, args):
457457
chan = ssh.invoke_shell(term=term)
458458
chan.setblocking(0)
459459
worker = Worker(self.loop, ssh, chan, dst_addr)
460-
worker.encoding = self.get_default_encoding(ssh)
460+
worker.encoding = options.encoding if options.encoding else \
461+
self.get_default_encoding(ssh)
461462
return worker
462463

463464
def check_origin(self):

webssh/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from webssh.handler import IndexHandler, WsockHandler, NotFoundHandler
88
from webssh.settings import (
99
get_app_settings, get_host_keys_settings, get_policy_setting,
10-
get_ssl_context, get_server_settings
10+
get_ssl_context, get_server_settings, check_encoding_setting
1111
)
1212

1313

@@ -42,6 +42,7 @@ def app_listen(app, port, address, server_settings):
4242

4343
def main():
4444
options.parse_command_line()
45+
check_encoding_setting(options.encoding)
4546
loop = tornado.ioloop.IOLoop.current()
4647
app = make_app(make_handlers(loop, options), get_app_settings(options))
4748
ssl_ctx = get_ssl_context(options)

webssh/settings.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
from webssh.policy import (
88
load_host_keys, get_policy_class, check_policy_setting
99
)
10-
from webssh.utils import to_ip_address, parse_origin_from_url
10+
from webssh.utils import (
11+
to_ip_address, parse_origin_from_url, is_valid_encoding
12+
)
1113
from webssh._version import __version__
1214

1315

@@ -44,6 +46,8 @@ def print_version(flag):
4446
define('maxconn', type=int, default=20,
4547
help='Maximum live connections (ssh sessions) per client')
4648
define('font', default='', help='custom font filename')
49+
define('encoding', default='',
50+
help='The default character encoding of ssh servers')
4751
define('version', type=bool, help='Show version information',
4852
callback=print_version)
4953

@@ -184,3 +188,9 @@ def get_font_filename(font, font_dir):
184188
font = filenames.pop()
185189

186190
return font
191+
192+
193+
def check_encoding_setting(encoding):
194+
if encoding and not is_valid_encoding(encoding):
195+
raise ValueError('Unknown character encoding.')
196+
return encoding

0 commit comments

Comments
 (0)