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
a8935079
Commit
a8935079
authored
May 26, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made WsockHandler more robust
parent
2c36c386
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
4 deletions
+35
-4
sshserver.py
tests/sshserver.py
+2
-1
test_app.py
tests/test_app.py
+18
-0
handler.py
webssh/handler.py
+15
-3
No files found.
tests/sshserver.py
View file @
a8935079
...
...
@@ -114,7 +114,8 @@ def run_ssh_server(port=2200, running=True):
chan
.
send
(
'
\r\n\r\n
Welcome!
\r\n\r\n
'
)
if
username
==
'bar'
:
print
(
chan
.
recv
(
1024
))
msg
=
chan
.
recv
(
1024
)
chan
.
send
(
msg
)
chan
.
close
()
t
.
close
()
...
...
tests/test_app.py
View file @
a8935079
...
...
@@ -136,5 +136,23 @@ class TestApp(AsyncHTTPTestCase):
ws
=
yield
tornado
.
websocket
.
websocket_connect
(
ws_url
)
msg
=
yield
ws
.
read_message
()
self
.
assertIn
(
b
'Welcome!'
,
msg
)
# message will be ignored silently
yield
ws
.
write_message
(
'hello'
)
yield
ws
.
write_message
(
'"hello"'
)
yield
ws
.
write_message
(
'[hello]'
)
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
[]}))
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
{}}))
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
[
100
]}))
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
[
100
]
*
10
}))
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
[
-
1
,
-
1
]}))
yield
ws
.
write_message
(
json
.
dumps
({
'data'
:
[
1
]}))
yield
ws
.
write_message
(
json
.
dumps
({
'data'
:
(
1
,)}))
yield
ws
.
write_message
(
json
.
dumps
({
'data'
:
{
'a'
:
2
}}))
yield
ws
.
write_message
(
json
.
dumps
({
'data'
:
1
}))
yield
ws
.
write_message
(
json
.
dumps
({
'data'
:
2.1
}))
yield
ws
.
write_message
(
json
.
dumps
({
'key-non-existed'
:
'hello'
}))
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
[
79
,
23
],
'data'
:
'bye'
}))
msg
=
yield
ws
.
read_message
()
self
.
assertEqual
(
b
'bye'
,
msg
)
ws
.
close
()
webssh/handler.py
View file @
a8935079
...
...
@@ -2,6 +2,7 @@ import io
import
json
import
logging
import
socket
import
struct
import
threading
import
traceback
import
weakref
...
...
@@ -9,6 +10,7 @@ import paramiko
import
tornado.web
from
tornado.ioloop
import
IOLoop
from
tornado.util
import
basestring_type
from
webssh.worker
import
Worker
,
recycle_worker
,
workers
try
:
...
...
@@ -200,15 +202,25 @@ class WsockHandler(MixinHandler, tornado.websocket.WebSocketHandler):
def
on_message
(
self
,
message
):
logging
.
debug
(
'{!r} from {}:{}'
.
format
(
message
,
*
self
.
src_addr
))
worker
=
self
.
worker_ref
()
msg
=
json
.
loads
(
message
)
try
:
msg
=
json
.
loads
(
message
)
except
ValueError
:
# py2
return
except
json
.
decoder
.
JSONDecodeError
:
# py3
return
if
not
isinstance
(
msg
,
dict
):
return
resize
=
msg
.
get
(
'resize'
)
if
resize
:
try
:
worker
.
chan
.
resize_pty
(
*
resize
)
except
paramiko
.
SSHException
:
except
(
TypeError
,
struct
.
error
,
paramiko
.
SSHException
)
:
pass
data
=
msg
.
get
(
'data'
)
if
data
:
if
data
and
isinstance
(
data
,
basestring_type
)
:
worker
.
data_to_dst
.
append
(
data
)
worker
.
on_write
()
...
...
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