Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
webssh
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
郑天保
webssh
Commits
688ca78b
Commit
688ca78b
authored
Aug 28, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use command "locale charmap" to detect encoding
parent
80bdddc2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
34 deletions
+7
-34
sshserver.py
tests/sshserver.py
+4
-6
test_handler.py
tests/test_handler.py
+1
-18
handler.py
webssh/handler.py
+2
-10
No files found.
tests/sshserver.py
View file @
688ca78b
...
@@ -51,13 +51,12 @@ class Server(paramiko.ServerInterface):
...
@@ -51,13 +51,12 @@ class Server(paramiko.ServerInterface):
b
'UWT10hcuO4Ks8='
)
b
'UWT10hcuO4Ks8='
)
good_pub_key
=
paramiko
.
RSAKey
(
data
=
decodebytes
(
data
))
good_pub_key
=
paramiko
.
RSAKey
(
data
=
decodebytes
(
data
))
langs
=
[
'en_US.UTF-8'
,
'zh_CN.
GBK'
]
encodings
=
[
'UTF-8'
,
'
GBK'
]
def
__init__
(
self
):
def
__init__
(
self
):
self
.
shell_event
=
threading
.
Event
()
self
.
shell_event
=
threading
.
Event
()
self
.
exec_event
=
threading
.
Event
()
self
.
exec_event
=
threading
.
Event
()
self
.
lang
=
random
.
choice
(
self
.
langs
)
self
.
encoding
=
random
.
choice
(
self
.
encodings
)
self
.
encoding
=
self
.
lang
.
split
(
'.'
)[
-
1
]
def
check_channel_request
(
self
,
kind
,
chanid
):
def
check_channel_request
(
self
,
kind
,
chanid
):
if
kind
==
'session'
:
if
kind
==
'session'
:
...
@@ -82,12 +81,11 @@ class Server(paramiko.ServerInterface):
...
@@ -82,12 +81,11 @@ class Server(paramiko.ServerInterface):
return
'password,publickey'
return
'password,publickey'
def
check_channel_exec_request
(
self
,
channel
,
command
):
def
check_channel_exec_request
(
self
,
channel
,
command
):
if
command
!=
b
'locale'
:
if
command
!=
b
'locale
charmap
'
:
ret
=
False
ret
=
False
else
:
else
:
ret
=
True
ret
=
True
result
=
'LANG={lang}
\n
LANGUAGE=
\n
LC_CTYPE="{lang}"
\n
'
.
format
(
lang
=
self
.
lang
)
# noqa
channel
.
send
(
self
.
encoding
)
channel
.
send
(
result
)
channel
.
shutdown
(
1
)
channel
.
shutdown
(
1
)
self
.
exec_event
.
set
()
self
.
exec_event
.
set
()
return
ret
return
ret
...
...
tests/test_handler.py
View file @
688ca78b
...
@@ -3,24 +3,7 @@ import paramiko
...
@@ -3,24 +3,7 @@ import paramiko
from
tornado.httputil
import
HTTPServerRequest
from
tornado.httputil
import
HTTPServerRequest
from
tests.utils
import
read_file
,
make_tests_data_path
from
tests.utils
import
read_file
,
make_tests_data_path
from
webssh.handler
import
(
from
webssh.handler
import
MixinHandler
,
IndexHandler
,
InvalidValueError
MixinHandler
,
IndexHandler
,
parse_encoding
,
InvalidValueError
)
class
TestHandler
(
unittest
.
TestCase
):
def
test_parse_encoding
(
self
):
data
=
''
self
.
assertIsNone
(
parse_encoding
(
data
))
data
=
'UTF-8'
self
.
assertEqual
(
parse_encoding
(
data
),
'UTF-8'
)
data
=
'en_US.UTF-8'
self
.
assertEqual
(
parse_encoding
(
data
),
'UTF-8'
)
data
=
'LANG=en_US.UTF-8
\n
LANGUAGE=
\n
LC_CTYPE="en_US.UTF-8"
\n
'
self
.
assertEqual
(
parse_encoding
(
data
),
'UTF-8'
)
data
=
'LANGUAGE=
\n
LC_CTYPE="en_US.UTF-8"
\n
'
self
.
assertEqual
(
parse_encoding
(
data
),
'UTF-8'
)
class
TestMixinHandler
(
unittest
.
TestCase
):
class
TestMixinHandler
(
unittest
.
TestCase
):
...
...
webssh/handler.py
View file @
688ca78b
...
@@ -32,13 +32,6 @@ DELAY = 3
...
@@ -32,13 +32,6 @@ DELAY = 3
KEY_MAX_SIZE
=
16384
KEY_MAX_SIZE
=
16384
def
parse_encoding
(
data
):
for
line
in
data
.
split
(
'
\n
'
):
s
=
line
.
split
(
'='
)[
-
1
]
if
s
:
return
s
.
strip
(
'"'
)
.
split
(
'.'
)[
-
1
]
class
InvalidValueError
(
Exception
):
class
InvalidValueError
(
Exception
):
pass
pass
...
@@ -176,12 +169,11 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
...
@@ -176,12 +169,11 @@ class IndexHandler(MixinHandler, tornado.web.RequestHandler):
def
get_default_encoding
(
self
,
ssh
):
def
get_default_encoding
(
self
,
ssh
):
try
:
try
:
_
,
stdout
,
_
=
ssh
.
exec_command
(
'locale'
)
_
,
stdout
,
_
=
ssh
.
exec_command
(
'locale
charmap
'
)
except
paramiko
.
SSHException
:
except
paramiko
.
SSHException
:
result
=
None
result
=
None
else
:
else
:
data
=
stdout
.
read
()
result
=
to_str
(
stdout
.
read
())
result
=
parse_encoding
(
to_str
(
data
))
return
result
if
result
else
'utf-8'
return
result
if
result
else
'utf-8'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment