Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
L
luna
Project
Project
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
ops
luna
Commits
293c5cea
Commit
293c5cea
authored
Dec 18, 2017
by
liuzheng712
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(update):
parent
7dff699a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
22 deletions
+40
-22
mock.py
mock.py
+40
-22
No files found.
mock.py
View file @
293c5cea
...
...
@@ -9,46 +9,64 @@ app = Flask(__name__, template_folder='dist')
class
SSHws
(
Namespace
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
clients
=
dict
()
super
()
.
__init__
(
*
args
,
**
kwargs
)
def
ssh_with_password
(
self
):
self
.
ssh
=
paramiko
.
SSHClient
()
self
.
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
self
.
ssh
.
connect
(
"127.0.0.1"
,
22
,
"liuzheng"
,
"liuzheng"
)
self
.
chan
=
self
.
ssh
.
invoke_shell
(
term
=
'xterm'
,
width
=
self
.
cols
,
height
=
self
.
rows
)
self
.
socketio
.
start_background_task
(
self
.
send_data
)
ssh
=
paramiko
.
SSHClient
()
ssh
.
set_missing_host_key_policy
(
paramiko
.
AutoAddPolicy
())
ssh
.
connect
(
"127.0.0.1"
,
22
,
"liuzheng"
,
"liuzheng"
)
self
.
clients
[
request
.
sid
][
"chan"
]
=
ssh
.
invoke_shell
(
term
=
'xterm'
,
width
=
self
.
clients
[
request
.
sid
][
"cols"
],
height
=
self
.
clients
[
request
.
sid
][
"rows"
])
# self.socketio.start_background_task(self.send_data, self.clients[request.sid]["chan"])
# self.chan.settimeout(0.1)
def
send_data
(
self
):
def
send_data
(
self
,
s
):
while
True
:
data
=
self
.
chan
.
recv
(
2048
)
.
decode
(
'utf-8'
,
'replace'
)
self
.
emit
(
event
=
'data'
,
data
=
data
,
room
=
self
.
room
)
for
sid
in
self
.
clients
:
try
:
if
self
.
clients
[
sid
][
"chan"
]:
data
=
self
.
clients
[
sid
][
"chan"
]
.
recv
(
2048
)
.
decode
(
'utf-8'
,
'replace'
)
s
.
emit
(
event
=
'data'
,
data
=
data
,
room
=
self
.
clients
[
sid
][
"room"
])
except
RuntimeError
:
print
(
data
)
print
(
self
.
clients
)
def
on_connect
(
self
):
self
.
cols
=
int
(
request
.
cookies
.
get
(
'cols'
,
80
))
self
.
rows
=
int
(
request
.
cookies
.
get
(
'rows'
,
24
))
print
(
request
.
sid
)
self
.
clients
[
request
.
sid
]
=
{
"cols"
:
int
(
request
.
cookies
.
get
(
'cols'
,
80
)),
"rows"
:
int
(
request
.
cookies
.
get
(
'rows'
,
24
)),
"room"
:
str
(
uuid
.
uuid4
()),
"chan"
:
None
}
print
(
self
.
clients
[
request
.
sid
][
"room"
])
join_room
(
self
.
clients
[
request
.
sid
][
"room"
])
self
.
socketio
.
start_background_task
(
self
.
send_data
,
self
)
def
on_data
(
self
,
message
):
self
.
c
han
.
send
(
message
)
self
.
c
lients
[
request
.
sid
][
"chan"
]
.
send
(
message
)
def
on_host
(
self
,
message
):
self
.
room
=
str
(
uuid
.
uuid4
())
self
.
emit
(
'room'
,
self
.
room
)
join_room
(
self
.
room
)
# self.clients[request.sid]["room"]
= str(uuid.uuid4())
# self.emit('room', self.clients[request.sid]["chan"]["room"]
)
# join_room(self.clients[request.sid]["room"]
)
self
.
ssh_with_password
()
print
(
message
,
self
.
room
)
print
(
message
,
self
.
clients
[
request
.
sid
][
"room"
]
)
def
on_resize
(
self
,
message
):
print
(
message
)
self
.
cols
=
message
.
get
(
'cols'
,
80
)
self
.
rows
=
message
.
get
(
'rows'
,
24
)
self
.
chan
.
resize_pty
(
width
=
self
.
cols
,
height
=
self
.
rows
,
width_pixels
=
1
,
height_pixels
=
1
)
self
.
clients
[
request
.
sid
][
"cols"
]
=
message
.
get
(
'cols'
,
80
)
self
.
clients
[
request
.
sid
][
"rows"
]
=
message
.
get
(
'rows'
,
24
)
self
.
clients
[
request
.
sid
][
"chan"
]
.
resize_pty
(
width
=
self
.
clients
[
request
.
sid
][
"rows"
],
height
=
self
.
clients
[
request
.
sid
][
"rows"
],
width_pixels
=
1
,
height_pixels
=
1
)
def
on_disconnect
(
self
):
print
(
"disconnect"
)
pass
def
on_join
(
self
,
room
):
join_room
(
room
)
self
.
room
=
room
def
on_leave
(
self
):
leave_room
(
self
.
room
)
...
...
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